tokenary/Encrypted Ink/Screens/ImportViewController.swift

49 lines
1.4 KiB
Swift
Raw Normal View History

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
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) {
if accountsService.addAccount(input: textField.stringValue) != nil {
2021-06-13 06:30:20 +03:00
showAccountsList()
} else {
// TODO: show error message
2021-06-12 20:37:56 +03:00
}
2021-06-12 19:33:24 +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
}
@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) {
okButton.isEnabled = accountsService.validateAccountInput(textField.stringValue)
2021-06-13 02:24:02 +03:00
}
}