From 9b3dbd73c8d299e2dfc714a76b30d136ad85b258 Mon Sep 17 00:00:00 2001 From: Prakhar Agarwal Date: Sun, 19 May 2024 17:22:26 +0530 Subject: [PATCH] fix: update persistent state property names, update test Signed-off-by: Prakhar Agarwal --- .storybook/views/story-screen.tsx | 2 +- __tests__/persistent-storage.spec.ts | 15 ++++++++------- app/hooks/use-app-config.ts | 7 ++++--- app/store/persistent-state/state-migrations.ts | 6 +++--- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/.storybook/views/story-screen.tsx b/.storybook/views/story-screen.tsx index bcb0dd85f3..8871a7798a 100644 --- a/.storybook/views/story-screen.tsx +++ b/.storybook/views/story-screen.tsx @@ -10,7 +10,7 @@ const PersistentStateWrapper: React.FC = ({ children }) id: "Main", }, galoyAuthToken: "", - galoySavedAccounts: [], + galoyAllAuthTokens: [], }, updateState: () => {}, resetState: () => {}, diff --git a/__tests__/persistent-storage.spec.ts b/__tests__/persistent-storage.spec.ts index 6f8888797b..c57daab7fe 100644 --- a/__tests__/persistent-storage.spec.ts +++ b/__tests__/persistent-storage.spec.ts @@ -25,20 +25,21 @@ it("returns default when schema is not present", async () => { expect(state).toEqual(defaultPersistentState) }) -it("migration from 5 to 6", async () => { - const state5 = { - schemaVersion: 5, +it("migration from 6 to 7", async () => { + const state6 = { + schemaVersion: 6, galoyInstance: { id: "Main" }, galoyAuthToken: "myToken", } - const state6 = { - schemaVersion: 6, + const state7 = { + schemaVersion: 7, galoyInstance: { id: "Main" }, galoyAuthToken: "myToken", + galoyAllAuthTokens: [], } - const res = await migrateAndGetPersistentState(state5) + const res = await migrateAndGetPersistentState(state6) - expect(res).toStrictEqual(state6) + expect(res).toStrictEqual(state7) }) diff --git a/app/hooks/use-app-config.ts b/app/hooks/use-app-config.ts index 58b9d429f1..9653bc4e44 100644 --- a/app/hooks/use-app-config.ts +++ b/app/hooks/use-app-config.ts @@ -10,12 +10,12 @@ export const useAppConfig = () => { () => ({ token: persistentState.galoyAuthToken, galoyInstance: resolveGaloyInstanceOrDefault(persistentState.galoyInstance), - savedAccounts: persistentState.galoySavedAccounts, + savedAccounts: persistentState.galoyAllAuthTokens, }), [ persistentState.galoyAuthToken, persistentState.galoyInstance, - persistentState.galoySavedAccounts, + persistentState.galoyAllAuthTokens, ], ) @@ -40,7 +40,7 @@ export const useAppConfig = () => { return { ...state, galoyAuthToken: token, - galoySavedAccounts: [...state.galoySavedAccounts, token], + galoyAllAuthTokens: [...state.galoyAllAuthTokens, token], } return undefined }) @@ -56,6 +56,7 @@ export const useAppConfig = () => { ...state, galoyInstance: instance, galoyAuthToken: token, + galoyAllAuthTokens: [...state.galoyAllAuthTokens, token], } return undefined }) diff --git a/app/store/persistent-state/state-migrations.ts b/app/store/persistent-state/state-migrations.ts index 39be7209b7..ffc16efff3 100644 --- a/app/store/persistent-state/state-migrations.ts +++ b/app/store/persistent-state/state-migrations.ts @@ -34,7 +34,7 @@ type PersistentState_7 = { schemaVersion: 7 galoyInstance: GaloyInstanceInput galoyAuthToken: string - galoySavedAccounts: string[] + galoyAllAuthTokens: string[] } const migrate7ToCurrent = (state: PersistentState_7): Promise => @@ -44,7 +44,7 @@ const migrate6ToCurrent = (state: PersistentState_6): Promise = return migrate7ToCurrent({ ...state, schemaVersion: 7, - galoySavedAccounts: [], + galoyAllAuthTokens: [], }) } @@ -130,7 +130,7 @@ export const defaultPersistentState: PersistentState = { schemaVersion: 7, galoyInstance: { id: "Main" }, galoyAuthToken: "", - galoySavedAccounts: [], + galoyAllAuthTokens: [], } export const migrateAndGetPersistentState = async (