From 185caa0550183682dcd67a1eb1cc5eea15ca88db Mon Sep 17 00:00:00 2001 From: beerosagos Date: Wed, 25 Oct 2023 11:29:38 +0200 Subject: [PATCH 1/2] backend/keystore: fix notification order on keystore deregister On keystore deregister the accounts linked to the keystore were closed and sent statusChanged events to the frontend + a final `accounts` event to notify the change in the accounts number. The lag between the status and the accounts events caused the execution of calls towards endpoint of already closed accounts, which generated unexpected errors. This send an accounts event immediately after each account close, fixing the lag. --- backend/accounts.go | 1 + backend/backend.go | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/accounts.go b/backend/accounts.go index cf7681a875..fb156dc18d 100644 --- a/backend/accounts.go +++ b/backend/accounts.go @@ -931,6 +931,7 @@ func (backend *Backend) uninitAccounts() { backend.onAccountUninit(account) } account.Close() + backend.emitAccountsStatusChanged() } backend.accounts = []accounts.Interface{} } diff --git a/backend/backend.go b/backend/backend.go index cf8376e9e7..9fd2ed5c0d 100644 --- a/backend/backend.go +++ b/backend/backend.go @@ -558,7 +558,6 @@ func (backend *Backend) DeregisterKeystore() { // TODO: classify accounts by keystore, remove only the ones belonging to the deregistered // keystore. For now we just remove all, then re-add the rest. backend.initPersistedAccounts() - backend.emitAccountsStatusChanged() } // Register registers the given device at this backend. From 40dbc55eb39938576fa23cf62dcb5e4ef9412fe1 Mon Sep 17 00:00:00 2001 From: beerosagos Date: Wed, 25 Oct 2023 12:26:27 +0200 Subject: [PATCH 2/2] backend/accounts: rename emitAccountsStatusChanged method `emitAccountsStatusChanged` is a misleading name, as it doesn't fire an event connected to the account status, but about the number of available accounts. As it is catched in the frontend by `syncAccountsList` subscription, now it is called `emitAccountsListChanged`. --- backend/accounts.go | 12 ++++++------ backend/backend.go | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/accounts.go b/backend/accounts.go index fb156dc18d..ed255570cc 100644 --- a/backend/accounts.go +++ b/backend/accounts.go @@ -474,7 +474,7 @@ func (backend *Backend) RenameAccount(accountCode accountsTypes.Code, name strin if err != nil { return err } - backend.emitAccountsStatusChanged() + backend.emitAccountsListChanged() return nil } @@ -566,7 +566,7 @@ func (backend *Backend) createAndAddAccount(coin coinpkg.Coin, persistedConfig * } } -func (backend *Backend) emitAccountsStatusChanged() { +func (backend *Backend) emitAccountsListChanged() { backend.Notify(observable.Event{ Subject: "accounts", Action: action.Reload, @@ -904,7 +904,7 @@ func (backend *Backend) initAccounts() { backend.initPersistedAccounts() - backend.emitAccountsStatusChanged() + backend.emitAccountsListChanged() // The updater fetches rates only for active accounts, so this seems the most // appropriate place to update exchange rate configuration. @@ -931,7 +931,7 @@ func (backend *Backend) uninitAccounts() { backend.onAccountUninit(account) } account.Close() - backend.emitAccountsStatusChanged() + backend.emitAccountsListChanged() } backend.accounts = []accounts.Interface{} } @@ -1058,7 +1058,7 @@ func (backend *Backend) maybeAddHiddenUnusedAccounts() { continue } backend.createAndAddAccount(coin, accountConfig) - backend.emitAccountsStatusChanged() + backend.emitAccountsListChanged() } } } @@ -1099,6 +1099,6 @@ func (backend *Backend) checkAccountUsed(account accounts.Interface) { log.WithError(err).Error("checkAccountUsed") return } - backend.emitAccountsStatusChanged() + backend.emitAccountsListChanged() backend.maybeAddHiddenUnusedAccounts() } diff --git a/backend/backend.go b/backend/backend.go index 9fd2ed5c0d..4db3dec677 100644 --- a/backend/backend.go +++ b/backend/backend.go @@ -476,7 +476,7 @@ func (backend *Backend) Start() <-chan interface{} { defer backend.accountsAndKeystoreLock.Lock()() backend.initPersistedAccounts() - backend.emitAccountsStatusChanged() + backend.emitAccountsListChanged() backend.ratesUpdater.StartCurrentRates() backend.configureHistoryExchangeRates()