2021-06-12 13:48:29 +03:00
|
|
|
// Copyright © 2021 Encrypted Ink. All rights reserved.
|
2021-06-12 13:32:27 +03:00
|
|
|
|
|
|
|
import Cocoa
|
|
|
|
|
2021-06-13 02:12:03 +03:00
|
|
|
class ImportViewController: NSViewController {
|
2021-06-12 17:39:42 +03:00
|
|
|
|
2021-07-17 20:20:51 +03:00
|
|
|
private let accountsService = AccountsService.shared
|
2021-06-13 06:30:20 +03:00
|
|
|
var onSelectedAccount: ((Account) -> Void)?
|
|
|
|
|
2021-06-13 02:24:02 +03:00
|
|
|
@IBOutlet weak var textField: NSTextField! {
|
|
|
|
didSet {
|
|
|
|
textField.delegate = self
|
2021-07-15 01:12:20 +03:00
|
|
|
textField.placeholderString = "Options:\n\n• Ethereum Private Key\n• Secret Words\n• Keystore"
|
2021-06-13 02:24:02 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
@IBOutlet weak var okButton: NSButton!
|
2021-06-12 17:39:42 +03:00
|
|
|
|
2021-06-12 13:32:27 +03:00
|
|
|
override func viewDidLoad() {
|
|
|
|
super.viewDidLoad()
|
|
|
|
}
|
|
|
|
|
2021-06-12 19:33:24 +03:00
|
|
|
@IBAction func actionButtonTapped(_ sender: Any) {
|
2021-07-17 20:20:51 +03:00
|
|
|
let account = accountsService.addAccount(input: textField.stringValue)
|
|
|
|
if let account = account, accountsService.getAccounts().count == 1, let onSelectedAccount = onSelectedAccount {
|
2021-06-13 06:30:20 +03:00
|
|
|
onSelectedAccount(account)
|
|
|
|
} else {
|
|
|
|
showAccountsList()
|
2021-06-12 20:37:56 +03:00
|
|
|
}
|
2021-06-12 19:33:24 +03:00
|
|
|
}
|
2021-06-13 04:05:42 +03:00
|
|
|
|
|
|
|
private func showAccountsList() {
|
2021-06-13 05:45:54 +03:00
|
|
|
let accountsListViewController = instantiate(AccountsListViewController.self)
|
2021-06-13 06:30:20 +03:00
|
|
|
accountsListViewController.onSelectedAccount = onSelectedAccount
|
2021-06-13 05:45:54 +03:00
|
|
|
view.window?.contentViewController = accountsListViewController
|
2021-06-13 04:05:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@IBAction func cancelButtonTapped(_ sender: NSButton) {
|
|
|
|
showAccountsList()
|
|
|
|
}
|
2021-06-12 19:33:24 +03:00
|
|
|
|
2021-06-12 13:32:27 +03:00
|
|
|
}
|
2021-06-13 02:24:02 +03:00
|
|
|
|
|
|
|
extension ImportViewController: NSTextFieldDelegate {
|
|
|
|
|
|
|
|
func controlTextDidChange(_ obj: Notification) {
|
2021-07-17 20:20:51 +03:00
|
|
|
okButton.isEnabled = accountsService.validateAccountInput(textField.stringValue)
|
2021-06-13 02:24:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|