From fbae2c35877377f99c0d565fed5732fbce2d64a8 Mon Sep 17 00:00:00 2001 From: Francis Rodriguez Date: Wed, 27 Sep 2023 11:54:44 -0300 Subject: [PATCH] Created a separated ChainStorage as when the app restarts the MainStorage is lost - chainId should never change! --- src/redux/slices/settingsSlice/index.ts | 14 ++++++++------ src/storage/ChainStorage.ts | 7 ++++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/redux/slices/settingsSlice/index.ts b/src/redux/slices/settingsSlice/index.ts index f34a9f701..c647eb80a 100644 --- a/src/redux/slices/settingsSlice/index.ts +++ b/src/redux/slices/settingsSlice/index.ts @@ -335,13 +335,15 @@ const initialState: SettingsSlice = { usedBitcoinAddresses: {}, } +const createInitialState = () => ({ + ...initialState, + chainId: getCurrentChainId(), + chainType: chainTypesById[getCurrentChainId()], +}) + const settingsSlice = createSlice({ name: 'settings', - initialState: () => ({ - ...initialState, - chainId: getCurrentChainId(), - chainType: chainTypesById[getCurrentChainId()], - }), + initialState: createInitialState, reducers: { setKeysExist: (state, { payload }: PayloadAction) => { state.keysExist = payload @@ -440,7 +442,7 @@ const settingsSlice = createSlice({ deleteKeys() deleteDomains() deleteCache() - return initialState + return createInitialState() }, setFullscreen: (state, { payload }: PayloadAction) => { state.fullscreen = payload diff --git a/src/storage/ChainStorage.ts b/src/storage/ChainStorage.ts index b419ffd01..06d1ccd0f 100644 --- a/src/storage/ChainStorage.ts +++ b/src/storage/ChainStorage.ts @@ -1,9 +1,10 @@ import { ChainTypesByIdType } from 'shared/constants/chainConstants' +import { MMKVStorage } from 'storage/MMKVStorage' -import { MainStorage } from './MainStorage' +const ChainStorage = new MMKVStorage('chainStorage') export const getCurrentChainId: () => ChainTypesByIdType = () => - MainStorage.get('chainId') || 31 + ChainStorage.get('chainId') || 31 export const setCurrentChainId = (chainId: ChainTypesByIdType) => - MainStorage.set('chainId', chainId) + ChainStorage.set('chainId', chainId)