on abbbcbc help sign in
bridge/src/views/Login/PrivateKey.js
38 lines 1.0 kB history raw
1import React, { useEffect } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import { Grid, Input } from 'indigo-react';
5import { useWallet } from 'store/wallet';
7import { useHexInput } from 'lib/useInputs';
8import { EthereumWallet, WALLET_TYPES, stripHexPrefix } from 'lib/wallet';
9import useLoginView from 'lib/useLoginView';
11export default function PrivateKey({ className }) {
12 useLoginView(WALLET_TYPES.PRIVATE_KEY);
14 const { setWallet } = useWallet();
16 const [privateKeyInput, { pass, data: privateKey }] = useHexInput({
17 length: 64,
18 name: 'privateKey',
19 label: 'Private key',
20 autoFocus: true,
21 });
23 useEffect(() => {
24 if (pass) {
25 const sec = Buffer.from(stripHexPrefix(privateKey), 'hex');
26 const newWallet = new EthereumWallet(sec);
27 setWallet(Just(newWallet));
28 } else {
29 setWallet(Nothing());
30 }
31 }, [pass, privateKey, setWallet]);
33 return (
34 <Grid className={className}>
35 <Grid.Item full as={Input} {...privateKeyInput} />
36 </Grid>
37 );