From 31ade3e742cfbad513e451bb4312ccedfb0e4864 Mon Sep 17 00:00:00 2001 From: Cuteivist Date: Wed, 31 Jul 2024 06:53:35 +0200 Subject: [PATCH] fix(wallet): Update preferred networks even when empty (#15841) --- .../shared_models/keypair_account_model.nim | 6 ++---- .../wallet_account/service_account.nim | 21 ++++++++++++------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/app/modules/shared_models/keypair_account_model.nim b/src/app/modules/shared_models/keypair_account_model.nim index 7ff78032ce..92547fa8f7 100644 --- a/src/app/modules/shared_models/keypair_account_model.nim +++ b/src/app/modules/shared_models/keypair_account_model.nim @@ -143,10 +143,8 @@ QtObject: proc updatePreferredSharingChainsForAddress*(self: KeyPairAccountModel, address, prodPreferredChainIds, testPreferredChainIds: string) = for i in 0 ..< self.items.len: if cmpIgnoreCase(self.items[i].getAddress(), address) == 0: - if prodPreferredChainIds.len > 0: - self.items[i].setProdPreferredChainIds(prodPreferredChainIds) - if testPreferredChainIds.len > 0: - self.items[i].setTestPreferredChainIds(testPreferredChainIds) + self.items[i].setProdPreferredChainIds(prodPreferredChainIds) + self.items[i].setTestPreferredChainIds(testPreferredChainIds) proc updateAccountHiddenInTotalBalance*(self: KeyPairAccountModel, address: string, hideFromTotalBalance: bool) = for i in 0 ..< self.items.len: diff --git a/src/app_service/service/wallet_account/service_account.nim b/src/app_service/service/wallet_account/service_account.nim index e4440fa02c..76027df759 100644 --- a/src/app_service/service/wallet_account/service_account.nim +++ b/src/app_service/service/wallet_account/service_account.nim @@ -306,15 +306,20 @@ proc updateAccountInLocalStoreAndNotify(self: Service, address, name, colorId, e if notify: self.events.emit(SIGNAL_WALLET_ACCOUNT_POSITION_UPDATED, Args()) -proc updatePreferredSharingChainsAndNotify(self: Service, address, prodPreferredChains, testPreferredChains: string) = +proc updateTestPreferredSharingChainsAndNotify(self: Service, address, testPreferredChains: string) = var account = self.getAccountByAddress(address) if account.isNil: - error "account's address is not among known addresses: ", address=address, procName="updatePreferredSharingChainsAndNotify" + error "account's address is not among known addresses: ", address=address, procName="updateTestPreferredSharingChainsAndNotify" return - if testPreferredChains.len > 0 and testPreferredChains != account.testPreferredChainIds: - account.testPreferredChainIds = testPreferredChains - if prodPreferredChains.len > 0 and prodPreferredChains != account.prodPreferredChainIds: - account.prodPreferredChainIds = prodPreferredChains + account.testPreferredChainIds = testPreferredChains + self.events.emit(SIGNAL_WALLET_ACCOUNT_PREFERRED_SHARING_CHAINS_UPDATED, AccountArgs(account: account)) + +proc updateProdPreferredSharingChainsAndNotify(self: Service, address, prodPreferredChains: string) = + var account = self.getAccountByAddress(address) + if account.isNil: + error "account's address is not among known addresses: ", address=address, procName="updateProdPreferredSharingChainsAndNotify" + return + account.prodPreferredChainIds = prodPreferredChains self.events.emit(SIGNAL_WALLET_ACCOUNT_PREFERRED_SHARING_CHAINS_UPDATED, AccountArgs(account: account)) ## if password is not provided local keystore file won't be created @@ -565,7 +570,7 @@ proc updateWalletAccountProdPreferredChains*(self: Service, address, preferredCh if not response.error.isNil: error "status-go error", procName="updateWalletAccountProdPreferredChains", errCode=response.error.code, errDesription=response.error.message return false - self.updatePreferredSharingChainsAndNotify(address, prodPreferredChains = preferredChainIds, testPreferredChains = "") + self.updateProdPreferredSharingChainsAndNotify(address, preferredChainIds) return true except Exception as e: error "error: ", procName="updateWalletAccountProdPreferredChains", errName=e.name, errDesription=e.msg @@ -582,7 +587,7 @@ proc updateWalletAccountTestPreferredChains*(self: Service, address, preferredCh if not response.error.isNil: error "status-go error", procName="updateWalletAccountTestPreferredChains", errCode=response.error.code, errDesription=response.error.message return false - self.updatePreferredSharingChainsAndNotify(address, prodPreferredChains = "", testPreferredChains = preferredChainIds) + self.updateTestPreferredSharingChainsAndNotify(address, preferredChainIds) return true except Exception as e: error "error: ", procName="updateWalletAccountTestPreferredChains", errName=e.name, errDesription=e.msg