feat(settings): Fixed changing network urls (#14353)

This commit is contained in:
Cuteivist 2024-05-13 12:06:05 +02:00 committed by GitHub
parent 6caea1c56e
commit 406f12d239
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 26 additions and 17 deletions

View File

@ -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)

View File

@ -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.} =

View File

@ -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)

View File

@ -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)

View File

@ -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:

View File

@ -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) {

View File

@ -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
}
}

View File

@ -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)
}
}
}