From 34526dcd4d261530ab2d73224e5ffffb945d19b5 Mon Sep 17 00:00:00 2001 From: Leo Unoki Date: Sun, 23 Jul 2023 17:16:30 +0900 Subject: [PATCH] Make accountslice take an array --- src/components/AccountToContactTile.test.tsx | 2 +- src/utils/accountsReducer.test.ts | 4 +-- src/utils/contactsReducer.test.ts | 2 +- src/utils/store/accountsSlice.ts | 6 ++-- src/views/home/AccountList.test.tsx | 32 +++++++++++--------- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/components/AccountToContactTile.test.tsx b/src/components/AccountToContactTile.test.tsx index 40d06084e..7fdfc29b5 100644 --- a/src/components/AccountToContactTile.test.tsx +++ b/src/components/AccountToContactTile.test.tsx @@ -39,7 +39,7 @@ describe("AccountOrContactTile", () => { it("displays account label if the address is in accounts", () => { const account = mockImplicitAccount(0); const pkh = account.address.pkh; - store.dispatch(add(account)); + store.dispatch(add([account])); render(AccountOrContactTileFixture(pkh)); expect(screen.queryByTestId("account-or-contact-tile")).toHaveTextContent(account.label); }); diff --git a/src/utils/accountsReducer.test.ts b/src/utils/accountsReducer.test.ts index ecc35d4d7..0afea3432 100644 --- a/src/utils/accountsReducer.test.ts +++ b/src/utils/accountsReducer.test.ts @@ -35,7 +35,7 @@ describe("Accounts reducer", () => { }); test("should handle adding accounts and arrays of accounts", () => { - store.dispatch(add(mockImplicitAccount(1))); + store.dispatch(add([mockImplicitAccount(1)])); expect(store.getState().accounts).toEqual({ items: [mockImplicitAccount(1)], seedPhrases: {}, @@ -51,7 +51,7 @@ describe("Accounts reducer", () => { test("adding account should throw and exception if it is a pkh duplicate and not modify state", () => { store.dispatch(add([mockImplicitAccount(1), mockImplicitAccount(2), mockImplicitAccount(3)])); - expect(() => store.dispatch(add(mockImplicitAccount(2)))).toThrowError( + expect(() => store.dispatch(add([mockImplicitAccount(2)]))).toThrowError( `Can't add account ${mockImplicitAccount(2).address.pkh} in store since it already exists.` ); diff --git a/src/utils/contactsReducer.test.ts b/src/utils/contactsReducer.test.ts index e50774412..aeeb6367f 100644 --- a/src/utils/contactsReducer.test.ts +++ b/src/utils/contactsReducer.test.ts @@ -70,7 +70,7 @@ describe("Contacts reducer", () => { test("should not add contact containing Account info", () => { const account = mockImplicitAccount(0); - store.dispatch(add(account)); + store.dispatch(add([account])); store.dispatch( checkAccountsAndUpsertContact({ name: account.label, pkh: account.address.pkh }) ); diff --git a/src/utils/store/accountsSlice.ts b/src/utils/store/accountsSlice.ts index 70b9837ae..0749d9647 100644 --- a/src/utils/store/accountsSlice.ts +++ b/src/utils/store/accountsSlice.ts @@ -38,10 +38,8 @@ const accountsSlice = createSlice({ state.items = newAccounts; delete state.seedPhrases[fingerPrint]; }, - add: (state, { payload }: { type: string; payload: ImplicitAccount | ImplicitAccount[] }) => { - const accounts = Array.isArray(payload) ? payload : [payload]; - - state.items = concatUnique(state.items, accounts); + add: (state, { payload }: { type: string; payload: ImplicitAccount[] }) => { + state.items = concatUnique(state.items, payload); }, }, }); diff --git a/src/views/home/AccountList.test.tsx b/src/views/home/AccountList.test.tsx index ba5823955..f2fb04e1c 100644 --- a/src/views/home/AccountList.test.tsx +++ b/src/views/home/AccountList.test.tsx @@ -194,23 +194,27 @@ const restore = async () => { ); store.dispatch( - addAccounts({ - type: AccountType.SOCIAL, - idp: "google", - address: mockImplicitAddress(6), - pk: mockPk(6), - label: GOOGLE_ACCOUNT_LABEL1, - }) + addAccounts([ + { + type: AccountType.SOCIAL, + idp: "google", + address: mockImplicitAddress(6), + pk: mockPk(6), + label: GOOGLE_ACCOUNT_LABEL1, + }, + ]) ); store.dispatch( - addAccounts({ - type: AccountType.SOCIAL, - idp: "google", - address: mockImplicitAddress(7), - pk: mockPk(7), - label: GOOGLE_ACCOUNT_LABEL2, - }) + addAccounts([ + { + type: AccountType.SOCIAL, + idp: "google", + address: mockImplicitAddress(7), + pk: mockPk(7), + label: GOOGLE_ACCOUNT_LABEL2, + }, + ]) ); store.dispatch(