Add flow types to Sync. No functional change.
This commit is contained in:
parent
3bce2e656f
commit
3040b9ea12
2 changed files with 36 additions and 16 deletions
16
flow-typed/sync.js
vendored
Normal file
16
flow-typed/sync.js
vendored
Normal file
|
@ -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,
|
||||
};
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue