fix(@desktop/wallet): Wallet:: grouped_account_assets_model:: Handle updates as updates and not reset entire model
fixes #15604
This commit is contained in:
parent
94c62dae26
commit
f752735bf8
|
@ -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()
|
||||
|
|
|
@ -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")
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
return self.controller.isChecksumValidForAddress(address)
|
||||
|
|
Loading…
Reference in New Issue