Skip to content

Commit c38f0c2

Browse files
committed
Swiftlint checked
1 parent 95d5cb4 commit c38f0c2

File tree

9 files changed

+145
-113
lines changed

9 files changed

+145
-113
lines changed

Example/myWeb3Wallet/myWeb3Wallet.xcodeproj/project.pbxproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 55;
6+
objectVersion = 70;
77
objects = {
88

99
/* Begin PBXBuildFile section */

Example/myWeb3Wallet/myWeb3Wallet/Core/Network.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct Network {
1616
let networkRPC: String
1717
/// Path to network explorer like https://bscscan.com/
1818
let explorer: String?
19-
19+
2020
/// list of tokens added in this network
2121
var tokens: [Token]
2222
}

Example/myWeb3Wallet/myWeb3Wallet/Core/WalletManager.swift

+7-22
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,32 @@ import web3swift
1010
import Web3Core
1111
import BigInt
1212

13-
final class Web3Network {
14-
let network: Network
15-
16-
/// web3 - sign, request and etc
17-
let web3: Web3
18-
19-
var tokensBalances: [String: BigUInt] = [:]
20-
21-
init(network: Network, web3: Web3) {
22-
self.network = network
23-
self.web3 = web3
24-
}
25-
}
26-
27-
2813
final class WalletManager {
2914
static let keystorePassword = "password"
30-
15+
3116
/// Container with private keys
3217
private let keystoreManager: KeystoreManager
33-
18+
3419
private(set) var networks: [Web3Network] = []
35-
20+
3621
let address: EthereumAddress
37-
22+
3823
init(keystoreManager: KeystoreManager) async {
3924
self.keystoreManager = keystoreManager
4025
self.address = keystoreManager.addresses!.first!
41-
26+
4227
for model in WalletChainsModel.networks {
4328
let network = Networks.Custom(networkID: BigUInt(model.chainId))
4429
guard let providerURL = URL(string: model.networkRPC),
4530
let provider = try? await Web3HttpProvider(url: providerURL, network: network,
4631
keystoreManager: keystoreManager)
4732
else { continue }
48-
33+
4934
let web3 = web3swift.Web3(provider: provider)
5035
networks.append(Web3Network(network: model, web3: web3))
5136
}
5237
}
53-
38+
5439
func loadBalances() async {
5540
for network in networks {
5641
if let nativeBalance = try? await network.web3.eth.getBalance(for: address),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//
2+
// Web3Network.swift
3+
// myWeb3Wallet
4+
//
5+
// Created by 6od9i on 20/01/25.
6+
//
7+
8+
import Foundation
9+
import web3swift
10+
import Web3Core
11+
import BigInt
12+
13+
final class Web3Network {
14+
let network: Network
15+
16+
/// web3 - sign, request and etc
17+
let web3: Web3
18+
19+
var tokensBalances: [String: BigUInt] = [:]
20+
21+
init(network: Network, web3: Web3) {
22+
self.network = network
23+
self.web3 = web3
24+
}
25+
}

Example/myWeb3Wallet/myWeb3Wallet/ViewControllers/AuthController/AuthViewController.swift

+12-13
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,32 @@ import web3swift
1010
import Web3Core
1111

1212
class AuthViewController: UIViewController {
13-
13+
1414
@IBOutlet weak var continueButton: UIButton!
1515
@IBOutlet weak var walletAddressLabel: UILabel!
1616
@IBOutlet weak var importWalletButton: UIButton!
1717
@IBOutlet weak var createWalletButton: UIButton!
18-
18+
1919
var walletAddress: String? {
2020
didSet {
2121
self.walletAddressLabel.text = walletAddress
2222
}
2323
}
24-
24+
2525
override func viewDidLoad() {
2626
super.viewDidLoad()
2727
self.createWalletButton.layer.cornerRadius = 5.0
2828
self.importWalletButton.layer.cornerRadius = 5.0
2929
}
30-
30+
3131
@IBAction func onClickCreateWallet(_ sender: UIButton) {
3232
self.createMnemonics()
33-
33+
3434
}
3535
@IBAction func onClickImportWalletButton(_ sender: UIButton) {
3636
self.showImportAlert()
3737
}
38-
38+
3939
@IBAction func onClickContinueButton(_ sender: UIButton) {
4040
}
4141
}
@@ -61,14 +61,14 @@ extension AuthViewController {
6161
alert.addAction(cancelAction)
6262
self.present(alert, animated: true, completion: nil)
6363
}
64-
64+
6565
fileprivate func createMnemonics() {
6666
guard let mnemonics = try? BIP39.generateMnemonics(bitsOfEntropy: 256, language: .english) else {
6767
self.showAlertMessage(title: "", message: "We are unable to create wallet", actionName: "Ok")
6868
return
6969
}
7070
print(mnemonics)
71-
71+
7272
guard let keystore = try? BIP32Keystore(mnemonics: mnemonics, password: WalletManager.keystorePassword),
7373
let walletAddress = keystore.addresses?.first else {
7474
self.showAlertMessage(title: "", message: "Unable to create wallet", actionName: "Ok")
@@ -78,13 +78,13 @@ extension AuthViewController {
7878
let privateKey = try! keystore.UNSAFE_getPrivateKeyData(password: WalletManager.keystorePassword,
7979
account: walletAddress)
8080
print(privateKey)
81-
81+
8282
Task {
8383
let walletManager = await WalletManager(keystoreManager: KeystoreManager([keystore]))
8484
openWallet(walletManager: walletManager)
8585
}
8686
}
87-
87+
8888
func importWalletWith(privateKey: String) {
8989
let formattedKey = privateKey.trimmingCharacters(in: .whitespacesAndNewlines)
9090
guard let dataKey = Data.fromHex(formattedKey) else {
@@ -94,7 +94,7 @@ extension AuthViewController {
9494
do {
9595
guard let keystore = try EthereumKeystoreV3(privateKey: dataKey, password: WalletManager.keystorePassword),
9696
let address = keystore.addresses?.first?.address else {
97-
throw NSError()
97+
throw NSError(domain: "Unknown", code: 400)
9898
}
9999
self.walletAddress = address
100100
Task { @MainActor in
@@ -122,7 +122,7 @@ extension AuthViewController {
122122
openWallet(walletManager: walletManager)
123123
}
124124
}
125-
125+
126126
func openWallet(walletManager: WalletManager) {
127127
let walletVC = WalletViewController(walletManager: walletManager)
128128
navigationController?.setViewControllers([walletVC], animated: true)
@@ -136,5 +136,4 @@ extension UIViewController {
136136
alertController.addAction(action)
137137
self.present(alertController, animated: true)
138138
}
139-
140139
}

0 commit comments

Comments
 (0)