@@ -17,11 +17,22 @@ export default ({ setAccount }: Props) => {
17
17
event
18
18
) {
19
19
event . preventDefault ( ) ;
20
- if ( checkValidPassword ( password , confirmPassword ) ) {
21
- setAccount ( newPrivateKey , password ) ;
20
+ if ( mustCreateSpendingPassword ) {
21
+ if ( checkValidPassword ( password , confirmPassword ) ) {
22
+ setAccount ( newPrivateKey , password ) ;
23
+ }
24
+ } else {
25
+ setAccount ( newPrivateKey , '' ) ;
22
26
}
23
27
} ;
24
28
29
+ const handleCheckCreateSpendingPassword = function handleCheckCreateSpendingPassword (
30
+ evt
31
+ ) {
32
+ setMustCreateSpendingPassword ( evt . target . checked ) ;
33
+ setHiddenSpendingPassword ( ! evt . target . checked ) ;
34
+ } ;
35
+
25
36
const checkValidPassword = function checkValidPassword ( pass , confirmation ) {
26
37
if ( ! pass && ! confirmation ) return true ;
27
38
if ( pass . length < 8 ) {
@@ -40,6 +51,10 @@ export default ({ setAccount }: Props) => {
40
51
41
52
const [ isValidPassword , setIsValidPassword ] = useState ( true ) ;
42
53
const [ newPrivateKey , setNewPrivateKey ] = useState ( '' ) ;
54
+ const [ mustCreateSpendingPassword , setMustCreateSpendingPassword ] = useState (
55
+ true
56
+ ) ;
57
+ const [ hiddenSpendingPassword , setHiddenSpendingPassword ] = useState ( false ) ;
43
58
44
59
const [
45
60
arePasswordAndConfirmationEqual ,
@@ -69,37 +84,46 @@ export default ({ setAccount }: Props) => {
69
84
ed25519e_sk15psr45hyqnpwcl8xd4lv0m32prenhh8kcltgte2305h5jgynndxect9274j0am0qmmd0snjuadnm6xkgssnkn2njvkg8et8qg0vevsgnwvmpl
70
85
</ code >
71
86
</ Form . Text >
72
- < Form . Label >
73
- Create a password to store your settings securely in an encrypted
74
- storage
75
- </ Form . Label >
76
- < Form . Control
77
- type = "password"
78
- id = "password"
79
- name = "password"
80
- placeholder = "New password (min 8 chars)"
81
- value = { password }
82
- isInvalid = { ! isValidPassword }
83
- onChange = { event => setPassword ( event . target . value ) }
84
- />
85
- < Form . Label className = "text-danger" hidden = { isValidPassword } >
86
- < code > The password must have at least 8 chars.</ code >
87
- </ Form . Label >
88
- < Form . Control
89
- type = "password"
90
- name = "confirmPassword"
91
- id = "confirmPassword"
92
- placeholder = "Confirm password"
93
- value = { confirmPassword }
94
- onChange = { event => setConfirmPassword ( event . target . value ) }
95
- className = "mt-3"
96
- />
97
- < Form . Label
98
- className = "text-danger"
99
- hidden = { arePasswordAndConfirmationEqual }
87
+ < Form . Group
88
+ controlId = "formCreateSpendingPasswordCheck"
89
+ className = "mt-4"
100
90
>
101
- < code > Password and confirmation must be the same.</ code >
102
- </ Form . Label >
91
+ < Form . Check
92
+ type = "switch"
93
+ label = "Create a password to store your settings securely in an encrypted
94
+ storage"
95
+ onChange = { event => handleCheckCreateSpendingPassword ( event ) }
96
+ />
97
+ </ Form . Group >
98
+ < Form . Group hidden = { hiddenSpendingPassword } >
99
+ < Form . Control
100
+ type = "password"
101
+ id = "password"
102
+ name = "password"
103
+ placeholder = "New password (min 8 chars)"
104
+ value = { password }
105
+ isInvalid = { ! isValidPassword }
106
+ onChange = { event => setPassword ( event . target . value ) }
107
+ />
108
+ < Form . Label className = "text-danger" hidden = { isValidPassword } >
109
+ < code > The password must have at least 8 chars.</ code >
110
+ </ Form . Label >
111
+ < Form . Control
112
+ type = "password"
113
+ name = "confirmPassword"
114
+ id = "confirmPassword"
115
+ placeholder = "Confirm password"
116
+ value = { confirmPassword }
117
+ onChange = { event => setConfirmPassword ( event . target . value ) }
118
+ className = "mt-3"
119
+ />
120
+ < Form . Label
121
+ className = "text-danger"
122
+ hidden = { arePasswordAndConfirmationEqual }
123
+ >
124
+ < code > Password and confirmation must be the same.</ code >
125
+ </ Form . Label >
126
+ </ Form . Group >
103
127
</ Form . Group >
104
128
< Row className = "justify-content-center" >
105
129
< Button variant = "primary" type = "submit" >
0 commit comments