fix(wallet): Update preferred networks even when empty (#15841)

This commit is contained in:
Cuteivist 2024-07-31 06:53:35 +02:00 committed by GitHub
parent 4dbae17bb9
commit 31ade3e742
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 12 deletions

View File

@ -143,10 +143,8 @@ QtObject:
proc updatePreferredSharingChainsForAddress*(self: KeyPairAccountModel, address, prodPreferredChainIds, testPreferredChainIds: string) = proc updatePreferredSharingChainsForAddress*(self: KeyPairAccountModel, address, prodPreferredChainIds, testPreferredChainIds: string) =
for i in 0 ..< self.items.len: for i in 0 ..< self.items.len:
if cmpIgnoreCase(self.items[i].getAddress(), address) == 0: if cmpIgnoreCase(self.items[i].getAddress(), address) == 0:
if prodPreferredChainIds.len > 0: self.items[i].setProdPreferredChainIds(prodPreferredChainIds)
self.items[i].setProdPreferredChainIds(prodPreferredChainIds) self.items[i].setTestPreferredChainIds(testPreferredChainIds)
if testPreferredChainIds.len > 0:
self.items[i].setTestPreferredChainIds(testPreferredChainIds)
proc updateAccountHiddenInTotalBalance*(self: KeyPairAccountModel, address: string, hideFromTotalBalance: bool) = proc updateAccountHiddenInTotalBalance*(self: KeyPairAccountModel, address: string, hideFromTotalBalance: bool) =
for i in 0 ..< self.items.len: for i in 0 ..< self.items.len:

View File

@ -306,15 +306,20 @@ proc updateAccountInLocalStoreAndNotify(self: Service, address, name, colorId, e
if notify: if notify:
self.events.emit(SIGNAL_WALLET_ACCOUNT_POSITION_UPDATED, Args()) 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) var account = self.getAccountByAddress(address)
if account.isNil: 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 return
if testPreferredChains.len > 0 and testPreferredChains != account.testPreferredChainIds: account.testPreferredChainIds = testPreferredChains
account.testPreferredChainIds = testPreferredChains self.events.emit(SIGNAL_WALLET_ACCOUNT_PREFERRED_SHARING_CHAINS_UPDATED, AccountArgs(account: account))
if prodPreferredChains.len > 0 and prodPreferredChains != account.prodPreferredChainIds:
account.prodPreferredChainIds = prodPreferredChains 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)) 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 ## 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: if not response.error.isNil:
error "status-go error", procName="updateWalletAccountProdPreferredChains", errCode=response.error.code, errDesription=response.error.message error "status-go error", procName="updateWalletAccountProdPreferredChains", errCode=response.error.code, errDesription=response.error.message
return false return false
self.updatePreferredSharingChainsAndNotify(address, prodPreferredChains = preferredChainIds, testPreferredChains = "") self.updateProdPreferredSharingChainsAndNotify(address, preferredChainIds)
return true return true
except Exception as e: except Exception as e:
error "error: ", procName="updateWalletAccountProdPreferredChains", errName=e.name, errDesription=e.msg 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: if not response.error.isNil:
error "status-go error", procName="updateWalletAccountTestPreferredChains", errCode=response.error.code, errDesription=response.error.message error "status-go error", procName="updateWalletAccountTestPreferredChains", errCode=response.error.code, errDesription=response.error.message
return false return false
self.updatePreferredSharingChainsAndNotify(address, prodPreferredChains = "", testPreferredChains = preferredChainIds) self.updateTestPreferredSharingChainsAndNotify(address, preferredChainIds)
return true return true
except Exception as e: except Exception as e:
error "error: ", procName="updateWalletAccountTestPreferredChains", errName=e.name, errDesription=e.msg error "error: ", procName="updateWalletAccountTestPreferredChains", errName=e.name, errDesription=e.msg