Skip to content

Commit 2333f15

Browse files
dmerniestic1987dmernies-iohk
authored andcommitted
Corrections by code review
1 parent 85eb7e7 commit 2333f15

File tree

15 files changed

+66
-147
lines changed

15 files changed

+66
-147
lines changed

examples/explorer/.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
},
1616
"rules": {
1717
"func-names": "error",
18-
"new-cap": "off",
18+
"new-cap": ["off", { "capIsNewExceptionPattern": "^Aesjs\.." }],
1919
"arrow-parens": "off",
2020
"consistent-return": "off",
2121
"comma-dangle": "off",

examples/wallet/app/Routes.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Settings from './pages/Settings';
99
import ChooseRestoreOrImport from './containers/ChooseRestoreOrImport';
1010
import Delegate from './pages/Delegate';
1111
import Index from './containers/Index';
12-
import InputKeys from './containers/InputKeys';
12+
import InputKeys from './pages/InputKeys';
1313
import UnlockWallet from './containers/UnlockWallet';
1414

1515
export default () => (

examples/wallet/app/actions/account.js

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import {
3232
} from '../utils/nodeConnection';
3333
import { isValidMnemonic, createSeedFromMnemonic } from '../utils/mnemonic';
3434
import {
35-
saveAccountInfoInDEN,
35+
saveEncryptedAccountInfo,
3636
saveSpendingPassword,
3737
readAccountKeysFromDEN
3838
} from '../utils/storage';
@@ -84,27 +84,22 @@ export function setAccountFromPrivateKey(
8484
privateKey: string
8585
): Thunk<SetKeysAction> {
8686
return function setAccountFromPrivateKeyThunk(dispatch) {
87-
return getAccountFromPrivateKey(privateKey)
88-
.then(loadedPrivateKey => {
89-
dispatch({
90-
type: SET_KEYS,
91-
...loadedPrivateKey
92-
});
93-
return Promise.all([
94-
dispatch(updateAccountTransactions()),
95-
dispatch(updateNodeSettings()),
96-
dispatch(updateAccountState())
97-
])
98-
.then(() => dispatch(push(routes.WALLET)))
99-
.catch(error => {
100-
console.log(error);
101-
dispatch(push(routes.INPUT_KEYS));
102-
});
103-
})
104-
.catch(error => {
105-
// TODO: SHOW A MESSAGE SHOWING ERROR
106-
console.log(error);
87+
return getAccountFromPrivateKey(privateKey).then(loadedPrivateKey => {
88+
dispatch({
89+
type: SET_KEYS,
90+
...loadedPrivateKey
10791
});
92+
return Promise.all([
93+
dispatch(updateAccountTransactions()),
94+
dispatch(updateNodeSettings()),
95+
dispatch(updateAccountState())
96+
])
97+
.then(() => dispatch(push(routes.WALLET)))
98+
.catch(error => {
99+
console.log(error);
100+
dispatch(push(routes.INPUT_KEYS));
101+
});
102+
});
108103
};
109104
}
110105

@@ -127,7 +122,7 @@ const initializeKeysAndRedirect = (
127122
});
128123

129124
saveSpendingPassword(spendingPassword);
130-
saveAccountInfoInDEN(spendingPassword, keys);
125+
saveEncryptedAccountInfo(spendingPassword, keys);
131126

132127
return Promise.all([
133128
dispatch(updateAccountTransactions()),

examples/wallet/app/components/RestoreWalletFromMnemonic.js

Lines changed: 20 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -11,50 +11,27 @@ type Props = {
1111
setAccountFromMnemonic: SetAccountFromMnemonic
1212
};
1313

14-
// FIXME: this has no error handling, neither while parsing the address
15-
// nor when fetching the balance.
1614
export default ({ setAccountFromMnemonic }: Props) => {
1715
const checkIsValidMnemonicPhrase = function checkIsValidMnemonicPhrase() {
1816
setIsMnemonicValid(isValidMnemonic(newMnemonicPhrase));
1917
};
2018

2119
const handleSubmitMnemonic = function handleSubmitMnemonic(event) {
2220
event.preventDefault();
23-
if (mustCreateSpendingPassword) {
24-
if (
25-
isValidMnemonic(newMnemonicPhrase) &&
26-
checkValidSpendingPassword(password, confirmPassword)
27-
) {
28-
return Promise.all([
29-
setAccountFromMnemonic(
30-
newMnemonicPhrase,
31-
newMnemonicPassword,
32-
password
33-
)
34-
]);
35-
}
36-
}
3721
if (isValidMnemonic(newMnemonicPhrase)) {
38-
return Promise.all([
39-
setAccountFromMnemonic(newMnemonicPhrase, newMnemonicPassword, '')
40-
]);
22+
if (checkValidSpendingPassword(password, confirmPassword)) {
23+
return setAccountFromMnemonic(
24+
newMnemonicPhrase,
25+
newMnemonicPassword,
26+
password
27+
);
28+
}
29+
} else {
30+
setIsMnemonicValid(false);
4131
}
42-
43-
setIsMnemonicValid(false);
44-
};
45-
46-
const handleCheckCreateSpendingPassword = function handleCheckCreateSpendingPassword(
47-
evt
48-
) {
49-
setMustCreateSpendingPassword(evt.target.checked);
50-
setHiddenSpendingPassword(!evt.target.checked);
5132
};
5233

5334
const [isMnemonicValid, setIsMnemonicValid] = useState(true);
54-
const [hiddenSpendingPassword, setHiddenSpendingPassword] = useState(false);
55-
const [mustCreateSpendingPassword, setMustCreateSpendingPassword] = useState(
56-
true
57-
);
5835

5936
const [newMnemonicPhrase, setNewMnemonicPhrase] = useState('');
6037

@@ -118,21 +95,17 @@ export default ({ setAccountFromMnemonic }: Props) => {
11895
<Form.Control
11996
type="password"
12097
name="mnemonicPassword"
121-
placeholder="Secret password"
98+
placeholder="Secret password of wallet seed"
12299
value={newMnemonicPassword}
123100
onChange={event => setNewMnemonicPassword(event.target.value)}
124101
className="mt-3"
125102
/>
126-
<Form.Group controlId="formCreateSpendingPassword" className="mt-4">
127-
<Form.Check
128-
type="switch"
129-
label="Create a password to store your settings securely in an encrypted
130-
storage"
131-
onChange={event => handleCheckCreateSpendingPassword(event)}
132-
checked={mustCreateSpendingPassword}
133-
/>
134-
</Form.Group>
135-
<Form.Group hidden={hiddenSpendingPassword}>
103+
<Form.Text>
104+
This secret password is part of the BIP39 standard to generate safer
105+
wallet seeds.
106+
</Form.Text>
107+
<Form.Label className="mt-5">Unlock wallet (optional):</Form.Label>
108+
<Form.Group>
136109
<Form.Control
137110
type="password"
138111
id="password"
@@ -154,6 +127,10 @@ export default ({ setAccountFromMnemonic }: Props) => {
154127
onChange={event => setConfirmPassword(event.target.value)}
155128
className="mt-3"
156129
/>
130+
<Form.Text>
131+
This key allows you to unlock your wallet every time you start it
132+
and to keep your account data in a more secure way.
133+
</Form.Text>
157134
<Form.Label
158135
className="text-danger"
159136
hidden={arePasswordAndConfirmationEqual}

examples/wallet/app/components/RestoreWalletFromPrivateKey.js

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,13 @@ type Props = {
1313
// FIXME: this has no error handling, neither while parsing the address
1414
// nor when fetching the balance.
1515
export default ({ setAccount }: Props) => {
16-
const handleSubmitCreateSpending = function handleSubmitCreateSpending(
17-
event
18-
) {
16+
const handleSubmit = function handleSubmit(event) {
1917
event.preventDefault();
20-
if (mustCreateSpendingPassword) {
21-
if (checkValidSpendingPassword(password, confirmPassword)) {
22-
setAccount(newPrivateKey, password);
23-
}
24-
} else {
25-
setAccount(newPrivateKey, '');
18+
if (checkValidSpendingPassword(password, confirmPassword)) {
19+
setAccount(newPrivateKey, password);
2620
}
2721
};
2822

29-
const handleCheckCreateSpendingPassword = function handleCheckCreateSpendingPassword(
30-
evt
31-
) {
32-
setMustCreateSpendingPassword(evt.target.checked);
33-
setHiddenSpendingPassword(!evt.target.checked);
34-
};
35-
3623
const checkValidSpendingPassword = function checkValidSpendingPassword(
3724
pass,
3825
confirmation
@@ -54,10 +41,6 @@ export default ({ setAccount }: Props) => {
5441

5542
const [isValidPassword, setIsValidPassword] = useState(true);
5643
const [newPrivateKey, setNewPrivateKey] = useState('');
57-
const [mustCreateSpendingPassword, setMustCreateSpendingPassword] = useState(
58-
true
59-
);
60-
const [hiddenSpendingPassword, setHiddenSpendingPassword] = useState(false);
6144

6245
const [
6346
arePasswordAndConfirmationEqual,
@@ -70,7 +53,7 @@ export default ({ setAccount }: Props) => {
7053

7154
return (
7255
<Container>
73-
<Form onSubmit={handleSubmitCreateSpending} className="mt-5">
56+
<Form onSubmit={handleSubmit} className="mt-5">
7457
<Form.Group>
7558
<Form.Label>Private key:</Form.Label>
7659
<Form.Control
@@ -87,19 +70,7 @@ export default ({ setAccount }: Props) => {
8770
ed25519e_sk15psr45hyqnpwcl8xd4lv0m32prenhh8kcltgte2305h5jgynndxect9274j0am0qmmd0snjuadnm6xkgssnkn2njvkg8et8qg0vevsgnwvmpl
8871
</code>
8972
</Form.Text>
90-
<Form.Group
91-
controlId="formCreateSpendingPasswordCheck"
92-
className="mt-4"
93-
>
94-
<Form.Check
95-
type="switch"
96-
label="Create a password to store your settings securely in an encrypted
97-
storage"
98-
checked={mustCreateSpendingPassword}
99-
onChange={event => handleCheckCreateSpendingPassword(event)}
100-
/>
101-
</Form.Group>
102-
<Form.Group hidden={hiddenSpendingPassword}>
73+
<Form.Group>
10374
<Form.Control
10475
type="password"
10576
id="password"

examples/wallet/app/containers/InputKeys.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

examples/wallet/app/containers/RestoreWalletFromMnemonic.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
import { bindActionCreators } from 'redux';
33
import { connect } from 'react-redux';
44
import RestoreWalletFromMnemonic from '../components/RestoreWalletFromMnemonic';
5-
import { setAccount } from '../actions/account';
5+
import { setAccountFromMnemonic } from '../actions/account';
66

77
function mapDispatchToProps(dispatch) {
8-
return bindActionCreators({ setAccount }, dispatch);
8+
return bindActionCreators({ setAccountFromMnemonic }, dispatch);
99
}
1010

1111
export default connect(

examples/wallet/app/pages/InputKeys.js

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,31 +2,17 @@
22
import React from 'react';
33
import Tabs from 'react-bootstrap/Tabs';
44
import Tab from 'react-bootstrap/Tab';
5-
import RestoreWalletFromPrivateKey from '../components/RestoreWalletFromPrivateKey';
6-
import RestoreWalletFromMnemonic from '../components/RestoreWalletFromMnemonic';
5+
import RestoreWalletFromPrivateKey from '../containers/RestoreWalletFromPrivateKey';
6+
import RestoreWalletFromMnemonic from '../containers/RestoreWalletFromMnemonic';
77

8-
import typeof {
9-
setAccountFromMnemonic as SetAccountFromMnemonic,
10-
setAccount as SetAccount
11-
} from '../actions/account';
12-
13-
type Props = {
14-
setAccountFromMnemonic: SetAccountFromMnemonic,
15-
setAccount: SetAccount
16-
};
17-
18-
// FIXME: this has no error handling, neither while parsing the address
19-
// nor when fetching the balance.
20-
export default ({ setAccountFromMnemonic, setAccount }: Props) => {
8+
export default () => {
219
return (
2210
<Tabs fill defaultActiveKey="keyString" className="justify-content-center">
2311
<Tab eventKey="keyString" title="Use key string">
24-
<RestoreWalletFromPrivateKey setAccount={setAccount} />
12+
<RestoreWalletFromPrivateKey />
2513
</Tab>
2614
<Tab eventKey="mnemonic" title="Use mnemonic phrase">
27-
<RestoreWalletFromMnemonic
28-
setAccountFromMnemonic={setAccountFromMnemonic}
29-
/>
15+
<RestoreWalletFromMnemonic />
3016
</Tab>
3117
</Tabs>
3218
);

examples/wallet/app/pages/UnlockWallet.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Form from 'react-bootstrap/Form';
44
import Button from 'react-bootstrap/Button';
55
import Container from 'react-bootstrap/Container';
66
import Row from 'react-bootstrap/Row';
7+
import styles from './UnlockWallet.scss';
78
import { isValidSpendingPassword } from '../utils/storage';
89
import typeof { setKeysWithSpendingPassword as SetKeysWithSpendingPassword } from '../actions/account';
910

@@ -17,7 +18,7 @@ export default ({ setKeysWithSpendingPassword }: Props) => {
1718
if (isValidSpendingPassword(spendingPassword)) {
1819
setIsWrongSpendingPassword(false);
1920
setHiddenSpendingPassword(true);
20-
return Promise.all([setKeysWithSpendingPassword(spendingPassword)]);
21+
return setKeysWithSpendingPassword(spendingPassword);
2122
}
2223
setIsWrongSpendingPassword(true);
2324
setHiddenSpendingPassword(false);
@@ -28,11 +29,11 @@ export default ({ setKeysWithSpendingPassword }: Props) => {
2829
const [hiddenSpendingPassword, setHiddenSpendingPassword] = useState(true);
2930

3031
return (
31-
<Container>
32+
<Container className={styles.container}>
3233
<Form onSubmit={handleSubmit} className="mt-5">
3334
<Form.Group>
3435
<Form.Label>
35-
Wellcome! Please insert you password to unlock wallet
36+
Welcome! Please insert you password to unlock wallet
3637
</Form.Label>
3738
<Form.Control
3839
type="password"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.container {
2+
vertical-align: middle;
3+
padding-top: 20%;
4+
}

0 commit comments

Comments
 (0)