Skip to content

Commit

Permalink
refactor: two state dispatches into one to prevent possible race (#1378)
Browse files Browse the repository at this point in the history
Signed-off-by: Bryce McMath <[email protected]>
  • Loading branch information
bryce-mcmath authored Jan 3, 2025
1 parent 54618e0 commit c27864a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 10 deletions.
8 changes: 2 additions & 6 deletions packages/legacy/core/App/contexts/reducers/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ import { generateRandomWalletName } from '../../utils/helpers'
import { PersistentStorage } from '../../services/storage'

enum StateDispatchAction {
STATE_DISPATCH = 'state/stateDispatch',
STATE_LOADED = 'state/stateLoaded',
STATE_DISPATCH = 'state/stateDispatch'
}

enum OnboardingDispatchAction {
Expand Down Expand Up @@ -110,12 +109,9 @@ export interface ReducerAction<R> {

export const reducer = <S extends State>(state: S, action: ReducerAction<DispatchAction>): S => {
switch (action.type) {
case StateDispatchAction.STATE_LOADED: {
return { ...state, stateLoaded: true }
}
case StateDispatchAction.STATE_DISPATCH: {
const newState: State = (action?.payload || []).pop()
return { ...state, ...newState }
return { ...state, ...newState, stateLoaded: true }
}
case PreferencesDispatchAction.ENABLE_DEVELOPER_MODE: {
const choice = (action?.payload ?? []).pop() ?? false
Expand Down
4 changes: 0 additions & 4 deletions packages/legacy/core/App/navigators/RootStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { DeviceEventEmitter } from 'react-native'
import IconButton, { ButtonLocation } from '../components/buttons/IconButton'
import { EventTypes } from '../constants'
import { TOKENS, useServices } from '../container-api'
import { DispatchAction } from '../contexts/reducers/store'
import { useStore } from '../contexts/store'
import { useTheme } from '../contexts/theme'
import { useDeepLinks } from '../hooks/deep-links'
Expand Down Expand Up @@ -67,9 +66,6 @@ const RootStack: React.FC = () => {

useEffect(() => {
loadState(dispatch)
.then(() => {
dispatch({ type: DispatchAction.STATE_LOADED })
})
.catch((err: unknown) => {
const error = new BifoldError(t('Error.Title1044'), t('Error.Message1044'), (err as Error).message, 1001)
DeviceEventEmitter.emit(EventTypes.ERROR_ADDED, error)
Expand Down

0 comments on commit c27864a

Please sign in to comment.