on faa39fb help sign in
bridge/src/views/Login/PrivateKey.js
51 lines 1.4 kB history raw
1import { Just, Nothing } from 'folktale/maybe';
2import React, { useState } from 'react';
4import View from '../../components/View';
5import { PassphraseInput } from '../../components/Inputs';
6import { ForwardButton } from '../../components/Buttons';
8import { EthereumWallet } from '../../lib/wallet';
9import { useWallet } from '../../store/wallet';
11export default function PrivateKey({ loginCompleted }) {
12 const { wallet, setWallet } = useWallet();
14 const [privateKey, setPrivateKey] = useState('');
16 const handlePrivateKeyInput = privateKey => {
17 setPrivateKey(privateKey);
18 constructWallet(privateKey);
19 };
21 const constructWallet = privateKey => {
22 if (/^[0-9A-Fa-f]{64}$/g.test(privateKey) === true) {
23 const sec = Buffer.from(privateKey, 'hex');
24 const newWallet = new EthereumWallet(sec);
25 setWallet(Just(newWallet));
26 } else {
27 setWallet(Nothing());
28 }
29 };
31 return (
32 <View>
33 Please enter your raw Ethereum private key here.
34 <PassphraseInput
35 type="password"
36 name="privateKey"
37 label="Private key"
38 initialValue={privateKey}
39 onValue={handlePrivateKeyInput}
40 autocomplete="off"
41 autoFocus
42 />
43 <ForwardButton
44 className="mt3"
45 disabled={Nothing.hasInstance(wallet)}
46 onClick={loginCompleted}>
47 Continue
48 </ForwardButton>
49 </View>
50 );