Skip to content

Commit 35d376f

Browse files
committed
Corrections by code review
1 parent b7cd72c commit 35d376f

File tree

8 files changed

+68
-64
lines changed

8 files changed

+68
-64
lines changed

examples/wallet/app/actions/account.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ import routes from '../constants/routes.json';
3939

4040
export type SetKeysAction = { type: 'SET_KEYS' } & AccountKeys;
4141
export const SET_KEYS = 'SET_KEYS';
42-
export const SET_VALID_UNLOCK_WALLET_PASSWORD =
43-
'SET_VALID_UNLOCK_WALLET_PASSWORD';
4442

4543
export function setAccount(
4644
privateKey: string,

examples/wallet/app/components/CreateUnlockWalletPassword.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
// @flow
22
import React, { useState } from 'react';
33
import Form from 'react-bootstrap/Form';
4+
import PropTypes from 'prop-types';
45

5-
// eslint-disable-next-line react/prop-types
6-
export default ({ setValidUnlockWalletPassword }) => {
6+
CreateUnlockWalletPassword.propTypes = {
7+
setValidCreateUnlockWalletPassword: PropTypes.func
8+
};
9+
export default function CreateUnlockWalletPassword({
10+
setValidCreateUnlockWalletPassword
11+
}) {
712
const checkValidUnlockWalletPassword = function checkValidUnlockWalletPassword(
813
pass
914
) {
@@ -33,7 +38,10 @@ export default ({ setValidUnlockWalletPassword }) => {
3338
isValidUnlockPassword = false;
3439
}
3540

36-
setValidUnlockWalletPassword(unlockWalletPassword, isValidUnlockPassword);
41+
setValidCreateUnlockWalletPassword(
42+
unlockWalletPassword,
43+
isValidUnlockPassword
44+
);
3745
return isValidUnlockPassword;
3846
};
3947

@@ -77,15 +85,13 @@ export default ({ setValidUnlockWalletPassword }) => {
7785
className="mt-3"
7886
/>
7987
<Form.Text>
80-
<span>
81-
This key allows you to unlock your wallet every time you start it
82-
and to keep your account data in a more secure way.
83-
</span>
88+
This key allows you to unlock your wallet every time you start it and
89+
to keep your account data in a more secure way.
8490
</Form.Text>
8591
<Form.Control.Feedback type="invalid">
8692
password and confirmation must be the same.
8793
</Form.Control.Feedback>
8894
</Form.Group>
8995
</Form.Group>
9096
);
91-
};
97+
}

examples/wallet/app/components/RestoreWalletFromMnemonic.js

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,10 @@ import { isValidMnemonic } from '../utils/mnemonic';
99
import CreateUnlockWalletPassword from '../containers/CreateUnlockWalletPassword';
1010

1111
type Props = {
12-
setAccountFromMnemonic: SetAccountFromMnemonic,
13-
unlockWalletPassword: string,
14-
isValidUnlockPassword: boolean
12+
setAccountFromMnemonic: SetAccountFromMnemonic
1513
};
1614

17-
export default ({
18-
setAccountFromMnemonic,
19-
unlockWalletPassword,
20-
isValidUnlockPassword
21-
}: Props) => {
15+
export default ({ setAccountFromMnemonic }: Props) => {
2216
const checkIsValidMnemonicPhrase = function checkIsValidMnemonicPhrase() {
2317
setIsMnemonicValid(isValidMnemonic(newMnemonicPhrase));
2418
};
@@ -38,6 +32,17 @@ export default ({
3832
setIsMnemonicValid(false);
3933
};
4034

35+
const setValidCreateUnlockWalletPassword = function setValidCreateUnlockWalletPassword(
36+
unlockPwd: string,
37+
isValid: boolean
38+
): void {
39+
setUnlockWalletPassword(unlockPwd);
40+
setIsValidUnlockPassword(isValid);
41+
};
42+
43+
const [unlockWalletPassword, setUnlockWalletPassword] = useState('');
44+
const [isValidUnlockPassword, setIsValidUnlockPassword] = useState(false);
45+
4146
const [isMnemonicValid, setIsMnemonicValid] = useState(true);
4247

4348
const [newMnemonicPhrase, setNewMnemonicPhrase] = useState('');
@@ -66,10 +71,8 @@ export default ({
6671
<Form.Text>
6772
Example:
6873
<br />
69-
<span>
70-
decade panther require cruise robust mail gadget advice tonight
71-
post inner snack
72-
</span>
74+
decade panther require cruise robust mail gadget advice tonight post
75+
inner snack
7376
</Form.Text>
7477
<Form.Control
7578
type="password"
@@ -80,12 +83,14 @@ export default ({
8083
className="mt-3"
8184
/>
8285
<Form.Text>
83-
<span>
84-
This secret password is part of the BIP39 standard to generate
85-
safer wallet seeds.
86-
</span>
86+
This secret password is part of the BIP39 standard to generate safer
87+
wallet seeds.
8788
</Form.Text>
88-
<CreateUnlockWalletPassword />
89+
<CreateUnlockWalletPassword
90+
setValidCreateUnlockWalletPassword={
91+
setValidCreateUnlockWalletPassword
92+
}
93+
/>
8994
</Form.Group>
9095
<Row className="justify-content-between">
9196
<Button variant="secondary" type="button">

examples/wallet/app/components/RestoreWalletFromPrivateKey.js

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,12 @@ import CreateUnlockWalletPassword from '../containers/CreateUnlockWalletPassword
99
import { getAccountFromPrivateKey } from '../utils/wasmWrapper';
1010

1111
type Props = {
12-
setAccount: SetAccount,
13-
unlockWalletPassword: string,
14-
isValidUnlockPassword: boolean
12+
setAccount: SetAccount
1513
};
1614

1715
// FIXME: this has no error handling, neither while parsing the address
1816
// nor when fetching the balance.
19-
export default ({
20-
setAccount,
21-
unlockWalletPassword,
22-
isValidUnlockPassword
23-
}: Props) => {
17+
export default ({ setAccount }: Props) => {
2418
const handleSubmit = function handleSubmit(event) {
2519
event.preventDefault();
2620
if (isValidUnlockPassword) {
@@ -40,6 +34,17 @@ export default ({
4034
});
4135
};
4236

37+
const setValidCreateUnlockWalletPassword = function setValidCreateUnlockWalletPassword(
38+
unlockPwd: string,
39+
isValid: boolean
40+
): void {
41+
setUnlockWalletPassword(unlockPwd);
42+
setIsValidUnlockPassword(isValid);
43+
};
44+
45+
const [unlockWalletPassword, setUnlockWalletPassword] = useState('');
46+
const [isValidUnlockPassword, setIsValidUnlockPassword] = useState(false);
47+
4348
const [newPrivateKey, setNewPrivateKey] = useState('');
4449
const [privateKeyErrorMessage, setPrivateKeyErrorMessage] = useState('');
4550

@@ -63,11 +68,13 @@ export default ({
6368
<Form.Text>
6469
It&apos;s a string like:
6570
<br />
66-
<span>
67-
ed25519e_sk15psr45hyqnpwcl8xd4lv0m32prenhh8kcltgte2305h5jgynndxect9274j0am0qmmd0snjuadnm6xkgssnkn2njvkg8et8qg0vevsgnwvmpl
68-
</span>
71+
ed25519e_sk15psr45hyqnpwcl8xd4lv0m32prenhh8kcltgte2305h5jgynndxect9274j0am0qmmd0snjuadnm6xkgssnkn2njvkg8et8qg0vevsgnwvmpl
6972
</Form.Text>
70-
<CreateUnlockWalletPassword />
73+
<CreateUnlockWalletPassword
74+
setValidCreateUnlockWalletPassword={
75+
setValidCreateUnlockWalletPassword
76+
}
77+
/>
7178
</Form.Group>
7279
<Row className="justify-content-center">
7380
<Button variant="primary" type="submit">
Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,5 @@
11
// @flow
22
import { connect } from 'react-redux';
33
import CreateUnlockWalletPassword from '../components/CreateUnlockWalletPassword';
4-
import { SET_VALID_UNLOCK_WALLET_PASSWORD } from '../actions/account';
54

6-
function mapDispatchToProps(dispatch) {
7-
return {
8-
setValidUnlockWalletPassword: (
9-
unlockWalletPassword: string,
10-
isValidUnlockPassword: boolean
11-
) =>
12-
dispatch({
13-
type: SET_VALID_UNLOCK_WALLET_PASSWORD,
14-
unlockWalletPassword,
15-
isValidUnlockPassword
16-
})
17-
};
18-
}
19-
20-
export default connect(
21-
undefined,
22-
mapDispatchToProps
23-
)(CreateUnlockWalletPassword);
5+
export default connect(undefined, undefined)(CreateUnlockWalletPassword);

examples/wallet/app/reducers/account.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// @flow
22
import sortBy from 'lodash/sortBy';
33
import {
4-
SET_VALID_UNLOCK_WALLET_PASSWORD,
54
SET_KEYS,
65
SET_ACCOUNT_STATE,
76
SEND_TRANSACTION,
@@ -32,11 +31,6 @@ export default function account(
3231
return { transactions: [] };
3332
}
3433
switch (action.type) {
35-
case SET_VALID_UNLOCK_WALLET_PASSWORD:
36-
return Object.assign({}, state, {
37-
unlockWalletPassword: action.unlockWalletPassword,
38-
isValidUnlockPassword: action.isValidUnlockPassword
39-
});
4034
case SET_KEYS:
4135
return {
4236
...state,

examples/wallet/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,10 @@
262262
"@forevolve/bootstrap-dark": "1.0.0-alpha.863",
263263
"@fortawesome/fontawesome-free": "5.12.0",
264264
"@hot-loader/react-dom": "16.11.0",
265+
"aes-js": "3.1.2",
265266
"axios": "0.19.0",
266267
"bip39": "3.0.2",
268+
"blakejs": "1.1.0",
267269
"bootstrap": "4.4.1",
268270
"classnames": "2.2.6",
269271
"clickable-box": "1.1.0",

examples/wallet/yarn.lock

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,11 @@ address@^1.0.1:
18121812
resolved "https://registry.yarnpkg.com/address/-/address-1.1.2.tgz#bf1116c9c758c51b7a933d296b72c221ed9428b6"
18131813
integrity sha512-aT6camzM4xEA54YVJYSqxz1kv4IHnQZRtThJJHhUMRExaU5spC7jX5ugSwTaTgJliIgs4VhZOk7htClvQ/LmRA==
18141814

1815+
aes-js@^3.1.2:
1816+
version "3.1.2"
1817+
resolved "https://registry.yarnpkg.com/aes-js/-/aes-js-3.1.2.tgz#db9aabde85d5caabbfc0d4f2a4446960f627146a"
1818+
integrity sha512-e5pEa2kBnBOgR4Y/p20pskXI74UEz7de8ZGVo58asOtvSVG5YAbJeELPZxOmt+Bnz3rX753YKhfIn4X4l1PPRQ==
1819+
18151820
aggregate-error@^3.0.0:
18161821
version "3.0.1"
18171822
resolved "https://registry.yarnpkg.com/aggregate-error/-/aggregate-error-3.0.1.tgz#db2fe7246e536f40d9b5442a39e117d7dd6a24e0"
@@ -3253,6 +3258,11 @@ bl@^1.0.0:
32533258
readable-stream "^2.3.5"
32543259
safe-buffer "^5.1.1"
32553260

3261+
blakejs@^1.1.0:
3262+
version "1.1.0"
3263+
resolved "https://registry.yarnpkg.com/blakejs/-/blakejs-1.1.0.tgz#69df92ef953aa88ca51a32df6ab1c54a155fc7a5"
3264+
integrity sha1-ad+S75U6qIylGjLfarHFShVfx6U=
3265+
32563266
block-stream@*:
32573267
version "0.0.9"
32583268
resolved "https://registry.yarnpkg.com/block-stream/-/block-stream-0.0.9.tgz#13ebfe778a03205cfe03751481ebb4b3300c126a"

0 commit comments

Comments
 (0)