From cff0d192f833564f9c912e8356649fd021b64958 Mon Sep 17 00:00:00 2001 From: Vladyslav shepitko Date: Tue, 5 Oct 2021 10:59:18 +0300 Subject: [PATCH] Integrate Ethermine (TaiChi replacement) #3266 --- .../Analytics/Models/AnalyticsTypes.swift | 1 + .../Contents.json | 21 +++++++++++++ .../icons-settings-taichi.svg | 8 +++++ AlphaWallet/Core/Features.swift | 1 + .../Localization/en.lproj/Localizable.strings | 1 + .../Localization/es.lproj/Localizable.strings | 1 + .../Localization/ja.lproj/Localizable.strings | 1 + .../Localization/ko.lproj/Localizable.strings | 1 + .../zh-Hans.lproj/Localizable.strings | 1 + AlphaWallet/Settings/Types/Config.swift | 16 ++++++++++ .../AdvancedSettingsViewController.swift | 31 +++++++++++++++++-- .../AdvancedSettingsViewModel.swift | 10 ++++-- ...nTransactionEtherscanDataCoordinator.swift | 2 +- .../SendTransactionCoordinator.swift | 17 +++++++++- .../TransactionConfirmationCoordinator.swift | 3 +- 15 files changed, 107 insertions(+), 8 deletions(-) create mode 100644 AlphaWallet/Assets.xcassets/iconsSettingsTaiChi.imageset/Contents.json create mode 100644 AlphaWallet/Assets.xcassets/iconsSettingsTaiChi.imageset/icons-settings-taichi.svg diff --git a/AlphaWallet/Analytics/Models/AnalyticsTypes.swift b/AlphaWallet/Analytics/Models/AnalyticsTypes.swift index 3dec0791c..f9009eb51 100644 --- a/AlphaWallet/Analytics/Models/AnalyticsTypes.swift +++ b/AlphaWallet/Analytics/Models/AnalyticsTypes.swift @@ -72,6 +72,7 @@ enum Analytics { case transactionType case name case messageType + case isPrivateNetworkEnabled case type case isAllFunds case addCustomChainType diff --git a/AlphaWallet/Assets.xcassets/iconsSettingsTaiChi.imageset/Contents.json b/AlphaWallet/Assets.xcassets/iconsSettingsTaiChi.imageset/Contents.json new file mode 100644 index 000000000..8ad4d3027 --- /dev/null +++ b/AlphaWallet/Assets.xcassets/iconsSettingsTaiChi.imageset/Contents.json @@ -0,0 +1,21 @@ +{ + "images" : [ + { + "filename" : "icons-settings-taichi.svg", + "idiom" : "universal", + "scale" : "1x" + }, + { + "idiom" : "universal", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/AlphaWallet/Assets.xcassets/iconsSettingsTaiChi.imageset/icons-settings-taichi.svg b/AlphaWallet/Assets.xcassets/iconsSettingsTaiChi.imageset/icons-settings-taichi.svg new file mode 100644 index 000000000..c16cc0ad5 --- /dev/null +++ b/AlphaWallet/Assets.xcassets/iconsSettingsTaiChi.imageset/icons-settings-taichi.svg @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/AlphaWallet/Core/Features.swift b/AlphaWallet/Core/Features.swift index b921ea8ef..f0c7ffa41 100644 --- a/AlphaWallet/Core/Features.swift +++ b/AlphaWallet/Core/Features.swift @@ -14,4 +14,5 @@ enum Features { static let isPromptForEmailListSubscriptionEnabled = true static let isAlertsEnabled = false static let isErc1155Enabled = true + static let isUsingPrivateNetwork = false } diff --git a/AlphaWallet/Localization/en.lproj/Localizable.strings b/AlphaWallet/Localization/en.lproj/Localizable.strings index 9cfea7dda..03efcdf27 100644 --- a/AlphaWallet/Localization/en.lproj/Localizable.strings +++ b/AlphaWallet/Localization/en.lproj/Localizable.strings @@ -89,6 +89,7 @@ "settings.backupWallet.button.title" = "Back up this Wallet"; "settings.showSeedPhrase.button.title" = "Show Seed Phrase"; "settings.walletConnect.button.title" = "WalletConnect"; +"settings.useEthermineNetwork.button.title" = "Use Ethermine for Ethereum"; "settings.language.useSystem.title" = "Use System Setting"; "settings.version.label.title" = "Version"; "settings.tokenScriptStandard.title" = "TokenScript Compatibility"; diff --git a/AlphaWallet/Localization/es.lproj/Localizable.strings b/AlphaWallet/Localization/es.lproj/Localizable.strings index dab82b00c..4f3dd4fa1 100644 --- a/AlphaWallet/Localization/es.lproj/Localizable.strings +++ b/AlphaWallet/Localization/es.lproj/Localizable.strings @@ -89,6 +89,7 @@ "settings.backupWallet.button.title" = "Hacer una copia de seguridad de este monedero"; "settings.showSeedPhrase.button.title" = "Show Seed Phrase"; "settings.walletConnect.button.title" = "WalletConnect"; +"settings.useEthermineNetwork.button.title" = "Use Ethermine for Ethereum"; "settings.language.useSystem.title" = "Usar la configuración del sistema"; "settings.version.label.title" = "Versión"; "settings.tokenScriptStandard.title" = "Compatibilidad de TokenScript"; diff --git a/AlphaWallet/Localization/ja.lproj/Localizable.strings b/AlphaWallet/Localization/ja.lproj/Localizable.strings index 8a4e8ca61..c8702fe4f 100644 --- a/AlphaWallet/Localization/ja.lproj/Localizable.strings +++ b/AlphaWallet/Localization/ja.lproj/Localizable.strings @@ -89,6 +89,7 @@ "settings.backupWallet.button.title" = "Back up this Wallet"; "settings.showSeedPhrase.button.title" = "Show Seed Phrase"; "settings.walletConnect.button.title" = "WalletConnect"; +"settings.useEthermineNetwork.button.title" = "Use Ethermine for Ethereum"; "settings.language.useSystem.title" = "システム設定を使用"; "settings.version.label.title" = "バージョン"; "settings.tokenScriptStandard.title" = "TokenScript Compatibility"; diff --git a/AlphaWallet/Localization/ko.lproj/Localizable.strings b/AlphaWallet/Localization/ko.lproj/Localizable.strings index baea3c190..e23592f24 100644 --- a/AlphaWallet/Localization/ko.lproj/Localizable.strings +++ b/AlphaWallet/Localization/ko.lproj/Localizable.strings @@ -89,6 +89,7 @@ "settings.backupWallet.button.title" = "Back up this Wallet"; "settings.showSeedPhrase.button.title" = "Show Seed Phrase"; "settings.walletConnect.button.title" = "WalletConnect"; +"settings.useEthermineNetwork.button.title" = "Use Ethermine for Ethereum"; "settings.language.useSystem.title" = "시스템 설정 사용"; "settings.version.label.title" = "버전"; "settings.tokenScriptStandard.title" = "TokenScript Compatibility"; diff --git a/AlphaWallet/Localization/zh-Hans.lproj/Localizable.strings b/AlphaWallet/Localization/zh-Hans.lproj/Localizable.strings index bc2620b3f..98b5e5509 100644 --- a/AlphaWallet/Localization/zh-Hans.lproj/Localizable.strings +++ b/AlphaWallet/Localization/zh-Hans.lproj/Localizable.strings @@ -89,6 +89,7 @@ "settings.backupWallet.button.title" = "备份此钱包"; "settings.showSeedPhrase.button.title" = "Show Seed Phrase"; "settings.walletConnect.button.title" = "WalletConnect"; +"settings.useEthermineNetwork.button.title" = "Use Ethermine for Ethereum"; "settings.language.useSystem.title" = "使用系统设置"; "settings.version.label.title" = "版本"; "settings.tokenScriptStandard.title" = "TokenScript 兼容性"; diff --git a/AlphaWallet/Settings/Types/Config.swift b/AlphaWallet/Settings/Types/Config.swift index 607c17c1f..135396145 100644 --- a/AlphaWallet/Settings/Types/Config.swift +++ b/AlphaWallet/Settings/Types/Config.swift @@ -153,12 +153,27 @@ struct Config { static let lastFetchedAutoDetectedTransactedTokenErc721BlockNumber = "lastFetchedAutoDetectedTransactedTokenErc721BlockNumber" static let lastFetchedAutoDetectedTransactedTokenNonErc20BlockNumber = "lastFetchedAutoDetectedTransactedTokenNonErc20BlockNumber" static let walletNames = "walletNames" + static let usePrivateNetwork = "usePrivateNetworkKey" static let customRpcServers = "customRpcServers" static let homePageURL = "homePageURL" } let defaults: UserDefaults + var usePrivateNetwork: Bool { + get { + guard Features.isUsingPrivateNetwork else { return false } + + return defaults.bool(forKey: Keys.usePrivateNetwork) + } + + set { + guard Features.isUsingPrivateNetwork else { return } + + defaults.set(newValue, forKey: Keys.usePrivateNetwork) + } + } + var enabledServers: [RPCServer] { get { if let chainIds = defaults.array(forKey: Keys.enabledServers) as? [Int] { @@ -234,6 +249,7 @@ struct Config { let oneInch = URL(string: "https://api.1inch.exchange")! let honeySwapTokens = URL(string: "https://tokens.honeyswap.org/")! let rampAssets = URL(string: "https://api-instant.ramp.network")! + let privateRpcUrl = URL(string: "https://rpc.ethermine.org") func anyEnabledServer() -> RPCServer { let servers = enabledServers diff --git a/AlphaWallet/Settings/ViewControllers/AdvancedSettingsViewController.swift b/AlphaWallet/Settings/ViewControllers/AdvancedSettingsViewController.swift index a5e8f6fbd..b558fcdb8 100644 --- a/AlphaWallet/Settings/ViewControllers/AdvancedSettingsViewController.swift +++ b/AlphaWallet/Settings/ViewControllers/AdvancedSettingsViewController.swift @@ -73,10 +73,33 @@ extension AdvancedSettingsViewController: UITableViewDataSource { func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let row = viewModel.rows[indexPath.row] - let cell: SettingTableViewCell = tableView.dequeueReusableCell(for: indexPath) - cell.configure(viewModel: .init(titleText: row.title, subTitleText: nil, icon: row.icon)) + switch row { + case .analytics, .changeCurrency, .changeLanguage, .clearBrowserCache, .console, .tokenScript: + let cell: SettingTableViewCell = tableView.dequeueReusableCell(for: indexPath) + cell.configure(viewModel: .init(titleText: row.title, subTitleText: nil, icon: row.icon)) + + return cell + case .usePrivateNetwork: + let cell: SwitchTableViewCell = tableView.dequeueReusableCell(for: indexPath) + cell.configure(viewModel: .init(titleText: row.title, icon: row.icon, value: config.usePrivateNetwork)) + cell.delegate = self + + return cell + } + } +} + +extension AdvancedSettingsViewController: SwitchTableViewCellDelegate { - return cell + func cell(_ cell: SwitchTableViewCell, switchStateChanged isOn: Bool) { + guard let indexPath = cell.indexPath else { return } + + switch viewModel.rows[indexPath.row] { + case .analytics, .changeCurrency, .changeLanguage, .clearBrowserCache, .console, .tokenScript: + break + case .usePrivateNetwork: + config.usePrivateNetwork = isOn + } } } @@ -116,6 +139,8 @@ extension AdvancedSettingsViewController: UITableViewDelegate { delegate?.advancedSettingsViewControllerChangeCurrencySelected(in: self) case .analytics: delegate?.advancedSettingsViewControllerAnalyticsSelected(in: self) + case .usePrivateNetwork: + break } } } diff --git a/AlphaWallet/Settings/ViewModels/AdvancedSettingsViewModel.swift b/AlphaWallet/Settings/ViewModels/AdvancedSettingsViewModel.swift index f73ad77fd..116de4514 100644 --- a/AlphaWallet/Settings/ViewModels/AdvancedSettingsViewModel.swift +++ b/AlphaWallet/Settings/ViewModels/AdvancedSettingsViewModel.swift @@ -10,10 +10,11 @@ import UIKit struct AdvancedSettingsViewModel { var rows: [AdvancedSettingsRow] = { + let privateNerworkRow: [AdvancedSettingsRow] = Features.isUsingPrivateNetwork ? [.usePrivateNetwork] : [] if Features.isLanguageSwitcherDisabled { - return [.console, .clearBrowserCache, .tokenScript] + return [.console, .clearBrowserCache, .tokenScript] + privateNerworkRow } else { - return [.console, .clearBrowserCache, .tokenScript, .changeLanguage] + return [.console, .clearBrowserCache, .tokenScript, .changeLanguage] + privateNerworkRow } }() @@ -29,6 +30,7 @@ enum AdvancedSettingsRow: CaseIterable { case changeLanguage case changeCurrency case analytics + case usePrivateNetwork var title: String { switch self { @@ -44,6 +46,8 @@ enum AdvancedSettingsRow: CaseIterable { return R.string.localizable.settingsChangeCurrencyTitle() case .analytics: return R.string.localizable.settingsAnalitycsTitle() + case .usePrivateNetwork: + return R.string.localizable.settingsUseEthermineNetworkButtonTitle() } } @@ -61,6 +65,8 @@ enum AdvancedSettingsRow: CaseIterable { return R.image.settings_currency()! case .analytics: return R.image.settings_analytics()! + case .usePrivateNetwork: + return R.image.iconsSettingsTaiChi()! } } } diff --git a/AlphaWallet/Transactions/Coordinators/SingleChainTransactionEtherscanDataCoordinator.swift b/AlphaWallet/Transactions/Coordinators/SingleChainTransactionEtherscanDataCoordinator.swift index 83d7b414d..b4de42f0b 100644 --- a/AlphaWallet/Transactions/Coordinators/SingleChainTransactionEtherscanDataCoordinator.swift +++ b/AlphaWallet/Transactions/Coordinators/SingleChainTransactionEtherscanDataCoordinator.swift @@ -245,7 +245,7 @@ class SingleChainTransactionEtherscanDataCoordinator: SingleChainTransactionData strongSelf.delete(transactions: [transaction]) } }).cauterize() - //The transaction might not be posted to this node yet (ie. it doesn't even think that this transaction is pending). Especially common if we post a transaction to TaiChi and fetch pending status through Etherscan + //The transaction might not be posted to this node yet (ie. it doesn't even think that this transaction is pending). Especially common if we post a transaction to Ethermine and fetch pending status through Etherscan case .responseNotFound, .errorObjectParseError, .unsupportedVersion, .unexpectedTypeObject, .missingBothResultAndError, .nonArrayResponse, .none: break } diff --git a/AlphaWallet/Transfer/Coordinators/SendTransactionCoordinator.swift b/AlphaWallet/Transfer/Coordinators/SendTransactionCoordinator.swift index 2f5ebc50c..91cf17134 100644 --- a/AlphaWallet/Transfer/Coordinators/SendTransactionCoordinator.swift +++ b/AlphaWallet/Transfer/Coordinators/SendTransactionCoordinator.swift @@ -100,7 +100,22 @@ class SendTransactionCoordinator { } private var rpcURL: URL { - session.server.rpcURL + session.server.rpcURLReplaceMainWithPrivateNetworkIfNeeded(config: config) + } +} + +fileprivate extension RPCServer { + func rpcURLReplaceMainWithPrivateNetworkIfNeeded(config: Config) -> URL { + switch self { + case .main where config.usePrivateNetwork: + if let url = config.privateRpcUrl { + return url + } else { + return rpcURL + } + case .xDai, .kovan, .ropsten, .rinkeby, .poa, .sokol, .classic, .callisto, .goerli, .artis_sigma1, .artis_tau1, .binance_smart_chain, .binance_smart_chain_testnet, .custom, .heco, .heco_testnet, .main, .fantom, .fantom_testnet, .avalanche, .avalanche_testnet, .polygon, .mumbai_testnet, .optimistic, .optimisticKovan, .cronosTestnet: + return self.rpcURL + } } } diff --git a/AlphaWallet/Transfer/Coordinators/TransactionConfirmationCoordinator.swift b/AlphaWallet/Transfer/Coordinators/TransactionConfirmationCoordinator.swift index fdb322ff3..67de53110 100644 --- a/AlphaWallet/Transfer/Coordinators/TransactionConfirmationCoordinator.swift +++ b/AlphaWallet/Transfer/Coordinators/TransactionConfirmationCoordinator.swift @@ -326,7 +326,8 @@ extension TransactionConfirmationCoordinator { var analyticsProperties: [String: AnalyticsEventPropertyValue] = [ Analytics.Properties.speedType.rawValue: speedType.rawValue, Analytics.Properties.chain.rawValue: server.chainID, - Analytics.Properties.transactionType.rawValue: transactionType.rawValue + Analytics.Properties.transactionType.rawValue: transactionType.rawValue, + Analytics.Properties.isPrivateNetworkEnabled.rawValue: configurator.session.config.usePrivateNetwork, ] switch configuration { case .sendFungiblesTransaction(_, _, _, amount: let amount, _):