From f752735bf8632965a2d6d0521364dfe0f5ed6136 Mon Sep 17 00:00:00 2001 From: Khushboo Mehta Date: Wed, 4 Sep 2024 19:38:19 +0200 Subject: [PATCH] fix(@desktop/wallet): Wallet:: grouped_account_assets_model:: Handle updates as updates and not reset entire model fixes #15604 --- .../assets/grouped_account_assets_model.nim | 38 ++++++++++++------- .../wallet_section/assets/io_interface.nim | 3 -- .../main/wallet_section/assets/module.nim | 3 -- .../modules/main/wallet_section/module.nim | 3 +- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/app/modules/main/wallet_section/assets/grouped_account_assets_model.nim b/src/app/modules/main/wallet_section/assets/grouped_account_assets_model.nim index 4b75dbf25f..4bd35a688d 100644 --- a/src/app/modules/main/wallet_section/assets/grouped_account_assets_model.nim +++ b/src/app/modules/main/wallet_section/assets/grouped_account_assets_model.nim @@ -59,17 +59,27 @@ QtObject: result = newQVariant(self.balancesPerChain[index.row]) proc modelsUpdated*(self: Model) = - self.beginResetModel() - let lengthOfGroupedAssets = self.delegate.getGroupedAccountsAssetsList().len - let balancesPerChainLen = self.balancesPerChain.len - let diff = abs(lengthOfGroupedAssets - balancesPerChainLen) - # Please note that in case more tokens are added either due to refresh or adding of new accounts - # new entries to fetch balances data are created. - # On the other hand we are not deleting in case the assets disappear either on refresh - # as there is no balance or accounts were deleted because it causes a crash on UI. - # Also this will automatically be removed on the next time app is restarted - if lengthOfGroupedAssets > balancesPerChainLen: - for i in countup(0, diff-1): - self.balancesPerChain.add(newBalancesModel(self.delegate, balancesPerChainLen+i)) - self.endResetModel() - self.countChanged() + # first time model is fetched + if self.balancesPerChain.len == 0: + self.beginResetModel() + for i in countup(0, self.delegate.getGroupedAccountsAssetsList().len-1): + self.balancesPerChain.add(newBalancesModel(self.delegate, i)) + self.endResetModel() + else : + # model is updated not reset + let lengthOfGroupedAssets = self.delegate.getGroupedAccountsAssetsList().len + let balancesPerChainLen = self.balancesPerChain.len + let diff = lengthOfGroupedAssets - balancesPerChainLen + + if diff > 0: + for i in countup(0, diff-1): + self.balancesPerChain.add(newBalancesModel(self.delegate, balancesPerChainLen+i)) + + let index = self.createIndex(0, 0, nil) + let lastindex = self.createIndex(lengthOfGroupedAssets-1, 0, nil) + defer: index.delete + defer: lastindex.delete + self.dataChanged(index, lastindex, @[ModelRole.TokensKey.int, ModelRole.Balances.int]) + + if diff > 0: + self.countChanged() diff --git a/src/app/modules/main/wallet_section/assets/io_interface.nim b/src/app/modules/main/wallet_section/assets/io_interface.nim index 6d31a25c36..6fb559ae71 100644 --- a/src/app/modules/main/wallet_section/assets/io_interface.nim +++ b/src/app/modules/main/wallet_section/assets/io_interface.nim @@ -26,6 +26,3 @@ method getGroupedAccountAssetsDataSource*(self: AccessInterface): GroupedAccount # inheritance, which is not well supported in Nim. method viewDidLoad*(self: AccessInterface) {.base.} = raise newException(ValueError, "No implementation available") - -method filterChanged*(self: AccessInterface, addresses: seq[string], chainIds: seq[int]) {.base.} = - raise newException(ValueError, "No implementation available") diff --git a/src/app/modules/main/wallet_section/assets/module.nim b/src/app/modules/main/wallet_section/assets/module.nim index afcdd15e98..a74effd660 100644 --- a/src/app/modules/main/wallet_section/assets/module.nim +++ b/src/app/modules/main/wallet_section/assets/module.nim @@ -73,6 +73,3 @@ method getGroupedAccountAssetsDataSource*(self: Module): GroupedAccountAssetsDat return ( getGroupedAccountsAssetsList: proc(): var seq[GroupedTokenItem] = self.controller.getGroupedAccountsAssetsList() ) - -method filterChanged*(self: Module, addresses: seq[string], chainIds: seq[int]) = - self.controller.buildAllTokens(addresses) diff --git a/src/app/modules/main/wallet_section/module.nim b/src/app/modules/main/wallet_section/module.nim index a2d6fc1cec..f04d187a5c 100644 --- a/src/app/modules/main/wallet_section/module.nim +++ b/src/app/modules/main/wallet_section/module.nim @@ -226,7 +226,6 @@ proc notifyModulesOnFilterChanged(self: Module) = self.activityController.globalFilterChanged(self.filter.addresses, self.filter.chainIds, self.filter.allChainsEnabled) self.allTokensModule.filterChanged(self.filter.addresses) self.allCollectiblesModule.refreshWalletAccounts() - self.assetsModule.filterChanged(self.filter.addresses, self.filter.chainIds) proc notifyModulesBalanceIsLoaded(self: Module) = self.overviewModule.filterChanged(self.filter.addresses, self.filter.chainIds) @@ -544,4 +543,4 @@ method reloadAccountTokens*(self: Module) = self.controller.reloadAccountTokens() method isChecksumValidForAddress*(self: Module, address: string): bool = - return self.controller.isChecksumValidForAddress(address) \ No newline at end of file + return self.controller.isChecksumValidForAddress(address)