Skip to content

Commit

Permalink
fix: update persistent state property names, update test
Browse files Browse the repository at this point in the history
Signed-off-by: Prakhar Agarwal <[email protected]>
  • Loading branch information
Prakhar-Agarwal-byte committed May 19, 2024
1 parent fd853da commit 9b3dbd7
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion .storybook/views/story-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const PersistentStateWrapper: React.FC<React.PropsWithChildren> = ({ children })
id: "Main",
},
galoyAuthToken: "",
galoySavedAccounts: [],
galoyAllAuthTokens: [],
},
updateState: () => {},
resetState: () => {},
Expand Down
15 changes: 8 additions & 7 deletions __tests__/persistent-storage.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
7 changes: 4 additions & 3 deletions app/hooks/use-app-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
)

Expand All @@ -40,7 +40,7 @@ export const useAppConfig = () => {
return {
...state,
galoyAuthToken: token,
galoySavedAccounts: [...state.galoySavedAccounts, token],
galoyAllAuthTokens: [...state.galoyAllAuthTokens, token],
}
return undefined
})
Expand All @@ -56,6 +56,7 @@ export const useAppConfig = () => {
...state,
galoyInstance: instance,
galoyAuthToken: token,
galoyAllAuthTokens: [...state.galoyAllAuthTokens, token],
}
return undefined
})
Expand Down
6 changes: 3 additions & 3 deletions app/store/persistent-state/state-migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type PersistentState_7 = {
schemaVersion: 7
galoyInstance: GaloyInstanceInput
galoyAuthToken: string
galoySavedAccounts: string[]
galoyAllAuthTokens: string[]
}

const migrate7ToCurrent = (state: PersistentState_7): Promise<PersistentState> =>
Expand All @@ -44,7 +44,7 @@ const migrate6ToCurrent = (state: PersistentState_6): Promise<PersistentState> =
return migrate7ToCurrent({
...state,
schemaVersion: 7,
galoySavedAccounts: [],
galoyAllAuthTokens: [],
})
}

Expand Down Expand Up @@ -130,7 +130,7 @@ export const defaultPersistentState: PersistentState = {
schemaVersion: 7,
galoyInstance: { id: "Main" },
galoyAuthToken: "",
galoySavedAccounts: [],
galoyAllAuthTokens: [],
}

export const migrateAndGetPersistentState = async (
Expand Down

0 comments on commit 9b3dbd7

Please sign in to comment.