Skip to content

Commit

Permalink
add migration to remove appUiConfigs key
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredvu committed Oct 31, 2024
1 parent 667bfaa commit 36e69be
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 17 deletions.
6 changes: 1 addition & 5 deletions src/hooks/useMarketsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from '@/hooks/usePerpetualMarketSparklines';

import { useAppSelector } from '@/state/appTypes';
import { getFavoritedMarkets } from '@/state/appUiConfigsSelectors';
import { getAssets } from '@/state/assetsSelectors';
import { getPerpetualMarkets, getPerpetualMarketsClobIds } from '@/state/perpetualsSelectors';

Expand Down Expand Up @@ -136,12 +137,7 @@ export const useMarketsData = ({
const sevenDaysSparklineData = usePerpetualMarketSparklines();
const featureFlags = useAllStatsigGateValues();
const unlaunchedMarkets = useMetadataService();
<<<<<<< HEAD
=======
const shouldHideLaunchableMarkets =
useAppSelector(getShouldHideLaunchableMarkets) || hideUnlaunchedMarkets;
const favoritedMarkets = useAppSelector(getFavoritedMarkets, shallowEqual);
>>>>>>> main
const hasMarketIds = Object.keys(allPerpetualMarkets).length > 0;

const markets = useMemo(() => {
Expand Down
2 changes: 1 addition & 1 deletion src/state/_store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const rootReducer = combineReducers(reducers);

const persistConfig = {
key: 'root',
version: 3,
version: 4,
storage,
whitelist: [
'affiliates',
Expand Down
9 changes: 0 additions & 9 deletions src/state/appUiConfigs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ export interface AppUIConfigsState {
hasSeenLaunchIncentives: boolean;
defaultToAllMarketsInPositionsOrdersFills: boolean;
displayUnit: DisplayUnit;
shouldHideLaunchableMarkets: boolean;
favoritedMarkets: string[];
}

Expand All @@ -47,7 +46,6 @@ export const initialState: AppUIConfigsState = {
hasSeenLaunchIncentives: false,
defaultToAllMarketsInPositionsOrdersFills: true,
displayUnit: DisplayUnit.Asset,
shouldHideLaunchableMarkets: false,
favoritedMarkets: [],
};

Expand All @@ -70,12 +68,6 @@ export const appUiConfigsSlice = createSlice({
markLaunchIncentivesSeen: (state: AppUIConfigsState) => {
state.hasSeenLaunchIncentives = true;
},
setShouldHideLaunchableMarkets: (
state: AppUIConfigsState,
{ payload }: PayloadAction<boolean>
) => {
state.shouldHideLaunchableMarkets = payload;
},
setDisplayUnit: (
state: AppUIConfigsState,
{
Expand Down Expand Up @@ -114,7 +106,6 @@ export const {
setAppThemeSetting,
setAppColorMode,
markLaunchIncentivesSeen,
setShouldHideLaunchableMarkets,
setDisplayUnit,
favoriteMarket,
unfavoriteMarket,
Expand Down
3 changes: 3 additions & 0 deletions src/state/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,15 @@ import { migration0 } from './migrations/0';
import { migration1 } from './migrations/1';
import { migration2 } from './migrations/2';
import { migration3 } from './migrations/3';
import { migration4 } from './migrations/4';

export const migrations: MigrationManifest = {
0: migration0,
1: migration1,
2: migration2,
3: migration3,
// @ts-expect-error PersistAppStateV4 is a union of PersistedState and new app state
4: migration4,
} as const;

/*
Expand Down
4 changes: 2 additions & 2 deletions src/state/migrations/3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export enum V3AppTheme {
Light = 'Light',
}

enum V3AppThemeSystemSetting {
export enum V3AppThemeSystemSetting {
System = 'System',
}

type V3AppThemeSetting = V3AppTheme | V3AppThemeSystemSetting;
export type V3AppThemeSetting = V3AppTheme | V3AppThemeSystemSetting;

export enum V3AppColorMode {
GreenUp = 'GreenUp',
Expand Down
28 changes: 28 additions & 0 deletions src/state/migrations/4.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { PersistedState } from 'redux-persist';

import { PersistAppStateV3, V3AppUiConfigs } from './3';

export type V4AppUiConfigs = Omit<V3AppUiConfigs, 'shouldHideLaunchableMarkets'>;

export type PersistAppStateV4 = PersistedState & {
appUiConfigs: V4AppUiConfigs;
};

/**
* Deprecate shouldHideLaunchableMarkets from AppUIConfigs state
*
*/
export function migration4(state: PersistAppStateV3 | undefined): PersistAppStateV4 {
if (!state) throw new Error('state must be defined');

const appUiConfigsCopy = { ...state.appUiConfigs };

// Remove shouldHideLaunchableMarkets
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { shouldHideLaunchableMarkets, ...restAppUiConfigs } = appUiConfigsCopy;

return {
...state,
appUiConfigs: restAppUiConfigs,
};
}
38 changes: 38 additions & 0 deletions src/state/migrations/__test__/4.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { afterEach, describe, expect, it } from 'vitest';

import { PersistAppStateV3, V3AppColorMode, V3AppTheme, V3DisplayUnit } from '../3';
import { migration4, PersistAppStateV4 } from '../4';

const v3State: PersistAppStateV3 = {
_persist: { version: 3, rehydrated: true },
appUiConfigs: {
appThemeSetting: V3AppTheme.Classic,
appColorMode: V3AppColorMode.GreenUp,
hasSeenLaunchIncentives: false,
defaultToAllMarketsInPositionsOrdersFills: true,
displayUnit: V3DisplayUnit.Asset,
shouldHideLaunchableMarkets: false,
},
};

const v4State: PersistAppStateV4 = {
_persist: { version: 4, rehydrated: true },
appUiConfigs: {
appThemeSetting: V3AppTheme.Classic,
appColorMode: V3AppColorMode.GreenUp,
hasSeenLaunchIncentives: false,
defaultToAllMarketsInPositionsOrdersFills: true,
displayUnit: V3DisplayUnit.Asset,
},
};

describe('migration4', () => {
afterEach(() => {
localStorage.clear();
});

it('updated appUiConfigs state should not include shouldHideLaunchableMarkets', () => {
const result = migration4(v3State);
expect(result.appUiConfigs).toMatchObject(v4State.appUiConfigs);
});
});

0 comments on commit 36e69be

Please sign in to comment.