Skip to content

Commit

Permalink
Merge pull request #881 from 6od9i/test-project-send
Browse files Browse the repository at this point in the history
Added send to example project
  • Loading branch information
yaroslavyaroslav authored Jan 21, 2025
2 parents 11f9c4a + c38f0c2 commit d8cfafe
Show file tree
Hide file tree
Showing 15 changed files with 867 additions and 175 deletions.
30 changes: 22 additions & 8 deletions Example/myWeb3Wallet/myWeb3Wallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 55;
objectVersion = 70;
objects = {

/* Begin PBXBuildFile section */
Expand All @@ -18,7 +18,7 @@
FA5308422721D59D002C1F06 /* myWeb3WalletUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA5308412721D59D002C1F06 /* myWeb3WalletUITests.swift */; };
FA5308442721D59D002C1F06 /* myWeb3WalletUITestsLaunchTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA5308432721D59D002C1F06 /* myWeb3WalletUITestsLaunchTests.swift */; };
FA5308512721F5BC002C1F06 /* SplashViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA5308502721F5BC002C1F06 /* SplashViewController.swift */; };
FA5308562721F647002C1F06 /* WalletViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA5308552721F647002C1F06 /* WalletViewController.swift */; };
FA5308562721F647002C1F06 /* AuthViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FA5308552721F647002C1F06 /* AuthViewController.swift */; };
FAF01E912722D848002CEE01 /* DashboardViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = FAF01E902722D848002CEE01 /* DashboardViewController.swift */; };
FAF01E942722E6F1002CEE01 /* simulator_screenshot_9B13C8F6-BE7A-4919-966A-9E69A2953F31.png in Resources */ = {isa = PBXBuildFile; fileRef = FAF01E932722E6F1002CEE01 /* simulator_screenshot_9B13C8F6-BE7A-4919-966A-9E69A2953F31.png */; };
FAF01E962722E713002CEE01 /* simulator_screenshot_38EB4733-C3DB-4280-BAF2-9ED97440A8AD.png in Resources */ = {isa = PBXBuildFile; fileRef = FAF01E952722E713002CEE01 /* simulator_screenshot_38EB4733-C3DB-4280-BAF2-9ED97440A8AD.png */; };
Expand Down Expand Up @@ -61,14 +61,20 @@
FA5308412721D59D002C1F06 /* myWeb3WalletUITests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = myWeb3WalletUITests.swift; sourceTree = "<group>"; };
FA5308432721D59D002C1F06 /* myWeb3WalletUITestsLaunchTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = myWeb3WalletUITestsLaunchTests.swift; sourceTree = "<group>"; };
FA5308502721F5BC002C1F06 /* SplashViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SplashViewController.swift; sourceTree = "<group>"; };
FA5308552721F647002C1F06 /* WalletViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WalletViewController.swift; sourceTree = "<group>"; };
FA5308552721F647002C1F06 /* AuthViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AuthViewController.swift; sourceTree = "<group>"; };
FAF01E902722D848002CEE01 /* DashboardViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DashboardViewController.swift; sourceTree = "<group>"; };
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>"; };
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>"; };
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>"; };
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>"; };
/* End PBXFileReference section */

/* Begin PBXFileSystemSynchronizedRootGroup section */
59490A822D3820A5004908B6 /* Core */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = Core; sourceTree = "<group>"; };
59490A9F2D3836D7004908B6 /* WalletViewController */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = WalletViewController; sourceTree = "<group>"; };
59490AA22D385847004908B6 /* SendViewController */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = SendViewController; sourceTree = "<group>"; };
/* End PBXFileSystemSynchronizedRootGroup section */

