Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d8cfafe

Browse files
Merge pull request #881 from 6od9i/test-project-send
Added send to example project
2 parents 11f9c4a + c38f0c2 commit d8cfafe

File tree

15 files changed

+867
-175
lines changed

15 files changed

+867
-175
lines changed

‎Example/myWeb3Wallet/myWeb3Wallet.xcodeproj/project.pbxproj‎

Lines changed: 22 additions & 8 deletions
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 */
@@ -18,7 +18,7 @@
1818
FA5308422721D59D002C1F06 /* myWeb3WalletUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA5308412721D59D002C1F06 /* myWeb3WalletUITests.swift */; };
1919
FA5308442721D59D002C1F06 /* myWeb3WalletUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA5308432721D59D002C1F06 /* myWeb3WalletUITestsLaunchTests.swift */; };
2020
FA5308512721F5BC002C1F06 /* SplashViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA5308502721F5BC002C1F06 /* SplashViewController.swift */; };
21-
FA5308562721F647002C1F06 /* WalletViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA5308552721F647002C1F06 /* WalletViewController.swift */; };
21+
FA5308562721F647002C1F06 /* AuthViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA5308552721F647002C1F06 /* AuthViewController.swift */; };
2222
FAF01E912722D848002CEE01 /* DashboardViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAF01E902722D848002CEE01 /* DashboardViewController.swift */; };
2323
FAF01E942722E6F1002CEE01 /* simulator_screenshot_9B13C8F6-BE7A-4919-966A-9E69A2953F31.png in Resources */ = {isa = PBXBuildFile; fileRef = FAF01E932722E6F1002CEE01 /* simulator_screenshot_9B13C8F6-BE7A-4919-966A-9E69A2953F31.png */; };
2424
FAF01E962722E713002CEE01 /* simulator_screenshot_38EB4733-C3DB-4280-BAF2-9ED97440A8AD.png in Resources */ = {isa = PBXBuildFile; fileRef = FAF01E952722E713002CEE01 /* simulator_screenshot_38EB4733-C3DB-4280-BAF2-9ED97440A8AD.png */; };
@@ -61,14 +61,20 @@
6161
FA5308412721D59D002C1F06 /* myWeb3WalletUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = myWeb3WalletUITests.swift; sourceTree = "<group>"; };
6262
FA5308432721D59D002C1F06 /* myWeb3WalletUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = myWeb3WalletUITestsLaunchTests.swift; sourceTree = "<group>"; };
6363
FA5308502721F5BC002C1F06 /* SplashViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashViewController.swift; sourceTree = "<group>"; };
64-
FA5308552721F647002C1F06 /* WalletViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletViewController.swift; sourceTree = "<group>"; };
64+
FA5308552721F647002C1F06 /* AuthViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthViewController.swift; sourceTree = "<group>"; };
6565
FAF01E902722D848002CEE01 /* DashboardViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardViewController.swift; sourceTree = "<group>"; };
6666
FAF01E932722E6F1002CEE01 /* simulator_screenshot_9B13C8F6-BE7A-4919-966A-9E69A2953F31.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "simulator_screenshot_9B13C8F6-BE7A-4919-966A-9E69A2953F31.png"; sourceTree = "<group>"; };
6767
FAF01E952722E713002CEE01 /* simulator_screenshot_38EB4733-C3DB-4280-BAF2-9ED97440A8AD.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "simulator_screenshot_38EB4733-C3DB-4280-BAF2-9ED97440A8AD.png"; sourceTree = "<group>"; };
6868
FAF01E972722E72C002CEE01 /* simulator_screenshot_C6881651-9D22-410A-BDC2-4CC3FFEF4FD8.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "simulator_screenshot_C6881651-9D22-410A-BDC2-4CC3FFEF4FD8.png"; sourceTree = "<group>"; };
6969
FAF01E992722E73D002CEE01 /* simulator_screenshot_10F04849-E85A-41AB-8A17-D3FC394285AE.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "simulator_screenshot_10F04849-E85A-41AB-8A17-D3FC394285AE.png"; sourceTree = "<group>"; };
7070
/* End PBXFileReference section */
7171

