on master help sign in
Add need.keystore
commit318dcaddb25fe9f5359863ec27fe89f1ff464a6a authorFang <git@fang.io> dateThu 20 Jun 2019, 22:48 (7 years ago) parent8f263ec
2 files changed+31−15
src/bridge/lib/need.js+28−1 src/bridge/views/Login/Keystore.js+3−14
src/bridge/lib/need.js+28−1
@@ -72,4 +72,31 @@ function fromPointCache(obj, point) {
7272 })();
7373}
7474
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';
66import { Input, InnerLabel, InputCaption } from '../../components/Base';
77import { Row, Col, H1, H3, Warning } from '../../components/Base';
88
9−import { BRIDGE_ERROR } from '../../lib/error';
9+import * as need from '../../lib/need';
1010import { EthereumWallet } from '../../lib/wallet';
1111import { compose } from '../../lib/lib';
1212import { withWallet } from '../../store/wallet';
@@ -32,21 +32,10 @@ class Keystore extends React.Component {
3232
3333 constructWallet() {
3434 const { setWallet } = this.props;
35− const { keystore, password } = this.state;
35+ const { password } = this.state;
3636
3737 try {
38− const text = keystore.matchWith({
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− });
38+ const text = need.keystore(this.state);
5039
5140 const json = JSON.parse(text);
5241 const privateKey = keythereum.recover(password, json);