From 22a9432ccbf9dfd19d5cc53fcf55eacefc79121b Mon Sep 17 00:00:00 2001 From: Michael Scoff Date: Tue, 9 Jan 2018 23:51:06 -0800 Subject: [PATCH] Add Sokol network support --- Trust/Core/ViewModels/InCoordinatorViewModel.swift | 4 ++-- Trust/Exchange/Types/ExchangeConfig.swift | 4 ++-- Trust/Exchange/Types/ExchangeTokens.swift | 2 +- Trust/Settings/Types/Config.swift | 2 ++ Trust/Settings/Types/ConfigExplorer.swift | 4 ++++ Trust/Settings/Types/RPCServers.swift | 9 +++++++-- .../ViewControllers/SettingsViewController.swift | 2 +- Trust/Settings/ViewModels/SettingsViewModel.swift | 1 + Trust/Tokens/Types/TokensDataStore.swift | 2 +- .../ViewModels/TransactionDetailsViewModel.swift | 2 +- .../Transactions/ViewModels/TransactionsViewModel.swift | 2 +- 11 files changed, 23 insertions(+), 11 deletions(-) diff --git a/Trust/Core/ViewModels/InCoordinatorViewModel.swift b/Trust/Core/ViewModels/InCoordinatorViewModel.swift index 9edf7d5a9..7790834df 100644 --- a/Trust/Core/ViewModels/InCoordinatorViewModel.swift +++ b/Trust/Core/ViewModels/InCoordinatorViewModel.swift @@ -12,7 +12,7 @@ struct InCoordinatorViewModel { var tokensAvailable: Bool { switch config.server { - case .main, .classic, .kovan, .ropsten, .poa: return true + case .main, .classic, .kovan, .ropsten, .poa, .sokol: return true } } @@ -22,7 +22,7 @@ struct InCoordinatorViewModel { var exchangeAvailable: Bool { switch config.server { - case .main, .classic, .ropsten, .poa: return false + case .main, .classic, .ropsten, .poa, .sokol: return false case .kovan: return false //config.isDebugEnabled } } diff --git a/Trust/Exchange/Types/ExchangeConfig.swift b/Trust/Exchange/Types/ExchangeConfig.swift index d4df7a5f3..cbd04b81f 100644 --- a/Trust/Exchange/Types/ExchangeConfig.swift +++ b/Trust/Exchange/Types/ExchangeConfig.swift @@ -13,7 +13,7 @@ struct ExchangeConfig { var contract: Address? { switch server { - case .main, .classic, .poa, .ropsten: + case .main, .classic, .poa, .ropsten, .sokol: return nil case .kovan: return Address(string: "0x9044968086e365216cc9e441a8e2cea300dd7228") @@ -22,7 +22,7 @@ struct ExchangeConfig { var tokenAddress: Address { switch server { - case .main, .classic, .poa, .ropsten: + case .main, .classic, .poa, .ropsten, .sokol: return Address(string: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee") case .kovan: return Address(string: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee") diff --git a/Trust/Exchange/Types/ExchangeTokens.swift b/Trust/Exchange/Types/ExchangeTokens.swift index 734f0cd9b..b99984936 100644 --- a/Trust/Exchange/Types/ExchangeTokens.swift +++ b/Trust/Exchange/Types/ExchangeTokens.swift @@ -6,7 +6,7 @@ import TrustKeystore struct ExchangeTokens { static func get(for server: RPCServer) -> [ExchangeToken] { switch server { - case .main, .classic, .ropsten, .poa: + case .main, .classic, .ropsten, .poa, .sokol: return [ ExchangeToken(name: "Ethereum", address: Address(string: "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"), symbol: "ETH", image: R.image.token_eth(), decimals: 18), ] diff --git a/Trust/Settings/Types/Config.swift b/Trust/Settings/Types/Config.swift index 3c2142db4..37172ffb3 100644 --- a/Trust/Settings/Types/Config.swift +++ b/Trust/Settings/Types/Config.swift @@ -69,6 +69,7 @@ struct Config { case .kovan: return "https://kovan.infura.io/llyrtzQ3YhkdESt2Fzrk" case .ropsten: return "https://ropsten.infura.io/llyrtzQ3YhkdESt2Fzrk" case .poa: return "https://core.poa.network" + case .sokol: return "https://sokol.poa.network" } }() return URL(string: urlString)! @@ -82,6 +83,7 @@ struct Config { case .kovan: return "https://kovan.trustwalletapp.com" case .ropsten: return "https://ropsten.trustwalletapp.com" case .poa: return "https://poa.trustwalletapp.com" + case .sokol: return "https://trust-sokol.herokuapp.com" } }() return URL(string: urlString)! diff --git a/Trust/Settings/Types/ConfigExplorer.swift b/Trust/Settings/Types/ConfigExplorer.swift index b2f84a639..dc7891e47 100644 --- a/Trust/Settings/Types/ConfigExplorer.swift +++ b/Trust/Settings/Types/ConfigExplorer.swift @@ -26,6 +26,8 @@ struct ConfigExplorer { return endpoint + "/tx/" + ID case .poa: return endpoint + "/tx/" + ID + case .sokol: + return endpoint + "/txid/search/" + ID } }() return URL(string: urlString)! @@ -42,6 +44,8 @@ struct ConfigExplorer { case .ropsten: return "https://ropsten.etherscan.io" case .poa: + return "https://poaexplorer.com" + case .sokol: return "http://testnet.oracles.org:4000" } } diff --git a/Trust/Settings/Types/RPCServers.swift b/Trust/Settings/Types/RPCServers.swift index 1efe185b7..cfca3b26b 100644 --- a/Trust/Settings/Types/RPCServers.swift +++ b/Trust/Settings/Types/RPCServers.swift @@ -7,6 +7,7 @@ enum RPCServer: String { case kovan case ropsten case poa + case sokol case classic var chainID: Int { @@ -15,6 +16,7 @@ enum RPCServer: String { case .kovan: return 42 case .ropsten: return 3 case .poa: return 99 + case .sokol: return 77 case .classic: return 61 } } @@ -25,6 +27,7 @@ enum RPCServer: String { case .kovan: return "Kovan" case .ropsten: return "Ropsten" case .poa: return "POA Network" + case .sokol: return "Sokol" case .classic: return "Ethereum Classic" } } @@ -32,7 +35,7 @@ enum RPCServer: String { var isTestNetwork: Bool { switch self { case .main, .poa, .classic: return false - case .kovan, .ropsten: return true + case .kovan, .ropsten, .sokol: return true } } @@ -41,7 +44,7 @@ enum RPCServer: String { case .main: return "ETH" case .classic: return "ETC" case .kovan, .ropsten: return "ETH" - case .poa: return "POA" + case .poa, .sokol: return "POA" } } @@ -57,6 +60,7 @@ enum RPCServer: String { case RPCServer.kovan.name: return .kovan case RPCServer.ropsten.name: return .ropsten case RPCServer.poa.name: return .poa + case RPCServer.sokol.name: return .sokol default: return .main } }() @@ -70,6 +74,7 @@ enum RPCServer: String { case RPCServer.kovan.chainID: return .kovan case RPCServer.ropsten.chainID: return .ropsten case RPCServer.poa.chainID: return .poa + case RPCServer.sokol.chainID: return .sokol default: return .main } }() diff --git a/Trust/Settings/ViewControllers/SettingsViewController.swift b/Trust/Settings/ViewControllers/SettingsViewController.swift index 62ac9bc39..754e4ecea 100644 --- a/Trust/Settings/ViewControllers/SettingsViewController.swift +++ b/Trust/Settings/ViewControllers/SettingsViewController.swift @@ -72,7 +72,7 @@ class SettingsViewController: FormViewController { selectorController.sectionKeyForValue = { option in switch option { case .main, .classic, .poa: return "" - case .kovan, .ropsten: return NSLocalizedString("settings.network.test.label.title", value: "Test", comment: "") + case .kovan, .ropsten, .sokol: return NSLocalizedString("settings.network.test.label.title", value: "Test", comment: "") } } }.cellSetup { cell, _ in diff --git a/Trust/Settings/ViewModels/SettingsViewModel.swift b/Trust/Settings/ViewModels/SettingsViewModel.swift index 200936645..d69306011 100644 --- a/Trust/Settings/ViewModels/SettingsViewModel.swift +++ b/Trust/Settings/ViewModels/SettingsViewModel.swift @@ -19,6 +19,7 @@ struct SettingsViewModel { RPCServer.poa, RPCServer.kovan, RPCServer.ropsten, + RPCServer.sokol, ] } diff --git a/Trust/Tokens/Types/TokensDataStore.swift b/Trust/Tokens/Types/TokensDataStore.swift index 35a318091..4f08e153a 100644 --- a/Trust/Tokens/Types/TokensDataStore.swift +++ b/Trust/Tokens/Types/TokensDataStore.swift @@ -89,7 +89,7 @@ class TokensDataStore { } } updatePrices() - case .classic, .kovan, .poa, .ropsten: + case .classic, .kovan, .poa, .ropsten, .sokol: updatePrices() refreshBalance() } diff --git a/Trust/Transactions/ViewModels/TransactionDetailsViewModel.swift b/Trust/Transactions/ViewModels/TransactionDetailsViewModel.swift index f19b7a07c..891cb0f72 100644 --- a/Trust/Transactions/ViewModels/TransactionDetailsViewModel.swift +++ b/Trust/Transactions/ViewModels/TransactionDetailsViewModel.swift @@ -52,7 +52,7 @@ struct TransactionDetailsViewModel { var detailsAvailable: Bool { switch config.server { case .main, .classic, .kovan, .ropsten: return true - case .poa: return false + case .poa, .sokol: return false } } diff --git a/Trust/Transactions/ViewModels/TransactionsViewModel.swift b/Trust/Transactions/ViewModels/TransactionsViewModel.swift index 914bd834e..791f62557 100644 --- a/Trust/Transactions/ViewModels/TransactionsViewModel.swift +++ b/Trust/Transactions/ViewModels/TransactionsViewModel.swift @@ -83,7 +83,7 @@ struct TransactionsViewModel { var isBuyActionAvailable: Bool { switch config.server { case .main: return true - case .kovan, .classic, .ropsten, .poa: return false + case .kovan, .classic, .ropsten, .poa, .sokol: return false } } }