diff --git a/protocol/messenger.go b/protocol/messenger.go index 8f5ec4c33..623c58cb2 100644 --- a/protocol/messenger.go +++ b/protocol/messenger.go @@ -2479,16 +2479,15 @@ func (m *Messenger) SyncDevices(ctx context.Context, ensName, photoPath string, return m.syncSocialSettings(ctx, rawMessageHandler) } -func (m *Messenger) SaveAccounts(accs []*accounts.Account) error { +func (m *Messenger) SaveAccount(acc *accounts.Account) error { clock, _ := m.getLastClockWithRelatedChat() - for _, acc := range accs { - acc.Clock = clock - } - err := m.settings.SaveAccounts(accs) + acc.Clock = clock + + err := m.settings.SaveAccounts([]*accounts.Account{acc}) if err != nil { return err } - return m.syncWallets(accs, m.dispatchMessage) + return m.syncWallets([]*accounts.Account{acc}, m.dispatchMessage) } func (m *Messenger) DeleteAccount(address types.Address) error { diff --git a/protocol/messenger_sync_wallets_test.go b/protocol/messenger_sync_wallets_test.go index 11125607c..9ca198095 100644 --- a/protocol/messenger_sync_wallets_test.go +++ b/protocol/messenger_sync_wallets_test.go @@ -290,8 +290,8 @@ func (s *MessengerSyncWalletSuite) TestSyncWallets() { for _, acc := range walletAccounts { acc.Name = acc.Name + "New" acc.Color = "lightblue" + s.Require().NoError(s.m.SaveAccount(acc)) } - s.Require().NoError(s.m.SaveAccounts(walletAccounts)) // Sync between devices is triggered automatically // via watch account changes subscription @@ -302,7 +302,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWallets() { return err } - if len(response.Accounts) != len(walletAccounts) { + if len(response.Accounts) != 1 { return errors.New("no sync wallet account received") } return nil diff --git a/services/accounts/accounts.go b/services/accounts/accounts.go index 856fcf819..f3e3b928a 100644 --- a/services/accounts/accounts.go +++ b/services/accounts/accounts.go @@ -38,13 +38,13 @@ type DerivedAddress struct { AlreadyCreated bool `json:"alreadyCreated"` } -func (api *API) SaveAccounts(ctx context.Context, accounts []*accounts.Account) error { - log.Info("[AccountsAPI::SaveAccounts]") - err := (*api.messenger).SaveAccounts(accounts) +func (api *API) SaveAccount(ctx context.Context, account *accounts.Account) error { + log.Info("[AccountsAPI::SaveAccount]") + err := (*api.messenger).SaveAccount(account) if err != nil { return err } - api.feed.Send(accounts) + api.feed.Send([]*accounts.Account{account}) return nil } @@ -179,7 +179,7 @@ func (api *API) AddAccount(ctx context.Context, password string, account *accoun } } - return api.SaveAccounts(ctx, []*accounts.Account{account}) + return api.SaveAccount(ctx, account) } // Imports a new private key and creates local keystore file.