1
0
mirror of https://github.com/trezor/trezor-wallet synced 2024-12-29 10:28:08 +00:00

Simplify input values, added verify

This commit is contained in:
Vladimir Volek 2018-10-18 14:18:48 +02:00
parent b89a825077
commit 18a424c214
4 changed files with 95 additions and 72 deletions

View File

@ -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<number>, message: string, hex: boolean = false): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
export const sign = (
path: Array<number>,
message: string,
hex: boolean = false,
): AsyncAction => async (dispatch: Dispatch, getState: GetState): Promise<void> => {
const selected = getState().wallet.selectedDevice;
const devicePath = selected.path;
const device = {
@ -31,7 +35,47 @@ export const sign = (path: Array<number>, 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<void> => {
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: [

View File

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

View File

@ -12,20 +12,14 @@ type OwnProps = {}
export type StateProps = {
selectedAccount: $ElementType<State, 'selectedAccount'>,
sendForm: $ElementType<State, 'sendForm'>,
wallet: $ElementType<State, 'wallet'>,
fiat: $ElementType<State, 'fiat'>,
localStorage: $ElementType<State, 'localStorage'>,
}
export type Props = StateProps & DispatchProps;
const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (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, OwnProps, DispatchProps> = (dispatch: Dispatch): DispatchProps => ({

View File

@ -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 (
<Content>
<Title>Sign & Verify</Title>
@ -116,9 +90,8 @@ class SignVerify extends Component {
<Row>
<Label>Address</Label>
<Input
name="address"
name="signAddress"
value={this.getAddress()}
onChange={this.handleSignInput}
height={50}
type="text"
isSmallText
@ -128,9 +101,9 @@ class SignVerify extends Component {
<Row>
<Label>Message</Label>
<Textarea
name="message"
value={this.state.sign.message}
onChange={this.handleSignInput}
name="signMessage"
value={this.state.signMessage}
onChange={this.handleInputChange}
rows="2"
maxLength="255"
/>
@ -138,9 +111,8 @@ class SignVerify extends Component {
<Row>
<Label>Signature</Label>
<Textarea
name="signature"
value={this.state.sign.signature}
onChange={this.handleSign}
name="signSignature"
value={this.props.signature}
rows="2"
maxLength="255"
isDisabled
@ -148,12 +120,12 @@ class SignVerify extends Component {
</Row>
<RowButtons>
<Button
onClick={this.clearVerify}
onClick={() => this.clearSign()}
isWhite
>Clear
</Button>
<StyledButton
onClick={() => signVerifyActions.sign(this.getPath(), this.state.sign.message)}
onClick={() => signVerifyActions.sign(this.getPath(), this.state.signMessage)}
>Sign
</StyledButton>
</RowButtons>
@ -162,9 +134,9 @@ class SignVerify extends Component {
<Row>
<Label>Address</Label>
<Input
name="address"
value={this.state.verify.address}
onChange={this.handleVerifyInput}
name="verifyAddress"
value={this.state.verifyAddress}
onChange={this.handleInputChange}
type="text"
isSmallText
/>
@ -172,9 +144,9 @@ class SignVerify extends Component {
<Row>
<Label>Message</Label>
<Textarea
name="message"
value={this.state.verify.message}
onChange={this.handleVerifyInput}
name="verifyMessage"
value={this.state.verifyMessage}
onChange={this.handleInputChange}
rows="4"
maxLength="255"
/>
@ -182,20 +154,27 @@ class SignVerify extends Component {
<Row>
<Label>Signature</Label>
<Textarea
name="signature"
value={this.state.verify.signature}
onChange={this.handleVerifyInput}
name="verifySignature"
value={this.state.verifySignature}
onChange={this.handleInputChange}
rows="4"
maxLength="255"
/>
</Row>
<RowButtons>
<Button
onClick={this.clearSign}
onClick={() => this.clearVerify()}
isWhite
>Clear
</Button>
<StyledButton>Verify</StyledButton>
<StyledButton
onClick={() => signVerifyActions.verify(
this.state.verifyAddress,
this.state.verifyMessage,
this.state.verifySignature,
)}
>Verify
</StyledButton>
</RowButtons>
</Verify>
</Wrapper>
@ -205,7 +184,7 @@ class SignVerify extends Component {
}
SignVerify.propTypes = {
sign: PropTypes.func.isRequired,
isVerifySuccess: PropTypes.bool,
};
export default SignVerify;