Validate private key on import screen

This commit is contained in:
Ivan Grachyov 2021-06-13 02:24:02 +03:00
parent bacf09b4b2
commit 6c2f69b800
3 changed files with 25 additions and 1 deletions

View File

@ -7,6 +7,11 @@ struct AccountsService {
private static let keychainKey = "EncryptedInkStorage"
static func validateAccountKey(_ key: String) -> Bool {
let address = try? EthPrivateKey(hex: key).address().value()
return address != nil
}
static func addAccount(privateKey: String) -> Account? {
guard
let addressBytes = try? EthPrivateKey(hex: privateKey).address().value()

View File

@ -753,6 +753,10 @@ DQ
<constraint firstItem="YPY-7C-6mv" firstAttribute="top" secondItem="feM-MO-Msf" secondAttribute="bottom" constant="30" id="wQT-nA-szt"/>
</constraints>
</view>
<connections>
<outlet property="okButton" destination="t6z-sy-JB9" id="qrY-Ga-zC6"/>
<outlet property="textField" destination="YPY-7C-6mv" id="8L3-RD-eXJ"/>
</connections>
</viewController>
<customObject id="rPt-NT-nkU" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>

View File

@ -4,13 +4,20 @@ import Cocoa
class ImportViewController: NSViewController {
@IBOutlet weak var label: NSTextField!
@IBOutlet weak var textField: NSTextField! {
didSet {
textField.delegate = self
}
}
@IBOutlet weak var okButton: NSButton!
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func actionButtonTapped(_ sender: Any) {
// TODO: open accounts list
WalletConnect.shared.connect(link: globalLink, address: "0xCf60CC6E4AD79187E7eBF62e0c21ae3a343180B2") { connected in
// TODO: close here
// use connected value
@ -22,3 +29,11 @@ class ImportViewController: NSViewController {
}
}
extension ImportViewController: NSTextFieldDelegate {
func controlTextDidChange(_ obj: Notification) {
okButton.isEnabled = AccountsService.validateAccountKey(textField.stringValue)
}
}