Skip to content

Commit

Permalink
fix types
Browse files Browse the repository at this point in the history
  • Loading branch information
aforaleka committed Oct 24, 2024
1 parent 7b161b5 commit 2d34d6a
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/hooks/tradingView/useTradingViewDatafeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ export const useTradingViewDatafeed = (
);
}

const volumeUnit = store.getState().configs.displayUnit;
const volumeUnit = store.getState().appUiConfigs.displayUnit;

const bars = [
...cachedBars,
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useMarketsData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ import {
} from '@/hooks/usePerpetualMarketSparklines';

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

import { getDisplayableAssetFromBaseAsset } from '@/lib/assetUtils';
Expand Down
2 changes: 2 additions & 0 deletions src/state/migrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ import { MigrationConfig } from 'redux-persist/lib/createMigrate';
import { migration0 } from './migrations/0';
import { migration1 } from './migrations/1';
import { migration2 } from './migrations/2';
import { migration3 } from './migrations/3';

export const migrations = {
0: migration0,
1: migration1,
2: migration2,
3: migration3,
} as const;

/*
Expand Down
3 changes: 2 additions & 1 deletion src/state/migrations/3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type V3State = PersistedState & {
};

export type AppUiConfigsKeys = keyof typeof appUiConfigsInitialState;
export type AppUIConfigsMappableLocalStorageKeys = keyof typeof appUiConfigsLocalStorageKeys;

export const appUiConfigsLocalStorageKeys = {
appThemeSetting: 'dydx.SelectedTheme',
Expand All @@ -16,7 +17,7 @@ export const appUiConfigsLocalStorageKeys = {
defaultToAllMarketsInPositionsOrdersFills: 'dydx.DefaultToAllMarketsInPositionsOrdersFills',
displayUnit: 'dydx.SelectedDisplayUnit',
shouldHideLaunchableMarkets: 'dydx.ShouldHideLaunchableMarkets',
} satisfies Record<AppUiConfigsKeys, string>;
};

/**
* 4th migration, moving over the app ui configs localStorage items
Expand Down
11 changes: 8 additions & 3 deletions src/state/migrations/__test__/3.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ import {
} from '@/state/appUiConfigs';

import { V2State } from '../2';
import { AppUiConfigsKeys, appUiConfigsLocalStorageKeys, migration3 } from '../3';
import {
appUiConfigsLocalStorageKeys,
AppUIConfigsMappableLocalStorageKeys,
migration3,
} from '../3';

const V2_STATE: V2State = {
_persist: { version: 2, rehydrated: true },
Expand All @@ -19,14 +23,15 @@ const V2_STATE: V2State = {
},
};

// values for testing -- they should be different than default / intial state
const oppositeUiConfigsLocalStorageValues = {
appThemeSetting: AppTheme.Light,
appColorMode: AppColorMode.RedUp,
hasSeenLaunchIncentives: true,
defaultToAllMarketsInPositionsOrdersFills: false,
displayUnit: DisplayUnit.Fiat,
shouldHideLaunchableMarkets: true,
} satisfies Record<AppUiConfigsKeys, any>;
} satisfies Record<AppUIConfigsMappableLocalStorageKeys, any>;

describe('migration3', () => {
afterEach(() => {
Expand All @@ -46,7 +51,7 @@ describe('migration3', () => {
it('should copy localStorage values to app ui configs object', () => {
Object.entries(oppositeUiConfigsLocalStorageValues).forEach(([key, value]) => {
localStorage.setItem(
appUiConfigsLocalStorageKeys[key as AppUiConfigsKeys],
appUiConfigsLocalStorageKeys[key as AppUIConfigsMappableLocalStorageKeys],
JSON.stringify(value)
);
});
Expand Down

0 comments on commit 2d34d6a

Please sign in to comment.