Skip to content

Commit 8275d1e

Browse files
Merge branch 'develop'
2 parents 119d179 + 133b891 commit 8275d1e

File tree

26 files changed

+906
-208
lines changed

26 files changed

+906
-208
lines changed

CONTRIBUTION.md

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,25 @@
11
# Contribution guide
22
## Version convention
33
We’re conforming [default versions convention](https://semver.org/).
4-
So in the `1.0.0` version each position means follow:
5-
- 1.\*.***major release**, includes API groundbreaking changes (ie: your old code will not work).
6-
- \*.1.***minor release**, we’ve added some new feature to the lib, but we didn’t break something in anyway (ie: everything will work as expected without any moves after update).
7-
- \*.*.1 — **patch release**, we’re haven’t add any breaking changes or even new features for the user, but we’ve fixed some bugs or rewrote something internal (ie: you should not event mention that anything were changed in the lib).
4+
So in the `1.0.0` version, each position means the following:
5+
- 1.\*.***major release**. Includes breaking changes. As the result, your old code will break with the new version;
6+
- \*.1.***minor release**. Added one or more new features to the lib and no breaking changes were introduced. Everything will work as expected, no changes are required in your projects;
7+
- \*.*.1 — **patch release**. Fixed one or more bugs, performed code refactoring, updated documentation or did something with the existing code base that doesn’t include new features nor breaks current ones.
88

9-
This library yet living within **three weeks minor release** schedule. Also please keep in mind that in sake of avoiding complex merge conflicts, we’re currently taking only **one big feature** in release, so if you want to take some, please drop us a message somewhere to avoiding reworking it after it’ll be broken by some massive merge.
9+
Though, this library is living within the **three weeks minor release** schedule, please keep in mind that for the sake of avoiding complex merge conflicts, we’re currently taking only **one big feature** per release, so if you want to take some, please drop us a message somewhere (e.g. in [Discord](https://discord.com/invite/8bHCNmhS7x) in #contributors channel) to avoiding reworking it after it’ll be broken by some massive merge and to plan it correctly before you start.
1010

11-
Critical bug fixes are should be marked with appropriate label in PR and should be proceed **within one week** till patch ’ll be released (at least we’ll try our best to made that).
11+
Critical bug fixes must be marked with the appropriate label in PR and should be processed **within one week** (at least we’ll try our best to make that).
1212

13-
## What task to choose
13+
## Choosing a task
1414
Please take it from the [roadmap](https://hackmd.io/G5znP3xAQY-BVc1X8Y1jSg) or from the [opened issues](https://github.com/skywinder/web3swift/issues?q=is:issue+is:open+sort:updated-desc "").
1515

16-
> If you want to make something completely new and purely magical, please drop us a message somewhere before, since it could ends up that this is what we planning to do a lot later or that we not planning at all.
16+
> If you want to make something completely new and purely magical, please drop us a message somewhere before you start (e.g. in [Discord](https://discord.com/invite/8bHCNmhS7x) in #contributors channel). Some features could be already planned but for a later stages or not planned (purposefuly not willing to include) at all.
1717
1818
## Codestyle guideline
1919
- `swiftlint` check should goes with no warnings.
20-
- Here’s some more detailed and human readable code style [guidelines](https://hackmd.io/8bACoAnTSsKc55Os596yCg "") (you can add there some suggestion if you’d like to).
21-
- We use [swift](https://www.swift.org/documentation/api-design-guidelines/ "") name convention.
20+
- Here’s some more detailed and human readable code style [guidelines](https://hackmd.io/8bACoAnTSsKc55Os596yCg) (you can add there some suggestion if you’d like to).
21+
- We use [swift](https://www.swift.org/documentation/api-design-guidelines/) name convention.
22+
2223
## Tests guideline
2324
1. Cover each new public method with tests.
2425
2. If you’re implementing some big feature encapsulate it in Separate file.
@@ -31,12 +32,16 @@ Please take it from the [roadmap](https://hackmd.io/G5znP3xAQY-BVc1X8Y1jSg) or f
3132
## Hacks & tricks & magic
3233
### TestPlans
3334
In ci/cd we’re using Xcode test plans feature to spread tests to local and remote one. So any time you’re adding any new test suit (file) please exclude it from `LocalTests.xctestplan` rather `RemoteTests.xctestplan` depends on what tests group it included.
35+
3436
### Swift package manager
3537
Please add any files unused due build process to `excludeFiles` array in `Package.swift`.
38+
3639
### Carthage
3740
Please do not forget to add & remove all new or dropped files and dependencies in carthage `.xcodeproj` file if you’re working with project anywhere but carthage project.
41+
3842
### Cocoapods
3943
Please do not forget to add & remove all dependencies within `web3swift.podspec` file.
44+
4045
### GitHub actions
4146
You’re able to use our github actions checks in your fork without needing to make PR to this repo. To get that just add your branch name to the branch list in file on path `.github/actions/ci.yml` to let the magic happening like follow:
4247

@@ -54,17 +59,17 @@ on:
5459
5560
## Good PR checklist
5661
### Code
57-
- [ ] All new functionality covered by unit tests.
58-
- [ ] Ci/cd green.
59-
- [ ] No redundant files are added (build cache, Xcode breakpoints settings and so on).
62+
- [ ] All new functionality is covered by unit tests;
63+
- [ ] All changes are focused on something specific, e.g. 1 feature 1 PR, 1 file refactored in 1 PR (depends on how much was refactored, etc.);
64+
- [ ] No redundant files are added (build cache, Xcode breakpoints settings and so on);
65+
- [ ] Documentation is added or updated. Refactoring a function with no documentation - add documentation. Fixing a bug - updated documentation to reflect changes correctly.
6066

6167
### Info
62-
- [ ] Relative and concrete PR title.
63-
- [ ] Issue or roadmap goal attached.
64-
- [ ] PR description filled with detail explanation of what it is and what’s its specific.
68+
- [ ] Short and understandable PR title;
69+
- [ ] Issue or roadmap goal is attached if applicable;
70+
- [ ] PR description filled with detailed explanation of what was changed and reasons for the changes made.
6571

6672
### Codestyle
67-
- [ ] All public method have `///` styled comments.
68-
- [ ] All magic or nonintuitive internal code parts are clearly explained in inline comments.
69-
- [ ] `swiftlint` ran have no warnings.
70-
- [ ] No commented out code lefts in PR.
73+
- [ ] All public method have `///` styled comments;
74+
- [ ] All magic or nonintuitive internal code parts are clearly explained with additional in inline comments;
75+
- [ ] No commented out code is left in a PR.

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+
}

0 commit comments

Comments
 (0)