on master help sign in
Add need.keystore
318dcadFang
src/bridge/lib/need.js+28−1
@@ -72,4 +72,31 @@ function fromPointCache(obj, point) {
72 })();
72 })();
73}
73}
74
74
75−export { web3, contracts, wallet, address, pointCursor, fromPointCache };
75+function keystore(obj) {
76+ return 'keystore' in obj === false
77+ ? (() => {
78+ throw BRIDGE_ERROR.MISSING_KEYSTORE;
79+ })()
80+ : obj.keystore.matchWith({
81+ Nothing: _ => {
82+ throw BRIDGE_ERROR.MISSING_KEYSTORE;
83+ },
84+ Just: ks =>
85+ ks.value.matchWith({
86+ Ok: result => result.value,
87+ Error: _ => {
88+ throw BRIDGE_ERROR.MISSING_KEYSTORE;
89+ },
90+ }),
91+ });
92+}
93+
94+export {
95+ web3,
96+ contracts,
97+ wallet,
98+ address,
99+ pointCursor,
100+ fromPointCache,
101+ keystore,
102+};
src/bridge/views/Login/Keystore.js+3−14
@@ -6,7 +6,7 @@ import { Button, UploadButton } from '../../components/Base';
6import { Input, InnerLabel, InputCaption } from '../../components/Base';
6import { Input, InnerLabel, InputCaption } from '../../components/Base';
7import { Row, Col, H1, H3, Warning } from '../../components/Base';
7import { Row, Col, H1, H3, Warning } from '../../components/Base';
8
8
9−import { BRIDGE_ERROR } from '../../lib/error';
9+import * as need from '../../lib/need';
10import { EthereumWallet } from '../../lib/wallet';
10import { EthereumWallet } from '../../lib/wallet';
11import { compose } from '../../lib/lib';
11import { compose } from '../../lib/lib';
12import { withWallet } from '../../store/wallet';
12import { withWallet } from '../../store/wallet';
@@ -32,21 +32,10 @@ class Keystore extends React.Component {
32
32
33 constructWallet() {
33 constructWallet() {
34 const { setWallet } = this.props;
34 const { setWallet } = this.props;
35− const { keystore, password } = this.state;
35+ const { password } = this.state;
36
36
37 try {
37 try {
38− const text = keystore.matchWith({
38+ const text = need.keystore(this.state);
39− Nothing: _ => {
40− throw BRIDGE_ERROR.MISSING_KEYSTORE;
41− },
42− Just: ks =>
43− ks.value.matchWith({
44− Ok: result => result.value,
45− Error: _ => {
46− throw BRIDGE_ERROR.MISSING_KEYSTORE;
47− },
48− }),
49− });
50
39
51 const json = JSON.parse(text);
40 const json = JSON.parse(text);
52 const privateKey = keythereum.recover(password, json);
41 const privateKey = keythereum.recover(password, json);