on fbcd6b6 help sign in
bridge/src/views/Login/PrivateKey.js
49 lines 1.4 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';
13import useResetPointCursor from 'lib/useResetPointCursor';
15export default function PrivateKey({ loginCompleted }) {
16 useResetPointCursor();
17 useWalletType(WALLET_TYPES.PRIVATE_KEY);
18 const { wallet, setWallet } = useWallet();
20 const privateKeyInput = usePassphraseInput({
21 name: 'privateKey',
22 label: 'Private key',
23 autoFocus: true,
24 });
25 const privateKey = privateKeyInput.data;
27 useEffect(() => {
28 if (/^[0-9A-Fa-f]{64}$/g.test(privateKey) === true) {
29 const sec = Buffer.from(privateKey, 'hex');
30 const newWallet = new EthereumWallet(sec);
31 setWallet(Just(newWallet));
32 } else {
33 setWallet(Nothing());
34 }
35 }, [privateKey, setWallet]);
37 return (
38 <View>
39 Please enter your raw Ethereum private key here.
40 <Input {...privateKeyInput} />
41 <ForwardButton
42 className="mt3"
43 disabled={Nothing.hasInstance(wallet)}
44 onClick={loginCompleted}>
45 Continue
46 </ForwardButton>
47 </View>
48 );