tokenary/Encrypted Ink/Screens/ImportViewController.swift
2021-06-28 16:46:17 +03:00

48 lines
1.3 KiB
Swift

// Copyright © 2021 Encrypted Ink. All rights reserved.
import Cocoa
class ImportViewController: NSViewController {
var onSelectedAccount: ((Account) -> Void)?
@IBOutlet weak var textField: NSTextField! {
didSet {
textField.delegate = self
}
}
@IBOutlet weak var okButton: NSButton!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func actionButtonTapped(_ sender: Any) {
let account = AccountsService.addAccount(privateKey: textField.stringValue)
if let account = account, AccountsService.getAccounts().count == 1, let onSelectedAccount = onSelectedAccount {
onSelectedAccount(account)
} else {
showAccountsList()
}
}
private func showAccountsList() {
let accountsListViewController = instantiate(AccountsListViewController.self)
accountsListViewController.onSelectedAccount = onSelectedAccount
view.window?.contentViewController = accountsListViewController
}
@IBAction func cancelButtonTapped(_ sender: NSButton) {
showAccountsList()
}
}
extension ImportViewController: NSTextFieldDelegate {
func controlTextDidChange(_ obj: Notification) {
okButton.isEnabled = AccountsService.validateAccountKey(textField.stringValue)
}
}