1import React, { useState } from 'react';
2import { Just, Nothing } from 'folktale/maybe';
3import { P, Grid, Input, ErrorText } from 'indigo-react';
4import * as keythereum from 'keythereum';
6import { useWallet } from 'store/wallet';
8import { usePassphraseInput } from 'lib/useInputs';
9import * as need from 'lib/need';
10import { EthereumWallet, WALLET_TYPES } from 'lib/wallet';
11import useLoginView from 'lib/useLoginView';
13import { ForwardButton } from 'components/Buttons';
14import UploadButton from 'components/UploadButton';
16export default function Keystore({ className }) {
17 useLoginView(WALLET_TYPES.KEYSTORE);
20 const { setWallet } = useWallet();
22 const [error, setError] = useState();
24 // keystore: Maybe<String>
25 const [keystore, setKeystore] = useState(Nothing());
26 const [passphraseInput, { data: passphrase }] = usePassphraseInput({
28 label: 'Keystore password',
32 const constructWallet = () => {
34 const text = need.keystore(keystore);
36 const json = JSON.parse(text);
37 const privateKey = keythereum.recover(passphrase, json);
39 const newWallet = new EthereumWallet(privateKey);
41 setWallet(Just(newWallet));
44 "Couldn't decrypt wallet. You may have entered an incorrect password."
50 const handleKeystoreUpload = element => {
51 const file = element.files.item(0);
52 const reader = new FileReader();
54 reader.onload = e => {
55 const keystore = e.target.result;
56 setKeystore(Just(keystore));
59 const failure = _ => {
60 setError('There was a problem uploading your Keystore file');
63 reader.onerror = failure;
64 reader.onabort = failure;
66 reader.readAsText(file);
70 <Grid className={className}>
71 <Grid.Item full as={P}>
72 Please upload your Ethereum keystore file. If your keystore file is
73 encrypted with a password, you'll also need to enter that below.
76 <Grid.Item full as={UploadButton} onChange={handleKeystoreUpload}>
81 <Grid.Item full as={ErrorText} className="mt1">
86 <Grid.Item full as={Input} className="mt3" {...passphraseInput} />
93 disabled={Nothing.hasInstance(keystore)}
94 onClick={constructWallet}>
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list