From ca460859ac95f695b3db464705ebc5e357a6395c Mon Sep 17 00:00:00 2001 From: Vladimir Volek Date: Wed, 17 Oct 2018 00:31:33 +0200 Subject: [PATCH] Added sign action --- src/actions/SignVerifyActions.js | 25 +++ src/actions/constants/signVerify.js | 4 + src/components/Textarea/index.js | 3 + src/reducers/SignVerifyReducer.js | 25 +++ .../views/Account/SignVerify/Container.js | 35 ++++ .../Wallet/views/Account/SignVerify/index.js | 154 ++++++++++++------ .../Wallet/views/Account/Summary/index.js | 1 + src/views/index.js | 2 +- 8 files changed, 202 insertions(+), 47 deletions(-) create mode 100644 src/actions/SignVerifyActions.js create mode 100644 src/actions/constants/signVerify.js create mode 100644 src/reducers/SignVerifyReducer.js create mode 100644 src/views/Wallet/views/Account/SignVerify/Container.js diff --git a/src/actions/SignVerifyActions.js b/src/actions/SignVerifyActions.js new file mode 100644 index 00000000..29207cce --- /dev/null +++ b/src/actions/SignVerifyActions.js @@ -0,0 +1,25 @@ +/* @flow */ +import TrezorConnect from 'trezor-connect'; + +import type { + GetState, + Dispatch, +} from 'flowtype'; + +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 = { + path: devicePath, + instance: selected.instance, + state: selected.state, + }; + + const response = await TrezorConnect + .ethereumSignMessage({ + device, path, hex, message, useEmptyPassphrase: selected.useEmptyPassphrase, + }); + + console.log(response); +}; \ No newline at end of file diff --git a/src/actions/constants/signVerify.js b/src/actions/constants/signVerify.js new file mode 100644 index 00000000..fc9e933b --- /dev/null +++ b/src/actions/constants/signVerify.js @@ -0,0 +1,4 @@ +/* @flow */ + +export const SIGN: 'send__init' = 'send__init'; +export const VERYFI: 'send__change' = 'send__change'; diff --git a/src/components/Textarea/index.js b/src/components/Textarea/index.js index 98f8a938..3b025961 100644 --- a/src/components/Textarea/index.js +++ b/src/components/Textarea/index.js @@ -114,6 +114,7 @@ const TextArea = ({ onFocus, onBlur, isDisabled, + name, onChange, topLabel, state = '', @@ -128,6 +129,7 @@ const TextArea = ({ { + switch (action.type) { + case SIGN.SUCCESS: + return initialState; + + default: + return state; + } +}; \ No newline at end of file diff --git a/src/views/Wallet/views/Account/SignVerify/Container.js b/src/views/Wallet/views/Account/SignVerify/Container.js new file mode 100644 index 00000000..3a25ec83 --- /dev/null +++ b/src/views/Wallet/views/Account/SignVerify/Container.js @@ -0,0 +1,35 @@ +/* @flow */ + +import { bindActionCreators } from 'redux'; +import { connect } from 'react-redux'; + +import * as SignVerifyActions from 'actions/SignVerifyActions'; +import type { MapStateToProps, MapDispatchToProps } from 'react-redux'; +import type { State, Dispatch } from 'flowtype'; +import Component from './index'; + +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, + sendForm: state.sendForm, + wallet: state.wallet, + fiat: state.fiat, + localStorage: state.localStorage, +}); + +const mapDispatchToProps: MapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({ + signVerifyActions: bindActionCreators(SignVerifyActions, dispatch), +}); + +export default connect(mapStateToProps, mapDispatchToProps)(Component); \ No newline at end of file diff --git a/src/views/Wallet/views/Account/SignVerify/index.js b/src/views/Wallet/views/Account/SignVerify/index.js index 4c003fc8..a2c8d7f1 100644 --- a/src/views/Wallet/views/Account/SignVerify/index.js +++ b/src/views/Wallet/views/Account/SignVerify/index.js @@ -1,6 +1,7 @@ -import React from 'react'; +import React, { Component } from 'react'; import styled from 'styled-components'; import Input from 'components/inputs/Input'; +import PropTypes from 'prop-types'; import Textarea from 'components/Textarea'; import Title from 'views/Wallet/components/Title'; import Button from 'components/Button'; @@ -47,48 +48,109 @@ const Label = styled.div` padding: 5px 0px 10px 0; `; -const AccountSignVerify = () => ( - - Sign & Verify - - - - - - - - -