fix(@desktop/wallet): fixing crash on switching testnet model from on to off

This commit is contained in:
Khushboo Mehta 2024-02-07 15:37:47 +01:00 committed by Khushboo-dev-cpp
parent 74bcdbe2c3
commit 3865c68737
11 changed files with 11 additions and 37 deletions

View File

@ -128,12 +128,9 @@ QtObject:
of ModelRole.MarketDetailsLoading: of ModelRole.MarketDetailsLoading:
result = newQVariant(self.delegate.getTokensMarketValuesLoading()) result = newQVariant(self.delegate.getTokensMarketValuesLoading())
proc modelsAboutToUpdate*(self: FlatTokensModel) =
self.tokenMarketDetails = @[]
self.beginResetModel()
proc modelsUpdated*(self: FlatTokensModel) = proc modelsUpdated*(self: FlatTokensModel) =
self.beginResetModel()
self.tokenMarketDetails = @[]
for token in self.delegate.getFlatTokensList(): for token in self.delegate.getFlatTokensList():
let symbol = if token.communityId.isEmptyOrWhitespace: token.symbol let symbol = if token.communityId.isEmptyOrWhitespace: token.symbol
else: "" else: ""

View File

@ -49,8 +49,6 @@ method load*(self: Module) =
self.controller.rebuildMarketData() self.controller.rebuildMarketData()
# Passing on the events for changes in model to abstract model # Passing on the events for changes in model to abstract model
self.events.on(SIGNAL_TOKENS_LIST_ABOUT_TO_BE_UPDATED) do(e: Args):
self.view.modelsAboutToUpdate()
self.events.on(SIGNAL_TOKENS_LIST_UPDATED) do(e: Args): self.events.on(SIGNAL_TOKENS_LIST_UPDATED) do(e: Args):
self.view.modelsUpdated() self.view.modelsUpdated()
self.view.setTokenListUpdatedAt(self.controller.getTokenListUpdatedAt()) self.view.setTokenListUpdatedAt(self.controller.getTokenListUpdatedAt())

View File

@ -69,8 +69,6 @@ QtObject:
of ModelRole.TokensCount: of ModelRole.TokensCount:
result = newQVariant(item.tokensCount) result = newQVariant(item.tokensCount)
proc modelsAboutToUpdate*(self: SourcesOfTokensModel) =
self.beginResetModel()
proc modelsUpdated*(self: SourcesOfTokensModel) = proc modelsUpdated*(self: SourcesOfTokensModel) =
self.beginResetModel()
self.endResetModel() self.endResetModel()

View File

@ -128,12 +128,10 @@ QtObject:
of ModelRole.MarketDetailsLoading: of ModelRole.MarketDetailsLoading:
result = newQVariant(self.delegate.getTokensMarketValuesLoading()) result = newQVariant(self.delegate.getTokensMarketValuesLoading())
proc modelsAboutToUpdate*(self: TokensBySymbolModel) = proc modelsUpdated*(self: TokensBySymbolModel) =
self.beginResetModel()
self.tokenMarketDetails = @[] self.tokenMarketDetails = @[]
self.addressPerChainModel = @[] self.addressPerChainModel = @[]
self.beginResetModel()
proc modelsUpdated*(self: TokensBySymbolModel) =
let tokensList = self.delegate.getTokenBySymbolList() let tokensList = self.delegate.getTokenBySymbolList()
for index in countup(0, tokensList.len-1): for index in countup(0, tokensList.len-1):
self.addressPerChainModel.add(newAddressPerChainModel(self.delegate, index)) self.addressPerChainModel.add(newAddressPerChainModel(self.delegate, index))

View File

@ -116,11 +116,6 @@ QtObject:
read = getTokensBySymbolModel read = getTokensBySymbolModel
notify = tokensBySymbolModelChanged notify = tokensBySymbolModelChanged
proc modelsAboutToUpdate*(self: View) =
self.sourcesOfTokensModel.modelsAboutToUpdate()
self.flatTokensModel.modelsAboutToUpdate()
self.tokensBySymbolModel.modelsAboutToUpdate()
proc modelsUpdated*(self: View) = proc modelsUpdated*(self: View) =
self.sourcesOfTokensModel.modelsUpdated() self.sourcesOfTokensModel.modelsUpdated()
self.flatTokensModel.modelsUpdated() self.flatTokensModel.modelsUpdated()

