fix: redux migration to flush german locale (#7584)
* fix: redux migration to flush german locale * lint * my linter was not workking
This commit is contained in:
parent
1feeaea181
commit
f903eedc15
@ -14,7 +14,7 @@ const defaultState = {
|
|||||||
user: {},
|
user: {},
|
||||||
_persist: {
|
_persist: {
|
||||||
rehydrated: true,
|
rehydrated: true,
|
||||||
version: 3,
|
version: 4,
|
||||||
},
|
},
|
||||||
application: {
|
application: {
|
||||||
chainId: null,
|
chainId: null,
|
||||||
|
@ -5,6 +5,7 @@ import { migration0 } from './migrations/0'
|
|||||||
import { migration1 } from './migrations/1'
|
import { migration1 } from './migrations/1'
|
||||||
import { migration2 } from './migrations/2'
|
import { migration2 } from './migrations/2'
|
||||||
import { migration3 } from './migrations/3'
|
import { migration3 } from './migrations/3'
|
||||||
|
import { migration4 } from './migrations/4'
|
||||||
import { legacyLocalStorageMigration } from './migrations/legacy'
|
import { legacyLocalStorageMigration } from './migrations/legacy'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -21,6 +22,7 @@ export const migrations: MigrationManifest = {
|
|||||||
1: migration1,
|
1: migration1,
|
||||||
2: migration2,
|
2: migration2,
|
||||||
3: migration3,
|
3: migration3,
|
||||||
|
4: migration4,
|
||||||
}
|
}
|
||||||
|
|
||||||
// We use a custom migration function for the initial state, because redux-persist
|
// We use a custom migration function for the initial state, because redux-persist
|
||||||
|
46
src/state/migrations/4.test.ts
Normal file
46
src/state/migrations/4.test.ts
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
import { DEFAULT_LOCALE } from 'constants/locales'
|
||||||
|
import { createMigrate } from 'redux-persist'
|
||||||
|
import { RouterPreference } from 'state/routing/types'
|
||||||
|
import { SlippageTolerance } from 'state/user/types'
|
||||||
|
|
||||||
|
import { migration1 } from './1'
|
||||||
|
import { migration2 } from './2'
|
||||||
|
import { migration3 } from './3'
|
||||||
|
import { migration4, PersistAppStateV4 } from './4'
|
||||||
|
|
||||||
|
const previousState: PersistAppStateV4 = {
|
||||||
|
user: {
|
||||||
|
userLocale: 'de-DE',
|
||||||
|
userRouterPreference: RouterPreference.API,
|
||||||
|
userHideClosedPositions: false,
|
||||||
|
userSlippageTolerance: SlippageTolerance.Auto,
|
||||||
|
userSlippageToleranceHasBeenMigratedToAuto: true,
|
||||||
|
userDeadline: 1800,
|
||||||
|
tokens: {},
|
||||||
|
pairs: {},
|
||||||
|
timestamp: Date.now(),
|
||||||
|
hideAndroidAnnouncementBanner: false,
|
||||||
|
},
|
||||||
|
_persist: {
|
||||||
|
version: 3,
|
||||||
|
rehydrated: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('migration to v4', () => {
|
||||||
|
it('should migrate users who currently have German as their set locale', async () => {
|
||||||
|
const migrator = createMigrate(
|
||||||
|
{
|
||||||
|
1: migration1,
|
||||||
|
2: migration2,
|
||||||
|
3: migration3,
|
||||||
|
4: migration4,
|
||||||
|
},
|
||||||
|
{ debug: false }
|
||||||
|
)
|
||||||
|
const result: any = await migrator(previousState, 4)
|
||||||
|
expect(result.user.userLocale).toEqual(DEFAULT_LOCALE)
|
||||||
|
|
||||||
|
expect(result?._persist.version).toEqual(4)
|
||||||
|
})
|
||||||
|
})
|
28
src/state/migrations/4.ts
Normal file
28
src/state/migrations/4.ts
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import { DEFAULT_LOCALE } from 'constants/locales'
|
||||||
|
import { PersistState } from 'redux-persist'
|
||||||
|
import { UserState } from 'state/user/reducer'
|
||||||
|
|
||||||
|
export type PersistAppStateV4 = {
|
||||||
|
_persist: PersistState
|
||||||
|
} & { user?: UserState }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Migration to set german locale to default locale, after
|
||||||
|
* the german locale was removed from supported locales.
|
||||||
|
*/
|
||||||
|
export const migration4 = (state: PersistAppStateV4 | undefined) => {
|
||||||
|
if (state?.user) {
|
||||||
|
if (state.user.userLocale === 'de-DE') {
|
||||||
|
state.user.userLocale = DEFAULT_LOCALE
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
_persist: {
|
||||||
|
...state._persist,
|
||||||
|
version: 4,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return state
|
||||||
|
}
|
@ -44,7 +44,7 @@ export type AppState = ReturnType<typeof appReducer>
|
|||||||
|
|
||||||
const persistConfig: PersistConfig<AppState> = {
|
const persistConfig: PersistConfig<AppState> = {
|
||||||
key: 'interface',
|
key: 'interface',
|
||||||
version: 3, // see migrations.ts for more details about this version
|
version: 4, // see migrations.ts for more details about this version
|
||||||
storage: localForage.createInstance({
|
storage: localForage.createInstance({
|
||||||
name: 'redux',
|
name: 'redux',
|
||||||
}),
|
}),
|
||||||
|
Loading…
Reference in New Issue
Block a user