From 34badf2405043069ad1ee5a303b2a434c1fad53c Mon Sep 17 00:00:00 2001 From: Sale Djenic Date: Fri, 21 Apr 2023 16:15:31 +0200 Subject: [PATCH] fix: `SaveAccounts` endpoint changed to `SaveAccount` which requires a single account to be provided instead of array of accounts --- protocol/messenger.go | 11 +++++------ protocol/messenger_sync_wallets_test.go | 4 ++-- services/accounts/accounts.go | 10 +++++----- 3 files changed, 12 insertions(+), 13 deletions(-) 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.