add networks source

This commit is contained in:
ivan grachev 2023-11-01 13:25:56 +03:00
parent 29ae4edbb7
commit bca590910a
4 changed files with 35 additions and 24 deletions

View File

@ -10,27 +10,10 @@ struct EthereumNetwork: Codable, Equatable {
let nodeURLString: String let nodeURLString: String
var symbolIsETH: Bool { return symbol == "ETH" } var symbolIsETH: Bool { return symbol == "ETH" }
var hasUSDPrice: Bool { return chainId == 1 } // TODO: list more chains with usd price var hasUSDPrice: Bool { return chainId == EthereumNetwork.ethMainnetChainId } // TODO: list more chains with usd price
var chainIdHexString: String { String.hex(chainId, withPrefix: true) } var chainIdHexString: String { String.hex(chainId, withPrefix: true) }
var isEthMainnet: Bool { return chainId == 1 } var isEthMainnet: Bool { return chainId == EthereumNetwork.ethMainnetChainId }
} static let ethMainnetChainId = 1
extension EthereumNetwork {
static var ethereum: EthereumNetwork {
return withChainId(1)!
}
static func withChainId(_ chainId: Int?) -> EthereumNetwork? {
guard let chainId = chainId else { return nil }
// TODO: get from json / defaults / etc
// TODO: initialize infura urls correctly (adding api key)
return EthereumNetwork(chainId: chainId, name: "", symbol: "", nodeURLString: "")
}
static func withChainIdHex(_ chainIdHex: String?) -> EthereumNetwork? {
return nil // TODO: implement
}
} }

View File

@ -0,0 +1,22 @@
// Copyright © 2023 Tokenary. All rights reserved.
import Foundation
struct Networks {
static var ethereum: EthereumNetwork {
return withChainId(EthereumNetwork.ethMainnetChainId)!
}
static func withChainId(_ chainId: Int?) -> EthereumNetwork? {
guard let chainId = chainId else { return nil }
// TODO: get from json / defaults / etc
// TODO: initialize infura urls correctly (adding api key)
return EthereumNetwork(chainId: chainId, name: "", symbol: "", nodeURLString: "")
}
static func withChainIdHex(_ chainIdHex: String?) -> EthereumNetwork? {
return nil // TODO: implement
}
}

View File

