Skip to content

Commit 80a468d

Browse files
committed
Create spending password screen is added and displayed when password does not exists.
1 parent a9fba84 commit 80a468d

File tree

1 file changed

+43
-20
lines changed

1 file changed

+43
-20
lines changed

examples/wallet/app/pages/CreateSpendingPassword.js

Lines changed: 43 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import Button from 'react-bootstrap/Button';
55
import Container from 'react-bootstrap/Container';
66
import Row from 'react-bootstrap/Row';
77
import typeof { setAccountFromMnemonic as SetAccountFromMnemonic } from '../actions/account';
8-
import { isValidMnemonic } from '../utils/mnemonic';
98

109
type Props = {
1110
setAccountFromMnemonic: SetAccountFromMnemonic
@@ -18,46 +17,70 @@ export default ({ setAccountFromMnemonic }: Props) => {
1817
event
1918
) {
2019
event.preventDefault();
21-
if (isValidMnemonic(newMnemonicPhrase)) {
22-
return Promise.all([
23-
setAccountFromMnemonic(newMnemonicPhrase, newMnemonicPassword)
24-
]);
20+
if (checkValidPassword(password, confirmPassword)) {
21+
return Promise.all([setAccountFromMnemonic(password, confirmPassword)]);
2522
}
26-
setIsMnemonicValid(false);
2723
};
2824

29-
const [isMnemonicValid, setIsMnemonicValid] = useState(true);
25+
const checkValidPassword = function checkValidPassword(pass, confirmation) {
26+
if (!pass) return false;
27+
if (pass.length < 8) {
28+
setIsValidPassword(false);
29+
return false;
30+
}
31+
setIsValidPassword(true);
32+
33+
if (pass !== confirmation) {
34+
setArePasswordAndConfirmationEqual(false);
35+
return false;
36+
}
37+
setArePasswordAndConfirmationEqual(true);
38+
return true;
39+
};
40+
41+
const [isValidPassword, setIsValidPassword] = useState(true);
42+
const [
43+
arePasswordAndConfirmationEqual,
44+
setArePasswordAndConfirmationEqual
45+
] = useState(true);
3046

31-
const [newMnemonicPhrase, setNewMnemonicPhrase] = useState('');
47+
const [password, setPassword] = useState('');
3248

33-
const [newMnemonicPassword, setNewMnemonicPassword] = useState('');
49+
const [confirmPassword, setConfirmPassword] = useState('');
3450

3551
return (
3652
<Container>
3753
<Form onSubmit={handleSubmitCreateSpending} className="mt-5">
3854
<Form.Group>
39-
<Form.Label>Create your new wallet password:</Form.Label>
55+
<Form.Label>Create a password for your encrypted storage</Form.Label>
4056
<Form.Control
4157
required
4258
type="password"
43-
id="mnemonicPhrase"
44-
name="mnemonicPhrase"
59+
id="password"
60+
name="password"
4561
placeholder="New password (min 8 chars)"
46-
value={newMnemonicPhrase}
47-
isInvalid={!isMnemonicValid}
48-
onChange={event => setNewMnemonicPhrase(event.target.value)}
62+
value={password}
63+
isInvalid={!isValidPassword}
64+
onChange={event => setPassword(event.target.value)}
4965
/>
50-
<Form.Label className="text-danger" hidden={isMnemonicValid}>
51-
<code>You should not share your password with others.</code>
66+
<Form.Label className="text-danger" hidden={isValidPassword}>
67+
<code>The password must have at least 8 chars.</code>
5268
</Form.Label>
5369
<Form.Control
5470
type="password"
55-
name="mnemonicPassword"
71+
name="confirmPassword"
72+
id="confirmPassword"
5673
placeholder="Confirm password"
57-
value={newMnemonicPassword}
58-
onChange={event => setNewMnemonicPassword(event.target.value)}
74+
value={confirmPassword}
75+
onChange={event => setConfirmPassword(event.target.value)}
5976
className="mt-3"
6077
/>
78+
<Form.Label
79+
className="text-danger"
80+
hidden={arePasswordAndConfirmationEqual}
81+
>
82+
<code>password and confirmation must be the same.</code>
83+
</Form.Label>
6184
</Form.Group>
6285
<Row className="justify-content-center">
6386
<Button variant="primary" type="submit">

0 commit comments

Comments
 (0)