@@ -1,80 +1,50 @@
1−import Maybe from 'folktale/maybe';
1+import { Just, Nothing } from 'folktale/maybe';
2−import React from 'react';
2+import React, { useState } from 'react';
3−import { Button } from '../../components/old/Base';
8−} from '../../components/old/Base';
9−import { Row, Col, H1 } from '../../components/old/Base';
11−import { EthereumWallet } from '../../lib/wallet';
4+import View from '../../components/View';
12−import { compose } from '../../lib/lib';
5+import { PassphraseInput } from '../../components/Inputs';
13−import { withWallet } from '../../store/wallet';
6+import { ForwardButton } from '../../components/Buttons';
15−class PrivateKey extends React.Component {
8+import { EthereumWallet } from '../../lib/wallet';
16− constructor(props) {
9+import { useWallet } from '../../store/wallet';
19− this.state = {
11+export default function PrivateKey({ loginCompleted }) {
20− privateKey: '',
12+ const { wallet, setWallet } = useWallet();
23− this.handlePrivateKeyInput = this.handlePrivateKeyInput.bind(this);
14+ const [privateKey, setPrivateKey] = useState('');
26− handlePrivateKeyInput(privateKey) {
16+ const handlePrivateKeyInput = privateKey => {
27− this.setState({ privateKey });
17+ setPrivateKey(privateKey);
28− this.constructWallet(privateKey);
18+ constructWallet(privateKey);
31− constructWallet(privateKey) {
21+ const constructWallet = privateKey => {
32− const { setWallet } = this.props;
33 if (/^[0-9A-Fa-f]{64}$/g.test(privateKey) === true) {
22 if (/^[0-9A-Fa-f]{64}$/g.test(privateKey) === true) {
34 const sec = Buffer.from(privateKey, 'hex');
23 const sec = Buffer.from(privateKey, 'hex');
35− const wallet = new EthereumWallet(sec);
24+ const newWallet = new EthereumWallet(sec);
36− setWallet(Maybe.Just(wallet));
25+ setWallet(Just(newWallet));
38− setWallet(Maybe.Nothing());
27+ setWallet(Nothing());
43− const { wallet } = this.props;
44− const { privateKey } = this.state;
48− <Col className={'measure-md'}>
49− <H1 className={'mb-4'}>{'Enter Your Private Key'}</H1>
51− {`Please enter your raw Ethereum private key here.`}
33+ Please enter your raw Ethereum private key here.
52− </InputCaption>
34+ <PassphraseInput
55− className="pt-8 mt-8"
57− prop-format="innerLabel"
58− type="password"
35+ type="password"
59− name="privateKey"
36+ name="privateKey"
38+ initialValue={privateKey}
60− onChange={this.handlePrivateKeyInput}
39+ onValue={handlePrivateKeyInput}
62− autocomplete="off"
40+ autocomplete="off"
63− autoFocus>
41+ autoFocus></PassphraseInput>
64− <InnerLabel>{'Private Key'}</InnerLabel>
42+ <ForwardButton
68− className={'mt-10'}
43+ className={'mt3'}
69− prop-size={'wide lg'}
70− disabled={Maybe.Nothing.hasInstance(wallet)}
44+ disabled={Nothing.hasInstance(wallet)}
71− onClick={this.props.loginCompleted}>
45+ onClick={loginCompleted}>
72− {'Continue →'}
46+ {'Continue →'}
73− </Button>
47+ </ForwardButton>
80−export default compose(withWallet)(PrivateKey);