diff --git a/src/constants/misc.ts b/src/constants/misc.ts index 0017965a400..14b4a25763d 100644 --- a/src/constants/misc.ts +++ b/src/constants/misc.ts @@ -5,7 +5,7 @@ export const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000' // TODO(WEB-1984): Convert the deadline to minutes and remove unecessary conversions from // seconds to minutes in the codebase. -// 30 minutes, denominated in seconds +// 10 minutes, denominated in seconds export const DEFAULT_DEADLINE_FROM_NOW = 60 * 10 export const L2_DEADLINE_FROM_NOW = 60 * 5 diff --git a/src/state/migrations/1.test.ts b/src/state/migrations/1.test.ts index d7490382a27..30c77054f46 100644 --- a/src/state/migrations/1.test.ts +++ b/src/state/migrations/1.test.ts @@ -1,5 +1,5 @@ +import { createMigrate } from 'redux-persist' import { RouterPreference } from 'state/routing/types' -import { UserState } from 'state/user/reducer' import { SlippageTolerance } from 'state/user/types' import { migration1, PersistAppStateV1 } from './1' @@ -24,27 +24,62 @@ const previousState: PersistAppStateV1 = { } describe('migration to v1', () => { - it('should migrate the default deadline', () => { - const result = migration1(previousState) + it('should migrate the default deadline', async () => { + const migrator = createMigrate( + { + 1: migration1, + }, + { debug: false } + ) + const result: any = await migrator(previousState, 1) expect(result?.user?.userDeadline).toEqual(600) + expect(result?._persist.version).toEqual(1) + + expect(result?.user?.userLocale).toEqual(null) + expect(result?.user?.userRouterPreference).toEqual(RouterPreference.API) + expect(result?.user?.userHideClosedPositions).toEqual(false) + expect(result?.user?.userSlippageTolerance).toEqual(SlippageTolerance.Auto) + expect(result?.user?.userSlippageToleranceHasBeenMigratedToAuto).toEqual(true) + expect(result?.user?.tokens).toEqual({}) + expect(result?.user?.pairs).toEqual({}) + expect(result?.user?.timestamp).toEqual(previousState.user?.timestamp) + expect(result?.user?.hideBaseWalletBanner).toEqual(false) }) - it('should not migrate a non-default value', () => { - const result = migration1({ - ...previousState, - user: { - ...previousState.user, - userDeadline: 300, - } as UserState, - }) + it('should not migrate a non-default value', async () => { + const migrator = createMigrate( + { + 1: migration1, + }, + { debug: false } + ) + const result: any = await migrator( + { + ...previousState, + user: { + ...previousState.user, + userDeadline: 300, + }, + } as PersistAppStateV1, + 1 + ) expect(result?.user?.userDeadline).toEqual(300) }) - it('should not migrate if user state is not set', () => { - const result = migration1({ - ...previousState, - user: undefined, - }) + it('should not migrate if user state is not set', async () => { + const migrator = createMigrate( + { + 1: migration1, + }, + { debug: false } + ) + const result: any = await migrator( + { + ...previousState, + user: undefined, + } as PersistAppStateV1, + 1 + ) expect(result?.user?.userDeadline).toBeUndefined() }) }) diff --git a/src/state/migrations/1.ts b/src/state/migrations/1.ts index 9bf10e8cc09..a0a8f493abe 100644 --- a/src/state/migrations/1.ts +++ b/src/state/migrations/1.ts @@ -18,6 +18,10 @@ export const migration1 = (state: PersistAppStateV1 | undefined) => { ...state.user, userDeadline: DEFAULT_DEADLINE_FROM_NOW, }, + _persist: { + ...state._persist, + version: 1, + }, } } return state