View File

@ -58,17 +58,18 @@ QtObject:
of ModelRole.Balances: of ModelRole.Balances:
result = newQVariant(self.balancesPerChain[index.row]) result = newQVariant(self.balancesPerChain[index.row])
proc modelsAboutToUpdate*(self: Model) =
self.beginResetModel()
proc modelsUpdated*(self: Model) = proc modelsUpdated*(self: Model) =
self.beginResetModel()
let lengthOfGroupedAssets = self.delegate.getGroupedAccountsAssetsList().len let lengthOfGroupedAssets = self.delegate.getGroupedAccountsAssetsList().len
let balancesPerChainLen = self.balancesPerChain.len let balancesPerChainLen = self.balancesPerChain.len
let diff = abs(lengthOfGroupedAssets - balancesPerChainLen) 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: if lengthOfGroupedAssets > balancesPerChainLen:
for i in countup(0, diff-1): for i in countup(0, diff-1):
self.balancesPerChain.add(newBalancesModel(self.delegate, balancesPerChainLen+i)) self.balancesPerChain.add(newBalancesModel(self.delegate, balancesPerChainLen+i))
elif lengthOfGroupedAssets < balancesPerChainLen:
self.balancesPerChain.delete(balancesPerChainLen - diff, balancesPerChainLen-1)
self.endResetModel() self.endResetModel()
self.countChanged() self.countChanged()

View File

@ -44,9 +44,6 @@ method delete*(self: Module) =
method load*(self: Module) = method load*(self: Module) =
singletonInstance.engine.setRootContextProperty("walletSectionAssets", newQVariant(self.view)) singletonInstance.engine.setRootContextProperty("walletSectionAssets", newQVariant(self.view))
self.events.on(SIGNAL_WALLET_ACCOUNT_TOKENS_BEING_FETCHED) do(e:Args):
self.view.modelsAboutToUpdate()
self.events.on(SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT) do(e:Args): self.events.on(SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT) do(e:Args):
self.view.modelsUpdated() self.view.modelsUpdated()
self.view.setHasBalanceCache(self.controller.getHasBalanceCache()) self.view.setHasBalanceCache(self.controller.getHasBalanceCache())

View File

@ -56,8 +56,5 @@ QtObject:
self.hasMarketValuesCache = hasMarketValuesCache self.hasMarketValuesCache = hasMarketValuesCache
self.hasMarketValuesCacheChanged() self.hasMarketValuesCacheChanged()
proc modelsAboutToUpdate*(self: View) =
self.groupedAccountAssetsModel.modelsAboutToUpdate()
proc modelsUpdated*(self: View) = proc modelsUpdated*(self: View) =
self.groupedAccountAssetsModel.modelsUpdated() self.groupedAccountAssetsModel.modelsUpdated()

View File

