Skip to content

Commit

Permalink
Created a separated ChainStorage as when the app restarts the MainSto…
Browse files Browse the repository at this point in the history
…rage is lost - chainId should never change!
  • Loading branch information
Freshenext committed Sep 27, 2023
1 parent c38b302 commit fbae2c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
14 changes: 8 additions & 6 deletions src/redux/slices/settingsSlice/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>) => {
state.keysExist = payload
Expand Down Expand Up @@ -440,7 +442,7 @@ const settingsSlice = createSlice({
deleteKeys()
deleteDomains()
deleteCache()
return initialState
return createInitialState()
},
setFullscreen: (state, { payload }: PayloadAction<boolean>) => {
state.fullscreen = payload
Expand Down
7 changes: 4 additions & 3 deletions src/storage/ChainStorage.ts
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit fbae2c3

Please sign in to comment.