fix(@desktop/wallet): Wallet:: grouped_account_assets_model:: Handle updates as updates and not reset entire model

fixes #15604
This commit is contained in:
Khushboo Mehta 2024-09-04 19:38:19 +02:00
parent 94c62dae26
commit f752735bf8
4 changed files with 25 additions and 22 deletions

View File

@ -59,17 +59,27 @@ QtObject:
result = newQVariant(self.balancesPerChain[index.row]) result = newQVariant(self.balancesPerChain[index.row])
proc modelsUpdated*(self: Model) = proc modelsUpdated*(self: Model) =
self.beginResetModel() # first time model is fetched
let lengthOfGroupedAssets = self.delegate.getGroupedAccountsAssetsList().len if self.balancesPerChain.len == 0:
let balancesPerChainLen = self.balancesPerChain.len self.beginResetModel()
let diff = abs(lengthOfGroupedAssets - balancesPerChainLen) for i in countup(0, self.delegate.getGroupedAccountsAssetsList().len-1):
# Please note that in case more tokens are added either due to refresh or adding of new accounts self.balancesPerChain.add(newBalancesModel(self.delegate, i))
# new entries to fetch balances data are created. self.endResetModel()
# On the other hand we are not deleting in case the assets disappear either on refresh else :
# as there is no balance or accounts were deleted because it causes a crash on UI. # model is updated not reset
# Also this will automatically be removed on the next time app is restarted let lengthOfGroupedAssets = self.delegate.getGroupedAccountsAssetsList().len
if lengthOfGroupedAssets > balancesPerChainLen: let balancesPerChainLen = self.balancesPerChain.len
for i in countup(0, diff-1): let diff = lengthOfGroupedAssets - balancesPerChainLen
self.balancesPerChain.add(newBalancesModel(self.delegate, balancesPerChainLen+i))
self.endResetModel() if diff > 0:
self.countChanged() 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()

View File

@ -26,6 +26,3 @@ method getGroupedAccountAssetsDataSource*(self: AccessInterface): GroupedAccount
# inheritance, which is not well supported in Nim. # inheritance, which is not well supported in Nim.
method viewDidLoad*(self: AccessInterface) {.base.} = method viewDidLoad*(self: AccessInterface) {.base.} =
raise newException(ValueError, "No implementation available") raise newException(ValueError, "No implementation available")
method filterChanged*(self: AccessInterface, addresses: seq[string], chainIds: seq[int]) {.base.} =
raise newException(ValueError, "No implementation available")

View File

@ -73,6 +73,3 @@ method getGroupedAccountAssetsDataSource*(self: Module): GroupedAccountAssetsDat
return ( return (
getGroupedAccountsAssetsList: proc(): var seq[GroupedTokenItem] = self.controller.getGroupedAccountsAssetsList() getGroupedAccountsAssetsList: proc(): var seq[GroupedTokenItem] = self.controller.getGroupedAccountsAssetsList()
) )
method filterChanged*(self: Module, addresses: seq[string], chainIds: seq[int]) =
self.controller.buildAllTokens(addresses)

View File

@ -226,7 +226,6 @@ proc notifyModulesOnFilterChanged(self: Module) =
self.activityController.globalFilterChanged(self.filter.addresses, self.filter.chainIds, self.filter.allChainsEnabled) self.activityController.globalFilterChanged(self.filter.addresses, self.filter.chainIds, self.filter.allChainsEnabled)
self.allTokensModule.filterChanged(self.filter.addresses) self.allTokensModule.filterChanged(self.filter.addresses)
self.allCollectiblesModule.refreshWalletAccounts() self.allCollectiblesModule.refreshWalletAccounts()
self.assetsModule.filterChanged(self.filter.addresses, self.filter.chainIds)
proc notifyModulesBalanceIsLoaded(self: Module) = proc notifyModulesBalanceIsLoaded(self: Module) =
self.overviewModule.filterChanged(self.filter.addresses, self.filter.chainIds) self.overviewModule.filterChanged(self.filter.addresses, self.filter.chainIds)
@ -544,4 +543,4 @@ method reloadAccountTokens*(self: Module) =
self.controller.reloadAccountTokens() self.controller.reloadAccountTokens()
method isChecksumValidForAddress*(self: Module, address: string): bool = method isChecksumValidForAddress*(self: Module, address: string): bool =
return self.controller.isChecksumValidForAddress(address) return self.controller.isChecksumValidForAddress(address)