@ -33,7 +33,6 @@ const CRYPTO_SUB_UNITS_TO_FACTOR = {
const SIGNAL_TOKEN_HISTORICAL_DATA_LOADED* = "tokenHistoricalDataLoaded" const SIGNAL_TOKEN_HISTORICAL_DATA_LOADED* = "tokenHistoricalDataLoaded"
const SIGNAL_BALANCE_HISTORY_DATA_READY* = "tokenBalanceHistoryDataReady" const SIGNAL_BALANCE_HISTORY_DATA_READY* = "tokenBalanceHistoryDataReady"
const SIGNAL_TOKENS_LIST_UPDATED* = "tokensListUpdated" const SIGNAL_TOKENS_LIST_UPDATED* = "tokensListUpdated"
const SIGNAL_TOKENS_LIST_ABOUT_TO_BE_UPDATED* = "tokensListAboutToBeUpdated"
const SIGNAL_TOKENS_DETAILS_ABOUT_TO_BE_UPDATED* = "tokensDetailsAboutToBeUpdated" const SIGNAL_TOKENS_DETAILS_ABOUT_TO_BE_UPDATED* = "tokensDetailsAboutToBeUpdated"
const SIGNAL_TOKENS_DETAILS_UPDATED* = "tokensDetailsUpdated" const SIGNAL_TOKENS_DETAILS_UPDATED* = "tokensDetailsUpdated"
const SIGNAL_TOKENS_MARKET_VALUES_ABOUT_TO_BE_UPDATED* = "tokensMarketValuesAboutToBeUpdated" const SIGNAL_TOKENS_MARKET_VALUES_ABOUT_TO_BE_UPDATED* = "tokensMarketValuesAboutToBeUpdated"
@ -342,8 +341,6 @@ QtObject:
error "error: ", errDesription error "error: ", errDesription
proc getSupportedTokensList*(self: Service) = proc getSupportedTokensList*(self: Service) =
# this is emited so that the models can know that an update is about to happen
self.events.emit(SIGNAL_TOKENS_LIST_ABOUT_TO_BE_UPDATED, Args())
let arg = QObjectTaskArg( let arg = QObjectTaskArg(
tptr: cast[ByteAddress](getSupportedTokenList), tptr: cast[ByteAddress](getSupportedTokenList),
vptr: cast[ByteAddress](self.vptr), vptr: cast[ByteAddress](self.vptr),

View File

@ -80,9 +80,6 @@ proc buildAllTokens*(self: Service, accounts: seq[string], store: bool) =
for waddress in accounts: for waddress in accounts:
self.updateAssetsLoadingState(waddress, true) self.updateAssetsLoadingState(waddress, true)
# this is emited so that the models can know that an update is about to happen
self.events.emit(SIGNAL_WALLET_ACCOUNT_TOKENS_BEING_FETCHED, Args())
let arg = BuildTokensTaskArg( let arg = BuildTokensTaskArg(
tptr: cast[ByteAddress](prepareTokensTask), tptr: cast[ByteAddress](prepareTokensTask),
vptr: cast[ByteAddress](self.vptr), vptr: cast[ByteAddress](self.vptr),

View File

@ -13,7 +13,6 @@ const SIGNAL_WALLET_ACCOUNT_DELETED* = "walletAccount/accountDeleted"
const SIGNAL_WALLET_ACCOUNT_UPDATED* = "walletAccount/walletAccountUpdated" const SIGNAL_WALLET_ACCOUNT_UPDATED* = "walletAccount/walletAccountUpdated"
const SIGNAL_WALLET_ACCOUNT_NETWORK_ENABLED_UPDATED* = "walletAccount/networkEnabledUpdated" const SIGNAL_WALLET_ACCOUNT_NETWORK_ENABLED_UPDATED* = "walletAccount/networkEnabledUpdated"
const SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT* = "walletAccount/tokensRebuilt" const SIGNAL_WALLET_ACCOUNT_TOKENS_REBUILT* = "walletAccount/tokensRebuilt"
const SIGNAL_WALLET_ACCOUNT_TOKENS_BEING_FETCHED* = "walletAccount/tokenFetching"
const SIGNAL_WALLET_ACCOUNT_DERIVED_ADDRESSES_FETCHED* = "walletAccount/derivedAddressesFetched" const SIGNAL_WALLET_ACCOUNT_DERIVED_ADDRESSES_FETCHED* = "walletAccount/derivedAddressesFetched"
const SIGNAL_WALLET_ACCOUNT_DERIVED_ADDRESSES_FROM_MNEMONIC_FETCHED* = "walletAccount/derivedAddressesFromMnemonicFetched" const SIGNAL_WALLET_ACCOUNT_DERIVED_ADDRESSES_FROM_MNEMONIC_FETCHED* = "walletAccount/derivedAddressesFromMnemonicFetched"
const SIGNAL_WALLET_ACCOUNT_ADDRESS_DETAILS_FETCHED* = "walletAccount/addressDetailsFetched" const SIGNAL_WALLET_ACCOUNT_ADDRESS_DETAILS_FETCHED* = "walletAccount/addressDetailsFetched"