1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-12-29 02:18:06 +00:00

Add clear actions

This commit is contained in:
Vladimir Volek 2018-11-21 19:32:28 +01:00
parent e41cc22e3b
commit 43906f505c
4 changed files with 39 additions and 27 deletions

View File

@ -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,
};

View File

@ -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';
export const CLEAR_SIGN: 'sign__verify__sign__clear' = 'sign__verify__sign__clear';
export const CLEAR_VERIFY: 'sign__verify__verify__clear' = 'sign__verify__verify__clear';

View File

@ -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:

View File

@ -56,12 +56,7 @@ type State = {
class SignVerify extends Component<Props, State> {
handleInputChange = (event: SyntheticInputEvent<Text>) => {
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<Props, State> {
if (!device || !account || !discovery || !shouldRender) return <Content type={type} title={title} message={message} isLoading />;
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 (
<Content>
<Title>Sign & Verify</Title>