diff --git a/src/app/modules/main/browser_section/current_account/controller.nim b/src/app/modules/main/browser_section/current_account/controller.nim index 5d5ab67bae..0d912296f0 100644 --- a/src/app/modules/main/browser_section/current_account/controller.nim +++ b/src/app/modules/main/browser_section/current_account/controller.nim @@ -43,10 +43,10 @@ proc getIndex*(self: Controller, address: string): int = return self.walletAccountService.getIndex(address) proc getChainIds*(self: Controller): seq[int] = - return self.networkService.getNetworks().map(n => n.chainId) + return self.networkService.getCurrentNetworks().map(n => n.chainId) proc getEnabledChainIds*(self: Controller): seq[int] = - return self.networkService.getNetworks().filter(n => n.enabled).map(n => n.chainId) + return self.networkService.getCurrentNetworks().filter(n => n.enabled).map(n => n.chainId) proc getCurrentCurrency*(self: Controller): string = return self.walletAccountService.getCurrency() diff --git a/src/app/modules/main/chat_section/controller.nim b/src/app/modules/main/chat_section/controller.nim index 61aa898a13..e6bdb0743e 100644 --- a/src/app/modules/main/chat_section/controller.nim +++ b/src/app/modules/main/chat_section/controller.nim @@ -713,9 +713,9 @@ proc getContractAddressesForToken*(self: Controller, symbol: string): Table[int, let token = self.tokenService.findTokenBySymbol(symbol) if token != nil: for addrPerChain in token.addressPerChainId: - # depending on areTestNetworksEnabled (in getNetwork), contractAddresses will + # depending on areTestNetworksEnabled (in getNetworkByChainId), contractAddresses will # contain mainnets or testnets only - let network = self.networkService.getNetwork(addrPerChain.chainId) + let network = self.networkService.getNetworkByChainId(addrPerChain.chainId) if network == nil: continue contractAddresses[addrPerChain.chainId] = addrPerChain.address diff --git a/src/app/modules/main/communities/controller.nim b/src/app/modules/main/communities/controller.nim index 2a85b78736..d230655a0a 100644 --- a/src/app/modules/main/communities/controller.nim +++ b/src/app/modules/main/communities/controller.nim @@ -372,8 +372,8 @@ proc getCommunityTokens*(self: Controller, communityId: string): seq[CommunityTo proc getAllCommunityTokens*(self: Controller): seq[CommunityTokenDto] = self.communityTokensService.getAllCommunityTokens() -proc getNetwork*(self:Controller, chainId: int): NetworkDto = - self.networksService.getNetwork(chainId) +proc getNetworkByChainId*(self:Controller, chainId: int): NetworkDto = + self.networksService.getNetworkByChainId(chainId) proc getTokenBySymbolList*(self: Controller): seq[TokenBySymbolItem] = return self.tokenService.getTokenBySymbolList() @@ -480,8 +480,8 @@ proc runSigningOnKeycard*(self: Controller, keyUid: string, path: string, dataTo proc removeCommunityChat*(self: Controller, communityId: string, channelId: string) = self.communityService.deleteCommunityChat(communityId, channelId) -proc getNetworks*(self: Controller): seq[NetworkDto] = - return self.networksService.getNetworks() +proc getCurrentNetworks*(self: Controller): seq[NetworkDto] = + return self.networksService.getCurrentNetworks() proc promoteSelfToControlNode*(self: Controller, communityId: string) = self.communityService.promoteSelfToControlNode(communityId) diff --git a/src/app/modules/main/communities/module.nim b/src/app/modules/main/communities/module.nim index 98b6c9ab91..bfc58e0bdc 100644 --- a/src/app/modules/main/communities/module.nim +++ b/src/app/modules/main/communities/module.nim @@ -613,7 +613,7 @@ proc buildTokensAndCollectiblesFromWallet(self: Module) = var tokenListItems: seq[TokenListItem] # Common ERC20 tokens - let allNetworks = self.controller.getNetworks().map(n => n.chainId) + let allNetworks = self.controller.getCurrentNetworks().map(n => n.chainId) let erc20Tokens = self.controller.getTokenBySymbolList().filter(t => (block: let filteredChains = t.addressPerChainId.filter(apC => allNetworks.contains(apc.chainId)) return filteredChains.len != 0 diff --git a/src/app/modules/main/communities/tokens/controller.nim b/src/app/modules/main/communities/tokens/controller.nim index db126fbba3..768b48e193 100644 --- a/src/app/modules/main/communities/tokens/controller.nim +++ b/src/app/modules/main/communities/tokens/controller.nim @@ -159,8 +159,8 @@ proc findContractByUniqueId*(self: Controller, contractUniqueKey: string): Commu proc computeBurnFee*(self: Controller, contractUniqueKey: string, amount: Uint256, addressFrom: string, requestId: string) = self.communityTokensService.computeBurnFee(contractUniqueKey, amount, addressFrom, requestId) -proc getNetwork*(self:Controller, chainId: int): NetworkDto = - self.networksService.getNetwork(chainId) +proc getNetworkByChainId*(self:Controller, chainId: int): NetworkDto = + self.networksService.getNetworkByChainId(chainId) proc getOwnerToken*(self: Controller, communityId: string): CommunityTokenDto = return self.communityTokensService.getOwnerToken(communityId) diff --git a/src/app/modules/main/communities/tokens/module.nim b/src/app/modules/main/communities/tokens/module.nim index fc89e12aee..3f11d06ca6 100644 --- a/src/app/modules/main/communities/tokens/module.nim +++ b/src/app/modules/main/communities/tokens/module.nim @@ -299,11 +299,11 @@ method computeBurnFee*(self: Module, contractUniqueKey: string, amount: string, self.controller.computeBurnFee(contractUniqueKey, amount.parse(Uint256), addressFrom, requestId) proc createUrl(self: Module, chainId: int, transactionHash: string): string = - let network = self.controller.getNetwork(chainId) + let network = self.controller.getNetworkByChainId(chainId) result = if network != nil: network.blockExplorerURL & "/tx/" & transactionHash else: "" proc getChainName(self: Module, chainId: int): string = - let network = self.controller.getNetwork(chainId) + let network = self.controller.getNetworkByChainId(chainId) result = if network != nil: network.chainName else: "" method onCommunityTokenDeployStateChanged*(self: Module, communityId: string, chainId: int, transactionHash: string, deployState: DeployState) = diff --git a/src/app/modules/main/controller.nim b/src/app/modules/main/controller.nim index 3508a8752f..408ac4e749 100644 --- a/src/app/modules/main/controller.nim +++ b/src/app/modules/main/controller.nim @@ -573,8 +573,8 @@ proc getRemainingSupply*(self: Controller, chainId: int, contractAddress: string proc getRemoteDestructedAmount*(self: Controller, chainId: int, contractAddress: string): Uint256 = return self.communityTokensService.getRemoteDestructedAmount(chainId, contractAddress) -proc getNetwork*(self:Controller, chainId: int): NetworkDto = - self.networksService.getNetwork(chainId) +proc getNetworkByChainId*(self:Controller, chainId: int): NetworkDto = + self.networksService.getNetworkByChainId(chainId) proc getAppNetwork*(self:Controller): NetworkDto = self.networksService.getAppNetwork() diff --git a/src/app/modules/main/module.nim b/src/app/modules/main/module.nim index 86108f1b03..b1055fda29 100644 --- a/src/app/modules/main/module.nim +++ b/src/app/modules/main/module.nim @@ -266,7 +266,7 @@ method onAppNetworkChanged*[T](self: Module[T]) = self.view.emitAppNetworkChangedSignal() proc createTokenItem[T](self: Module[T], tokenDto: CommunityTokenDto) : token_item.TokenItem = - let network = self.controller.getNetwork(tokenDto.chainId) + let network = self.controller.getNetworkByChainId(tokenDto.chainId) let tokenOwners = self.controller.getCommunityTokenOwners(tokenDto.communityId, tokenDto.chainId, tokenDto.address) let ownerAddressName = if len(tokenDto.deployer) > 0: self.controller.getCommunityTokenOwnerName(tokenDto.deployer) else: "" let remainingSupply = if tokenDto.infiniteSupply: stint.parse("0", Uint256) else: self.controller.getRemainingSupply(tokenDto.chainId, tokenDto.address) @@ -277,7 +277,7 @@ proc createTokenItem[T](self: Module[T], tokenDto: CommunityTokenDto) : token_it proc createTokenItemImproved[T](self: Module[T], tokenDto: CommunityTokenDto, communityTokenJsonItems: JsonNode) : token_item.TokenItem = # These 3 values come from local caches so they can be done sync - let network = self.controller.getNetwork(tokenDto.chainId) + let network = self.controller.getNetworkByChainId(tokenDto.chainId) let tokenOwners = self.controller.getCommunityTokenOwners(tokenDto.communityId, tokenDto.chainId, tokenDto.address) let ownerAddressName = if len(tokenDto.deployer) > 0: self.controller.getCommunityTokenOwnerName(tokenDto.deployer) else: "" diff --git a/src/app/modules/main/profile_section/profile/controller.nim b/src/app/modules/main/profile_section/profile/controller.nim index e4afc26311..859d017cf3 100644 --- a/src/app/modules/main/profile_section/profile/controller.nim +++ b/src/app/modules/main/profile_section/profile/controller.nim @@ -102,10 +102,10 @@ proc getWalletAccounts*(self: Controller): seq[wallet_account_service.WalletAcco self.walletAccountService.getWalletAccounts(true) proc getChainIds*(self: Controller): seq[int] = - self.networkService.getNetworks().map(n => n.chainId) + self.networkService.getCurrentNetworks().map(n => n.chainId) proc getEnabledChainIds*(self: Controller): seq[int] = - self.networkService.getNetworks().filter(n => n.enabled).map(n => n.chainId) + self.networkService.getCurrentNetworks().filter(n => n.enabled).map(n => n.chainId) proc setSocialLinks*(self: Controller, links: SocialLinks) = self.settingsService.setSocialLinks(links) diff --git a/src/app/modules/main/profile_section/wallet/networks/controller.nim b/src/app/modules/main/profile_section/wallet/networks/controller.nim index 5ec5e2d69a..02d1c7ec25 100644 --- a/src/app/modules/main/profile_section/wallet/networks/controller.nim +++ b/src/app/modules/main/profile_section/wallet/networks/controller.nim @@ -41,7 +41,7 @@ proc init*(self: Controller) = self.events.on(SIGNAL_NETWORK_ENDPOINT_UPDATED) do(e: Args): self.delegate.refreshNetworks() -proc getNetworks*(self: Controller): seq[CombinedNetworkDto] = +proc getCombinedNetworks*(self: Controller): seq[CombinedNetworkDto] = return self.networkService.getCombinedNetworks() proc areTestNetworksEnabled*(self: Controller): bool = diff --git a/src/app/modules/main/profile_section/wallet/networks/module.nim b/src/app/modules/main/profile_section/wallet/networks/module.nim index bb6a2ad4b7..19eb9d4c40 100644 --- a/src/app/modules/main/profile_section/wallet/networks/module.nim +++ b/src/app/modules/main/profile_section/wallet/networks/module.nim @@ -41,7 +41,7 @@ method getModuleAsVariant*(self: Module): QVariant = method refreshNetworks*(self: Module) = var items: seq[Item] = @[] var combinedItems: seq[CombinedItem] = @[] - for n in self.controller.getNetworks(): + for n in self.controller.getCombinedNetworks(): var prod = newItem( n.prod.chainId, n.prod.layer, diff --git a/src/app/modules/main/wallet_section/accounts/controller.nim b/src/app/modules/main/wallet_section/accounts/controller.nim index 7803b581bf..352dd0439e 100644 --- a/src/app/modules/main/wallet_section/accounts/controller.nim +++ b/src/app/modules/main/wallet_section/accounts/controller.nim @@ -40,7 +40,7 @@ proc deleteAccount*(self: Controller, address: string) = self.walletAccountService.deleteAccount(address) proc getEnabledChainIds*(self: Controller): seq[int] = - return self.networkService.getNetworks().filter(n => n.enabled).map(n => n.chainId) + return self.networkService.getCurrentNetworks().filter(n => n.enabled).map(n => n.chainId) proc getCurrentCurrency*(self: Controller): string = return self.walletAccountService.getCurrency() diff --git a/src/app/modules/main/wallet_section/all_collectibles/controller.nim b/src/app/modules/main/wallet_section/all_collectibles/controller.nim index b1cbdc07f6..b3f0e60c18 100644 --- a/src/app/modules/main/wallet_section/all_collectibles/controller.nim +++ b/src/app/modules/main/wallet_section/all_collectibles/controller.nim @@ -50,7 +50,7 @@ proc getWalletAddresses*(self: Controller): seq[string] = return self.walletAccountService.getWalletAddresses() proc getChainIds*(self: Controller): seq[int] = - return self.networkService.getNetworks().map(n => n.chainId) + return self.networkService.getCurrentNetworks().map(n => n.chainId) proc updateCollectiblePreferences*(self: Controller, tokenPreferencesJson: string) = self.collectibleService.updateCollectiblePreferences(tokenPreferencesJson) diff --git a/src/app/modules/main/wallet_section/assets/controller.nim b/src/app/modules/main/wallet_section/assets/controller.nim index 23d4ec4638..169b440e00 100644 --- a/src/app/modules/main/wallet_section/assets/controller.nim +++ b/src/app/modules/main/wallet_section/assets/controller.nim @@ -35,7 +35,7 @@ proc init*(self: Controller) = discard proc getChainIds*(self: Controller): seq[int] = - return self.networkService.getNetworks().map(n => n.chainId) + return self.networkService.getCurrentNetworks().map(n => n.chainId) proc getCurrentCurrency*(self: Controller): string = return self.walletAccountService.getCurrency() diff --git a/src/app/modules/main/wallet_section/controller.nim b/src/app/modules/main/wallet_section/controller.nim index 66a70bd6f8..c723ef70c3 100644 --- a/src/app/modules/main/wallet_section/controller.nim +++ b/src/app/modules/main/wallet_section/controller.nim @@ -54,14 +54,14 @@ proc getCurrencyAmount*(self: Controller, amount: float64, symbol: string): Curr proc updateCurrency*(self: Controller, currency: string) = self.walletAccountService.updateCurrency(currency) -proc getNetworks*(self: Controller): seq[NetworkDto] = - return self.networkService.getNetworks() +proc getCurrentNetworks*(self: Controller): seq[NetworkDto] = + return self.networkService.getCurrentNetworks() proc getWalletAccounts*(self: Controller): seq[wallet_account_service.WalletAccountDto] = return self.walletAccountService.getWalletAccounts() proc getEnabledChainIds*(self: Controller): seq[int] = - return self.networkService.getNetworks().filter(n => n.enabled).map(n => n.chainId) + return self.networkService.getCurrentNetworks().filter(n => n.enabled).map(n => n.chainId) proc getKeypairByAccountAddress*(self: Controller, address: string): KeypairDto = return self.walletAccountService.getKeypairByAccountAddress(address) diff --git a/src/app/modules/main/wallet_section/filter.nim b/src/app/modules/main/wallet_section/filter.nim index 2499278069..5428e684a7 100644 --- a/src/app/modules/main/wallet_section/filter.nim +++ b/src/app/modules/main/wallet_section/filter.nim @@ -46,7 +46,7 @@ proc removeAddress*(self: Filter, address: string) = proc updateNetworks*(self: Filter) = self.chainIds = self.controller.getEnabledChainIds() - self.allChainsEnabled = (self.chainIds.len == self.controller.getNetworks().len) + self.allChainsEnabled = (self.chainIds.len == self.controller.getCurrentNetworks().len) proc load*(self: Filter) = self.setFillterAllAddresses() diff --git a/src/app/modules/main/wallet_section/io_interface.nim b/src/app/modules/main/wallet_section/io_interface.nim index 095ebdc96d..fbabb651bc 100644 --- a/src/app/modules/main/wallet_section/io_interface.nim +++ b/src/app/modules/main/wallet_section/io_interface.nim @@ -88,9 +88,6 @@ method onAddAccountModuleLoaded*(self: AccessInterface) {.base.} = method destroyAddAccountPopup*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") -method getNetworkLayer*(self: AccessInterface, chainId: int): string {.base.} = - raise newException(ValueError, "No implementation available") - method getLatestBlockNumber*(self: AccessInterface, chainId: int): string {.base.} = raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/wallet_section/module.nim b/src/app/modules/main/wallet_section/module.nim index f511932fa3..f63708e9b2 100644 --- a/src/app/modules/main/wallet_section/module.nim +++ b/src/app/modules/main/wallet_section/module.nim @@ -413,9 +413,6 @@ method getAddAccountModule*(self: Module): QVariant = method onAddAccountModuleLoaded*(self: Module) = self.view.emitDisplayAddAccountPopup() -method getNetworkLayer*(self: Module, chainId: int): string = - return self.networksModule.getNetworkLayer(chainId) - method getLatestBlockNumber*(self: Module, chainId: int): string = return self.transactionService.getLatestBlockNumber(chainId) diff --git a/src/app/modules/main/wallet_section/networks/controller.nim b/src/app/modules/main/wallet_section/networks/controller.nim index 86d5699d1f..dfbbacf659 100644 --- a/src/app/modules/main/wallet_section/networks/controller.nim +++ b/src/app/modules/main/wallet_section/networks/controller.nim @@ -34,7 +34,7 @@ proc init*(self: Controller) = self.events.on(SIGNAL_WALLET_ACCOUNT_NETWORK_ENABLED_UPDATED) do(e: Args): self.delegate.refreshNetworks() -proc getFlatNetworks*(self: Controller): seq[NetworkDto] = +proc getFlatNetworks*(self: Controller): var seq[NetworkDto] = return self.networkService.getFlatNetworks() proc setNetworksState*(self: Controller, chainIds: seq[int], enabled: bool) = 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 04d088c172..b1d53547d1 100644 --- a/src/app/modules/main/wallet_section/networks/io_interface.nim +++ b/src/app/modules/main/wallet_section/networks/io_interface.nim @@ -1,3 +1,10 @@ +import app_service/service/network/dto + +type + NetworksDataSource* = tuple[ + getFlatNetworksList: proc(): var seq[NetworkDto] + ] + type AccessInterface* {.pure inheritable.} = ref object of RootObj ## Abstract class for any input/interaction with this module. @@ -23,5 +30,5 @@ method setNetworksState*(self: AccessInterface, chainIds: seq[int], enable: bool method refreshNetworks*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") -method getNetworkLayer*(self: AccessInterface, chainId: int): string {.base.} = +method getNetworksDataSource*(self: AccessInterface): NetworksDataSource {.base.} = raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/wallet_section/networks/item.nim b/src/app/modules/main/wallet_section/networks/item.nim deleted file mode 100644 index d297572947..0000000000 --- a/src/app/modules/main/wallet_section/networks/item.nim +++ /dev/null @@ -1,115 +0,0 @@ -import stew/shims/strformat - -type - UxEnabledState* {.pure.} = enum - Enabled - AllEnabled - Disabled - -type - Item* = object - chainId: int - nativeCurrencyDecimals: int - layer: int - chainName: string - rpcURL: string - blockExplorerURL: string - nativeCurrencyName: string - nativeCurrencySymbol: string - isTest: bool - isEnabled: bool - iconUrl: string - chainColor: string - shortName: string - enabledState: UxEnabledState - -proc initItem*( - chainId: int, - nativeCurrencyDecimals: int, - layer: int, - chainName: string, - rpcURL: string, - blockExplorerURL: string, - nativeCurrencyName: string, - nativeCurrencySymbol: string, - isTest: bool, - isEnabled: bool, - iconUrl: string, - chainColor: string, - shortName: string, - enabledState: UxEnabledState, -): Item = - result.chainId = chainId - result.nativeCurrencyDecimals = nativeCurrencyDecimals - result.layer = layer - result.chainName = chainName - result.rpcURL = rpcURL - result.blockExplorerURL = blockExplorerURL - result.nativeCurrencyName = nativeCurrencyName - result.nativeCurrencySymbol = nativeCurrencySymbol - result.isTest = isTest - result.isEnabled = isEnabled - result.iconUrl = iconUrl - result.chainColor = chainColor - result.shortName = shortName - result.enabledState = enabledState - -proc `$`*(self: Item): string = - result = fmt"""NetworkItem( - chainId: {self.chainId}, - chainName: {self.chainName}, - layer: {self.layer}, - nativeCurrencyDecimals: {self.nativeCurrencyDecimals}, - rpcURL: {self.rpcURL}, - blockExplorerURL:{self.blockExplorerURL}, - nativeCurrencyName:{self.nativeCurrencyName}, - nativeCurrencySymbol:{self.nativeCurrencySymbol}, - isTest:{self.isTest}, - isEnabled:{self.isEnabled}, - iconUrl:{self.iconUrl}, - shortName: {self.shortName}, - chainColor: {self.chainColor}, - enabledState: {self.enabledState} - ]""" - -proc getChainId*(self: Item): int = - return self.chainId - -proc getNativeCurrencyDecimals*(self: Item): int = - return self.nativeCurrencyDecimals - -proc getLayer*(self: Item): int = - return self.layer - -proc getChainName*(self: Item): string = - return self.chainName - -proc getRpcURL*(self: Item): string = - return self.rpcURL - -proc getBlockExplorerURL*(self: Item): string = - return self.blockExplorerURL - -proc getNativeCurrencyName*(self: Item): string = - return self.nativeCurrencyName - -proc getNativeCurrencySymbol*(self: Item): string = - return self.nativeCurrencySymbol - -proc getIsTest*(self: Item): bool = - return self.isTest - -proc getIsEnabled*(self: Item): bool = - return self.isEnabled - -proc getIconURL*(self: Item): string = - return self.iconUrl - -proc getShortName*(self: Item): string = - return self.shortName - -proc getChainColor*(self: Item): string = - return self.chainColor - -proc getEnabledState*(self: Item): UxEnabledState = - return self.enabledState diff --git a/src/app/modules/main/wallet_section/networks/model.nim b/src/app/modules/main/wallet_section/networks/model.nim index eb6d4cafde..d1882d8b55 100644 --- a/src/app/modules/main/wallet_section/networks/model.nim +++ b/src/app/modules/main/wallet_section/networks/model.nim @@ -1,7 +1,7 @@ -import NimQml, Tables, strutils, stew/shims/strformat, sequtils, sugar +import NimQml, Tables, strutils, sequtils, sugar -import app_service/service/network/types -import ./item +import app_service/service/network/dto +import ./io_interface const EXPLORER_TX_PREFIX* = "/tx/" @@ -25,34 +25,30 @@ type QtObject: type Model* = ref object of QAbstractListModel - items: seq[Item] + delegate: io_interface.NetworksDataSource proc delete(self: Model) = - self.items = @[] self.QAbstractListModel.delete proc setup(self: Model) = self.QAbstractListModel.setup - proc newModel*(): Model = + proc newModel*(delegate: io_interface.NetworksDataSource): Model = new(result, delete) result.setup - - proc `$`*(self: Model): string = - for i in 0 ..< self.items.len: - result &= fmt"""[{i}]:({$self.items[i]})""" + result.delegate = delegate proc countChanged(self: Model) {.signal.} proc getCount(self: Model): int {.slot.} = - self.items.len + return self.delegate.getFlatNetworksList().len QtProperty[int] count: read = getCount notify = countChanged method rowCount*(self: Model, index: QModelIndex = nil): int = - return self.items.len + return self.delegate.getFlatNetworksList().len method roleNames(self: Model): Table[int, string] = { @@ -76,179 +72,118 @@ QtObject: if (not index.isValid): return - if (index.row < 0 or index.row >= self.items.len): + if (index.row < 0 or index.row >= self.rowCount()): return - let item = self.items[index.row] + let item = self.delegate.getFlatNetworksList()[index.row] let enumRole = role.ModelRole case enumRole: of ModelRole.ChainId: - result = newQVariant(item.getChainId()) + result = newQVariant(item.chainId) of ModelRole.NativeCurrencyDecimals: - result = newQVariant(item.getNativeCurrencyDecimals()) + result = newQVariant(item.nativeCurrencyDecimals) of ModelRole.Layer: - result = newQVariant(item.getLayer()) + result = newQVariant(item.layer) of ModelRole.ChainName: - result = newQVariant(item.getChainName()) + result = newQVariant(item.chainName) of ModelRole.RpcURL: - result = newQVariant(item.getRpcURL()) + result = newQVariant(item.rpcURL) of ModelRole.BlockExplorerURL: - result = newQVariant(item.getBlockExplorerURL()) + result = newQVariant(item.blockExplorerURL) of ModelRole.NativeCurrencyName: - result = newQVariant(item.getNativeCurrencyName()) + result = newQVariant(item.nativeCurrencyName) of ModelRole.NativeCurrencySymbol: - result = newQVariant(item.getNativeCurrencySymbol()) + result = newQVariant(item.nativeCurrencySymbol) of ModelRole.IsTest: - result = newQVariant(item.getIsTest()) + result = newQVariant(item.isTest) of ModelRole.IsEnabled: - result = newQVariant(item.getIsEnabled()) + result = newQVariant(item.enabled) of ModelRole.IconUrl: - result = newQVariant(item.getIconURL()) + result = newQVariant(item.iconURL) of ModelRole.ShortName: - result = newQVariant(item.getShortName()) + result = newQVariant(item.shortName) of ModelRole.ChainColor: - result = newQVariant(item.getChainColor()) + result = newQVariant(item.chainColor) of ModelRole.EnabledState: - result = newQVariant(item.getEnabledState().int) + result = newQVariant(item.enabledState.int) proc rowData*(self: Model, index: int, column: string): string {.slot.} = - if (index >= self.items.len): + if (index >= self.rowCount()): return - let item = self.items[index] + let item = self.delegate.getFlatNetworksList()[index] case column: - of "chainId": result = $item.getChainId() - of "nativeCurrencyDecimals": result = $item.getNativeCurrencyDecimals() - of "layer": result = $item.getLayer() - of "chainName": result = $item.getChainName() - of "rpcURL": result = $item.getRpcURL() - of "blockExplorerURL": result = $item.getBlockExplorerURL() - of "nativeCurrencyName": result = $item.getNativeCurrencyName() - of "nativeCurrencySymbol": result = $item.getNativeCurrencySymbol() - of "isTest": result = $item.getIsTest() - of "isEnabled": result = $item.getIsEnabled() - of "iconUrl": result = $item.getIconURL() - of "chainColor": result = $item.getChainColor() - of "shortName": result = $item.getShortName() - of "enabledState": result = $item.getEnabledState().int + of "chainId": result = $item.chainId + of "nativeCurrencyDecimals": result = $item.nativeCurrencyDecimals + of "layer": result = $item.layer + of "chainName": result = $item.chainName + of "rpcURL": result = $item.rpcURL + of "blockExplorerURL": result = $item.blockExplorerURL + of "nativeCurrencyName": result = $item.nativeCurrencyName + of "nativeCurrencySymbol": result = $item.nativeCurrencySymbol + of "isTest": result = $item.isTest + of "isEnabled": result = $item.enabled + of "iconUrl": result = $item.iconURL + of "chainColor": result = $item.chainColor + of "shortName": result = $item.shortName + of "enabledState": result = $item.enabledState.int - proc setItems*(self: Model, items: seq[Item]) = + proc refreshModel*(self: Model) = self.beginResetModel() - self.items = items self.endResetModel() - self.countChanged() - proc getChainColor*(self: Model, chainId: int): string {.slot.} = - for item in self.items: - if(item.getChainId() == chainId): - return item.getChainColor() - return "" - - proc getIconUrl*(self: Model, chainId: int): string {.slot.} = - for item in self.items: - if(item.getChainId() == chainId): - return item.getIconURL() - return "" - - proc getNetworkShortName*(self: Model, chainId: int): string {.slot.} = - for item in self.items: - if(item.getChainId() == chainId): - return item.getShortName() - return "" - - proc getNetworkFullName*(self: Model, chainId: int): string {.slot.} = - for item in self.items: - if(item.getChainId() == chainId): - return item.getChainName() - return "" - - proc getNetworkLayer*(self: Model, chainId: int): string {.slot.} = - for item in self.items: - if(item.getChainId() == chainId): - return $item.getLayer() - return "" - - proc getNetworkIconUrl*(self: Model, shortName: string): string {.slot.} = - for item in self.items: - if cmpIgnoreCase(item.getShortName(), shortName) == 0: - return item.getIconURL() - return "" - - proc getNetworkName*(self: Model, shortName: string): string {.slot.} = - for item in self.items: - if cmpIgnoreCase(item.getShortName(), shortName) == 0: - return item.getChainName() - return "" - - proc getNetworkColor*(self: Model, shortName: string): string {.slot.} = - for item in self.items: - if cmpIgnoreCase(item.getShortName(), shortName) == 0: - return item.getChainColor() - return "" - - proc getNetworkChainId*(self: Model, shortName: string): int {.slot.} = - for item in self.items: - if cmpIgnoreCase(item.getShortName(), shortName) == 0: - return item.getChainId() - return 0 - - proc getLayer1Network*(self: Model, testNet: bool): int = - for item in self.items: - if item.getLayer() == NETWORK_LAYER_1 and item.getIsTest() == testNet: - return item.getChainId() - return 0 - - proc getBlockExplorerURL*(self: Model, chainId: int): string {.slot.} = - for item in self.items: - if(item.getChainId() == chainId): - return item.getBlockExplorerURL() & EXPLORER_TX_PREFIX + proc getBlockExplorerURL*(self: Model, chainId: int): string = + for item in self.delegate.getFlatNetworksList(): + if(item.chainId == chainId): + return item.blockExplorerURL & EXPLORER_TX_PREFIX return "" proc getEnabledState*(self: Model, chainId: int): UxEnabledState = - for item in self.items: - if(item.getChainId() == chainId): - return item.getEnabledState() + for item in self.delegate.getFlatNetworksList(): + if(item.chainId == chainId): + return item.enabledState return UxEnabledState.Disabled # Returns the chains that need to be enabled or disabled (the second return value) # to satisty the transitions: all enabled to only chainId enabled and # only chainId enabled to all enabled - proc networksToChangeStateOnUserActionFor*(self: Model, chainId: int): (seq[int], bool) = + proc networksToChangeStateOnUserActionFor*(self: Model, chainId: int, areTestNetworksEnabled: bool): (seq[int], bool) = + let filteredNetworks = self.delegate.getFlatNetworksList().filter(n => n.isTest == areTestNetworksEnabled) var chainIds: seq[int] = @[] var enable = false case self.getEnabledState(chainId): of UxEnabledState.Enabled: # Iterate to check for the only chainId enabled case ... - for item in self.items: - if item.getEnabledState() == UxEnabledState.Enabled and item.getChainId() != chainId: + for item in filteredNetworks: + if item.enabledState == UxEnabledState.Enabled and item.chainId != chainId: # ... as soon as we find another enabled chain mark this by adding it to the list chainIds.add(chainId) break # ... if no other chains are enabled, then it's a transition from only chainId enabled to all enabled if chainIds.len == 0: - for item in self.items: - if item.getChainId() != chainId: - chainIds.add(item.getChainId()) + for item in filteredNetworks: + if item.chainId != chainId: + chainIds.add(item.chainId) enable = true of UxEnabledState.Disabled: chainIds.add(chainId) enable = true of UxEnabledState.AllEnabled: # disable all but chainId - for item in self.items: - if item.getChainId() != chainId: - chainIds.add(item.getChainId()) + for item in filteredNetworks: + if item.chainId != chainId: + chainIds.add(item.chainId) return (chainIds, enable) - proc getNetworkShortNames*(self: Model, preferredNetworks: string): string = + proc getNetworkShortNames*(self: Model, preferredNetworks: string, areTestNetworksEnabled: bool): string = var networkString = "" let networks = preferredNetworks.split(":") for nw in networks: - for item in self.items: - if $item.getChainId() == nw: - networkString = networkString & item.getShortName() & ':' + for item in self.delegate.getFlatNetworksList(): + if $item.chainId == nw and item.isTest == areTestNetworksEnabled: + networkString = networkString & item.shortName & ':' break return networkString @@ -256,11 +191,11 @@ QtObject: var networkIds = "" let networksNames = shortNames.split(":") for name in networksNames: - for item in self.items: - if item.getShortName() == name: - networkIds = networkIds & $item.getChainId() & ':' + for item in self.delegate.getFlatNetworksList(): + if item.shortName == name: + networkIds = networkIds & $item.chainId & ':' break return networkIds - proc getAllNetworksChainIds*(self: Model): string = - return self.items.map(x => x.getChainId()).join(":") + proc getEnabledChainIds*(self: Model, areTestNetworksEnabled: bool): string = + return self.delegate.getFlatNetworksList().filter(n => n.enabled and n.isTest == areTestNetworksEnabled).map(n => n.chainId).join(":") diff --git a/src/app/modules/main/wallet_section/networks/module.nim b/src/app/modules/main/wallet_section/networks/module.nim index e0fa69d860..ca958838bc 100644 --- a/src/app/modules/main/wallet_section/networks/module.nim +++ b/src/app/modules/main/wallet_section/networks/module.nim @@ -40,7 +40,7 @@ method delete*(self: Module) = method refreshNetworks*(self: Module) = self.view.setAreTestNetworksEnabled(self.controller.areTestNetworksEnabled()) - self.view.setItems(self.controller.getFlatNetworks()) + self.view.refreshModel() method load*(self: Module) = self.controller.init() @@ -63,5 +63,9 @@ method viewDidLoad*(self: Module) = method setNetworksState*(self: Module, chainIds: seq[int], enabled: bool) = self.controller.setNetworksState(chainIds, enabled) -method getNetworkLayer*(self: Module, chainId: int): string = - return self.view.getNetworkLayer(chainId) +# Interfaces for getting lists from the service files into the abstract models + +method getNetworksDataSource*(self: Module): NetworksDataSource = + return ( + getFlatNetworksList: proc(): var seq[NetworkDto] = self.controller.getFlatNetworks() + ) diff --git a/src/app/modules/main/wallet_section/networks/view.nim b/src/app/modules/main/wallet_section/networks/view.nim index 691a4fb9c6..bf634f54a9 100644 --- a/src/app/modules/main/wallet_section/networks/view.nim +++ b/src/app/modules/main/wallet_section/networks/view.nim @@ -1,21 +1,12 @@ -import NimQml, sequtils, sugar, strutils +import NimQml, sequtils, strutils -import app_service/service/network/[dto, types] import ./io_interface import ./model -import ./item - -proc networkEnabledToUxEnabledState(enabled: bool, allEnabled: bool): UxEnabledState -proc areAllEnabled(networks: seq[NetworkDto]): bool QtObject: type View* = ref object of QObject delegate: io_interface.AccessInterface - all: Model - enabled: Model - layer1: Model - layer2: Model flatNetworks: Model areTestNetworksEnabled: bool enabledChainIds: string @@ -29,11 +20,7 @@ QtObject: proc newView*(delegate: io_interface.AccessInterface): View = new(result, delete) result.delegate = delegate - result.all = newModel() - result.layer1 = newModel() - result.layer2 = newModel() - result.enabled = newModel() - result.flatNetworks = newModel() + result.flatNetworks = newModel(delegate.getNetworksDataSource()) result.enabledChainIds = "" result.setup() @@ -50,34 +37,6 @@ QtObject: self.areTestNetworksEnabled = areTestNetworksEnabled self.areTestNetworksEnabledChanged() - proc allChanged*(self: View) {.signal.} - - proc getAll(self: View): QVariant {.slot.} = - return newQVariant(self.all) - - QtProperty[QVariant] all: - read = getAll - notify = allChanged - - proc layer1Changed*(self: View) {.signal.} - - proc getLayer1(self: View): QVariant {.slot.} = - return newQVariant(self.layer1) - - QtProperty[QVariant] layer1: - read = getLayer1 - notify = layer1Changed - - proc layer2Changed*(self: View) {.signal.} - - proc getLayer2(self: View): QVariant {.slot.} = - return newQVariant(self.layer2) - - QtProperty[QVariant] layer2: - read = getLayer2 - notify = layer2Changed - - proc flatNetworksChanged*(self: View) {.signal.} proc getFlatNetworks(self: View): QVariant {.slot.} = return newQVariant(self.flatNetworks) @@ -85,15 +44,6 @@ QtObject: read = getFlatNetworks notify = flatNetworksChanged - proc enabledChanged*(self: View) {.signal.} - - proc getEnabled(self: View): QVariant {.slot.} = - return newQVariant(self.enabled) - - QtProperty[QVariant] enabled: - read = getEnabled - notify = enabledChanged - proc enabledChainIdsChanged*(self: View) {.signal.} proc getEnabledChainIds(self: View): QVariant {.slot.} = return newQVariant(self.enabledChainIds) @@ -101,71 +51,24 @@ QtObject: read = getEnabledChainIds notify = enabledChainIdsChanged - proc setItems*(self: View, networks: seq[NetworkDto]) = - var items: seq[Item] = @[] - let allEnabled = areAllEnabled(networks) - for n in networks: - items.add(initItem( - n.chainId, - n.nativeCurrencyDecimals, - n.layer, - n.chainName, - n.rpcURL, - n.blockExplorerURL, - n.nativeCurrencyName, - n.nativeCurrencySymbol, - n.isTest, - n.enabled, - n.iconUrl, - n.chainColor, - n.shortName, - # Ensure we mark all as enabled if all are enabled - networkEnabledToUxEnabledState(n.enabled, allEnabled) - )) - - let filteredItems = items.filter(i => i.getIsTest() == self.areTestNetworksEnabled) - self.flatNetworks.setItems(items) - self.all.setItems(filteredItems) - self.layer1.setItems(filteredItems.filter(i => i.getLayer() == NETWORK_LAYER_1)) - self.layer2.setItems(filteredItems.filter(i => i.getLayer() == NETWORK_LAYER_2)) - self.enabled.setItems(filteredItems.filter(i => i.getIsEnabled())) - self.enabledChainIds = filteredItems.filter(i => i.getIsEnabled()).map(a => a.getChainId()).join(":") - - self.allChanged() - self.layer1Changed() - self.layer2Changed() - self.enabledChanged() + proc refreshModel*(self: View) = + self.flatNetworks.refreshModel() + self.enabledChainIds = self.flatNetworks.getEnabledChainIds(self.areTestNetworksEnabled) + self.flatNetworksChanged() self.enabledChainIdsChanged() proc load*(self: View) = self.delegate.viewDidLoad() proc toggleNetwork*(self: View, chainId: int) {.slot.} = - let (chainIds, enable) = self.all.networksToChangeStateOnUserActionFor(chainId) + let (chainIds, enable) = self.flatNetworks.networksToChangeStateOnUserActionFor(chainId, self.areTestNetworksEnabled) self.delegate.setNetworksState(chainIds, enable) - proc getMainnetChainId*(self: View): int {.slot.} = - return self.layer1.getLayer1Network(self.areTestNetworksEnabled) - proc getNetworkShortNames*(self: View, preferredNetworks: string): string {.slot.} = - return self.all.getNetworkShortNames(preferredNetworks) + return self.flatNetworks.getNetworkShortNames(preferredNetworks, self.areTestNetworksEnabled) proc getNetworkIds*(self: View, shortNames: string): string {.slot.} = - return self.all.getNetworkIds(shortNames) + return self.flatNetworks.getNetworkIds(shortNames) - proc getAllNetworksChainIds*(self: View): string {.slot.} = - return self.all.getAllNetworksChainIds() - -proc networkEnabledToUxEnabledState(enabled: bool, allEnabled: bool): UxEnabledState = - return if allEnabled: - UxEnabledState.AllEnabled - elif enabled: - UxEnabledState.Enabled - else: - UxEnabledState.Disabled - -proc areAllEnabled(networks: seq[NetworkDto]): bool = - return networks.allIt(it.enabled) - -proc getNetworkLayer*(self: View, chainId: int): string = - return self.all.getNetworkLayer(chainId) + proc getBlockExplorerURL*(self: View, chainId: int): string {.slot.} = + return self.flatNetworks.getBlockExplorerURL(chainId) diff --git a/src/app/modules/main/wallet_section/send/controller.nim b/src/app/modules/main/wallet_section/send/controller.nim index f457e803bf..c80b286ebc 100644 --- a/src/app/modules/main/wallet_section/send/controller.nim +++ b/src/app/modules/main/wallet_section/send/controller.nim @@ -80,10 +80,10 @@ proc getWalletAccounts*(self: Controller): seq[wallet_account_service.WalletAcco return self.walletAccountService.getWalletAccounts() proc getChainIds*(self: Controller): seq[int] = - return self.networkService.getNetworks().map(n => n.chainId) + return self.networkService.getCurrentNetworks().map(n => n.chainId) proc getEnabledChainIds*(self: Controller): seq[int] = - return self.networkService.getNetworks().filter(n => n.enabled).map(n => n.chainId) + return self.networkService.getCurrentNetworks().filter(n => n.enabled).map(n => n.chainId) proc getCurrentCurrency*(self: Controller): string = return self.walletAccountService.getCurrency() @@ -130,8 +130,8 @@ proc areTestNetworksEnabled*(self: Controller): bool = proc getTotalCurrencyBalance*(self: Controller, address: seq[string], chainIds: seq[int]): float64 = return self.walletAccountService.getTotalCurrencyBalance(address, chainIds) -proc getNetworks*(self: Controller): seq[NetworkDto] = - return self.networkService.getNetworks() +proc getCurrentNetworks*(self: Controller): seq[NetworkDto] = + return self.networkService.getCurrentNetworks() proc getKeypairByAccountAddress*(self: Controller, address: string): KeypairDto = return self.walletAccountService.getKeypairByAccountAddress(address) diff --git a/src/app/modules/main/wallet_section/send/module.nim b/src/app/modules/main/wallet_section/send/module.nim index 58149ad623..9c1639dc3c 100644 --- a/src/app/modules/main/wallet_section/send/module.nim +++ b/src/app/modules/main/wallet_section/send/module.nim @@ -194,7 +194,7 @@ method refreshWalletAccounts*(self: Module) = self.view.switchReceiveAccount(self.receiveCurrentAccountIndex) proc refreshNetworks*(self: Module) = - let networks = self.controller.getNetworks() + let networks = self.controller.getCurrentNetworks() let fromNetworks = networks.map(x => self.convertNetworkDtoToNetworkItem(x)) let toNetworks = networks.map(x => self.convertNetworkDtoToNetworkItem(x)) self.view.setNetworkItems(fromNetworks, toNetworks) diff --git a/src/app/modules/main/wallet_section/send/network_model.nim b/src/app/modules/main/wallet_section/send/network_model.nim index 74b41cafee..3fbc3e1f0a 100644 --- a/src/app/modules/main/wallet_section/send/network_model.nim +++ b/src/app/modules/main/wallet_section/send/network_model.nim @@ -262,7 +262,7 @@ QtObject: self.items[i].isPreferred = true self.dataChanged(index, index, @[ModelRole.IsPreferred.int]) - proc getNetworkColor*(self: NetworkModel, shortName: string): string {.slot.} = + proc getNetworkColor*(self: NetworkModel, shortName: string): string = for item in self.items: if cmpIgnoreCase(item.getShortName(), shortName) == 0: return item.getChainColor() diff --git a/src/app/modules/shared_modules/collectible_details/controller.nim b/src/app/modules/shared_modules/collectible_details/controller.nim index cb569d5c25..60d11220da 100644 --- a/src/app/modules/shared_modules/collectible_details/controller.nim +++ b/src/app/modules/shared_modules/collectible_details/controller.nim @@ -54,7 +54,7 @@ QtObject: notify = isDetailedEntryLoadingChanged proc getExtraData(self: Controller, chainID: int): ExtraData = - let network = self.networkService.getNetwork(chainID) + let network = self.networkService.getNetworkByChainId(chainID) return getExtraData(network) proc processGetCollectiblesDetailsResponse(self: Controller, response: JsonNode) = diff --git a/src/app/modules/shared_modules/collectibles/controller.nim b/src/app/modules/shared_modules/collectibles/controller.nim index 2728d456cb..fd0c03260a 100644 --- a/src/app/modules/shared_modules/collectibles/controller.nim +++ b/src/app/modules/shared_modules/collectibles/controller.nim @@ -147,7 +147,7 @@ QtObject: self.loadMoreItems() proc getExtraData(self: Controller, chainID: int): ExtraData = - let network = self.networkService.getNetwork(chainID) + let network = self.networkService.getNetworkByChainId(chainID) return getExtraData(network) proc setTempItems(self: Controller, newItems: seq[CollectiblesEntry], offset: int) = diff --git a/src/app_service/service/message/service.nim b/src/app_service/service/message/service.nim index 8f7c9ac9e9..044e07641d 100644 --- a/src/app_service/service/message/service.nim +++ b/src/app_service/service/message/service.nim @@ -470,7 +470,7 @@ QtObject: self.resetMessageCursor(chatArg.chatId) proc getTransactionDetails*(self: Service, message: MessageDto): (string, string) = - let networksDto = self.networkService.getNetworks() + let networksDto = self.networkService.getCurrentNetworks() var token = self.tokenService.findTokenByAddress(networksDto[0].chainId, ZERO_ADDRESS) if message.transactionParameters.contract != "": diff --git a/src/app_service/service/network/dto.nim b/src/app_service/service/network/dto.nim index 7d66ce546d..4b80147944 100644 --- a/src/app_service/service/network/dto.nim +++ b/src/app_service/service/network/dto.nim @@ -5,6 +5,12 @@ import ./types export types +type + UxEnabledState* {.pure.} = enum + Enabled + AllEnabled + Disabled + type NetworkDto* = ref object chainId* {.serializedFieldName("chainId").}: int nativeCurrencyDecimals* {.serializedFieldName("nativeCurrencyDecimals").}: int @@ -23,6 +29,7 @@ type NetworkDto* = ref object chainColor* {.serializedFieldName("chainColor").}: string shortName* {.serializedFieldName("shortName").}: string relatedChainId* {.serializedFieldName("relatedChainId").}: int + enabledState*: UxEnabledState proc `$`*(self: NetworkDto): string = return fmt"""Network( @@ -40,7 +47,8 @@ proc `$`*(self: NetworkDto): string = isTest:{self.isTest}, enabled:{self.enabled}, chainColor:{self.chainColor}, shortName:{self.shortName}, - relatedChainId:{self.relatedChainId} + relatedChainId:{self.relatedChainId}, + enabledState:{self.enabledState} )""" proc hash*(self: NetworkDto): Hash = @@ -56,3 +64,10 @@ proc `$`*(self: CombinedNetworkDto): string = test:{$self.test}, )""" +proc networkEnabledToUxEnabledState*(enabled: bool, allEnabled: bool): UxEnabledState = + return if allEnabled: + UxEnabledState.AllEnabled + elif enabled: + UxEnabledState.Enabled + else: + UxEnabledState.Disabled diff --git a/src/app_service/service/network/service.nim b/src/app_service/service/network/service.nim index 20643fbbe1..358099b82e 100644 --- a/src/app_service/service/network/service.nim +++ b/src/app_service/service/network/service.nim @@ -1,4 +1,4 @@ -import json, json_serialization, chronicles, atomics +import json, json_serialization, chronicles, sugar, sequtils import ../../../app/core/eventemitter import ../../../backend/backend as backend @@ -21,12 +21,10 @@ type NetworkEndpointUpdatedArgs* = ref object of Args type Service* = ref object of RootObj events: EventEmitter - networks: seq[CombinedNetworkDto] - networksInited: bool - dirty: Atomic[bool] + combinedNetworks: seq[CombinedNetworkDto] + flatNetworks: seq[NetworkDto] settingsService: settings_service.Service - proc delete*(self: Service) = discard @@ -35,50 +33,38 @@ proc newService*(events: EventEmitter, settingsService: settings_service.Service result.events = events result.settingsService = settingsService -proc init*(self: Service) = - discard +proc fetchNetworks*(self: Service): seq[CombinedNetworkDto]= + let response = backend.getEthereumChains() + if not response.error.isNil: + raise newException(Exception, "Error getting combinedNetworks: " & response.error.message) + result = if response.result.isNil or response.result.kind == JNull: @[] + else: Json.decode($response.result, seq[CombinedNetworkDto], allowUnknownFields = true) + self.combinedNetworks = result + let allTestEnabled = self.combinedNetworks.filter(n => n.test.enabled).len == self.combinedNetworks.len + let allProdEnabled = self.combinedNetworks.filter(n => n.prod.enabled).len == self.combinedNetworks.len + for n in self.combinedNetworks: + n.test.enabledState = networkEnabledToUxEnabledState(n.test.enabled, allTestEnabled) + n.prod.enabledState = networkEnabledToUxEnabledState(n.prod.enabled, allProdEnabled) + self.flatNetworks = @[] + for network in self.combinedNetworks: + self.flatNetworks.add(network.test) + self.flatNetworks.add(network.prod) -proc fetchNetworks*(self: Service, useCached: bool = true): seq[CombinedNetworkDto] = - let cacheIsDirty = not self.networksInited or self.dirty.load - if useCached and not cacheIsDirty: - result = self.networks - else: - let response = backend.getEthereumChains() - if not response.error.isNil: - raise newException(Exception, "Error getting networks: " & response.error.message) - result = if response.result.isNil or response.result.kind == JNull: @[] - else: Json.decode($response.result, seq[CombinedNetworkDto], allowUnknownFields = true) - self.dirty.store(false) - self.networks = result - self.networksInited = true +proc init*(self: Service) = + discard self.fetchNetworks() proc resetNetworks*(self: Service) = - discard self.fetchNetworks(useCached = false) + discard self.fetchNetworks() proc getCombinedNetworks*(self: Service): seq[CombinedNetworkDto] = - return self.fetchNetworks() + return self.combinedNetworks -# TODO:: update the networks service to unify the model exposed from this service -# We currently have 3 types: combined, test/mainet and flat and probably can be optimized -# follow up task https://github.com/status-im/status-desktop/issues/12717 -proc getFlatNetworks*(self: Service): seq[NetworkDto] = - for network in self.fetchNetworks(): - result.add(network.test) - result.add(network.prod) +proc getFlatNetworks*(self: Service): var seq[NetworkDto] = + return self.flatNetworks -proc getNetworks*(self: Service): seq[NetworkDto] = - let testNetworksEnabled = self.settingsService.areTestNetworksEnabled() - - for network in self.fetchNetworks(): - if testNetworksEnabled: - result.add(network.test) - else: - result.add(network.prod) - -proc getAllNetworkChainIds*(self: Service): seq[int] = - for network in self.fetchNetworks(): - result.add(network.test.chainId) - result.add(network.prod.chainId) +# passes networks based on users choice of test/mainnet +proc getCurrentNetworks*(self: Service): seq[NetworkDto] = + self.flatNetworks.filter(n => n.isTest == self.settingsService.areTestNetworksEnabled()) proc upsertNetwork*(self: Service, network: NetworkDto): bool = let response = backend.addEthereumChain(backend.Network( @@ -100,48 +86,34 @@ proc upsertNetwork*(self: Service, network: NetworkDto): bool = shortName: network.shortName, relatedChainID: network.relatedChainID, )) - self.dirty.store(true) return response.error == nil proc deleteNetwork*(self: Service, network: NetworkDto) = discard backend.deleteEthereumChain(network.chainId) - self.dirty.store(true) -proc getNetwork*(self: Service, chainId: int): NetworkDto = +proc getNetworkByChainId*(self: Service, chainId: int): NetworkDto = + var networks = self.combinedNetworks + if self.combinedNetworks.len == 0: + networks = self.fetchNetworks() let testNetworksEnabled = self.settingsService.areTestNetworksEnabled() - for network in self.fetchNetworks(): + for network in networks: let net = if testNetworksEnabled: network.test else: network.prod if chainId == net.chainId: return net - -proc getNetworkByChainId*(self: Service, chainId: int): NetworkDto = - for network in self.fetchNetworks(): - if chainId == network.prod.chainId: - return network.prod - elif chainId == network.test.chainId: - return network.test - -proc getNetwork*(self: Service, networkType: NetworkType): NetworkDto = - let testNetworksEnabled = self.settingsService.areTestNetworksEnabled() - for network in self.fetchNetworks(): - let net = if testNetworksEnabled: network.test - else: network.prod - if networkType.toChainId() == net.chainId: - return net - - # Will be removed, this is used in case of legacy chain Id - return NetworkDto(chainId: networkType.toChainId()) + return nil proc setNetworksState*(self: Service, chainIds: seq[int], enabled: bool) = for chainId in chainIds: - let network = self.getNetwork(chainId) + let network = self.getNetworkByChainId(chainId) - if network.enabled == enabled: - continue + if not network.isNil: + if network.enabled == enabled: + continue - network.enabled = enabled - discard self.upsertNetwork(network) + network.enabled = enabled + discard self.upsertNetwork(network) + discard self.fetchNetworks() ## This procedure retuns the network to be used based on the app mode (testnet/mainnet). ## We don't need to check if retuned network is nil cause it should never be, but if somehow it is, the app will be closed. @@ -159,7 +131,7 @@ proc getAppNetwork*(self: Service): NetworkDto = networkId = Sepolia if self.settingsService.isGoerliEnabled(): networkId = Goerli - let network = self.getNetwork(networkId) + let network = self.getNetworkByChainId(networkId) if network.isNil: # we should not be here ever error "the app network cannot be resolved" @@ -169,11 +141,12 @@ proc getAppNetwork*(self: Service): NetworkDto = proc updateNetworkEndPointValues*(self: Service, chainId: int, newMainRpcInput, newFailoverRpcUrl: string, revertToDefault: bool) = let network = self.getNetworkByChainId(chainId) - if network.rpcURL != newMainRpcInput: - network.rpcURL = newMainRpcInput + if not network.isNil: + if network.rpcURL != newMainRpcInput: + network.rpcURL = newMainRpcInput - if network.fallbackURL != newFailoverRpcUrl: - network.fallbackURL = newFailoverRpcUrl + if network.fallbackURL != newFailoverRpcUrl: + network.fallbackURL = newFailoverRpcUrl - if self.upsertNetwork(network): - self.events.emit(SIGNAL_NETWORK_ENDPOINT_UPDATED, NetworkEndpointUpdatedArgs(isTest: network.isTest, networkName: network.chainName, revertedToDefault: revertToDefault)) + if self.upsertNetwork(network): + self.events.emit(SIGNAL_NETWORK_ENDPOINT_UPDATED, NetworkEndpointUpdatedArgs(isTest: network.isTest, networkName: network.chainName, revertedToDefault: revertToDefault)) diff --git a/src/app_service/service/network_connection/service.nim b/src/app_service/service/network_connection/service.nim index 02103c023d..b8235397fa 100644 --- a/src/app_service/service/network_connection/service.nim +++ b/src/app_service/service/network_connection/service.nim @@ -143,7 +143,7 @@ QtObject: var chaindIdsDown: seq[int] = @[] var lastSuccessAt: int = connection_status_backend.INVALID_TIMESTAMP # latest succesful connectinon between the down chains - let allChainIds = self.networkService.getNetworks().map(a => a.chainId) + let allChainIds = self.networkService.getCurrentNetworks().map(a => a.chainId) for id in allChainIds: if chainStatusTable.hasKey($id) and chainStatusTable[$id].value != connection_status_backend.StateValue.Unknown: if chainStatusTable[$id].value == connection_status_backend.StateValue.Connected: diff --git a/src/app_service/service/token/service.nim b/src/app_service/service/token/service.nim index 478d139499..d01613757e 100644 --- a/src/app_service/service/token/service.nim +++ b/src/app_service/service/token/service.nim @@ -279,12 +279,11 @@ QtObject: let tokenList = Json.decode($tokensResult, TokenListDto, allowUnknownFields = true) self.tokenListUpdatedAt = tokenList.updatedAt - let supportedNetworkChains = self.networkService.getAllNetworkChainIds() + let supportedNetworkChains = self.networkService.getFlatNetworks().map(n => n.chainId) var flatTokensList: Table[string, TokenItem] = initTable[string, TokenItem]() var tokenBySymbolList: Table[string, TokenBySymbolItem] = initTable[string, TokenBySymbolItem]() var tokenSymbols: seq[string] = @[] - for s in tokenList.data: let newSource = SupportedSourcesItem(name: s.name, source: s.source, version: s.version, tokensCount: s.tokens.len) self.sourcesOfTokensList.add(newSource) diff --git a/src/app_service/service/transaction/service.nim b/src/app_service/service/transaction/service.nim index 86d01f7060..90eff1f445 100644 --- a/src/app_service/service/transaction/service.nim +++ b/src/app_service/service/transaction/service.nim @@ -487,8 +487,8 @@ QtObject: if token != nil: tokenSymbol = token.symbol - let network = self.networkService.getNetwork(chainID) - if network.nativeCurrencySymbol == tokenSymbol: + let network = self.networkService.getNetworkByChainId(chainID) + if not network.isNil and network.nativeCurrencySymbol == tokenSymbol: isEthTx = true if(isEthTx): diff --git a/src/app_service/service/wallet_account/balance_history.nim b/src/app_service/service/wallet_account/balance_history.nim index c37d2b2ad6..c02817e4fe 100644 --- a/src/app_service/service/wallet_account/balance_history.nim +++ b/src/app_service/service/wallet_account/balance_history.nim @@ -10,7 +10,7 @@ proc tokenBalanceHistoryDataResolved*(self: Service, response: string) {.slot.} proc fetchHistoricalBalanceForTokenAsJson*(self: Service, addresses: seq[string], allAddresses: bool, tokenSymbol: string, currencySymbol: string, timeInterval: BalanceHistoryTimeInterval) = # create an empty list of chain ids - var chainIds: seq[int] = self.networkService.getNetworks().filter(n => n.enabled and n.nativeCurrencySymbol == tokenSymbol).map(n => n.chainId) + var chainIds: seq[int] = self.networkService.getCurrentNetworks().filter(n => n.enabled and n.nativeCurrencySymbol == tokenSymbol).map(n => n.chainId) if chainIds.len == 0: let tokenChainIds = self.tokenService.getFlatTokensList().filter(t => t.symbol == tokenSymbol and t.communityId.isEmptyOrWhitespace).map(t => t.chainID) chainIds = concat(chainIds, tokenChainIds) diff --git a/src/app_service/service/wallet_account/service_account.nim b/src/app_service/service/wallet_account/service_account.nim index 1ed4eeefac..baa90390e6 100644 --- a/src/app_service/service/wallet_account/service_account.nim +++ b/src/app_service/service/wallet_account/service_account.nim @@ -761,7 +761,7 @@ proc fetchChainIdForUrl*(self: Service, url: string, isMainUrl: bool) = self.threadpool.start(arg) proc getEnabledChainIds*(self: Service): seq[int] = - return self.networkService.getNetworks().filter(n => n.enabled).map(n => n.chainId) + return self.networkService.getCurrentNetworks().filter(n => n.enabled).map(n => n.chainId) proc getCurrencyFormat*(self: Service, symbol: string): CurrencyFormatDto = return self.currencyService.getCurrencyFormat(symbol) diff --git a/src/app_service/service/wallet_account/service_token.nim b/src/app_service/service/wallet_account/service_token.nim index 11617b29cb..e66161cc2a 100644 --- a/src/app_service/service/wallet_account/service_token.nim +++ b/src/app_service/service/wallet_account/service_token.nim @@ -132,7 +132,7 @@ proc getOrFetchBalanceForAddressInPreferredCurrency*(self: Service, address: str result.balance = 0.0 result.fetched = false return - let chainIds = self.networkService.getNetworks().map(n => n.chainId) + let chainIds = self.networkService.getCurrentNetworks().map(n => n.chainId) result.balance = self.getTotalCurrencyBalance(@[acc.address], chainIds) result.fetched = true @@ -159,7 +159,7 @@ proc checkRecentHistory*(self: Service, addresses: seq[string]) = if(not main_constants.WALLET_ENABLED): return try: - let chainIds = self.networkService.getNetworks().map(a => a.chainId) + let chainIds = self.networkService.getCurrentNetworks().map(a => a.chainId) status_go_transactions.checkRecentHistory(chainIds, addresses) except Exception as e: let errDescription = e.msg diff --git a/storybook/pages/AccountViewPage.qml b/storybook/pages/AccountViewPage.qml index 0ebbd4a532..d06b79e388 100644 --- a/storybook/pages/AccountViewPage.qml +++ b/storybook/pages/AccountViewPage.qml @@ -1,6 +1,8 @@ import QtQuick 2.14 import QtQuick.Controls 2.14 +import SortFilterProxyModel 0.2 + import AppLayouts.Profile.views.wallet 1.0 import StatusQ.Core.Theme 0.1 @@ -48,7 +50,10 @@ SplitView { } readonly property QtObject walletStore: QtObject { - property var networks: NetworksModel.mainNetworks + property var networks: SortFilterProxyModel { + sourceModel: NetworksModel.flatNetworks + filters: ValueFilter { roleName: "isTest"; value: areTestNetworksEnabledCheckbox.checked } + } property bool areTestNetworksEnabled: areTestNetworksEnabledCheckbox.checked function toggleNetwork(chainId) { } diff --git a/storybook/pages/AssetsViewPage.qml b/storybook/pages/AssetsViewPage.qml index c9df721c0c..2d6c8c0398 100644 --- a/storybook/pages/AssetsViewPage.qml +++ b/storybook/pages/AssetsViewPage.qml @@ -146,7 +146,7 @@ SplitView { Layout.fillHeight: true Layout.fillWidth: true currencyStore: d.currencyStore - allNetworksModel: NetworksModel.allNetworks + allNetworksModel: NetworksModel.flatNetworks networkFilters: d.networksChainsCurrentlySelected } } @@ -178,7 +178,7 @@ SplitView { } Repeater { id: networksRepeater - model: NetworksModel.allNetworks + model: NetworksModel.flatNetworks delegate: CheckBox { property int chainID: chainId width: parent.width diff --git a/storybook/pages/CollectibleDetailViewPage.qml b/storybook/pages/CollectibleDetailViewPage.qml index e7b192693c..e77b1859e1 100644 --- a/storybook/pages/CollectibleDetailViewPage.qml +++ b/storybook/pages/CollectibleDetailViewPage.qml @@ -72,14 +72,6 @@ SplitView { function formatCurrencyAmount(cryptoValue, symbol) { return "%L1 %2".arg(cryptoValue).arg(symbol) } - - function getNetworkFullName(chainId) { - return chainId - } - - function getNetworkColor(chainId) { - return "pink" - } } walletRootStore: QtObject { function getNameForAddress(address) { diff --git a/storybook/pages/CollectiblesViewPage.qml b/storybook/pages/CollectiblesViewPage.qml index 6ed2fb528b..1d75083bab 100644 --- a/storybook/pages/CollectiblesViewPage.qml +++ b/storybook/pages/CollectiblesViewPage.qml @@ -164,7 +164,7 @@ SplitView { } Repeater { id: networksRepeater - model: NetworksModel.allNetworks + model: NetworksModel.flatNetworks delegate: CheckBox { property int chainID: chainId width: parent.width diff --git a/storybook/pages/EditCommunityTokenViewPage.qml b/storybook/pages/EditCommunityTokenViewPage.qml index 3502e42266..64b84bfe03 100644 --- a/storybook/pages/EditCommunityTokenViewPage.qml +++ b/storybook/pages/EditCommunityTokenViewPage.qml @@ -28,8 +28,6 @@ SplitView { anchors.fill: parent anchors.margins: 50 isAssetView: isAssetBox.checked - layer1Networks: NetworksModel.layer1Networks - layer2Networks: NetworksModel.layer2Networks accounts: WalletAccountsModel {} tokensModel: MintedTokensModel {} referenceAssetsBySymbolModel: ListModel { diff --git a/storybook/pages/EditOwnerTokenViewPage.qml b/storybook/pages/EditOwnerTokenViewPage.qml index 8b907bc1fc..3c774f6180 100644 --- a/storybook/pages/EditOwnerTokenViewPage.qml +++ b/storybook/pages/EditOwnerTokenViewPage.qml @@ -2,6 +2,8 @@ import QtQuick 2.14 import QtQuick.Controls 2.14 import QtQuick.Layouts 1.14 +import SortFilterProxyModel 0.2 + import StatusQ.Core.Theme 0.1 import StatusQ.Components 0.1 @@ -45,10 +47,10 @@ SplitView { communityLogo: doodles.checked ? ModelsData.collectibles.doodles : ModelsData.collectibles.mana communityColor: color1.checked ? "#FFC4E9" : "#f44336" - layer1Networks: NetworksModel.layer1Networks - layer2Networks: NetworksModel.layer2Networks - enabledNetworks: NetworksModel.enabledNetworks - allNetworks: enabledNetworks + flatNetworks: SortFilterProxyModel { + sourceModel: NetworksModel.flatNetworks + filters: ValueFilter { roleName: "isTest"; value: false } + } accounts: WalletAccountsModel {} onMintClicked: logs.logEvent("EditOwnerTokenView::onMintClicked") diff --git a/storybook/pages/MintTokensSettingsPanelPage.qml b/storybook/pages/MintTokensSettingsPanelPage.qml index 6881844d69..fefb2b35fd 100644 --- a/storybook/pages/MintTokensSettingsPanelPage.qml +++ b/storybook/pages/MintTokensSettingsPanelPage.qml @@ -109,10 +109,10 @@ SplitView { // Models: tokensModel: editorModelChecked.checked ? emptyModel : privilegedModelChecked.checked ? privilegedTokensModel : mintedTokensModel - layer1Networks: NetworksModel.layer1Networks - layer2Networks: NetworksModel.layer2Networks - enabledNetworks: NetworksModel.enabledNetworks - allNetworks: enabledNetworks + flatNetworks: SortFilterProxyModel { + sourceModel: NetworksModel.flatNetworks + filters: ValueFilter { roleName: "isTest"; value: false } + } accounts: WalletAccountsModel {} referenceAssetsBySymbolModel: ListModel { ListElement { diff --git a/storybook/pages/NetworkFilterPage.qml b/storybook/pages/NetworkFilterPage.qml index 8ca8ce71d3..4f2a6fc334 100644 --- a/storybook/pages/NetworkFilterPage.qml +++ b/storybook/pages/NetworkFilterPage.qml @@ -5,6 +5,8 @@ import QtQuick.Layouts 1.13 import Storybook 1.0 import Models 1.0 +import SortFilterProxyModel 0.2 + import AppLayouts.Wallet.controls 1.0 SplitView { @@ -36,12 +38,11 @@ SplitView { id: networkFilter anchors.centerIn: parent - width: 200 - layer1Networks: NetworksModel.layer1Networks - layer2Networks: NetworksModel.layer2Networks - enabledNetworks: NetworksModel.enabledNetworks - allNetworks: enabledNetworks + flatNetworks: SortFilterProxyModel { + sourceModel: NetworksModel.flatNetworks + filters: ValueFilter { roleName: "isTest"; value: false; } + } multiSelection: multiSelectionCheckBox.checked diff --git a/storybook/pages/NetworkSelectPopupPage.qml b/storybook/pages/NetworkSelectPopupPage.qml index bd7daca774..6e66956005 100644 --- a/storybook/pages/NetworkSelectPopupPage.qml +++ b/storybook/pages/NetworkSelectPopupPage.qml @@ -38,23 +38,7 @@ SplitView { Layout.alignment: Qt.AlignHCenter - allNetworks: simulatedNimModel - layer1Networks: SortFilterProxyModel { - function rowData(index, propName) { - return get(index)[propName] - } - sourceModel: simulatedNimModel - filters: ValueFilter { roleName: "layer"; value: 1; } - } - layer2Networks: SortFilterProxyModel { - sourceModel: simulatedNimModel - filters: [ValueFilter { roleName: "layer"; value: 2; }, - ValueFilter { roleName: "isTest"; value: false; }] - } - enabledNetworks: SortFilterProxyModel { - sourceModel: simulatedNimModel - filters: ValueFilter { roleName: "isEnabled"; value: true; } - } + flatNetworks: simulatedNimModel onToggleNetwork: (network) => { if(multiSelection) { @@ -77,8 +61,7 @@ SplitView { NetworkSelectPopup { id: networkSelectPopup - layer1Networks: networkFilter.layer1Networks - layer2Networks: networkFilter.layer2Networks + flatNetworks: simulatedNimModel useEnabledRole: false @@ -112,7 +95,7 @@ SplitView { Layout.preferredWidth: selectPopupLoader.item ? selectPopupLoader.item.width : 0 Layout.preferredHeight: selectPopupLoader.item ? selectPopupLoader.item.height : 0 - property var currentModel: networkFilter.layer2Networks + property var currentModel: networkFilter.flatNetworks property int currentIndex: 0 Loader { @@ -121,8 +104,7 @@ SplitView { active: false sourceComponent: NetworkSelectPopup { - layer1Networks: networkFilter.layer1Networks - layer2Networks: networkFilter.layer2Networks + flatNetworks: simulatedNimModel singleSelection { enabled: true @@ -230,7 +212,7 @@ SplitView { return get(index)[propName] } - sourceModel: NetworksModel.allNetworks + sourceModel: NetworksModel.flatNetworks filters: ValueFilter { roleName: "isTest"; value: testModeCheckbox.checked; } } diff --git a/storybook/pages/ReceiveModalPage.qml b/storybook/pages/ReceiveModalPage.qml index 7da99f8cab..5c15c607fb 100644 --- a/storybook/pages/ReceiveModalPage.qml +++ b/storybook/pages/ReceiveModalPage.qml @@ -2,6 +2,10 @@ import QtQuick 2.15 import QtQuick.Controls 2.15 import QtQuick.Layouts 1.15 +import SortFilterProxyModel 0.2 + +import StatusQ.Core.Utils 0.1 + import Storybook 1.0 import Models 1.0 import AppLayouts.Wallet.popups 1.0 @@ -40,19 +44,61 @@ SplitView { "name": "My account", "emoji": "", "address": "0x1234567890123456789012345678901234567890", - "preferredSharingChainIds": "opt:eth:" + "preferredSharingChainIds": "10:42161:1:" } switchingAccounsEnabled: true changingPreferredChainsEnabled: true hasFloatingButtons: true qrImageSource: "https://upload.wikimedia.org/wikipedia/commons/4/41/QR_Code_Example.svg" getNetworkShortNames: function (chainIDsString) { - return networksNames + let chainArray = chainIDsString.split(":") + let chainNameString = "" + for (let i =0; i { return (cryptoValue * 1800).toPrecision(2) } - RootStore.getNetworkIcon = (chainId) => { return "tiny/network/Network=Ethereum" } RootStore.getLatestBlockNumber = () => { return 4 } RootStore.hex2Dec = (number) => { return 10 } - RootStore.getNetworkColor = (number) => { return "blue" } - RootStore.getNetworkFullName = (chainId) => { return "Ethereum Mainnet" } - RootStore.getNetworkShortName = (chainId) => { return "eth" } RootStore.formatCurrencyAmount = (value, symbol) => { return value + " " + symbol } RootStore.getNameForSavedWalletAddress = (address) => { return "Saved Wallet Name" } RootStore.getNameForAddress = (address) => { return "Address Name" } RootStore.getEnsForSavedWalletAddress = (address) => { return "123" } RootStore.getChainShortNamesForSavedWalletAddress = (address) => { return "" } RootStore.getGasEthValue = (gasAmount, gasPrice) => { return (gasAmount * Math.pow(10, -9)).toPrecision(5) } - RootStore.getNetworkLayer = (chainId) => { return 1 } RootStore.currentCurrency = "USD" + RootStore.flatNetworks = NetworksModel.flatNetworks root.rootStoreReady = true } diff --git a/storybook/pages/WalletHeaderPage.qml b/storybook/pages/WalletHeaderPage.qml index d9dee23c7a..eee59d7b9d 100644 --- a/storybook/pages/WalletHeaderPage.qml +++ b/storybook/pages/WalletHeaderPage.qml @@ -1,6 +1,8 @@ import QtQuick 2.14 import QtQuick.Controls 2.14 +import SortFilterProxyModel 0.2 + import AppLayouts.Wallet.panels 1.0 import AppLayouts.Wallet.controls 1.0 import AppLayouts.Chat.panels 1.0 @@ -78,10 +80,10 @@ SplitView { } readonly property QtObject walletStore: QtObject { - property var allNetworks: enabledNetworks - property var layer1Networks: NetworksModel.layer1Networks - property var layer2Networks: NetworksModel.layer2Networks - property var enabledNetworks: NetworksModel.enabledNetworks + property var filteredFlatModel: SortFilterProxyModel { + sourceModel: NetworksModel.flatNetworks + filters: ValueFilter { roleName: "isTest"; value: false } + } function toggleNetwork(chainId) { } diff --git a/storybook/src/Models/NetworksModel.qml b/storybook/src/Models/NetworksModel.qml index 41cf9a0370..5689c45cda 100644 --- a/storybook/src/Models/NetworksModel.qml +++ b/storybook/src/Models/NetworksModel.qml @@ -12,6 +12,26 @@ QtObject { readonly property int testnetNet: 5 readonly property int customNet: 6 + function getShortChainName(chainId) { + if(chainId === root.ethNet) + return "eth" + + if(chainId === root.optimismNet) + return "opt" + + if(chainId === root.arbitrumNet) + return "arb" + + if(chainId === root.hermezNet) + return "her" + + if(chainId === root.testnetNet) + return "goe" + + if(chainId === root.customNet) + return "cus" + } + function getChainName(chainId) { if(chainId === root.ethNet) return "Mainnet" @@ -39,157 +59,7 @@ QtObject { } } - readonly property var layer1Networks: CustomNetworkModel { - Component.onCompleted: - append([ - { - chainId: ethNet, - chainName: "Ethereum Mainnet", - iconUrl: ModelsData.networks.ethereum, - isActive: true, - isEnabled: true, - shortName: "ETH", - chainColor: "blue", - isTest: false - } - ]) - } - - readonly property var layer2Networks: CustomNetworkModel { - Component.onCompleted: - append([ - { - chainId: optimismNet, - chainName: "Optimism", - iconUrl: ModelsData.networks.optimism, - isActive: false, - isEnabled: true, - shortName: "OPT", - chainColor: "red", - isTest: false - }, - { - chainId: arbitrumNet, - chainName: "Arbitrum", - iconUrl: ModelsData.networks.arbitrum, - isActive: false, - isEnabled: true, - shortName: "ARB", - chainColor: "purple", - isTest: false - } - ]) - } - - readonly property var testNetworks: CustomNetworkModel { - Component.onCompleted: - append([ - { - chainId: hermezNet, - chainName: "Hermez", - iconUrl: ModelsData.networks.hermez, - isActive: false, - isEnabled: true, - shortName: "HEZ", - chainColor: "orange", - isTest: true - }, - { - chainId: testnetNet, - chainName: "Testnet", - iconUrl: ModelsData.networks.testnet, - isActive: false, - isEnabled: true, - shortName: "TNET", - chainColor: "lightblue", - isTest: true - }, - { - chainId: customNet, - chainName: "Custom", - iconUrl: ModelsData.networks.custom, - isActive: false, - isEnabled: true, - shortName: "CUSTOM", - chainColor: "orange", - isTest: true - } - ]) - } - - readonly property var enabledNetworks: CustomNetworkModel { - Component.onCompleted: - append([ - { - chainId: 1, - layer: 1, - chainName: "Ethereum Mainnet", - iconUrl: ModelsData.networks.ethereum, - isActive: true, - isEnabled: false, - shortName: "ETH", - chainColor: "blue", - isTest: false - }, - { - chainId: 2, - layer: 2, - chainName: "Optimism", - iconUrl: ModelsData.networks.optimism, - isActive: false, - isEnabled: true, - shortName: "OPT", - chainColor: "red", - isTest: false - }, - { - chainId: 3, - layer: 2, - chainName: "Arbitrum", - iconUrl: ModelsData.networks.arbitrum, - isActive: false, - isEnabled: true, - shortName: "ARB", - chainColor: "purple", - isTest: false - }, - { - chainId: 4, - layer: 2, - chainName: "Hermez", - iconUrl: ModelsData.networks.hermez, - isActive: false, - isEnabled: true, - shortName: "HEZ", - chainColor: "orange", - isTest: false - }, - { - chainId: 5, - layer: 1, - chainName: "Testnet", - iconUrl: ModelsData.networks.testnet, - isActive: false, - isEnabled: true, - shortName: "TNET", - chainColor: "lightblue", - isTest: true - }, - { - chainId: 6, - layer: 1, - chainName: "Custom", - iconUrl: ModelsData.networks.custom, - isActive: false, - isEnabled: true, - shortName: "CUSTOM", - chainColor: "orange", - isTest: false - } - ]) - } - - readonly property var allNetworks: CustomNetworkModel { + readonly property var flatNetworks: CustomNetworkModel { Component.onCompleted: append([ { chainId: 1, @@ -278,44 +148,6 @@ QtObject { ) } - readonly property var mainNetworks: CustomNetworkModel { - Component.onCompleted: append([ - { - chainId: 1, - chainName: "Ethereum Mainnet", - iconUrl: ModelsData.networks.ethereum, - isActive: true, - isEnabled: true, - shortName: "ETH", - chainColor: "blue", - layer: 1, - isTest: false - }, - { - chainId: 10, - chainName: "Optimism", - iconUrl: ModelsData.networks.optimism, - isActive: false, - isEnabled: true, - shortName: "OPT", - chainColor: "red", - layer: 2, - isTest: false - }, - { - chainId: 42161, - chainName: "Arbitrum", - iconUrl: ModelsData.networks.arbitrum, - isActive: false, - isEnabled: true, - shortName: "ARB", - chainColor: "purple", - layer: 2, - isTest: false - } - ]) - } - readonly property var sendFromNetworks: CustomNetworkModel { function updateFromNetworks(paths){ reset() diff --git a/storybook/src/Models/SourceOfTokensModel.qml b/storybook/src/Models/SourceOfTokensModel.qml index 8ba7a4fa49..f823cf2cf6 100644 --- a/storybook/src/Models/SourceOfTokensModel.qml +++ b/storybook/src/Models/SourceOfTokensModel.qml @@ -16,7 +16,8 @@ ListModel { source: "https://gateway.ipfs.io/ipns/tokens.uniswap.org", version: "11.6.0", tokensCount: 731, - image: ModelsData.assets.uni + image: ModelsData.assets.uni, + updatedAt: 1710538948 }, { key: root.status, @@ -24,7 +25,8 @@ ListModel { source: "https://status.im/", version: "11.6.0", tokensCount: 250, - image: ModelsData.assets.snt + image: ModelsData.assets.snt, + updatedAt: 1710538948 } ] diff --git a/storybook/stubs/nim/sectionmocks/NetworksModule.qml b/storybook/stubs/nim/sectionmocks/NetworksModule.qml index 486b173481..a7002844f5 100644 --- a/storybook/stubs/nim/sectionmocks/NetworksModule.qml +++ b/storybook/stubs/nim/sectionmocks/NetworksModule.qml @@ -6,8 +6,5 @@ QtObject { // // Silence warnings - readonly property ListModel layer1: ListModel {} - readonly property ListModel layer2: ListModel {} - readonly property ListModel enabled: ListModel {} - readonly property ListModel all: ListModel {} -} \ No newline at end of file + readonly property ListModel flatNetworks: ListModel {} +} diff --git a/storybook/stubs/shared/stores/RootStore.qml b/storybook/stubs/shared/stores/RootStore.qml index 1f3a34c0aa..2acd669d32 100644 --- a/storybook/stubs/shared/stores/RootStore.qml +++ b/storybook/stubs/shared/stores/RootStore.qml @@ -14,20 +14,16 @@ QtObject { property var currencyStore: CurrenciesStore {} property var history - property var getNetworkIcon property var getFiatValue property var getLatestBlockNumber property var hex2Dec - property var getNetworkColor - property var getNetworkFullName - property var getNetworkShortName property var formatCurrencyAmount property var getNameForSavedWalletAddress property var getNameForAddress property var getEnsForSavedWalletAddress property var getChainShortNamesForSavedWalletAddress property var getGasEthValue - property var getNetworkLayer + property var flatNetworks function copyToClipboard(text) { console.warn("STUB: copyToClipboard:", text) diff --git a/storybook/stubs/shared/stores/send/TransactionStore.qml b/storybook/stubs/shared/stores/send/TransactionStore.qml index 356b9b3f77..bee27e98e8 100644 --- a/storybook/stubs/shared/stores/send/TransactionStore.qml +++ b/storybook/stubs/shared/stores/send/TransactionStore.qml @@ -24,7 +24,7 @@ QtObject { property ListModel model: ListModel{} } - property var allNetworksModel: NetworksModel.allNetworks + property var flatNetworksModel: NetworksModel.flatNetworks property var fromNetworksModel: NetworksModel.sendFromNetworks property var toNetworksModel: NetworksModel.sendToNetworks property var selectedSenderAccount: senderAccounts.get(0) @@ -182,7 +182,7 @@ QtObject { let listOfChains = chainIds.split(":") let listOfChainIds = [] for (let k =0;k { diff --git a/ui/app/AppLayouts/Wallet/controls/NetworkFilter.qml b/ui/app/AppLayouts/Wallet/controls/NetworkFilter.qml index c1934216d8..486ea6e41b 100644 --- a/ui/app/AppLayouts/Wallet/controls/NetworkFilter.qml +++ b/ui/app/AppLayouts/Wallet/controls/NetworkFilter.qml @@ -1,12 +1,15 @@ import QtQuick 2.15 import QtQuick.Layouts 1.13 +import StatusQ 0.1 import StatusQ.Core 0.1 import StatusQ.Core.Theme 0.1 import StatusQ.Core.Utils 0.1 import StatusQ.Components 0.1 import StatusQ.Controls 0.1 +import SortFilterProxyModel 0.2 + import AppLayouts.Wallet.helpers 1.0 import utils 1.0 @@ -16,10 +19,7 @@ import "../views" StatusComboBox { id: root - required property var allNetworks - required property var layer1Networks - required property var layer2Networks - required property var enabledNetworks + required property var flatNetworks property bool multiSelection: true property bool preferredNetworksMode: false property var preferredSharingNetworks: [] @@ -30,31 +30,31 @@ StatusComboBox { signal toggleNetwork(var network) function setChain(chainId) { - if(!multiSelection && !!d.currentModel && d.currentModel.count > 0) { - d.currentModel = NetworkModelHelpers.getLayerNetworkModelByChainId(root.layer1Networks, - root.layer2Networks, - chainId) ?? root.layer2Networks - d.currentIndex = NetworkModelHelpers.getChainIndexByChainId(root.layer1Networks, - root.layer2Networks, - chainId) + if(!multiSelection && !!root.flatNetworks && root.flatNetworks.count > 0) { + d.currentIndex = NetworkModelHelpers.getChainIndexByChainId(root.flatNetworks, chainId) + if(d.currentIndex == -1) + d.currentIndex = NetworkModelHelpers.getChainIndexForFirstLayer2Network(root.flatNetworks) // Notify change: - root.toggleNetwork(ModelUtils.get(d.currentModel, d.currentIndex)) + root.toggleNetwork(ModelUtils.get(root.flatNetworks, d.currentIndex)) } } QtObject { id: d - readonly property string selectedChainName: NetworkModelHelpers.getChainName(d.currentModel, d.currentIndex) - readonly property string selectedIconUrl: NetworkModelHelpers.getChainIconUrl(d.currentModel, d.currentIndex) - readonly property bool allSelected: (!!root.enabledNetworks && !!root.allNetworks) ? root.enabledNetworks.count === root.allNetworks.count : - false - readonly property bool noneSelected: (!!root.enabledNetworks) ? root.enabledNetworks.count === 0 : false + readonly property string selectedChainName: NetworkModelHelpers.getChainName(root.flatNetworks, d.currentIndex) + readonly property string selectedIconUrl: NetworkModelHelpers.getChainIconUrl(root.flatNetworks, d.currentIndex) + readonly property bool allSelected: enabledFlatNetworks.len === root.flatNetworks.count + readonly property bool noneSelected: enabledFlatNetworks.len === 0 // Persist selection between selectPopupLoader reloads - property var currentModel: layer2Networks property int currentIndex: 0 + + property SortFilterProxyModel enabledFlatNetworks: SortFilterProxyModel { + sourceModel: root.flatNetworks + filters: ValueFilter { roleName: "isEnabled"; value: true; enabled: !root.preferredNetworksMode} + } } onMultiSelectionChanged: root.setChain() @@ -103,21 +103,20 @@ StatusComboBox { visible: !d.allSelected && chainRepeater.count > 0 Repeater { id: chainRepeater - model: root.multiSelection ? root.enabledNetworks : [] + model: root.preferredNetworksMode ? root.flatNetworks: root.multiSelection ? d.enabledFlatNetworks: [] delegate: StatusRoundedImage { width: 24 height: 24 - visible: image.source !== "" image.source: Style.svg(model.iconUrl) z: index + 1 + visible: root.preferredNetworksMode ? root.preferredSharingNetworks.includes(model.chainId.toString()): image.source !== "" } } } } control.popup.contentItem: NetworkSelectionView { - layer1Networks: root.layer1Networks - layer2Networks: root.layer2Networks + flatNetworks: root.flatNetworks preferredSharingNetworks: root.preferredSharingNetworks preferredNetworksMode: root.preferredNetworksMode @@ -126,14 +125,13 @@ StatusComboBox { singleSelection { enabled: !root.multiSelection - currentModel: d.currentModel + currentModel: root.flatNetworks currentIndex: d.currentIndex } useEnabledRole: false - onToggleNetwork: (network, networkModel, index) => { - d.currentModel = networkModel + onToggleNetwork: (network, index) => { d.currentIndex = index root.toggleNetwork(network) if(singleSelection.enabled) diff --git a/ui/app/AppLayouts/Wallet/helpers/NetworkModelHelpers.qml b/ui/app/AppLayouts/Wallet/helpers/NetworkModelHelpers.qml index eb8510b2e0..e71ace1974 100644 --- a/ui/app/AppLayouts/Wallet/helpers/NetworkModelHelpers.qml +++ b/ui/app/AppLayouts/Wallet/helpers/NetworkModelHelpers.qml @@ -20,30 +20,33 @@ QtObject { return ModelUtils.get(model, index, "iconUrl") ?? "" } - // Given a layer1 network model and layer2 network model, it looks for the provided chainId and returns + // Given a network model, it looks for the provided chainId and returns // the layer network model that contains the specific chain. If not found, returns undefined. - function getLayerNetworkModelByChainId(layer1NetworksModel, layer2NetworksModel, chainId) { + function getLayerNetworkModelByChainId(networksModel, chainId) { if(chainId) { - if(!!layer1NetworksModel && ModelUtils.contains(layer1NetworksModel, "chainId", chainId)) - return layer1NetworksModel - - else if(!!layer2NetworksModel && ModelUtils.contains(layer2NetworksModel, "chainId", chainId)) - return layer2NetworksModel + if(!!networksModel && ModelUtils.contains(networksModel, "chainId", chainId)) + return networksModel } // Default value if chainId is not part of any provided layer network model return undefined } - // Given a layer1 network model and layer2 network model, it looks for the provided chainId and returns + // Given a network model, it looks for the provided chainId and returns // the index of the the specific chain. If not found, returns 0 value. - function getChainIndexByChainId(layer1NetworksModel, layer2NetworksModel, chainId) { - const currentModel = getLayerNetworkModelByChainId(layer1NetworksModel, layer2NetworksModel, chainId) + function getChainIndexByChainId(networksModel, chainId) { + if(!!networksModel && chainId !== undefined) + return ModelUtils.indexOf(networksModel, "chainId", chainId) - if(!!currentModel) - return ModelUtils.indexOf(currentModel, "chainId", chainId) + // Default value if no model specified + return 0 + } - // Default value if no model specified + function getChainIndexForFirstLayer2Network(networksModel) { + if(!!networksModel) + return ModelUtils.indexOf(networksModel, "layer", 2) + + // Default value if no model specified return 0 } } diff --git a/ui/app/AppLayouts/Wallet/panels/WalletHeader.qml b/ui/app/AppLayouts/Wallet/panels/WalletHeader.qml index fdef1b88e2..0658f381d7 100644 --- a/ui/app/AppLayouts/Wallet/panels/WalletHeader.qml +++ b/ui/app/AppLayouts/Wallet/panels/WalletHeader.qml @@ -1,12 +1,15 @@ import QtQuick 2.13 import QtQuick.Layouts 1.13 +import StatusQ 0.1 import StatusQ.Core 0.1 import StatusQ.Controls 0.1 import StatusQ.Components 0.1 import StatusQ.Core.Theme 0.1 import StatusQ.Core.Utils 0.1 as StatusQUtils +import SortFilterProxyModel 0.2 + import utils 1.0 import "../controls" @@ -99,10 +102,7 @@ Item { Layout.alignment: Qt.AlignTop - allNetworks: walletStore.allNetworks - layer1Networks: walletStore.layer1Networks - layer2Networks: walletStore.layer2Networks - enabledNetworks: walletStore.enabledNetworks + flatNetworks: walletStore.filteredFlatModel onToggleNetwork: (network) => { walletStore.toggleNetwork(network.chainId) diff --git a/ui/app/AppLayouts/Wallet/popups/AddEditSavedAddressPopup.qml b/ui/app/AppLayouts/Wallet/popups/AddEditSavedAddressPopup.qml index a88eb59fea..c5fb7ab614 100644 --- a/ui/app/AppLayouts/Wallet/popups/AddEditSavedAddressPopup.qml +++ b/ui/app/AppLayouts/Wallet/popups/AddEditSavedAddressPopup.qml @@ -27,7 +27,7 @@ import ".." StatusModal { id: root - property var allNetworks + property var flatNetworks closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside @@ -187,7 +187,7 @@ StatusModal { d.ens = "" d.address = Constants.zeroAddress d.chainShortNames = "" - allNetworksModelCopy.setEnabledNetworks([]) + flatNetworksModelCopy.setEnabledNetworks([]) } d.cardsModel.clear() @@ -467,7 +467,7 @@ StatusModal { if (!prefixArrWithColumn) prefixArrWithColumn = [] - allNetworksModelCopy.setEnabledNetworks(prefixArrWithColumn) + flatNetworksModelCopy.setEnabledNetworks(prefixArrWithColumn) } } @@ -496,8 +496,8 @@ StatusModal { function getUnknownPrefixes(prefixes) { let unknownPrefixes = prefixes.filter(e => { - for (let i = 0; i < allNetworksModelCopy.count; i++) { - if (e == allNetworksModelCopy.get(i).shortName) + for (let i = 0; i < flatNetworksModelCopy.count; i++) { + if (e == flatNetworksModelCopy.get(i).shortName) return false } return true @@ -610,7 +610,7 @@ StatusModal { } itemsModel: SortFilterProxyModel { - sourceModel: allNetworksModelCopy + sourceModel: flatNetworksModelCopy filters: ValueFilter { roleName: "isEnabled" value: true @@ -674,20 +674,7 @@ StatusModal { NetworkSelectPopup { id: networkSelectPopup - layer1Networks: SortFilterProxyModel { - sourceModel: allNetworksModelCopy - filters: ValueFilter { - roleName: "layer" - value: 1 - } - } - layer2Networks: SortFilterProxyModel { - sourceModel: allNetworksModelCopy - filters: ValueFilter { - roleName: "layer" - value: 2 - } - } + flatNetworks: flatNetworksModelCopy onToggleNetwork: (network) => { network.isEnabled = !network.isEnabled @@ -718,9 +705,9 @@ StatusModal { ] CloneModel { - id: allNetworksModelCopy + id: flatNetworksModelCopy - sourceModel: root.allNetworks + sourceModel: root.flatNetworks roles: ["layer", "chainId", "chainColor", "chainName","shortName", "iconUrl"] rolesOverride: [{ role: "isEnabled", transform: (modelData) => Boolean(false) }] diff --git a/ui/app/AppLayouts/Wallet/popups/NetworkSelectPopup.qml b/ui/app/AppLayouts/Wallet/popups/NetworkSelectPopup.qml index 9ee6e94ee5..3f7f10687b 100644 --- a/ui/app/AppLayouts/Wallet/popups/NetworkSelectPopup.qml +++ b/ui/app/AppLayouts/Wallet/popups/NetworkSelectPopup.qml @@ -2,9 +2,12 @@ import QtQuick 2.15 import QtQuick.Controls 2.15 import QtGraphicalEffects 1.0 +import StatusQ 0.1 import StatusQ.Core.Theme 0.1 import StatusQ.Popups.Dialog 0.1 +import SortFilterProxyModel 0.2 + import utils 1.0 import "../stores/NetworkSelectPopup" @@ -14,8 +17,7 @@ import "../views" StatusDialog { id: root - required property var layer1Networks - required property var layer2Networks + property var flatNetworks property var preferredSharingNetworks: [] property bool preferredNetworksMode: false @@ -29,7 +31,7 @@ StatusDialog { /// It is called for every toggled network if \c singleSelection.enabled is \c false /// If \c singleSelection.enabled is \c true, it is called only for the selected network when the selection changes /// \see SingleSelectionInfo - signal toggleNetwork(var network, var model, int index) + signal toggleNetwork(var network, int index) QtObject { id: d @@ -65,15 +67,16 @@ StatusDialog { NetworkSelectionView { id: scrollView + width: parent.width + height: parent.height anchors.fill: parent - layer1Networks: root.layer1Networks - layer2Networks: root.layer2Networks + flatNetworks: root.flatNetworks preferredNetworksMode: root.preferredNetworksMode preferredSharingNetworks: root.preferredSharingNetworks useEnabledRole: root.useEnabledRole singleSelection: d.singleSelection onToggleNetwork: { - root.toggleNetwork(network, model, index) + root.toggleNetwork(network, index) if(d.singleSelection.enabled) close() } diff --git a/ui/app/AppLayouts/Wallet/popups/ReceiveModal.qml b/ui/app/AppLayouts/Wallet/popups/ReceiveModal.qml index 8f75e58ca4..d200ed1d7e 100644 --- a/ui/app/AppLayouts/Wallet/popups/ReceiveModal.qml +++ b/ui/app/AppLayouts/Wallet/popups/ReceiveModal.qml @@ -32,9 +32,9 @@ StatusModal { property bool switchingAccounsEnabled: true property bool changingPreferredChainsEnabled: true - property string qrImageSource: RootStore.getQrCode(d.visibleAddress) + property string qrImageSource: store.getQrCode(d.visibleAddress) property var getNetworkShortNames: function(chainIDsString) { - return RootStore.getNetworkShortNames(chainIDsString) + return store.getNetworkShortNames(chainIDsString) } property var store: RootStore @@ -131,7 +131,7 @@ StatusModal { } onOpened: { - RootStore.addressWasShown(root.selectedAccount.address) + store.addressWasShown(root.selectedAccount.address) } QtObject { @@ -145,8 +145,6 @@ StatusModal { readonly property string preferredChainShortNames: d.multiChainView? root.getNetworkShortNames(d.preferredChainIds) : "" readonly property string visibleAddress: "%1%2".arg(d.preferredChainShortNames).arg(root.selectedAccount.address) - - readonly property var networkProxies: [layer1NetworksClone, layer2NetworksClone] } Column { @@ -260,16 +258,13 @@ StatusModal { spacing: 5 Repeater { - model: d.networkProxies.length - delegate: Repeater { - model: d.networkProxies[index] - delegate: StatusNetworkListItemTag { - enabled: false - button.visible: false - title: model.shortName - asset.name: Style.svg("tiny/" + model.iconUrl) - visible: d.preferredChainIdsArray.includes(model.chainId.toString()) - } + model: root.store.filteredFlatModel + delegate: StatusNetworkListItemTag { + enabled: false + button.visible: false + title: model.shortName + asset.name: Style.svg("tiny/" + model.iconUrl) + visible: d.preferredChainIdsArray.includes(model.chainId.toString()) } } } @@ -295,8 +290,7 @@ StatusModal { margins: -1 // to allow positioning outside the bounds of the dialog - layer1Networks: layer1NetworksClone - layer2Networks: layer2NetworksClone + flatNetworks: root.store.filteredFlatModel preferredNetworksMode: true preferredSharingNetworks: d.preferredChainIdsArray @@ -304,33 +298,13 @@ StatusModal { closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside - onToggleNetwork: (network, networkModel, index) => { - d.preferredChainIdsArray = RootStore.processPreferredSharingNetworkToggle(d.preferredChainIdsArray, network) + onToggleNetwork: (network, index) => { + d.preferredChainIdsArray = store.processPreferredSharingNetworkToggle(d.preferredChainIdsArray, network) } onClosed: { root.updatePreferredChains(root.selectedAccount.address, d.preferredChainIds) } - - CloneModel { - id: layer1NetworksClone - - sourceModel: root.store.layer1Networks - roles: ["layer", "chainId", "chainColor", "chainName","shortName", "iconUrl", "isEnabled"] - // rowData used to clone returns string. Convert it to bool for bool arithmetics - rolesOverride: [{ - role: "isEnabled", - transform: (modelData) => root.readOnly ? root.chainShortNames.includes(modelData.shortName) : Boolean(modelData.isEnabled) - }] - } - - CloneModel { - id: layer2NetworksClone - - sourceModel: root.store.layer2Networks - roles: layer1NetworksClone.roles - rolesOverride: layer1NetworksClone.rolesOverride - } } } } diff --git a/ui/app/AppLayouts/Wallet/stores/NetworkSelectPopup/SingleSelectionInfo.qml b/ui/app/AppLayouts/Wallet/stores/NetworkSelectPopup/SingleSelectionInfo.qml index 98c5df6337..0de6a03acd 100644 --- a/ui/app/AppLayouts/Wallet/stores/NetworkSelectPopup/SingleSelectionInfo.qml +++ b/ui/app/AppLayouts/Wallet/stores/NetworkSelectPopup/SingleSelectionInfo.qml @@ -3,6 +3,6 @@ import QtQml 2.15 /// Inline component was failing on Linux with "Cannot assign to property of unknown type" so we need to use a separate file for it. QtObject { property bool enabled: false - property var currentModel: root.layer2Networks + property var currentModel property int currentIndex: 0 } diff --git a/ui/app/AppLayouts/Wallet/stores/RootStore.qml b/ui/app/AppLayouts/Wallet/stores/RootStore.qml index 1482f7fb85..1f4d5083c5 100644 --- a/ui/app/AppLayouts/Wallet/stores/RootStore.qml +++ b/ui/app/AppLayouts/Wallet/stores/RootStore.qml @@ -139,12 +139,14 @@ QtObject { return d.chainColors[chainShortName] } - property var layer1Networks: networksModule.layer1 - property var layer2Networks: networksModule.layer2 - property var enabledNetworks: networksModule.enabled - property var allNetworks: networksModule.all - onAllNetworksChanged: { - d.initChainColors(allNetworks) + property var flatNetworks: networksModule.flatNetworks + property SortFilterProxyModel filteredFlatModel: SortFilterProxyModel { + sourceModel: root.flatNetworks + filters: ValueFilter { roleName: "isTest"; value: root.areTestNetworksEnabled } + } + + onFlatNetworksChanged: { + d.initChainColors(flatNetworks) } property var cryptoRampServicesModel: walletSectionBuySellCrypto.model @@ -440,7 +442,12 @@ QtObject { } function getAllNetworksChainIds() { - return networksModule.getAllNetworksChainIds() + let result = [] + let chainIdsArray = SQUtils.ModelUtils.modelToFlatArray(root.filteredFlatModel, "chainId") + for(let i = 0; i< chainIdsArray.length; i++) { + result.push(chainIdsArray[i].toString()) + } + return result } function getNetworkShortNames(chainIds) { @@ -462,7 +469,7 @@ QtObject { function processPreferredSharingNetworkToggle(preferredSharingNetworks, toggledNetwork) { let prefChains = preferredSharingNetworks - if(prefChains.length === allNetworks.count) { + if(prefChains.length === root.filteredFlatModel.count) { prefChains = [toggledNetwork.chainId.toString()] } else if(!prefChains.includes(toggledNetwork.chainId.toString())) { @@ -470,7 +477,7 @@ QtObject { } else { if(prefChains.length === 1) { - prefChains = getAllNetworksChainIds().split(":") + prefChains = getAllNetworksChainIds() } else { for(var i = 0; i < prefChains.length;i++) { diff --git a/ui/app/AppLayouts/Wallet/views/NetworkSelectionView.qml b/ui/app/AppLayouts/Wallet/views/NetworkSelectionView.qml index e061c9603e..5d63d633aa 100644 --- a/ui/app/AppLayouts/Wallet/views/NetworkSelectionView.qml +++ b/ui/app/AppLayouts/Wallet/views/NetworkSelectionView.qml @@ -11,79 +11,51 @@ import utils 1.0 import "../stores/NetworkSelectPopup" import "../controls" -StatusScrollView { +StatusListView { id: root - required property var layer1Networks - required property var layer2Networks + required property var flatNetworks property bool useEnabledRole: true property SingleSelectionInfo singleSelection: SingleSelectionInfo {} property var preferredSharingNetworks: [] property bool preferredNetworksMode: false - signal toggleNetwork(var network, var model, int index) + signal toggleNetwork(var network, int index) - contentWidth: availableWidth - padding: 0 + model: root.flatNetworks - ScrollBar.horizontal.policy: ScrollBar.AlwaysOff - - Column { - id: content - - width: root.availableWidth - spacing: 4 - - Repeater { - id: chainRepeater1 + delegate: NetworkSelectItemDelegate { + implicitHeight: 48 + implicitWidth: root.width + radioButtonGroup: radioBtnGroup + networkModel: root.model + useEnabledRole: root.useEnabledRole + singleSelection: root.singleSelection + onToggleNetwork: root.toggleNetwork(network, index) + preferredNetworksMode: root.preferredNetworksMode + preferredSharingNetworks: root.preferredSharingNetworks + allChecked: root.preferredSharingNetworks.length === root.count + } + section { + property: "layer" + delegate: Loader { + required property int section width: parent.width - height: parent.height + sourceComponent: section === 2 ? layer2text: null - objectName: "networkSelectPopupChainRepeaterLayer1" - model: root.layer1Networks - - delegate: NetworkSelectItemDelegate { - implicitHeight: 48 - implicitWidth: root.width - radioButtonGroup: radioBtnGroup - networkModel: chainRepeater1.model - useEnabledRole: root.useEnabledRole - singleSelection: root.singleSelection - onToggleNetwork: root.toggleNetwork(network, model, index) - preferredNetworksMode: root.preferredNetworksMode - preferredSharingNetworks: root.preferredSharingNetworks - allChecked: root.preferredSharingNetworks.length === layer1Networks.count + layer2Networks.count - } - } - - StatusBaseText { - font.pixelSize: Style.current.primaryTextFontSize - color: Theme.palette.baseColor1 - text: qsTr("Layer 2") - height: 40 - leftPadding: 16 - topPadding: 10 - verticalAlignment: Text.AlignVCenter - - visible: chainRepeater2.count > 0 - } - - Repeater { - id: chainRepeater2 - - model: root.layer2Networks - delegate: NetworkSelectItemDelegate { - implicitHeight: 48 - width: parent.width - radioButtonGroup: radioBtnGroup - networkModel: chainRepeater2.model - useEnabledRole: root.useEnabledRole - singleSelection: root.singleSelection - onToggleNetwork: root.toggleNetwork(network, model, index) - preferredNetworksMode: root.preferredNetworksMode - preferredSharingNetworks: root.preferredSharingNetworks - allChecked: root.preferredSharingNetworks.length === layer1Networks.count + layer2Networks.count + Component { + id: layer2text + StatusBaseText { + width: parent.width + font.pixelSize: Style.current.primaryTextFontSize + color: Theme.palette.baseColor1 + text: qsTr("Layer 2") + height: 40 + leftPadding: 16 + topPadding: 10 + verticalAlignment: Text.AlignVCenter + } } } } diff --git a/ui/app/AppLayouts/Wallet/views/RightTabView.qml b/ui/app/AppLayouts/Wallet/views/RightTabView.qml index eacdea6992..57845f2cda 100644 --- a/ui/app/AppLayouts/Wallet/views/RightTabView.qml +++ b/ui/app/AppLayouts/Wallet/views/RightTabView.qml @@ -255,7 +255,7 @@ RightTabBaseView { visible: (stack.currentIndex === 2) - allNetworksModel: RootStore.allNetworks + allNetworksModel: RootStore.filteredFlatModel address: RootStore.overview.mixedcaseAddress showAllAccounts: RootStore.showAllAccounts currencyStore: RootStore.currencyStore diff --git a/ui/app/AppLayouts/Wallet/views/TransactionDetailView.qml b/ui/app/AppLayouts/Wallet/views/TransactionDetailView.qml index aadd11c34e..a3d501046a 100644 --- a/ui/app/AppLayouts/Wallet/views/TransactionDetailView.qml +++ b/ui/app/AppLayouts/Wallet/views/TransactionDetailView.qml @@ -7,6 +7,7 @@ import QtGraphicalEffects 1.15 import StatusQ.Components 0.1 import StatusQ.Core.Theme 0.1 import StatusQ.Core 0.1 +import StatusQ.Core.Utils 0.1 import StatusQ.Controls 0.1 import StatusQ.Popups 0.1 @@ -66,13 +67,13 @@ Item { } readonly property bool isIncoming: transactionType === Constants.TransactionType.Received || transactionType === Constants.TransactionType.ContractDeployment - readonly property string networkShortName: d.isTransactionValid ? RootStore.getNetworkShortName(transaction.chainId) : "" - readonly property string networkIcon: isTransactionValid ? RootStore.getNetworkIcon(transaction.chainId) : "network/Network=Custom" + readonly property string networkShortName: d.isTransactionValid ? ModelUtils.getByKey(RootStore.flatNetworks, "chainId", transaction.chainId, "shortName") : "" + readonly property string networkIcon: isTransactionValid ? ModelUtils.getByKey(RootStore.flatNetworks, "chainId", transaction.chainId, "iconUrl") : "network/Network=Custom" readonly property int blockNumber: isDetailsValid ? details.blockNumber : 0 readonly property int blockNumberIn: isDetailsValid ? details.blockNumberIn : 0 readonly property int blockNumberOut: isDetailsValid ? details.blockNumberOut : 0 readonly property string networkShortNameOut: networkShortName - readonly property string networkShortNameIn: transactionHeader.isMultiTransaction ? RootStore.getNetworkShortName(transaction.chainIdIn) : "" + readonly property string networkShortNameIn: transactionHeader.isMultiTransaction ? ModelUtils.getByKey(RootStore.flatNetworks, "chainId", transaction.chainIdIn, "shortName") : "" readonly property string symbol: isTransactionValid ? transaction.symbol : "" readonly property string inSymbol: isTransactionValid ? transaction.inSymbol : "" readonly property string outSymbol: isTransactionValid ? transaction.outSymbol : "" @@ -188,8 +189,9 @@ Item { readonly property int latestBlockNumberIn: d.isTransactionValid && !pending && !error && transactionHeader.isMultiTransaction && d.isBridge ? WalletStores.RootStore.getEstimatedLatestBlockNumber(d.transaction.chainIdIn) : 0 error: transactionHeader.transactionStatus === Constants.TransactionStatus.Failed pending: transactionHeader.transactionStatus === Constants.TransactionStatus.Pending - outNetworkLayer: d.isTransactionValid ? Number(RootStore.getNetworkLayer(transactionHeader.isMultiTransaction ? d.transaction.chainIdOut : d.transaction.chainId)) : 0 - inNetworkLayer: d.isTransactionValid && transactionHeader.isMultiTransaction && d.isBridge ? Number(RootStore.getNetworkLayer(d.transaction.chainIdIn)) : 0 + outNetworkLayer: d.isTransactionValid ? Number(ModelUtils.getByKey(RootStore.flatNetworks, "chainId", transactionHeader.isMultiTransaction ? d.transaction.chainIdOut : d.transaction.chainId, "layer")) : 0 + inNetworkLayer: d.isTransactionValid && transactionHeader.isMultiTransaction && d.isBridge ? + ModelUtils.getByKey(RootStore.flatNetworks, "chainId", d.transaction.chainIdIn, "layer") : 0 outNetworkTimestamp: d.isTransactionValid ? d.transaction.timestamp : 0 inNetworkTimestamp: d.isTransactionValid ? d.transaction.timestamp : 0 outChainName: transactionHeader.isMultiTransaction ? transactionHeader.networkNameOut : transactionHeader.networkName @@ -260,7 +262,7 @@ Item { case Constants.TransactionType.Swap: return Constants.tokenIcon(d.outSymbol) case Constants.TransactionType.Bridge: - return Style.svg(RootStore.getNetworkIcon(d.transaction.chainIdOut)) ?? Style.svg("network/Network=Custom") + return Style.svg(ModelUtils.getByKey(RootStore.flatNetworks, "chainId", d.transaction.chainIdOut, "iconUrl")) ?? Style.svg("network/Network=Custom") default: return "" } @@ -287,7 +289,7 @@ Item { case Constants.TransactionType.Swap: return Constants.tokenIcon(d.inSymbol) case Constants.TransactionType.Bridge: - return Style.svg(RootStore.getNetworkIcon(d.transaction.chainIdIn)) ?? Style.svg("network/Network=Custom") + return Style.svg(RootStore.Icon(d.transaction.chainIdIn)) ?? Style.svg("network/Network=Custom") default: return "" } diff --git a/ui/app/AppLayouts/stores/CloneModel.qml b/ui/app/AppLayouts/stores/CloneModel.qml index 7cb095f732..6ee39c3760 100644 --- a/ui/app/AppLayouts/stores/CloneModel.qml +++ b/ui/app/AppLayouts/stores/CloneModel.qml @@ -44,7 +44,10 @@ ListModel { for (let i = 0; i < model.count; i++) { const clonedItem = new Object() for (var propName of roles) { - clonedItem[propName] = model.rowData(i, propName) + if(model.rowData === undefined) + clonedItem[propName] = model.get(i, propName) + else + clonedItem[propName] = model.rowData(i, propName) } for (var newProp of rolesOverride) { clonedItem[newProp.role] = newProp.transform(clonedItem) @@ -52,4 +55,4 @@ ListModel { append(clonedItem) } } -} \ No newline at end of file +} diff --git a/ui/app/AppLayouts/stores/RootStore.qml b/ui/app/AppLayouts/stores/RootStore.qml index 57a8372480..269d141c2b 100644 --- a/ui/app/AppLayouts/stores/RootStore.qml +++ b/ui/app/AppLayouts/stores/RootStore.qml @@ -161,10 +161,10 @@ QtObject { readonly property bool showBrowserSelector: localAccountSensitiveSettings.showBrowserSelector readonly property bool openLinksInStatus: false - property var allNetworks: networksModule.all + property var flatNetworks: networksModule.flatNetworks function getEtherscanLink(chainID) { - return allNetworks.getBlockExplorerURL(chainID) + return networksModule.getBlockExplorerURL(chainID) } function createCommunity(communityName, communityDescription, checkedMembership, communityColor, communityTags, diff --git a/ui/app/mainui/AppMain.qml b/ui/app/mainui/AppMain.qml index d4f35a890d..1a936c07da 100644 --- a/ui/app/mainui/AppMain.qml +++ b/ui/app/mainui/AppMain.qml @@ -1809,7 +1809,7 @@ Item { } sourceComponent: WalletPopups.AddEditSavedAddressPopup { - allNetworks: RootStore.allNetworks + flatNetworks: WalletStore.RootStore.filteredFlatModel onClosed: { addEditSavedAddress.close() diff --git a/ui/imports/shared/controls/TransactionDelegate.qml b/ui/imports/shared/controls/TransactionDelegate.qml index b9f89c511e..20ad8c5b43 100644 --- a/ui/imports/shared/controls/TransactionDelegate.qml +++ b/ui/imports/shared/controls/TransactionDelegate.qml @@ -6,6 +6,7 @@ import StatusQ.Components 0.1 import StatusQ.Core.Theme 0.1 import StatusQ.Core 0.1 import StatusQ.Controls 0.1 +import StatusQ.Core.Utils 0.1 as SQUtils import AppLayouts.Wallet 1.0 @@ -62,10 +63,10 @@ StatusListItem { readonly property double outFiatValue: isModelDataValid && isMultiTransaction ? rootStore.getFiatValue(outCryptoValue, modelData.outSymbol): 0.0 readonly property double feeCryptoValue: 0.0 // TODO fill when bridge data is implemented readonly property double feeFiatValue: 0.0 // TODO fill when bridge data is implemented - readonly property string networkColor: isModelDataValid ? rootStore.getNetworkColor(modelData.chainId) : "" - readonly property string networkName: isModelDataValid ? rootStore.getNetworkFullName(modelData.chainId) : "" - readonly property string networkNameIn: isMultiTransaction ? rootStore.getNetworkFullName(modelData.chainIdIn) : "" - readonly property string networkNameOut: isMultiTransaction ? rootStore.getNetworkFullName(modelData.chainIdOut) : "" + readonly property string networkColor: isModelDataValid ? SQUtils.ModelUtils.getByKey(rootStore.flatNetworks, "chainId", modelData.chainId, "chainColor") : "" + readonly property string networkName: isModelDataValid ? SQUtils.ModelUtils.getByKey(rootStore.flatNetworks, "chainId", modelData.chainId, "chainName") : "" + readonly property string networkNameIn: isMultiTransaction ? SQUtils.ModelUtils.getByKey(rootStore.flatNetworks, "chainId", modelData.chainIdIn, "chainName") : "" + readonly property string networkNameOut: isMultiTransaction ? SQUtils.ModelUtils.getByKey(rootStore.flatNetworks, "chainId", modelData.chainIdOut, "chainName") : "" readonly property string addressNameTo: isModelDataValid ? walletRootStore.getNameForAddress(modelData.recipient) : "" readonly property string addressNameFrom: isModelDataValid ? walletRootStore.getNameForAddress(modelData.sender) : "" readonly property bool isNFT: isModelDataValid && modelData.isNFT @@ -246,7 +247,7 @@ StatusListItem { } // PROGRESS - const networkLayer = rootStore.getNetworkLayer(modelData.chainId) + const networkLayer = SQUtils.ModelUtils.getByKey(rootStore.flatNetworks, "chainId", modelData.chainId, "layer") const isBridge = type === Constants.TransactionType.Bridge switch(transactionStatus) { @@ -272,7 +273,7 @@ StatusListItem { details += qsTr("Confirmed on %1").arg(root.networkName) + endl details += LocaleUtils.formatDateTime(confirmationTimeStamp * 1000, Locale.LongFormat) + endl2 if (isBridge) { - const networkInLayer = rootStore.getNetworkLayer(modelData.chainIdIn) + const networkInLayer = SQUtils.ModelUtils.getByKey(rootStore.flatNetworks, "chainId", modelData.chainIdIn, "layer") const confirmationTimeStampIn = WalletUtils.calculateConfirmationTimestamp(networkInLayer, modelData.timestamp) details += qsTr("Signed on %1").arg(root.networkNameIn) + endl + timestampString + endl2 details += qsTr("Confirmed on %1").arg(root.networkNameIn) + endl @@ -293,7 +294,7 @@ StatusListItem { details += qsTr("Finalised on %1").arg(root.networkName) + endl details += LocaleUtils.formatDateTime(finalisationTimeStamp * 1000, Locale.LongFormat) + endl2 if (isBridge) { - const networkInLayer = rootStore.getNetworkLayer(modelData.chainIdIn) + const networkInLayer = SQUtils.ModelUtils.getByKey(rootStore.flatNetworks, "chainId", modelData.chainIdIn, "layer") const confirmationTimeStampIn = WalletUtils.calculateConfirmationTimestamp(networkInLayer, modelData.timestamp) const finalisationTimeStampIn = WalletUtils.calculateFinalisationTimestamp(networkInLayer, modelData.timestamp) const epochIn = Math.abs(walletRootStore.getEstimatedLatestBlockNumber(modelData.chainIdIn) - detailsObj.blockNumberIn) diff --git a/ui/imports/shared/popups/send/SendModal.qml b/ui/imports/shared/popups/send/SendModal.qml index fd8f9a2826..20bee4ba50 100644 --- a/ui/imports/shared/popups/send/SendModal.qml +++ b/ui/imports/shared/popups/send/SendModal.qml @@ -268,7 +268,7 @@ StatusDialog { selectedSenderAccount: store.selectedSenderAccount.address assetsModel: popup.store.processedAssetsModel collectiblesModel: popup.preSelectedAccount ? popup.nestedCollectiblesModel : null - networksModel: popup.store.allNetworksModel + networksModel: popup.store.flatNetworksModel currentCurrencySymbol: d.currencyStore.currentCurrencySymbol visible: (!!d.selectedHolding && d.selectedHoldingType !== Constants.TokenType.Unknown) || (!!d.hoveredHolding && d.hoveredHoldingType !== Constants.TokenType.Unknown) @@ -400,7 +400,7 @@ StatusDialog { selectedSenderAccount: store.selectedSenderAccount.address assets: popup.store.processedAssetsModel collectibles: popup.preSelectedAccount ? popup.nestedCollectiblesModel : null - networksModel: popup.store.allNetworksModel + networksModel: popup.store.flatNetworksModel onlyAssets: holdingSelector.onlyAssets onTokenSelected: { d.setSelectedHoldingId(symbol, holdingType) diff --git a/ui/imports/shared/popups/send/views/NetworkSelector.qml b/ui/imports/shared/popups/send/views/NetworkSelector.qml index faaf311954..c47f5608e5 100644 --- a/ui/imports/shared/popups/send/views/NetworkSelector.qml +++ b/ui/imports/shared/popups/send/views/NetworkSelector.qml @@ -88,7 +88,7 @@ Item { errorMode: root.errorMode errorType: root.errorType toNetworksList: root.toNetworksList - selectedSymbol: root.selectedAsset.symbol + selectedSymbol: !!root.selectedAsset ? root.selectedAsset.symbol: "" weiToEth: function(wei) { if(!!selectedAsset && root.selectedAsset !== undefined) return parseFloat(store.getWei2Eth(wei, root.selectedAsset.decimals)) diff --git a/ui/imports/shared/stores/CommunityTokensStore.qml b/ui/imports/shared/stores/CommunityTokensStore.qml index ce752b52ce..3a2b75d347 100644 --- a/ui/imports/shared/stores/CommunityTokensStore.qml +++ b/ui/imports/shared/stores/CommunityTokensStore.qml @@ -1,4 +1,6 @@ import QtQuick 2.15 +import SortFilterProxyModel 0.2 + import utils 1.0 QtObject { @@ -7,10 +9,11 @@ QtObject { property var communityTokensModuleInst: communityTokensModule ?? null // Network selection properties: - property var layer1Networks: networksModule.layer1 - property var layer2Networks: networksModule.layer2 - property var enabledNetworks: networksModule.enabled - property var allNetworks: networksModule.all + property var flatNetworks: networksModule.flatNetworks + property SortFilterProxyModel filteredFlatModel: SortFilterProxyModel { + sourceModel: root.flatNetworks + filters: ValueFilter { roleName: "isTest"; value: networksModule.areTestNetworksEnabled } + } // set by asyncGetOwnerTokenDetails readonly property var ownerTokenDetails: { diff --git a/ui/imports/shared/stores/NetworkConnectionStore.qml b/ui/imports/shared/stores/NetworkConnectionStore.qml index 3ceb0e2202..ffe6dd8c01 100644 --- a/ui/imports/shared/stores/NetworkConnectionStore.qml +++ b/ui/imports/shared/stores/NetworkConnectionStore.qml @@ -1,5 +1,7 @@ import QtQuick 2.13 +import SortFilterProxyModel 0.2 + import StatusQ.Core 0.1 import StatusQ.Core.Utils 0.1 @@ -15,8 +17,13 @@ QtObject { readonly property bool balanceCache: walletSectionAssets.hasBalanceCache readonly property bool marketValuesCache: walletSectionAssets.hasMarketValuesCache + readonly property SortFilterProxyModel __filteredflatNetworks: SortFilterProxyModel { + sourceModel: networksModule.flatNetworks + filters: ValueFilter { roleName: "isTest"; value: networksModule.areTestNetworksEnabled } + } + readonly property var blockchainNetworksDown: !!networkConnectionModule.blockchainNetworkConnection.chainIds ? networkConnectionModule.blockchainNetworkConnection.chainIds.split(";") : [] - readonly property bool atleastOneBlockchainNetworkAvailable: blockchainNetworksDown.length < networksModule.all.count + readonly property bool atleastOneBlockchainNetworkAvailable: blockchainNetworksDown.length < __filteredflatNetworks.count readonly property bool sendBuyBridgeEnabled: localAppSettings.testEnvironment || (isOnline && (!networkConnectionModule.blockchainNetworkConnection.completelyDown && atleastOneBlockchainNetworkAvailable) && @@ -52,9 +59,10 @@ QtObject { readonly property bool noTokenBalanceAvailable: notOnlineWithNoCache || noBlockchainConnectionAndNoCache readonly property bool ensNetworkAvailable: !blockchainNetworksDown.includes(mainModule.appNetworkId.toString()) - readonly property string ensNetworkUnavailableText: qsTr("Requires POKT/Infura for %1, which is currently unavailable").arg(networksModule.all.getNetworkFullName(mainModule.appNetworkId)) + readonly property string ensNetworkUnavailableText: qsTr("Requires POKT/Infura for %1, which is currently unavailable").arg(appNetworkName) readonly property bool stickersNetworkAvailable: !blockchainNetworksDown.includes(mainModule.appNetworkId.toString()) - readonly property string stickersNetworkUnavailableText: qsTr("Requires POKT/Infura for %1, which is currently unavailable").arg(networksModule.all.getNetworkFullName(mainModule.appNetworkId)) + readonly property string stickersNetworkUnavailableText: qsTr("Requires POKT/Infura for %1, which is currently unavailable").arg(appNetworkName) + readonly property string appNetworkName: ModelUtils.getByKey(networksModule.flatNetworks, "chainId", mainModule.appNetworkId, "chainName") function getBlockchainNetworkDownTextForToken(balances) { if(!!balances && !networkConnectionModule.blockchainNetworkConnection.completelyDown && !notOnlineWithNoCache) { @@ -88,7 +96,7 @@ QtObject { let jointChainIdString = "" for (const chain of chainIdsDown) { jointChainIdString = (!!jointChainIdString) ? jointChainIdString + " & " : jointChainIdString - jointChainIdString += networksModule.all.getNetworkFullName(parseInt(chain)) + jointChainIdString += ModelUtils.getByKey(networksModule.flatNetworks, "chainId", parseInt(chain), "chainName") } return jointChainIdString } diff --git a/ui/imports/shared/stores/RootStore.qml b/ui/imports/shared/stores/RootStore.qml index 998636f6f6..5876b72e66 100644 --- a/ui/imports/shared/stores/RootStore.qml +++ b/ui/imports/shared/stores/RootStore.qml @@ -30,41 +30,12 @@ QtObject { property bool isNonArchivalNode: Global.appIsReady && walletSectionInst.isNonArchivalNode property var marketValueStore: TokenMarketValuesStore{} - property var allNetworks: networksModule.all function resetActivityData() { walletSectionInst.activityController.resetActivityData() } - // TODO remove all these by linking chainId for networks and activity using LeftJoinModel - // not possible currently due to the current structure of the activity model - function getNetworkColor(chainId) { - return networksModule.all.getChainColor(chainId) - } - - function getNetworkIcon(chainId) { - return networksModule.all.getIconUrl(chainId) - } - - function getNetworkShortName(chainId) { - return networksModule.all.getNetworkShortName(chainId) - } - - function getNetworkFullName(chainId) { - return networksModule.all.getNetworkFullName(chainId) - } - - function getNetworkLayer(chainId) { - return networksModule.all.getNetworkLayer(chainId) - } - - function getNetworkIconUrl(symbol) { - return networksModule.all.getNetworkIconUrl(symbol) - } - - function getNetworkName(symbol) { - return networksModule.all.getNetworkName(symbol) - } + property var flatNetworks: networksModule.flatNetworks function hex2Dec(value) { return globalUtils.hex2Dec(value) diff --git a/ui/imports/shared/stores/send/TransactionStore.qml b/ui/imports/shared/stores/send/TransactionStore.qml index a8bbd7162c..2af3b8d040 100644 --- a/ui/imports/shared/stores/send/TransactionStore.qml +++ b/ui/imports/shared/stores/send/TransactionStore.qml @@ -23,7 +23,7 @@ QtObject { property var fromNetworksModel: walletSectionSendInst.fromNetworksModel property var toNetworksModel: walletSectionSendInst.toNetworksModel - property var allNetworksModel: networksModule.all + property var flatNetworksModel: networksModule.flatNetworks property var senderAccounts: walletSectionSendInst.senderAccounts property var selectedSenderAccount: walletSectionSendInst.selectedSenderAccount property var accounts: walletSectionSendInst.accounts @@ -55,7 +55,7 @@ QtObject { } function getEtherscanLink(chainID) { - return networksModule.all.getBlockExplorerURL(chainID) + return networksModule.getBlockExplorerURL(chainID) } function copyToClipboard(text) {