1
0
mirror of https://github.com/trezor/trezor-wallet synced 2025-01-01 03:40:53 +00:00

Added sign response, style

This commit is contained in:
Vladimir Volek 2018-10-17 17:57:21 +02:00
parent 1ebb893487
commit b89a825077
8 changed files with 66 additions and 26 deletions

View File

@ -1,25 +1,48 @@
/* @flow */ /* @flow */
import TrezorConnect from 'trezor-connect'; import TrezorConnect from 'trezor-connect';
import type { GetState, Dispatch } from 'flowtype';
import type { import * as NOTIFICATION from 'actions/constants/notification';
GetState, import * as SIGN_VERIFY from './constants/signVerify';
Dispatch,
} from 'flowtype';
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 selected = getState().wallet.selectedDevice;
const devicePath = selected.path; const devicePath = selected.path;
const device = { const device = {
path: devicePath, path: devicePath,
instance: selected.instance, instance: selected.instance,
state: selected.state, state: selected.state,
}; };
const response = await TrezorConnect const response = await TrezorConnect.ethereumSignMessage({
.ethereumSignMessage({ device,
device, path, hex, message, useEmptyPassphrase: selected.useEmptyPassphrase, path,
}); hex,
message,
useEmptyPassphrase: selected.useEmptyPassphrase,
});
console.log(response); if (response && response.success) {
dispatch({
type: SIGN_VERIFY.SIGN_SUCCESS,
signature: response.payload.signature,
});
} else {
dispatch({
type: NOTIFICATION.ADD,
payload: {
type: 'error',
title: 'Signing error',
message: response.payload.error,
cancelable: true,
actions: [
{
label: 'Try again',
callback: () => {
dispatch(() => {});
},
},
],
},
});
}
}; };

View File

@ -1,4 +1,4 @@
/* @flow */ /* @flow */
export const SIGN: 'send__init' = 'send__init'; export const SIGN_SUCCESS: 'sign__verify__sign__success' = 'sign__verify__sign__success';
export const VERYFI: 'send__change' = 'send__change'; export const VERIFY_SUCCESS: 'sign__verify__verify__success' = 'sign__verify__verify__success';

View File

