fix: `SaveAccounts` endpoint changed to `SaveAccount` which requires a single account to be provided instead of array of accounts

This commit is contained in:
Sale Djenic 2023-04-21 16:15:31 +02:00 committed by saledjenic
parent a0b062b503
commit 34badf2405
3 changed files with 12 additions and 13 deletions

View File

@ -2479,16 +2479,15 @@ func (m *Messenger) SyncDevices(ctx context.Context, ensName, photoPath string,
return m.syncSocialSettings(ctx, rawMessageHandler) return m.syncSocialSettings(ctx, rawMessageHandler)
} }
func (m *Messenger) SaveAccounts(accs []*accounts.Account) error { func (m *Messenger) SaveAccount(acc *accounts.Account) error {
clock, _ := m.getLastClockWithRelatedChat() clock, _ := m.getLastClockWithRelatedChat()
for _, acc := range accs {
acc.Clock = clock acc.Clock = clock
}
err := m.settings.SaveAccounts(accs) err := m.settings.SaveAccounts([]*accounts.Account{acc})
if err != nil { if err != nil {
return err return err
} }
return m.syncWallets(accs, m.dispatchMessage) return m.syncWallets([]*accounts.Account{acc}, m.dispatchMessage)
} }
func (m *Messenger) DeleteAccount(address types.Address) error { func (m *Messenger) DeleteAccount(address types.Address) error {

View File

@ -290,8 +290,8 @@ func (s *MessengerSyncWalletSuite) TestSyncWallets() {
for _, acc := range walletAccounts { for _, acc := range walletAccounts {
acc.Name = acc.Name + "New" acc.Name = acc.Name + "New"
acc.Color = "lightblue" acc.Color = "lightblue"
s.Require().NoError(s.m.SaveAccount(acc))
} }
s.Require().NoError(s.m.SaveAccounts(walletAccounts))
// Sync between devices is triggered automatically // Sync between devices is triggered automatically
// via watch account changes subscription // via watch account changes subscription
@ -302,7 +302,7 @@ func (s *MessengerSyncWalletSuite) TestSyncWallets() {
return err return err
} }
if len(response.Accounts) != len(walletAccounts) { if len(response.Accounts) != 1 {
return errors.New("no sync wallet account received") return errors.New("no sync wallet account received")
} }
return nil return nil

View File

@ -38,13 +38,13 @@ type DerivedAddress struct {
AlreadyCreated bool `json:"alreadyCreated"` AlreadyCreated bool `json:"alreadyCreated"`
} }
func (api *API) SaveAccounts(ctx context.Context, accounts []*accounts.Account) error { func (api *API) SaveAccount(ctx context.Context, account *accounts.Account) error {
log.Info("[AccountsAPI::SaveAccounts]") log.Info("[AccountsAPI::SaveAccount]")
err := (*api.messenger).SaveAccounts(accounts) err := (*api.messenger).SaveAccount(account)
if err != nil { if err != nil {
return err return err
} }
api.feed.Send(accounts) api.feed.Send([]*accounts.Account{account})
return nil 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. // Imports a new private key and creates local keystore file.