@ -28,7 +28,7 @@ struct DappRequestProcessor {
return walletsManager.getSpecificAccount(coin: coin, address: configuration.address) return walletsManager.getSpecificAccount(coin: coin, address: configuration.address)
} }
let chainId = body.providerConfigurations.compactMap { $0.chainId }.first let chainId = body.providerConfigurations.compactMap { $0.chainId }.first
let network = EthereumNetwork.withChainIdHex(chainId) let network = Networks.withChainIdHex(chainId)
let initiallyConnectedProviders = Set(body.providerConfigurations.map { $0.provider }) let initiallyConnectedProviders = Set(body.providerConfigurations.map { $0.provider })
let action = SelectAccountAction(peer: request.peerMeta, let action = SelectAccountAction(peer: request.peerMeta,
coinType: nil, coinType: nil,
@ -141,7 +141,7 @@ struct DappRequestProcessor {
case .signTransaction: case .signTransaction:
if let transaction = ethereumRequest.transaction, if let transaction = ethereumRequest.transaction,
let chainId = ethereumRequest.currentChainId, let chainId = ethereumRequest.currentChainId,
let chain = EthereumNetwork.withChainId(chainId), let chain = Networks.withChainId(chainId),
let account = account, let account = account,
let privateKey = privateKey { let privateKey = privateKey {
let action = SendTransactionAction(provider: request.provider, let action = SendTransactionAction(provider: request.provider,

View File

@ -191,6 +191,8 @@
2CED86B82AF18192006F9E26 /* Nodes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CED86B52AF17D5A006F9E26 /* Nodes.swift */; }; 2CED86B82AF18192006F9E26 /* Nodes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CED86B52AF17D5A006F9E26 /* Nodes.swift */; };
2CED86BA2AF1820E006F9E26 /* NodesService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CED86B92AF1820E006F9E26 /* NodesService.swift */; }; 2CED86BA2AF1820E006F9E26 /* NodesService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CED86B92AF1820E006F9E26 /* NodesService.swift */; };
2CED86BB2AF1820E006F9E26 /* NodesService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CED86B92AF1820E006F9E26 /* NodesService.swift */; }; 2CED86BB2AF1820E006F9E26 /* NodesService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CED86B92AF1820E006F9E26 /* NodesService.swift */; };
2CED86BF2AF25C32006F9E26 /* Networks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CED86BE2AF25C32006F9E26 /* Networks.swift */; };
2CED86C02AF25C32006F9E26 /* Networks.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CED86BE2AF25C32006F9E26 /* Networks.swift */; };
2CEFEB16274D5DCA00CE23BD /* inpage.js in Resources */ = {isa = PBXBuildFile; fileRef = 2CEFEB15274D5DC900CE23BD /* inpage.js */; }; 2CEFEB16274D5DCA00CE23BD /* inpage.js in Resources */ = {isa = PBXBuildFile; fileRef = 2CEFEB15274D5DC900CE23BD /* inpage.js */; };
2CF25597275A46D300AE54B9 /* Defaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C528A15267FA8EB00CA3ADD /* Defaults.swift */; }; 2CF25597275A46D300AE54B9 /* Defaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C528A15267FA8EB00CA3ADD /* Defaults.swift */; };
2CF25598275A46D600AE54B9 /* Strings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C901C492689F01700D0926A /* Strings.swift */; }; 2CF25598275A46D600AE54B9 /* Strings.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2C901C492689F01700D0926A /* Strings.swift */; };
@ -407,6 +409,7 @@
2CED86AF2AF0167F006F9E26 /* EIP155ChainData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EIP155ChainData.swift; sourceTree = "<group>"; }; 2CED86AF2AF0167F006F9E26 /* EIP155ChainData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EIP155ChainData.swift; sourceTree = "<group>"; };
2CED86B52AF17D5A006F9E26 /* Nodes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Nodes.swift; sourceTree = "<group>"; }; 2CED86B52AF17D5A006F9E26 /* Nodes.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Nodes.swift; sourceTree = "<group>"; };
2CED86B92AF1820E006F9E26 /* NodesService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodesService.swift; sourceTree = "<group>"; }; 2CED86B92AF1820E006F9E26 /* NodesService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NodesService.swift; sourceTree = "<group>"; };
2CED86BE2AF25C32006F9E26 /* Networks.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Networks.swift; sourceTree = "<group>"; };
2CEFEB15274D5DC900CE23BD /* inpage.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = inpage.js; sourceTree = "<group>"; }; 2CEFEB15274D5DC900CE23BD /* inpage.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = inpage.js; sourceTree = "<group>"; };
2CF255B3275A744000AE54B9 /* PasswordViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasswordViewController.swift; sourceTree = "<group>"; }; 2CF255B3275A744000AE54B9 /* PasswordViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PasswordViewController.swift; sourceTree = "<group>"; };
2CF255B5275A746000AE54B9 /* AccountsListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountsListViewController.swift; sourceTree = "<group>"; }; 2CF255B5275A746000AE54B9 /* AccountsListViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountsListViewController.swift; sourceTree = "<group>"; };
@ -654,9 +657,10 @@
isa = PBXGroup; isa = PBXGroup;
children = ( children = (
2C1995552674D0F300A8E370 /* Ethereum.swift */, 2C1995552674D0F300A8E370 /* Ethereum.swift */,
2CE3D011267F73C00032A62E /* Transaction.swift */,
2C8944CA2AEB0C10006A711F /* EthereumRPC.swift */, 2C8944CA2AEB0C10006A711F /* EthereumRPC.swift */,
2C9F0B6726BDCB2E008FA3D6 /* EthereumNetwork.swift */, 2C9F0B6726BDCB2E008FA3D6 /* EthereumNetwork.swift */,
2CE3D011267F73C00032A62E /* Transaction.swift */, 2CED86BE2AF25C32006F9E26 /* Networks.swift */,
); );
path = Ethereum; path = Ethereum;
sourceTree = "<group>"; sourceTree = "<group>";
@ -1328,6 +1332,7 @@
2C264BC127B2F2C100234393 /* EthereumSafariRequest.swift in Sources */, 2C264BC127B2F2C100234393 /* EthereumSafariRequest.swift in Sources */,
2C264BD027B2F30C00234393 /* UnknownSafariRequest.swift in Sources */, 2C264BD027B2F30C00234393 /* UnknownSafariRequest.swift in Sources */,
2CED86B82AF18192006F9E26 /* Nodes.swift in Sources */, 2CED86B82AF18192006F9E26 /* Nodes.swift in Sources */,
2CED86BF2AF25C32006F9E26 /* Networks.swift in Sources */,
2C134BA627553EC500DAFBDB /* Browser.swift in Sources */, 2C134BA627553EC500DAFBDB /* Browser.swift in Sources */,
2CC89471269A334A00879245 /* UserDefaults.swift in Sources */, 2CC89471269A334A00879245 /* UserDefaults.swift in Sources */,
2C78F8282683BDCC00C10670 /* Alert.swift in Sources */, 2C78F8282683BDCC00C10670 /* Alert.swift in Sources */,
@ -1405,6 +1410,7 @@
2CF255A7275A48BB00AE54B9 /* PriceService.swift in Sources */, 2CF255A7275A48BB00AE54B9 /* PriceService.swift in Sources */,
2CF25598275A46D600AE54B9 /* Strings.swift in Sources */, 2CF25598275A46D600AE54B9 /* Strings.swift in Sources */,
2C4768B52826ED83005E8D4D /* CoinType.swift in Sources */, 2C4768B52826ED83005E8D4D /* CoinType.swift in Sources */,
2CED86C02AF25C32006F9E26 /* Networks.swift in Sources */,
2CF255AE275A48CF00AE54B9 /* Transaction.swift in Sources */, 2CF255AE275A48CF00AE54B9 /* Transaction.swift in Sources */,
2C96D38F2762317300687301 /* AccountTableViewCell.swift in Sources */, 2C96D38F2762317300687301 /* AccountTableViewCell.swift in Sources */,
2C264BEC27B6B50700234393 /* DappRequestProcessor.swift in Sources */, 2C264BEC27B6B50700234393 /* DappRequestProcessor.swift in Sources */,