@ -38,9 +38,9 @@ const StyledInput = styled.input`
padding: 5px ${props => (props.hasIcon ? '40px' : '12px')} 6px 12px; padding: 5px ${props => (props.hasIcon ? '40px' : '12px')} 6px 12px;
line-height: 1.42857143; line-height: 1.42857143;
font-size: ${FONT_SIZE.SMALL}; font-size: ${props => (props.isSmallText ? `${FONT_SIZE.SMALLER}` : `${FONT_SIZE.SMALL}`)};
font-weight: ${FONT_WEIGHT.BASE}; font-weight: ${FONT_WEIGHT.BASE};
color: ${props => (props.color ? props.color : colors.TEXT_SECONDARY)}; color: ${props => (props.color ? props.color : colors.TEXT)};
border-radius: 2px; border-radius: 2px;
${props => props.hasAddon && css` ${props => props.hasAddon && css`
@ -52,6 +52,7 @@ const StyledInput = styled.input`
background-color: ${colors.WHITE}; background-color: ${colors.WHITE};
transition: ${TRANSITION.HOVER}; transition: ${TRANSITION.HOVER};
&:disabled { &:disabled {
pointer-events: none; pointer-events: none;
background: ${colors.GRAY_LIGHT}; background: ${colors.GRAY_LIGHT};
@ -114,6 +115,7 @@ class Input extends PureComponent {
/> />
)} )}
<StyledInput <StyledInput
isSmallText={this.props.isSmallText}
hasIcon={this.getIcon(this.props.state).length > 0} hasIcon={this.getIcon(this.props.state).length > 0}
innerRef={this.props.innerRef} innerRef={this.props.innerRef}
hasAddon={!!this.props.sideAddons} hasAddon={!!this.props.sideAddons}
@ -163,6 +165,7 @@ Input.propTypes = {
sideAddons: PropTypes.arrayOf(PropTypes.node), sideAddons: PropTypes.arrayOf(PropTypes.node),
isDisabled: PropTypes.bool, isDisabled: PropTypes.bool,
name: PropTypes.string, name: PropTypes.string,
isSmallText: PropTypes.string,
}; };
Input.defaultProps = { Input.defaultProps = {

View File

@ -6,7 +6,6 @@ import * as RECEIVE from 'actions/constants/receive';
import * as ACCOUNT from 'actions/constants/account'; import * as ACCOUNT from 'actions/constants/account';
import type { Action } from 'flowtype'; import type { Action } from 'flowtype';
export type State = { export type State = {
addressVerified: boolean; addressVerified: boolean;
addressUnverified: boolean; addressUnverified: boolean;

View File

@ -3,21 +3,24 @@
import type { Action } from 'flowtype'; import type { Action } from 'flowtype';
import type { NetworkToken } from './LocalStorageReducer'; import type { NetworkToken } from './LocalStorageReducer';
import { SIGN_SUCCESS } from '../actions/constants/signVerify';
export type State = { export type State = {
details: boolean; details: boolean;
selectedToken: ?NetworkToken; selectedToken: ?NetworkToken;
} }
const SIGN = 'sign';
export const initialState: State = { export const initialState: State = {
signature: null,
}; };
export default (state: State = initialState, action: Action): State => { export default (state: State = initialState, action: Action): State => {
switch (action.type) { switch (action.type) {
case SIGN.SUCCESS: case SIGN_SUCCESS:
return initialState; return {
...state,
signature: state.signature,
};
default: default:
return state; return state;

View File

@ -20,6 +20,7 @@ import fiat from 'reducers/FiatRateReducer';
import wallet from 'reducers/WalletReducer'; import wallet from 'reducers/WalletReducer';
import devices from 'reducers/DevicesReducer'; import devices from 'reducers/DevicesReducer';
import blockchain from 'reducers/BlockchainReducer'; import blockchain from 'reducers/BlockchainReducer';
import signVerifyReducer from 'reducers/SignVerifyReducer';
const reducers = { const reducers = {
router: routerReducer, router: routerReducer,
@ -41,6 +42,7 @@ const reducers = {
wallet, wallet,
devices, devices,
blockchain, blockchain,
signVerifyReducer,
}; };
export type Reducers = typeof reducers; export type Reducers = typeof reducers;

View File

@ -22,7 +22,7 @@ export type Props = StateProps & DispatchProps;
const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (state: State): StateProps => ({ const mapStateToProps: MapStateToProps<State, OwnProps, StateProps> = (state: State): StateProps => ({
selectedAccount: state.selectedAccount, selectedAccount: state.selectedAccount,
sendForm: state.sendForm, signature: state.signature,
wallet: state.wallet, wallet: state.wallet,
fiat: state.fiat, fiat: state.fiat,
localStorage: state.localStorage, localStorage: state.localStorage,

View File

@ -69,13 +69,21 @@ class SignVerify extends Component {
return this.props.selectedAccount.account.addressPath; return this.props.selectedAccount.account.addressPath;
} }
getAddress() {
let result = null;
const { selectedAccount } = this.props;
if (selectedAccount.account && selectedAccount.account.address) {
result = selectedAccount.account.address;
}
return result || 'loading...';
}
handleSignInput = (e) => { handleSignInput = (e) => {
this.setState({ sign: { [e.target.name]: e.target.value } }); this.setState({ sign: { [e.target.name]: e.target.value } });
} }
handleVerifyInput = (e) => { handleVerifyInput = (e) => {
this.setState({ verify: { [e.target.name]: e.target.value } }); this.setState({ verify: { [e.target.name]: e.target.value } });
console.log(this.state);
} }
clearSign = () => { clearSign = () => {
@ -109,11 +117,12 @@ class SignVerify extends Component {
<Label>Address</Label> <Label>Address</Label>
<Input <Input
name="address" name="address"
value={this.state.sign.address} value={this.getAddress()}
onChange={this.handleSignInput} onChange={this.handleSignInput}
height={50} height={50}
type="text" type="text"
disabled isSmallText
isDisabled
/> />
</Row> </Row>
<Row> <Row>
@ -134,7 +143,7 @@ class SignVerify extends Component {
onChange={this.handleSign} onChange={this.handleSign}
rows="2" rows="2"
maxLength="255" maxLength="255"
disabled isDisabled
/> />
</Row> </Row>
<RowButtons> <RowButtons>
@ -157,6 +166,7 @@ class SignVerify extends Component {
value={this.state.verify.address} value={this.state.verify.address}
onChange={this.handleVerifyInput} onChange={this.handleVerifyInput}
type="text" type="text"
isSmallText
/> />
</Row> </Row>
<Row> <Row>