2021-06-28 14:46:53 +03:00
|
|
|
// Copyright © 2021 Encrypted Ink. All rights reserved.
|
|
|
|
|
|
|
|
import Cocoa
|
|
|
|
|
|
|
|
class ApproveTransactionViewController: NSViewController {
|
|
|
|
|
|
|
|
@IBOutlet weak var titleLabel: NSTextField!
|
|
|
|
@IBOutlet var metaTextView: NSTextView!
|
|
|
|
@IBOutlet weak var okButton: NSButton!
|
|
|
|
@IBOutlet weak var speedSlider: NSSlider!
|
|
|
|
@IBOutlet weak var slowSpeedLabel: NSTextField!
|
|
|
|
@IBOutlet weak var fastSpeedLabel: NSTextField!
|
|
|
|
|
2021-06-28 16:25:56 +03:00
|
|
|
private let gasService = GasService.shared
|
2021-06-28 16:15:53 +03:00
|
|
|
private var transaction: Transaction!
|
|
|
|
private var completion: ((Transaction?) -> Void)!
|
2021-06-28 14:46:53 +03:00
|
|
|
|
2021-06-28 16:15:53 +03:00
|
|
|
static func with(transaction: Transaction, completion: @escaping (Transaction?) -> Void) -> ApproveTransactionViewController {
|
2021-06-28 14:46:53 +03:00
|
|
|
let new = instantiate(ApproveTransactionViewController.self)
|
2021-06-28 16:15:53 +03:00
|
|
|
new.transaction = transaction
|
2021-06-28 14:46:53 +03:00
|
|
|
new.completion = completion
|
|
|
|
return new
|
|
|
|
}
|
|
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
2021-06-28 16:15:53 +03:00
|
|
|
titleLabel.stringValue = Strings.sendTransaction
|
|
|
|
updateInterface()
|
|
|
|
prepareTransaction()
|
|
|
|
}
|
|
|
|
|
|
|
|
private func prepareTransaction() {
|
|
|
|
Ethereum.prepareTransaction(transaction) { [weak self] updated in
|
|
|
|
self?.transaction = updated
|
|
|
|
self?.updateInterface()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func updateInterface() {
|
|
|
|
let meta = transaction.meta
|
|
|
|
if metaTextView.string != meta {
|
|
|
|
metaTextView.string = meta
|
|
|
|
}
|
2021-06-28 16:25:56 +03:00
|
|
|
let info = gasService.currentInfo
|
|
|
|
enableSpeedConfiguration(transaction.hasFee && info != nil)
|
2021-06-28 14:46:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private func enableSpeedConfiguration(_ enable: Bool) {
|
|
|
|
slowSpeedLabel.alphaValue = enable ? 1 : 0.5
|
|
|
|
fastSpeedLabel.alphaValue = enable ? 1 : 0.5
|
|
|
|
speedSlider.isEnabled = enable
|
|
|
|
}
|
|
|
|
|
|
|
|
@IBAction func sliderValueChanged(_ sender: NSSlider) {
|
|
|
|
print(sender.intValue)
|
|
|
|
}
|
|
|
|
|
|
|
|
@IBAction func actionButtonTapped(_ sender: Any) {
|
2021-06-28 16:15:53 +03:00
|
|
|
completion(transaction)
|
2021-06-28 14:46:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@IBAction func cancelButtonTapped(_ sender: NSButton) {
|
2021-06-28 16:15:53 +03:00
|
|
|
completion(nil)
|
2021-06-28 14:46:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|