/* Begin PBXFrameworksBuildPhase section */
FA53081A2721D59B002C1F06 /* Frameworks */ = {
isa = PBXFrameworksBuildPhase;
Expand Down Expand Up @@ -129,6 +135,7 @@
FA53081F2721D59B002C1F06 /* myWeb3Wallet */ = {
isa = PBXGroup;
children = (
59490A822D3820A5004908B6 /* Core */,
FAF01E922722E673002CEE01 /* ScreenShot */,
FA5308532721F615002C1F06 /* ViewControllers */,
FA5308522721F5C8002C1F06 /* Appdelegate */,
Expand Down Expand Up @@ -170,19 +177,21 @@
FA5308532721F615002C1F06 /* ViewControllers */ = {
isa = PBXGroup;
children = (
FA5308542721F62E002C1F06 /* WalletController */,
59490AA22D385847004908B6 /* SendViewController */,
59490A9F2D3836D7004908B6 /* WalletViewController */,
FA5308542721F62E002C1F06 /* AuthController */,
);
path = ViewControllers;
sourceTree = "<group>";
};
FA5308542721F62E002C1F06 /* WalletController */ = {
FA5308542721F62E002C1F06 /* AuthController */ = {
isa = PBXGroup;
children = (
FA5308502721F5BC002C1F06 /* SplashViewController.swift */,
FA5308552721F647002C1F06 /* WalletViewController.swift */,
FA5308552721F647002C1F06 /* AuthViewController.swift */,
FAF01E902722D848002CEE01 /* DashboardViewController.swift */,
);
path = WalletController;
path = AuthController;
sourceTree = "<group>";
};
FAF01E922722E673002CEE01 /* ScreenShot */ = {
Expand Down Expand Up @@ -211,6 +220,11 @@
);
dependencies = (
);
fileSystemSynchronizedGroups = (
59490A822D3820A5004908B6 /* Core */,
59490A9F2D3836D7004908B6 /* WalletViewController */,
59490AA22D385847004908B6 /* SendViewController */,
);
name = myWeb3Wallet;
packageProductDependencies = (
D6DD90D12991966100EE140E /* web3swift */,
Expand Down Expand Up @@ -342,7 +356,7 @@
FA5308212721D59B002C1F06 /* AppDelegate.swift in Sources */,
FA5308232721D59B002C1F06 /* SceneDelegate.swift in Sources */,
FA5308512721F5BC002C1F06 /* SplashViewController.swift in Sources */,
FA5308562721F647002C1F06 /* WalletViewController.swift in Sources */,
FA5308562721F647002C1F06 /* AuthViewController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
4 changes: 2 additions & 2 deletions Example/myWeb3Wallet/myWeb3Wallet/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@
</objects>
<point key="canvasLocation" x="18.840579710144929" y="66.964285714285708"/>
</scene>
<!--Wallet View Controller-->
<!--Auth View Controller-->
<scene sceneID="0m1-99-x4x">
<objects>
<viewController storyboardIdentifier="WalletViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="oox-Y6-Jww" customClass="WalletViewController" customModule="myWeb3Wallet" customModuleProvider="target" sceneMemberID="viewController">
<viewController storyboardIdentifier="WalletViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="oox-Y6-Jww" customClass="AuthViewController" customModule="myWeb3Wallet" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="Wu8-YM-FMv">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
Expand Down
22 changes: 22 additions & 0 deletions Example/myWeb3Wallet/myWeb3Wallet/Core/Network.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Network.swift
// myWeb3Wallet
//
// Created by 6od9i on 15/01/25.
//

import Foundation

struct Network {
/// Id of chain
let chainId: Int
/// Name of the network
let name: String
/// Some rpc api paths - for network provider
let networkRPC: String
/// Path to network explorer like https://bscscan.com/
let explorer: String?

/// list of tokens added in this network
var tokens: [Token]
}
18 changes: 18 additions & 0 deletions Example/myWeb3Wallet/myWeb3Wallet/Core/Token.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// Token.swift
// myWeb3Wallet
//
// Created by 6od9i on 15/01/25.
//

import Foundation

struct Token {
var isNative: Bool = false
/// Token symbol, for example - "ETH"/"USDT"
let symbol: String
/// Token contract address
let address: String
/// Decimals number
let decimals: Int
}
64 changes: 64 additions & 0 deletions Example/myWeb3Wallet/myWeb3Wallet/Core/WalletChainsModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
//
// WalletChainsModel.swift
// myWeb3Wallet
//
// Created by 6od9i on 15/01/25.
//

import Foundation

struct WalletChainsModel {
static let networks: [Network] = [
Network(chainId: 1, name: "Ethereum",
networkRPC: "https://ethereum-rpc.publicnode.com",
explorer: "https://etherscan.io/", tokens: [
Token(isNative: true,
symbol: "ETH",
address: "0x0",
decimals: 18),
Token(symbol: "USDT",
address: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
decimals: 6),
Token(symbol: "USDC",
address: "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
decimals: 6),
Token(symbol: "BTC",
address: "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599",
decimals: 8)
]),
Network(chainId: 56, name: "Binance Smart Chain",
networkRPC: "https://bsc-dataseed.binance.org/",
explorer: "https://bscscan.com/", tokens: [
Token(isNative: true,
symbol: "BNB",
address: "0x0",
decimals: 18),
Token(symbol: "USDT",
address: "0x55d398326f99059fF775485246999027B3197955",
decimals: 18),
Token(symbol: "USDC",
address: "0x8AC76a51cc950d9822D68b83fE1Ad97B32Cd580d",
decimals: 18),
Token(symbol: "BTC",
address: "0x7130d2A12B9BCbFAe4f2634d864A1Ee1Ce3Ead9c",
decimals: 18)
]),
Network(chainId: 137, name: "Polygon",
networkRPC: "https://polygon.llamarpc.com",
explorer: "https://polygonscan.com/", tokens: [
Token(isNative: true,
symbol: "POL",
address: "0x0",
decimals: 18),
Token(symbol: "USDT",
address: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
decimals: 6),
Token(symbol: "USDC",
address: "0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359",
decimals: 6),
Token(symbol: "WBTC",
address: "0x1BFD67037B42Cf73acF2047067bd4F2C47D9BfD6",
decimals: 8)
])
]
}
56 changes: 56 additions & 0 deletions Example/myWeb3Wallet/myWeb3Wallet/Core/WalletManager.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// WalletManager.swift
// myWeb3Wallet
//
// Created by 6od9i on 15/01/25.
//

import Foundation
import web3swift
import Web3Core
import BigInt

final class WalletManager {
static let keystorePassword = "password"

/// Container with private keys
private let keystoreManager: KeystoreManager

private(set) var networks: [Web3Network] = []

let address: EthereumAddress

init(keystoreManager: KeystoreManager) async {
self.keystoreManager = keystoreManager
self.address = keystoreManager.addresses!.first!

for model in WalletChainsModel.networks {
let network = Networks.Custom(networkID: BigUInt(model.chainId))
guard let providerURL = URL(string: model.networkRPC),
let provider = try? await Web3HttpProvider(url: providerURL, network: network,
keystoreManager: keystoreManager)
else { continue }

let web3 = web3swift.Web3(provider: provider)
networks.append(Web3Network(network: model, web3: web3))
}
}

func loadBalances() async {
for network in networks {
if let nativeBalance = try? await network.web3.eth.getBalance(for: address),
let nativeSymbol = network.network.tokens.first(where: { $0.isNative })?.symbol {
network.tokensBalances[nativeSymbol] = nativeBalance
}
for token in network.network.tokens {
guard token.isNative == false,
let contract = network.web3.contract(Web3.Utils.erc20ABI, at: EthereumAddress(token.address)),
let operation = contract.createReadOperation("balanceOf", parameters: [address]),
let result = try? await operation.callContractMethod(),
let balance = result["balance"] as? BigUInt
else { continue }
network.tokensBalances[token.symbol] = balance
}
}
}
}
25 changes: 25 additions & 0 deletions Example/myWeb3Wallet/myWeb3Wallet/Core/Web3Network.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// Web3Network.swift
// myWeb3Wallet
//
// Created by 6od9i on 20/01/25.
//

import Foundation
import web3swift
import Web3Core
import BigInt

final class Web3Network {
let network: Network

/// web3 - sign, request and etc
let web3: Web3

var tokensBalances: [String: BigUInt] = [:]

init(network: Network, web3: Web3) {
self.network = network
self.web3 = web3
}
}
Loading

0 comments on commit d8cfafe

Please sign in to comment.