diff --git a/src/redux/rootReducer.ts b/src/redux/rootReducer.ts index 3b0d910b0..9695cae91 100644 --- a/src/redux/rootReducer.ts +++ b/src/redux/rootReducer.ts @@ -1,5 +1,10 @@ import { combineReducers } from '@reduxjs/toolkit' -import { persistReducer, createMigrate, PersistConfig } from 'redux-persist' +import { + persistReducer, + createMigrate, + PersistConfig, + getStoredState, +} from 'redux-persist' import { reduxStorage } from 'storage/ReduxStorage' import { contactsReducer } from 'store/slices/contactsSlice' @@ -33,6 +38,26 @@ const migrations = { }), } +const firstPersistentDataMigration = async state => { + // First migration, check if state already exists + if (!state) { + // First step is to get old settings storage - usually testnet storage has all the info + const oldStorage = await getStoredState({ + key: 'settings', + storage: reduxStorage(31), + }) + // If old storage exists, we will migrate it to the current state + if (oldStorage) { + return { + keysExist: oldStorage.keysExist, + isFirstLaunch: oldStorage.isFirstLaunch, + pin: oldStorage.pin, + } + } + } + return state +} + export const createRootReducer = () => { const persistedReduxStorageAcrossChainSwitches = reduxStorage(0) @@ -46,6 +71,7 @@ export const createRootReducer = () => { key: 'persistentData', whitelist: ['keysExist', 'isFirstLaunch', 'pin'], storage: persistedReduxStorageAcrossChainSwitches, + migrate: firstPersistentDataMigration, } const usdPricesPersistConfig: PersistConfig = { diff --git a/src/redux/slices/persistentDataSlice/index.ts b/src/redux/slices/persistentDataSlice/index.ts index e63682d5f..f1ba756dc 100644 --- a/src/redux/slices/persistentDataSlice/index.ts +++ b/src/redux/slices/persistentDataSlice/index.ts @@ -2,10 +2,9 @@ import { createSlice, PayloadAction } from '@reduxjs/toolkit' import { PersistentDataState } from './types' -// @TODO switch back variable state after 15 days - 1 month (november) (keysExist false by default, isFirst.. true by default) const initialState: PersistentDataState = { - keysExist: true, - isFirstLaunch: false, + keysExist: false, + isFirstLaunch: true, pin: null, }