From 43906f505c53064e71389cb89b2ef634e6a6eb53 Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Wed, 21 Nov 2018 19:32:28 +0100 Subject: [PATCH] Add clear actions --- src/actions/SignVerifyActions.js | 13 ++++++--- src/actions/constants/signVerify.js | 3 ++- src/reducers/SignVerifyReducer.js | 23 +++++++++++----- .../Wallet/views/Account/SignVerify/index.js | 27 +++++++------------ 4 files changed, 39 insertions(+), 27 deletions(-) diff --git a/src/actions/SignVerifyActions.js b/src/actions/SignVerifyActions.js index fbe561ec..c0894a66 100644 --- a/src/actions/SignVerifyActions.js +++ b/src/actions/SignVerifyActions.js @@ -123,15 +123,22 @@ const inputChange = (name, value): ThunkAction => (dispatch: Dispatch): void => }); }; -const clear = (): ThunkAction => (dispatch: Dispatch): void => { +const clearSign = (): ThunkAction => (dispatch: Dispatch): void => { dispatch({ - type: SIGN_VERIFY.CLEAR, + type: SIGN_VERIFY.CLEAR_SIGN, + }); +}; + +const clearVerify = (): ThunkAction => (dispatch: Dispatch): void => { + dispatch({ + type: SIGN_VERIFY.CLEAR_VERIFY, }); }; export default { sign, verify, - clear, + clearSign, + clearVerify, inputChange, }; \ No newline at end of file diff --git a/src/actions/constants/signVerify.js b/src/actions/constants/signVerify.js index fdf622c7..7c6040af 100644 --- a/src/actions/constants/signVerify.js +++ b/src/actions/constants/signVerify.js @@ -2,4 +2,5 @@ export const SIGN_SUCCESS: 'sign__verify__sign__success' = 'sign__verify__sign__success'; export const INPUT_CHANGE: 'sign__verify__input__change' = 'sign__verify__input__change'; export const TOUCH: 'sign__verify__input__touch' = 'sign__verify__input__touch'; -export const CLEAR: 'sign__verify__sign__clear' = 'sign__verify__sign__clear'; \ No newline at end of file +export const CLEAR_SIGN: 'sign__verify__sign__clear' = 'sign__verify__sign__clear'; +export const CLEAR_VERIFY: 'sign__verify__verify__clear' = 'sign__verify__verify__clear'; \ No newline at end of file diff --git a/src/reducers/SignVerifyReducer.js b/src/reducers/SignVerifyReducer.js index cdbe1ee8..ea1987fa 100644 --- a/src/reducers/SignVerifyReducer.js +++ b/src/reducers/SignVerifyReducer.js @@ -1,6 +1,6 @@ /* @flow */ import type { Action } from 'flowtype'; -import * as SIGN_VERIFY from 'actions/constants/signVerify'; +import * as ACTION from 'actions/constants/signVerify'; export type State = { signAddress: string, @@ -24,13 +24,13 @@ export const initialState: State = { export default (state: State = initialState, action: Action): State => { switch (action.type) { - case SIGN_VERIFY.SIGN_SUCCESS: + case ACTION.SIGN_SUCCESS: return { ...initialState, signature: action.signature, }; - case SIGN_VERIFY.TOUCH: { + case ACTION.TOUCH: { if (!state.touched.includes(action.name)) { return { ...state, @@ -40,14 +40,25 @@ export default (state: State = initialState, action: Action): State => { return state; } - case SIGN_VERIFY.INPUT_CHANGE: { + case ACTION.INPUT_CHANGE: { const changes = { [action.name]: action.value }; return { ...state, ...changes }; } - case SIGN_VERIFY.CLEAR: + case ACTION.CLEAR_SIGN: return { - ...initialState, + ...state, + signAddress: '', + signMessage: '', + signSignature: '', + }; + + case ACTION.CLEAR_VERIFY: + return { + ...state, + verifyAddress: '', + verifyMessage: '', + verifySignature: '', }; default: diff --git a/src/views/Wallet/views/Account/SignVerify/index.js b/src/views/Wallet/views/Account/SignVerify/index.js index 2913fc9c..7933193a 100644 --- a/src/views/Wallet/views/Account/SignVerify/index.js +++ b/src/views/Wallet/views/Account/SignVerify/index.js @@ -56,12 +56,7 @@ type State = { class SignVerify extends Component { handleInputChange = (event: SyntheticInputEvent) => { - const touched = true; - this.props.signVerifyActions.inputChange( - event.target.name, - event.target.value, - touched, - ); + this.props.signVerifyActions.inputChange(event.target.name, event.target.value); } render() { @@ -73,19 +68,17 @@ class SignVerify extends Component { if (!device || !account || !discovery || !shouldRender) return ; const { signVerifyActions, - signVerify, + signVerify: { + signAddress, + signMessage, + signSignature, + verifyAddress, + verifyMessage, + verifySignature, + touched, + }, } = this.props; - const { - signAddress, - signMessage, - signSignature, - verifyAddress, - verifyMessage, - verifySignature, - touched, - } = signVerify; - console.log(touched); return ( Sign & Verify