1import { Just, Nothing } from 'folktale/maybe';
2import { Ok, Error } from 'folktale/result';
3import React, { useState } from 'react';
4import * as keythereum from 'keythereum';
5import { H3, Input } from 'indigo-react';
7import View from 'components/View';
8import { usePassphraseInput } from 'components/Inputs';
9import { ForwardButton } from 'components/Buttons';
10import { InputCaption, UploadButton, Warning } from 'components/old/Base';
12import { useWallet } from 'store/wallet';
14import * as need from 'lib/need';
15import { EthereumWallet, WALLET_TYPES } from 'lib/wallet';
16import useWalletType from 'lib/useWalletType';
18export default function Keystore({ loginCompleted }) {
19 useWalletType(WALLET_TYPES.KEYSTORE);
22 const { wallet, setWallet } = useWallet();
25 // keystore: Maybe<Result<String, String>>
26 const [keystore, setKeystore] = useState(Nothing());
27 const passphraseInput = usePassphraseInput({
29 label: 'Keystore password',
32 const passphrase = passphraseInput.data;
34 const [decryptionProblem, setDecryptionProblem] = useState(false);
36 const constructWallet = () => {
38 const text = need.keystore(keystore);
40 const json = JSON.parse(text);
41 const privateKey = keythereum.recover(passphrase, json);
43 const newWallet = new EthereumWallet(privateKey);
44 setDecryptionProblem(false);
45 setWallet(Just(newWallet));
47 setDecryptionProblem(true);
52 const handleKeystoreUpload = event => {
53 const file = event.files.item(0);
54 const reader = new FileReader();
56 reader.onload = e => {
57 const keystore = e.target.result;
58 setKeystore(Just(Ok(keystore)));
61 const failure = _ => {
62 const message = 'There was a problem uploading your Keystore file';
63 setKeystore(Just(Error(message)));
66 reader.onerror = failure;
67 reader.onabort = failure;
69 reader.readAsText(file);
72 const uploadButtonClass = keystore.matchWith({
73 Nothing: _ => 'bg-blue white',
76 Ok: _ => 'bg-green white',
77 Error: _ => 'bg-yellow black',
81 const decryptMessage =
82 decryptionProblem === false ? (
85 <Warning className="mt-8">
86 <H3 style={{ marginTop: 0, paddingTop: 0 }}>
87 Couldn't decrypt wallet.
89 You may have entered an incorrect password.
96 Please upload your Ethereum keystore file. If your keystore file is
97 encrypted with a password, you'll also need to enter that below.
101 className={`${uploadButtonClass} mt3`}
102 onChange={handleKeystoreUpload}>
103 <div className="flex-center-all fs-4 h-11 pointer">
108 <Input {...passphraseInput} />
112 disabled={Nothing.hasInstance(keystore)}
113 onClick={constructWallet}>
121 disabled={Nothing.hasInstance(wallet)}
122 onClick={loginCompleted}>
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