diff --git a/backend/accounts.go b/backend/accounts.go index a06caa724f..e8d2e3900c 100644 --- a/backend/accounts.go +++ b/backend/accounts.go @@ -750,12 +750,16 @@ func (backend *Backend) addAccount(account accounts.Interface) { }) if event.Subject == string(accountsTypes.EventSyncDone) { backend.notifyNewTxs(account) + go backend.checkAccountUsed(account) } }) + if err := account.Initialize(); err != nil { + backend.log.WithError(err).Error("error initializing account") + return + } if backend.onAccountInit != nil { backend.onAccountInit(account) } - go backend.checkAccountUsed(account) } // The accountsAndKeystoreLock must be held when calling this function. @@ -1529,10 +1533,6 @@ func (backend *Backend) checkAccountUsed(account accounts.Interface) { } } log := backend.log.WithField("accountCode", account.Config().Config.Code) - if err := account.Initialize(); err != nil { - log.WithError(err).Error("error initializing account") - return - } txs, err := account.Transactions() if err != nil { log.WithError(err).Error("discoverAccount") diff --git a/backend/backend.go b/backend/backend.go index 03c23c8aec..bd928dcf53 100644 --- a/backend/backend.go +++ b/backend/backend.go @@ -22,6 +22,7 @@ import ( "net/url" "os" "path/filepath" + "slices" "strings" "time" @@ -590,7 +591,7 @@ func (backend *Backend) Testing() bool { // Accounts returns the current accounts of the backend. func (backend *Backend) Accounts() AccountsList { defer backend.accountsAndKeystoreLock.RLock()() - return backend.accounts + return slices.Clone(backend.accounts) } // KeystoreTotalAmount represents the total balance amount of the accounts belonging to a keystore.