72+
/* Begin PBXFileSystemSynchronizedRootGroup section */
73+
59490A822D3820A5004908B6 /* Core */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = Core; sourceTree = "<group>"; };
74+
59490A9F2D3836D7004908B6 /* WalletViewController */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = WalletViewController; sourceTree = "<group>"; };
75+
59490AA22D385847004908B6 /* SendViewController */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = SendViewController; sourceTree = "<group>"; };
76+
/* End PBXFileSystemSynchronizedRootGroup section */
77+
7278
/* Begin PBXFrameworksBuildPhase section */
7379
FA53081A2721D59B002C1F06 /* Frameworks */ = {
7480
isa = PBXFrameworksBuildPhase;
@@ -129,6 +135,7 @@
129135
FA53081F2721D59B002C1F06 /* myWeb3Wallet */ = {
130136
isa = PBXGroup;
131137
children = (
138+
59490A822D3820A5004908B6 /* Core */,
132139
FAF01E922722E673002CEE01 /* ScreenShot */,
133140
FA5308532721F615002C1F06 /* ViewControllers */,
134141
FA5308522721F5C8002C1F06 /* Appdelegate */,
@@ -170,19 +177,21 @@
170177
FA5308532721F615002C1F06 /* ViewControllers */ = {
171178
isa = PBXGroup;
172179
children = (
173-
FA5308542721F62E002C1F06 /* WalletController */,
180+
59490AA22D385847004908B6 /* SendViewController */,
181+
59490A9F2D3836D7004908B6 /* WalletViewController */,
182+
FA5308542721F62E002C1F06 /* AuthController */,
174183
);
175184
path = ViewControllers;
176185
sourceTree = "<group>";
177186
};
178-
FA5308542721F62E002C1F06 /* WalletController */ = {
187+
FA5308542721F62E002C1F06 /* AuthController */ = {
179188
isa = PBXGroup;
180189
children = (
181190
FA5308502721F5BC002C1F06 /* SplashViewController.swift */,
182-
FA5308552721F647002C1F06 /* WalletViewController.swift */,
191+
FA5308552721F647002C1F06 /* AuthViewController.swift */,
183192
FAF01E902722D848002CEE01 /* DashboardViewController.swift */,
184193
);
185-
path = WalletController;
194+
path = AuthController;
186195
sourceTree = "<group>";
187196
};
188197
FAF01E922722E673002CEE01 /* ScreenShot */ = {
@@ -211,6 +220,11 @@
211220
);
212221
dependencies = (
213222
);
223+
fileSystemSynchronizedGroups = (
224+
59490A822D3820A5004908B6 /* Core */,
225+
59490A9F2D3836D7004908B6 /* WalletViewController */,
226+
59490AA22D385847004908B6 /* SendViewController */,
227+
);
214228
name = myWeb3Wallet;
215229
packageProductDependencies = (
216230
D6DD90D12991966100EE140E /* web3swift */,
@@ -342,7 +356,7 @@
342356
FA5308212721D59B002C1F06 /* AppDelegate.swift in Sources */,
343357
FA5308232721D59B002C1F06 /* SceneDelegate.swift in Sources */,
344358
FA5308512721F5BC002C1F06 /* SplashViewController.swift in Sources */,
345-
FA5308562721F647002C1F06 /* WalletViewController.swift in Sources */,
359+
FA5308562721F647002C1F06 /* AuthViewController.swift in Sources */,
346360
);
347361
runOnlyForDeploymentPostprocessing = 0;
348362
};

‎Example/myWeb3Wallet/myWeb3Wallet/Base.lproj/Main.storyboard‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@
5757
</objects>
5858
<point key="canvasLocation" x="18.840579710144929" y="66.964285714285708"/>
5959
</scene>
60-
<!--Wallet View Controller-->
60+
<!--Auth View Controller-->
6161
<scene sceneID="0m1-99-x4x">
6262
<objects>
63-
<viewController storyboardIdentifier="WalletViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="oox-Y6-Jww" customClass="WalletViewController" customModule="myWeb3Wallet" customModuleProvider="target" sceneMemberID="viewController">
63+
<viewController storyboardIdentifier="WalletViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="oox-Y6-Jww" customClass="AuthViewController" customModule="myWeb3Wallet" customModuleProvider="target" sceneMemberID="viewController">
6464
<view key="view" contentMode="scaleToFill" id="Wu8-YM-FMv">
6565
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
6666
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// Network.swift
3+
// myWeb3Wallet
4+
//
5+
// Created by 6od9i on 15/01/25.
6+
//
7+
8+
import Foundation
9+
10+
struct Network {
11+
/// Id of chain
12+
let chainId: Int
13+
/// Name of the network
14+
let name: String
15+
/// Some rpc api paths - for network provider
16+
let networkRPC: String
17+
/// Path to network explorer like https://bscscan.com/
18+
let explorer: String?
19+
20+
/// list of tokens added in this network
21+
var tokens: [Token]
22+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// Token.swift
3+
// myWeb3Wallet
4+
//
5+
// Created by 6od9i on 15/01/25.
6+
//
7+
8+
import Foundation
9+
10+
struct Token {
11+
var isNative: Bool = false
12+
/// Token symbol, for example - "ETH"/"USDT"
13+
let symbol: String
14+
/// Token contract address
15+
let address: String
16+
/// Decimals number
17+
let decimals: Int
18+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
//
2+
// WalletChainsModel.swift
3+
// myWeb3Wallet
4+
//
5+
// Created by 6od9i on 15/01/25.
6+
//
7+
8+
import Foundation
9+
10+
struct WalletChainsModel {
11+
static let networks: [Network] = [
12+
Network(chainId: 1, name: "Ethereum",
13+
networkRPC: "https://ethereum-rpc.publicnode.com",
14+
explorer: "https://etherscan.io/", tokens: [
15+
Token(isNative: true,
16+
symbol: "ETH",
17+
address: "0x0",
18+
decimals: 18),
19+
Token(symbol: "USDT",
20+
address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
21+
decimals: 6),
22+
Token(symbol: "USDC",
23+
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
24+
decimals: 6),
25+
Token(symbol: "BTC",
26+
address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
27+
decimals: 8)
28+
]),
29+
Network(chainId: 56, name: "Binance Smart Chain",
30+
networkRPC: "https://bsc-dataseed.binance.org/",
31+
explorer: "https://bscscan.com/", tokens: [
32+
Token(isNative: true,
33+
symbol: "BNB",
34+
address: "0x0",
35+
decimals: 18),
36+
Token(symbol: "USDT",
37+
address: "0x55d398326f99059fF775485246999027B3197955",
38+
decimals: 18),
39+
Token(symbol: "USDC",
40+
address: "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",
41+
decimals: 18),
42+
Token(symbol: "BTC",
43+
address: "0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c",
44+
decimals: 18)
45+
]),
46+
Network(chainId: 137, name: "Polygon",
47+
networkRPC: "https://polygon.llamarpc.com",
48+
explorer: "https://polygonscan.com/", tokens: [
49+
Token(isNative: true,
50+
symbol: "POL",
51+
address: "0x0",
52+
decimals: 18),
53+
Token(symbol: "USDT",
54+
address: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
55+
decimals: 6),
56+
Token(symbol: "USDC",
57+
address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
58+
decimals: 6),
59+
Token(symbol: "WBTC",
60+
address: "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6",
61+
decimals: 8)
62+
])
63+
]
64+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
// WalletManager.swift
3+
// myWeb3Wallet
4+
//
5+
// Created by 6od9i on 15/01/25.
6+
//
7+
8+
import Foundation
9+
import web3swift
10+
import Web3Core
11+
import BigInt
12+
13+
final class WalletManager {
14+
static let keystorePassword = "password"
15+
16+
/// Container with private keys
17+
private let keystoreManager: KeystoreManager
18+
19+
private(set) var networks: [Web3Network] = []
20+
21+
let address: EthereumAddress
22+
23+
init(keystoreManager: KeystoreManager) async {
24+
self.keystoreManager = keystoreManager
25+
self.address = keystoreManager.addresses!.first!
26+
27+
for model in WalletChainsModel.networks {
28+
let network = Networks.Custom(networkID: BigUInt(model.chainId))
29+
guard let providerURL = URL(string: model.networkRPC),
30+
let provider = try? await Web3HttpProvider(url: providerURL, network: network,
31+
keystoreManager: keystoreManager)
32+
else { continue }
33+
34+
let web3 = web3swift.Web3(provider: provider)
35+
networks.append(Web3Network(network: model, web3: web3))
36+
}
37+
}
38+
39+
func loadBalances() async {
40+
for network in networks {
41+
if let nativeBalance = try? await network.web3.eth.getBalance(for: address),
42+
let nativeSymbol = network.network.tokens.first(where: { 0ドル.isNative })?.symbol {
43+
network.tokensBalances[nativeSymbol] = nativeBalance
44+
}
45+
for token in network.network.tokens {
46+
guard token.isNative == false,
47+
let contract = network.web3.contract(Web3.Utils.erc20ABI, at: EthereumAddress(token.address)),
48+
let operation = contract.createReadOperation("balanceOf", parameters: [address]),
49+
let result = try? await operation.callContractMethod(),
50+
let balance = result["balance"] as? BigUInt
51+
else { continue }
52+
network.tokensBalances[token.symbol] = balance
53+
}
54+
}
55+
}
56+
}
Lines changed: 25 additions & 0 deletions
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+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /