on adbcda8 help sign in
bridge/src/views/Login/PrivateKey.js
44 lines 1.2 kB history raw
1import { Just, Nothing } from 'folktale/maybe';
2import React, { useEffect } from 'react';
4import View from 'components/View';
5import { usePassphraseInput } from 'components/Inputs';
6import { ForwardButton } from 'components/Buttons';
8import { EthereumWallet } from 'lib/wallet';
9import { useWallet } from 'store/wallet';
10import { Input } from 'indigo-react';
12export default function PrivateKey({ loginCompleted }) {
13 const { wallet, setWallet } = useWallet();
15 const privateKeyInput = usePassphraseInput({
16 name: 'privateKey',
17 label: 'Private key',
18 autoFocus: true,
19 });
20 const privateKey = privateKeyInput.data;
22 useEffect(() => {
23 if (/^[0-9A-Fa-f]{64}$/g.test(privateKey) === true) {
24 const sec = Buffer.from(privateKey, 'hex');
25 const newWallet = new EthereumWallet(sec);
26 setWallet(Just(newWallet));
27 } else {
28 setWallet(Nothing());
29 }
30 }, [privateKey, setWallet]);
32 return (
33 <View>
34 Please enter your raw Ethereum private key here.
35 <Input {...privateKeyInput} />
36 <ForwardButton
37 className="mt3"
38 disabled={Nothing.hasInstance(wallet)}
39 onClick={loginCompleted}>
40 Continue
41 </ForwardButton>
42 </View>
43 );