From 18a424c214cacc63edfa6062674c81358e76860a Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Thu, 18 Oct 2018 14:18:48 +0200 Subject: [PATCH] Simplify input values, added verify --- src/actions/SignVerifyActions.js | 48 ++++++++- src/reducers/SignVerifyReducer.js | 12 ++- .../views/Account/SignVerify/Container.js | 10 +- .../Wallet/views/Account/SignVerify/index.js | 97 ++++++++----------- 4 files changed, 95 insertions(+), 72 deletions(-) diff --git a/src/actions/SignVerifyActions.js b/src/actions/SignVerifyActions.js index 51cc1ed8..99e734ac 100644 --- a/src/actions/SignVerifyActions.js +++ b/src/actions/SignVerifyActions.js @@ -4,7 +4,11 @@ import type { GetState, Dispatch } from 'flowtype'; import * as NOTIFICATION from 'actions/constants/notification'; import * as SIGN_VERIFY from './constants/signVerify'; -export const sign = (path: Array, message: string, hex: boolean = false): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise => { +export const sign = ( + path: Array, + message: string, + hex: boolean = false, +): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise => { const selected = getState().wallet.selectedDevice; const devicePath = selected.path; const device = { @@ -31,7 +35,47 @@ export const sign = (path: Array, message: string, hex: boolean = false) type: NOTIFICATION.ADD, payload: { type: 'error', - title: 'Signing error', + title: 'Sign error', + message: response.payload.error, + cancelable: true, + actions: [{ + label: 'Try again', + callback: () => { + dispatch(() => {}); + }, + }, + ], + }, + }); + } +}; + +export const verify = ( + address: string, + message: string, + signature: string, + hex: boolean = false, +): AsyncAction => async (dispatch: Dispatch): Promise => { + const input = { + address, + message, + signature, + hex, + }; + console.log('input', input); + const response = await TrezorConnect.ethereumVerifyMessage(input); + + if (response && response.success) { + dispatch({ + type: SIGN_VERIFY.VERIFY_SUCCESS, + signature: response.payload.success, + }); + } else { + dispatch({ + type: NOTIFICATION.ADD, + payload: { + type: 'error', + title: 'Verify error', message: response.payload.error, cancelable: true, actions: [ diff --git a/src/reducers/SignVerifyReducer.js b/src/reducers/SignVerifyReducer.js index d6e289f9..2a1f1287 100644 --- a/src/reducers/SignVerifyReducer.js +++ b/src/reducers/SignVerifyReducer.js @@ -3,7 +3,7 @@ import type { Action } from 'flowtype'; import type { NetworkToken } from './LocalStorageReducer'; -import { SIGN_SUCCESS } from '../actions/constants/signVerify'; +import * as SIGN_VERIFY from '../actions/constants/signVerify'; export type State = { details: boolean; @@ -16,10 +16,16 @@ export const initialState: State = { export default (state: State = initialState, action: Action): State => { switch (action.type) { - case SIGN_SUCCESS: + case SIGN_VERIFY.SIGN_SUCCESS: return { ...state, - signature: state.signature, + signature: action.signature, + }; + + case SIGN_VERIFY.VERIFY_SUCCESS: + return { + ...state, + signature: action.signature, }; default: diff --git a/src/views/Wallet/views/Account/SignVerify/Container.js b/src/views/Wallet/views/Account/SignVerify/Container.js index af7c1871..570b8f2b 100644 --- a/src/views/Wallet/views/Account/SignVerify/Container.js +++ b/src/views/Wallet/views/Account/SignVerify/Container.js @@ -12,20 +12,14 @@ type OwnProps = {} export type StateProps = { selectedAccount: $ElementType, - sendForm: $ElementType, - wallet: $ElementType, - fiat: $ElementType, - localStorage: $ElementType, } export type Props = StateProps & DispatchProps; const mapStateToProps: MapStateToProps = (state: State): StateProps => ({ selectedAccount: state.selectedAccount, - signature: state.signature, - wallet: state.wallet, - fiat: state.fiat, - localStorage: state.localStorage, + signature: state.signVerifyReducer.signature, + isVerifySuccess: state.signVerifyReducer.isVerifySuccess, }); const mapDispatchToProps: MapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({ diff --git a/src/views/Wallet/views/Account/SignVerify/index.js b/src/views/Wallet/views/Account/SignVerify/index.js index 1d5ef18d..96c641a7 100644 --- a/src/views/Wallet/views/Account/SignVerify/index.js +++ b/src/views/Wallet/views/Account/SignVerify/index.js @@ -52,16 +52,10 @@ class SignVerify extends Component { constructor(props) { super(props); this.state = { - sign: { - address: '', - message: '', - signature: '', - }, - verify: { - address: '', - message: '', - signature: '', - }, + signMessage: '', + verifyAddress: '', + verifyMessage: '', + verifySignature: '', }; } @@ -78,36 +72,16 @@ class SignVerify extends Component { return result || 'loading...'; } - handleSignInput = (e) => { - this.setState({ sign: { [e.target.name]: e.target.value } }); - } - - handleVerifyInput = (e) => { - this.setState({ verify: { [e.target.name]: e.target.value } }); - } - - clearSign = () => { - this.setState({ - sign: { - address: '', - message: '', - signature: '', - }, - }); - } - - clearVerify = () => { - this.setState({ - verify: { - address: '', - message: '', - signature: '', - }, - }); + handleInputChange = (event) => { + this.setState({ [event.target.name]: event.target.value }); } render() { - const { signVerifyActions } = this.props; + const { + signVerifyActions, + signature, + isVerifySuccess, + } = this.props; return ( Sign & Verify @@ -116,9 +90,8 @@ class SignVerify extends Component {