on 80f2d29 help sign in
bridge/src/views/PrivateKey.js
85 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 { Row, Col, 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';
17class PrivateKey extends React.Component {
18 constructor(props) {
19 super(props);
21 this.state = {
22 privateKey: '',
23 };
25 this.handlePrivateKeyInput = this.handlePrivateKeyInput.bind(this);
26 }
28 handlePrivateKeyInput(privateKey) {
29 this.setState({ privateKey });
30 this.constructWallet(privateKey);
31 }
33 constructWallet(privateKey) {
34 const { setWallet } = this.props;
35 if (/^[0-9A-Fa-f]{64}$/g.test(privateKey) === true) {
36 const sec = Buffer.from(privateKey, 'hex');
37 const wallet = new EthereumWallet(sec);
38 setWallet(Maybe.Just(wallet));
39 } else {
40 setWallet(Maybe.Nothing());
41 }
42 }
44 render() {
45 const { history, wallet } = this.props;
46 const { privateKey } = this.state;
48 return (
49 <Row>
50 <Col className={'measure-md'}>
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.SHIPS)}>
74 {'Continue →'}
75 </Button>
76 </Col>
77 </Row>
78 );
79 }
82export default compose(
83 withHistory,
84 withWallet
85)(PrivateKey);