diff --git a/src/app/modules/main/wallet_section/networks/controller.nim b/src/app/modules/main/wallet_section/networks/controller.nim index 4d2f544fc6..8ff3481d6e 100644 --- a/src/app/modules/main/wallet_section/networks/controller.nim +++ b/src/app/modules/main/wallet_section/networks/controller.nim @@ -64,8 +64,8 @@ proc isGoerliEnabled*(self: Controller): bool = proc toggleIsGoerliEnabled*(self: Controller) = self.walletAccountService.toggleIsGoerliEnabled() -proc updateNetworkEndPointValues*(self: Controller, chainId: int, newMainRpcInput, newFailoverRpcUrl: string, revertToDefault: bool) = - self.networkService.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl, revertToDefault) +proc updateNetworkEndPointValues*(self: Controller, chainId: int, testNetwork: bool, newMainRpcInput, newFailoverRpcUrl: string, revertToDefault: bool) = + self.networkService.updateNetworkEndPointValues(chainId, testNetwork, newMainRpcInput, newFailoverRpcUrl, revertToDefault) proc fetchChainIdForUrl*(self: Controller, url: string, isMainUrl: bool) = self.walletAccountService.fetchChainIdForUrl(url, isMainUrl) diff --git a/src/app/modules/main/wallet_section/networks/io_interface.nim b/src/app/modules/main/wallet_section/networks/io_interface.nim index 9a908ae465..4cf9bb6b5c 100644 --- a/src/app/modules/main/wallet_section/networks/io_interface.nim +++ b/src/app/modules/main/wallet_section/networks/io_interface.nim @@ -38,7 +38,7 @@ method setNetworksState*(self: AccessInterface, chainIds: seq[int], enable: bool method refreshNetworks*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") -method updateNetworkEndPointValues*(self: AccessInterface, chainId: int, newMainRpcInput, newFailoverRpcUrl: string, revertToDefault: bool) {.base.} = +method updateNetworkEndPointValues*(self: AccessInterface, chainId: int, testNetwork: bool, newMainRpcInput, newFailoverRpcUrl: string, revertToDefault: bool) {.base.} = raise newException(ValueError, "No implementation available") method fetchChainIdForUrl*(self: AccessInterface, url: string, isMainUrl: bool) {.base.} = diff --git a/src/app/modules/main/wallet_section/networks/module.nim b/src/app/modules/main/wallet_section/networks/module.nim index d69799a99c..b44f11eef3 100644 --- a/src/app/modules/main/wallet_section/networks/module.nim +++ b/src/app/modules/main/wallet_section/networks/module.nim @@ -73,8 +73,8 @@ method toggleIsGoerliEnabled*(self: Module) = method setNetworksState*(self: Module, chainIds: seq[int], enabled: bool) = self.controller.setNetworksState(chainIds, enabled) -method updateNetworkEndPointValues*(self: Module, chainId: int, newMainRpcInput, newFailoverRpcUrl: string, revertToDefault: bool) = - self.controller.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl, revertToDefault) +method updateNetworkEndPointValues*(self: Module, chainId: int, testNetwork: bool, newMainRpcInput, newFailoverRpcUrl: string, revertToDefault: bool) = + self.controller.updateNetworkEndPointValues(chainId, testNetwork, newMainRpcInput, newFailoverRpcUrl, revertToDefault) method fetchChainIdForUrl*(self: Module, url: string, isMainUrl: bool) = self.controller.fetchChainIdForUrl(url, isMainUrl) diff --git a/src/app/modules/main/wallet_section/networks/view.nim b/src/app/modules/main/wallet_section/networks/view.nim index 84220eacd4..4a4df17499 100644 --- a/src/app/modules/main/wallet_section/networks/view.nim +++ b/src/app/modules/main/wallet_section/networks/view.nim @@ -100,8 +100,8 @@ QtObject: proc getBlockExplorerURL*(self: View, chainId: int): string {.slot.} = return self.flatNetworks.getBlockExplorerURL(chainId) - proc updateNetworkEndPointValues*(self: View, chainId: int, newMainRpcInput: string, newFailoverRpcUrl: string, revertToDefault: bool) {.slot.} = - self.delegate.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl, revertToDefault) + proc updateNetworkEndPointValues*(self: View, chainId: int, testNetwork: bool, newMainRpcInput: string, newFailoverRpcUrl: string, revertToDefault: bool) {.slot.} = + self.delegate.updateNetworkEndPointValues(chainId, testNetwork, newMainRpcInput, newFailoverRpcUrl, revertToDefault) proc fetchChainIdForUrl*(self: View, url: string, isMainUrl: bool) {.slot.} = self.delegate.fetchChainIdForUrl(url, isMainUrl) diff --git a/src/app_service/service/network/service.nim b/src/app_service/service/network/service.nim index 481887687c..15bc9cc0f5 100644 --- a/src/app_service/service/network/service.nim +++ b/src/app_service/service/network/service.nim @@ -93,11 +93,10 @@ proc upsertNetwork*(self: Service, network: NetworkItem): bool = proc deleteNetwork*(self: Service, network: NetworkItem) = discard backend.deleteEthereumChain(network.chainId) -proc getNetworkByChainId*(self: Service, chainId: int): NetworkItem = +proc getNetworkByChainId*(self: Service, chainId: int, testNetworksEnabled: bool): NetworkItem = var networks = self.combinedNetworks if self.combinedNetworks.len == 0: networks = self.fetchNetworks() - let testNetworksEnabled = self.settingsService.areTestNetworksEnabled() for network in networks: let net = if testNetworksEnabled: network.test else: network.prod @@ -105,6 +104,9 @@ proc getNetworkByChainId*(self: Service, chainId: int): NetworkItem = return net return nil +proc getNetworkByChainId*(self: Service, chainId: int): NetworkItem = + return self.getNetworkByChainId(chainId, self.settingsService.areTestNetworksEnabled()) + proc setNetworksState*(self: Service, chainIds: seq[int], enabled: bool) = for chainId in chainIds: let network = self.getNetworkByChainId(chainId) @@ -140,8 +142,8 @@ proc getAppNetwork*(self: Service): NetworkItem = quit() # quit the app return network -proc updateNetworkEndPointValues*(self: Service, chainId: int, newMainRpcInput, newFailoverRpcUrl: string, revertToDefault: bool) = - let network = self.getNetworkByChainId(chainId) +proc updateNetworkEndPointValues*(self: Service, chainId: int, testNetwork: bool, newMainRpcInput, newFailoverRpcUrl: string, revertToDefault: bool) = + let network = self.getNetworkByChainId(chainId, testNetwork) if not network.isNil: if network.rpcURL != newMainRpcInput: diff --git a/ui/app/AppLayouts/Profile/stores/WalletStore.qml b/ui/app/AppLayouts/Profile/stores/WalletStore.qml index ce470e5f8c..7d309d2ba5 100644 --- a/ui/app/AppLayouts/Profile/stores/WalletStore.qml +++ b/ui/app/AppLayouts/Profile/stores/WalletStore.qml @@ -108,8 +108,8 @@ QtObject { return networksModuleInst.fetchChainIdForUrl(url, isMainUrl) } - function updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl, revertToDefault) { - networksModuleInst.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl, revertToDefault) + function updateNetworkEndPointValues(chainId, testNetwork, newMainRpcInput, newFailoverRpcUrl, revertToDefault) { + networksModuleInst.updateNetworkEndPointValues(chainId, testNetwork, newMainRpcInput, newFailoverRpcUrl, revertToDefault) } function updateWalletAccountPreferredChains(address, preferredChainIds) { diff --git a/ui/app/AppLayouts/Profile/views/WalletView.qml b/ui/app/AppLayouts/Profile/views/WalletView.qml index 610bbeac80..711fa26329 100644 --- a/ui/app/AppLayouts/Profile/views/WalletView.qml +++ b/ui/app/AppLayouts/Profile/views/WalletView.qml @@ -264,9 +264,10 @@ SettingsContentBase { Layout.fillWidth: true networksModule: root.walletStore.networksModuleInst networkRPCChanged: root.walletStore.networkRPCChanged + areTestNetworksEnabled: root.walletStore.areTestNetworksEnabled onEvaluateRpcEndPoint: root.walletStore.evaluateRpcEndPoint(url, isMainUrl) onUpdateNetworkValues: { - root.walletStore.updateNetworkEndPointValues(chainId, newMainRpcInput, newFailoverRpcUrl, revertToDefault) + root.walletStore.updateNetworkEndPointValues(chainId, testNetwork, newMainRpcInput, newFailoverRpcUrl, revertToDefault) stackContainer.currentIndex = networksViewIndex } } diff --git a/ui/app/AppLayouts/Profile/views/wallet/EditNetworkView.qml b/ui/app/AppLayouts/Profile/views/wallet/EditNetworkView.qml index a727c7582f..c59dad4ee7 100644 --- a/ui/app/AppLayouts/Profile/views/wallet/EditNetworkView.qml +++ b/ui/app/AppLayouts/Profile/views/wallet/EditNetworkView.qml @@ -13,9 +13,15 @@ ColumnLayout { property var networksModule property var combinedNetwork property var networkRPCChanged + property bool areTestNetworksEnabled: false signal evaluateRpcEndPoint(string url, bool isMainUrl) - signal updateNetworkValues(int chainId, string newMainRpcInput, string newFailoverRpcUrl, bool revertToDefault) + signal updateNetworkValues(int chainId, bool testNetwork, string newMainRpcInput, string newFailoverRpcUrl, bool revertToDefault) + + onVisibleChanged: { + if (visible) + editPreviwTabBar.currentIndex = root.areTestNetworksEnabled ? 1 : 0 + } StatusTabBar { id: editPreviwTabBar @@ -47,7 +53,7 @@ ColumnLayout { networksModule: root.networksModule networkRPCChanged: root.networkRPCChanged onEvaluateRpcEndPoint: root.evaluateRpcEndPoint(url, isMainUrl) - onUpdateNetworkValues: root.updateNetworkValues(chainId, newMainRpcInput, newFailoverRpcUrl, revertToDefault) + onUpdateNetworkValues: root.updateNetworkValues(chainId, false, newMainRpcInput, newFailoverRpcUrl, revertToDefault) } } @@ -58,7 +64,7 @@ ColumnLayout { networksModule: root.networksModule networkRPCChanged: root.networkRPCChanged onEvaluateRpcEndPoint: root.evaluateRpcEndPoint(url, isMainUrl) - onUpdateNetworkValues: root.updateNetworkValues(chainId, newMainRpcInput, newFailoverRpcUrl, revertToDefault) + onUpdateNetworkValues: root.updateNetworkValues(chainId, true, newMainRpcInput, newFailoverRpcUrl, revertToDefault) } } }