reducer.ts
1 import * as types from './types'; 2 3 export const INITIAL_STATE: types.ParitySignerState = { 4 requested: null 5 }; 6 7 function requestTransactionSignature( 8 state: types.ParitySignerState, 9 action: types.RequestTransactionSignatureAction 10 ): types.ParitySignerState { 11 return { 12 ...state, 13 requested: action.payload 14 }; 15 } 16 17 function requestMessageSignature( 18 state: types.ParitySignerState, 19 action: types.RequestMessageSignatureAction 20 ): types.ParitySignerState { 21 return { 22 ...state, 23 requested: action.payload 24 }; 25 } 26 27 function finalizeSignature(state: types.ParitySignerState): types.ParitySignerState { 28 return { 29 ...state, 30 requested: null 31 }; 32 } 33 34 export function paritySignerReducer( 35 state: types.ParitySignerState = INITIAL_STATE, 36 action: types.ParitySignerAction 37 ): types.ParitySignerState { 38 switch (action.type) { 39 case types.ParitySignerActions.REQUEST_TX_SIGNATURE: 40 return requestTransactionSignature(state, action); 41 case types.ParitySignerActions.REQUEST_MSG_SIGNATURE: 42 return requestMessageSignature(state, action); 43 case types.ParitySignerActions.FINALIZE_SIGNATURE: 44 return finalizeSignature(state); 45 default: 46 return state; 47 } 48 }