diff --git a/.storybook/views/story-screen.tsx b/.storybook/views/story-screen.tsx index 631f86398c..bcb0dd85f3 100644 --- a/.storybook/views/story-screen.tsx +++ b/.storybook/views/story-screen.tsx @@ -5,11 +5,12 @@ const PersistentStateWrapper: React.FC = ({ children }) {}, resetState: () => {}, diff --git a/app/hooks/use-app-config.ts b/app/hooks/use-app-config.ts index 88d4765a40..58b9d429f1 100644 --- a/app/hooks/use-app-config.ts +++ b/app/hooks/use-app-config.ts @@ -10,8 +10,13 @@ export const useAppConfig = () => { () => ({ token: persistentState.galoyAuthToken, galoyInstance: resolveGaloyInstanceOrDefault(persistentState.galoyInstance), + savedAccounts: persistentState.galoySavedAccounts, }), - [persistentState.galoyAuthToken, persistentState.galoyInstance], + [ + persistentState.galoyAuthToken, + persistentState.galoyInstance, + persistentState.galoySavedAccounts, + ], ) const setGaloyInstance = useCallback( @@ -35,6 +40,7 @@ export const useAppConfig = () => { return { ...state, galoyAuthToken: token, + galoySavedAccounts: [...state.galoySavedAccounts, token], } return undefined }) diff --git a/app/store/persistent-state/state-migrations.ts b/app/store/persistent-state/state-migrations.ts index 64af8ecb4b..39be7209b7 100644 --- a/app/store/persistent-state/state-migrations.ts +++ b/app/store/persistent-state/state-migrations.ts @@ -30,9 +30,24 @@ type PersistentState_6 = { galoyAuthToken: string } -const migrate6ToCurrent = (state: PersistentState_6): Promise => +type PersistentState_7 = { + schemaVersion: 7 + galoyInstance: GaloyInstanceInput + galoyAuthToken: string + galoySavedAccounts: string[] +} + +const migrate7ToCurrent = (state: PersistentState_7): Promise => Promise.resolve(state) +const migrate6ToCurrent = (state: PersistentState_6): Promise => { + return migrate7ToCurrent({ + ...state, + schemaVersion: 7, + galoySavedAccounts: [], + }) +} + const migrate5ToCurrent = (state: PersistentState_5): Promise => { return migrate6ToCurrent({ ...state, @@ -98,6 +113,7 @@ type StateMigrations = { 4: (state: PersistentState_4) => Promise 5: (state: PersistentState_5) => Promise 6: (state: PersistentState_6) => Promise + 7: (state: PersistentState_7) => Promise } const stateMigrations: StateMigrations = { @@ -105,14 +121,16 @@ const stateMigrations: StateMigrations = { 4: migrate4ToCurrent, 5: migrate5ToCurrent, 6: migrate6ToCurrent, + 7: migrate7ToCurrent, } -export type PersistentState = PersistentState_6 +export type PersistentState = PersistentState_7 export const defaultPersistentState: PersistentState = { - schemaVersion: 6, + schemaVersion: 7, galoyInstance: { id: "Main" }, galoyAuthToken: "", + galoySavedAccounts: [], } export const migrateAndGetPersistentState = async ( @@ -122,7 +140,7 @@ export const migrateAndGetPersistentState = async ( data: any, ): Promise => { if (Boolean(data) && data.schemaVersion in stateMigrations) { - const schemaVersion: 3 | 4 | 5 | 6 = data.schemaVersion + const schemaVersion: 3 | 4 | 5 | 6 | 7 = data.schemaVersion try { const migration = stateMigrations[schemaVersion] const persistentState = await migration(data)