on 69dc015 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/Base'
4import { RequiredInput, InnerLabel, InputCaption } from '../components/Base'
5import { Row, Col, H1 } from '../components/Base'
7import { ROUTE_NAMES } from '../lib/router'
8import { EthereumWallet } from '../lib/wallet'
10const secre = /[0-9A-Fa-f]{64}/g
12class PrivateKey extends React.Component {
14 constructor(props) {
15 super(props)
17 this.state = {
18 privateKey: '',
19 }
21 this.handlePrivateKeyInput = this.handlePrivateKeyInput.bind(this)
22 }
24 handlePrivateKeyInput(privateKey) {
25 this.setState({ privateKey })
26 this.constructWallet(privateKey)
27 }
29 constructWallet(privateKey) {
30 const { setWallet } = this.props
31 if (secre.test(privateKey) === true) {
32 const sec = Buffer.from(privateKey, 'hex')
33 const wallet = new EthereumWallet(sec)
34 setWallet(Maybe.Just(wallet))
35 } else {
36 setWallet(Maybe.Nothing())
37 }
38 }
40 render() {
41 const { pushRoute, popRoute, wallet } = this.props
42 const { privateKey } = this.state
44 return (
45 <Row>
46 <Col className={'measure-md'}>
47 <H1 className={'mb-4'}>{ 'Enter Your Private Key' }</H1>
48 <InputCaption>
49 { `Please enter your raw Ethereum private key here.` }
50 </InputCaption>
52 <RequiredInput
53 className='pt-8 mt-8'
54 prop-size='md'
55 prop-format='innerLabel'
56 type='password'
57 name='privateKey'
58 onChange={ this.handlePrivateKeyInput }
59 value={ privateKey }
60 autocomplete='off'
61 autoFocus>
62 <InnerLabel>{'Private Key'}</InnerLabel>
63 </RequiredInput>
65 <Button
66 className={'mt-10'}
67 prop-size={ 'wide lg' }
68 disabled={ Maybe.Nothing.hasInstance(wallet) }
69 onClick={ () => {
70 popRoute()
71 pushRoute(ROUTE_NAMES.SHIPS)
72 }
73 }
74 >
75 { 'Continue →' }
76 </Button>
77 </Col>
78 </Row>
81 )
82 }
85export default PrivateKey