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