From 3040b9ea1215c540c337e5bde6ecf71b48ab4f2e Mon Sep 17 00:00:00 2001 From: infinite-persistence Date: Fri, 17 Dec 2021 12:08:16 +0800 Subject: [PATCH] Add flow types to Sync. No functional change. --- flow-typed/sync.js | 16 ++++++++++++++++ ui/redux/reducers/sync.js | 36 ++++++++++++++++++++---------------- 2 files changed, 36 insertions(+), 16 deletions(-) create mode 100644 flow-typed/sync.js diff --git a/flow-typed/sync.js b/flow-typed/sync.js new file mode 100644 index 000000000..b30603340 --- /dev/null +++ b/flow-typed/sync.js @@ -0,0 +1,16 @@ +declare type SyncState = { + hasSyncedWallet: boolean, + syncHash: ?string, + syncData: ?string, + setSyncErrorMessage: ?string, + getSyncErrorMessage: ?string, + syncApplyErrorMessage: string, + syncApplyIsPending: boolean, + syncApplyPasswordError: boolean, + getSyncIsPending: boolean, + setSyncIsPending: boolean, + prefsReady: boolean, + syncLocked: boolean, + hashChanged: boolean, + fatalError: boolean, +}; diff --git a/ui/redux/reducers/sync.js b/ui/redux/reducers/sync.js index a53817f0d..0e0e55a93 100644 --- a/ui/redux/reducers/sync.js +++ b/ui/redux/reducers/sync.js @@ -1,7 +1,9 @@ +// @flow import * as ACTIONS from 'constants/action_types'; const reducers = {}; -const defaultState = { + +const defaultState: SyncState = { hasSyncedWallet: false, syncHash: null, syncData: null, @@ -18,7 +20,8 @@ const defaultState = { fatalError: false, }; -reducers[ACTIONS.USER_STATE_POPULATE] = (state) => { +reducers[ACTIONS.USER_STATE_POPULATE] = (state: SyncState) => { + // $FlowFixMe - 'syncReady' doesn't exist. A bug? const { syncReady } = state; if (!syncReady) { return Object.assign({}, state, { @@ -29,20 +32,21 @@ reducers[ACTIONS.USER_STATE_POPULATE] = (state) => { } }; -reducers[ACTIONS.SET_PREFS_READY] = (state, action) => Object.assign({}, state, { prefsReady: action.data }); +reducers[ACTIONS.SET_PREFS_READY] = (state: SyncState, action: any) => + Object.assign({}, state, { prefsReady: action.data }); -reducers[ACTIONS.GET_SYNC_STARTED] = (state) => +reducers[ACTIONS.GET_SYNC_STARTED] = (state: SyncState) => Object.assign({}, state, { getSyncIsPending: true, getSyncErrorMessage: null, }); -reducers[ACTIONS.SET_SYNC_LOCK] = (state, action) => +reducers[ACTIONS.SET_SYNC_LOCK] = (state: SyncState, action: any) => Object.assign({}, state, { syncLocked: action.data, }); -reducers[ACTIONS.GET_SYNC_COMPLETED] = (state, action) => +reducers[ACTIONS.GET_SYNC_COMPLETED] = (state: SyncState, action: any) => Object.assign({}, state, { syncHash: action.data.syncHash, syncData: action.data.syncData, @@ -52,25 +56,25 @@ reducers[ACTIONS.GET_SYNC_COMPLETED] = (state, action) => fatalError: action.data.fatalError, }); -reducers[ACTIONS.GET_SYNC_FAILED] = (state, action) => +reducers[ACTIONS.GET_SYNC_FAILED] = (state: SyncState, action: any) => Object.assign({}, state, { getSyncIsPending: false, getSyncErrorMessage: action.data.error, }); -reducers[ACTIONS.SET_SYNC_STARTED] = (state) => +reducers[ACTIONS.SET_SYNC_STARTED] = (state: SyncState) => Object.assign({}, state, { setSyncIsPending: true, setSyncErrorMessage: null, }); -reducers[ACTIONS.SET_SYNC_FAILED] = (state, action) => +reducers[ACTIONS.SET_SYNC_FAILED] = (state: SyncState, action: any) => Object.assign({}, state, { setSyncIsPending: false, setSyncErrorMessage: action.data.error, }); -reducers[ACTIONS.SET_SYNC_COMPLETED] = (state, action) => +reducers[ACTIONS.SET_SYNC_COMPLETED] = (state: SyncState, action: any) => Object.assign({}, state, { setSyncIsPending: false, setSyncErrorMessage: null, @@ -78,31 +82,31 @@ reducers[ACTIONS.SET_SYNC_COMPLETED] = (state, action) => syncHash: action.data.syncHash, }); -reducers[ACTIONS.SYNC_APPLY_STARTED] = (state) => +reducers[ACTIONS.SYNC_APPLY_STARTED] = (state: SyncState) => Object.assign({}, state, { syncApplyPasswordError: false, syncApplyIsPending: true, syncApplyErrorMessage: '', }); -reducers[ACTIONS.SYNC_APPLY_COMPLETED] = (state) => +reducers[ACTIONS.SYNC_APPLY_COMPLETED] = (state: SyncState) => Object.assign({}, state, { syncApplyIsPending: false, syncApplyErrorMessage: '', }); -reducers[ACTIONS.SYNC_APPLY_FAILED] = (state, action) => +reducers[ACTIONS.SYNC_APPLY_FAILED] = (state: SyncState, action: any) => Object.assign({}, state, { syncApplyIsPending: false, syncApplyErrorMessage: action.data.error, }); -reducers[ACTIONS.SYNC_APPLY_BAD_PASSWORD] = (state) => +reducers[ACTIONS.SYNC_APPLY_BAD_PASSWORD] = (state: SyncState) => Object.assign({}, state, { syncApplyPasswordError: true, }); -reducers[ACTIONS.SYNC_FATAL_ERROR] = (state) => { +reducers[ACTIONS.SYNC_FATAL_ERROR] = (state: SyncState) => { return Object.assign({}, state, { fatalError: true, }); @@ -110,7 +114,7 @@ reducers[ACTIONS.SYNC_FATAL_ERROR] = (state) => { reducers[ACTIONS.SYNC_RESET] = () => defaultState; -export default function syncReducer(state = defaultState, action) { +export default function syncReducer(state: SyncState = defaultState, action: any) { const handler = reducers[action.type]; if (handler) return handler(state, action); return state;