@@ -10,32 +10,32 @@ import web3swift
10
10
import Web3Core
11
11
12
12
class AuthViewController : UIViewController {
13
-
13
+
14
14
@IBOutlet weak var continueButton : UIButton !
15
15
@IBOutlet weak var walletAddressLabel : UILabel !
16
16
@IBOutlet weak var importWalletButton : UIButton !
17
17
@IBOutlet weak var createWalletButton : UIButton !
18
-
18
+
19
19
var walletAddress : String ? {
20
20
didSet {
21
21
self . walletAddressLabel. text = walletAddress
22
22
}
23
23
}
24
-
24
+
25
25
override func viewDidLoad( ) {
26
26
super. viewDidLoad ( )
27
27
self . createWalletButton. layer. cornerRadius = 5.0
28
28
self . importWalletButton. layer. cornerRadius = 5.0
29
29
}
30
-
30
+
31
31
@IBAction func onClickCreateWallet( _ sender: UIButton ) {
32
32
self . createMnemonics ( )
33
-
33
+
34
34
}
35
35
@IBAction func onClickImportWalletButton( _ sender: UIButton ) {
36
36
self . showImportAlert ( )
37
37
}
38
-
38
+
39
39
@IBAction func onClickContinueButton( _ sender: UIButton ) {
40
40
}
41
41
}
@@ -61,14 +61,14 @@ extension AuthViewController {
61
61
alert. addAction ( cancelAction)
62
62
self . present ( alert, animated: true , completion: nil )
63
63
}
64
-
64
+
65
65
fileprivate func createMnemonics( ) {
66
66
guard let mnemonics = try ? BIP39 . generateMnemonics ( bitsOfEntropy: 256 , language: . english) else {
67
67
self . showAlertMessage ( title: " " , message: " We are unable to create wallet " , actionName: " Ok " )
68
68
return
69
69
}
70
70
print ( mnemonics)
71
-
71
+
72
72
guard let keystore = try ? BIP32Keystore ( mnemonics: mnemonics, password: WalletManager . keystorePassword) ,
73
73
let walletAddress = keystore. addresses? . first else {
74
74
self . showAlertMessage ( title: " " , message: " Unable to create wallet " , actionName: " Ok " )
@@ -78,13 +78,13 @@ extension AuthViewController {
78
78
let privateKey = try ! keystore. UNSAFE_getPrivateKeyData ( password: WalletManager . keystorePassword,
79
79
account: walletAddress)
80
80
print ( privateKey)
81
-
81
+
82
82
Task {
83
83
let walletManager = await WalletManager ( keystoreManager: KeystoreManager ( [ keystore] ) )
84
84
openWallet ( walletManager: walletManager)
85
85
}
86
86
}
87
-
87
+
88
88
func importWalletWith( privateKey: String ) {
89
89
let formattedKey = privateKey. trimmingCharacters ( in: . whitespacesAndNewlines)
90
90
guard let dataKey = Data . fromHex ( formattedKey) else {
@@ -94,7 +94,7 @@ extension AuthViewController {
94
94
do {
95
95
guard let keystore = try EthereumKeystoreV3 ( privateKey: dataKey, password: WalletManager . keystorePassword) ,
96
96
let address = keystore. addresses? . first? . address else {
97
- throw NSError ( )
97
+ throw NSError ( domain : " Unknown " , code : 400 )
98
98
}
99
99
self . walletAddress = address
100
100
Task { @MainActor in
@@ -122,7 +122,7 @@ extension AuthViewController {
122
122
openWallet ( walletManager: walletManager)
123
123
}
124
124
}
125
-
125
+
126
126
func openWallet( walletManager: WalletManager ) {
127
127
let walletVC = WalletViewController ( walletManager: walletManager)
128
128
navigationController? . setViewControllers ( [ walletVC] , animated: true )
@@ -136,5 +136,4 @@ extension UIViewController {
136
136
alertController. addAction ( action)
137
137
self . present ( alertController, animated: true )
138
138
}
139
-
140
139
}
0 commit comments