on dd12472 help sign in
bridge/src/views/PrivateKey.js
84 lines 2.2 kB history raw
1import Maybe from 'folktale/maybe';
2import React from 'react';
3import { Button } from '../components/old/Base';
4import {
5 RequiredInput,
6 InnerLabel,
7 InputCaption,
8} from '../components/old/Base';
9import { H1 } from '../components/old/Base';
11import { ROUTE_NAMES } from '../lib/routeNames';
12import { withHistory } from '../store/history';
13import { EthereumWallet } from '../lib/wallet';
14import { compose } from '../lib/lib';
15import { withWallet } from '../store/wallet';
16import View from 'components/View';
18class PrivateKey extends React.Component {
19 constructor(props) {
20 super(props);
22 this.state = {
23 privateKey: '',
24 };
26 this.handlePrivateKeyInput = this.handlePrivateKeyInput.bind(this);
27 }
29 handlePrivateKeyInput(privateKey) {
30 this.setState({ privateKey });
31 this.constructWallet(privateKey);
32 }
34 constructWallet(privateKey) {
35 const { setWallet } = this.props;
36 if (/^[0-9A-Fa-f]{64}$/g.test(privateKey) === true) {
37 const sec = Buffer.from(privateKey, 'hex');
38 const wallet = new EthereumWallet(sec);
39 setWallet(Maybe.Just(wallet));
40 } else {
41 setWallet(Maybe.Nothing());
42 }
43 }
45 render() {
46 const { history, wallet } = this.props;
47 const { privateKey } = this.state;
49 return (
50 <View>
51 <H1 className={'mb-4'}>{'Enter Your Private Key'}</H1>
52 <InputCaption>
53 {`Please enter your raw Ethereum private key here.`}
54 </InputCaption>
56 <RequiredInput
57 className="pt-8 mt-8"
58 prop-size="md"
59 prop-format="innerLabel"
60 type="password"
61 name="privateKey"
62 onChange={this.handlePrivateKeyInput}
63 value={privateKey}
64 autocomplete="off"
65 autoFocus>
66 <InnerLabel>{'Private Key'}</InnerLabel>
67 </RequiredInput>
69 <Button
70 className={'mt-10'}
71 prop-size={'wide lg'}
72 disabled={Maybe.Nothing.hasInstance(wallet)}
73 onClick={() => history.popAndPush(ROUTE_NAMES.POINTS)}>
74 {'Continue →'}
75 </Button>
76 </View>
77 );
78 }
81export default compose(
82 withHistory,
83 withWallet
84)(PrivateKey);