@@ -5,7 +5,6 @@ import Button from 'react-bootstrap/Button';
5
5
import Container from 'react-bootstrap/Container' ;
6
6
import Row from 'react-bootstrap/Row' ;
7
7
import typeof { setAccountFromMnemonic as SetAccountFromMnemonic } from '../actions/account' ;
8
- import { isValidMnemonic } from '../utils/mnemonic' ;
9
8
10
9
type Props = {
11
10
setAccountFromMnemonic : SetAccountFromMnemonic
@@ -18,46 +17,70 @@ export default ({ setAccountFromMnemonic }: Props) => {
18
17
event
19
18
) {
20
19
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 ) ] ) ;
25
22
}
26
- setIsMnemonicValid ( false ) ;
27
23
} ;
28
24
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 ) ;
30
46
31
- const [ newMnemonicPhrase , setNewMnemonicPhrase ] = useState ( '' ) ;
47
+ const [ password , setPassword ] = useState ( '' ) ;
32
48
33
- const [ newMnemonicPassword , setNewMnemonicPassword ] = useState ( '' ) ;
49
+ const [ confirmPassword , setConfirmPassword ] = useState ( '' ) ;
34
50
35
51
return (
36
52
< Container >
37
53
< Form onSubmit = { handleSubmitCreateSpending } className = "mt-5" >
38
54
< Form . Group >
39
- < Form . Label > Create your new wallet password: </ Form . Label >
55
+ < Form . Label > Create a password for your encrypted storage </ Form . Label >
40
56
< Form . Control
41
57
required
42
58
type = "password"
43
- id = "mnemonicPhrase "
44
- name = "mnemonicPhrase "
59
+ id = "password "
60
+ name = "password "
45
61
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 ) }
49
65
/>
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 >
52
68
</ Form . Label >
53
69
< Form . Control
54
70
type = "password"
55
- name = "mnemonicPassword"
71
+ name = "confirmPassword"
72
+ id = "confirmPassword"
56
73
placeholder = "Confirm password"
57
- value = { newMnemonicPassword }
58
- onChange = { event => setNewMnemonicPassword ( event . target . value ) }
74
+ value = { confirmPassword }
75
+ onChange = { event => setConfirmPassword ( event . target . value ) }
59
76
className = "mt-3"
60
77
/>
78
+ < Form . Label
79
+ className = "text-danger"
80
+ hidden = { arePasswordAndConfirmationEqual }
81
+ >
82
+ < code > password and confirmation must be the same.</ code >
83
+ </ Form . Label >
61
84
</ Form . Group >
62
85
< Row className = "justify-content-center" >
63
86
< Button variant = "primary" type = "submit" >
0 commit comments