1
- import { useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
2
1
import { AdenaWallet } from 'adena-module' ;
2
+ import { useCallback , useEffect , useMemo , useRef , useState } from 'react' ;
3
3
4
- import { RoutePath } from '@types' ;
5
4
import { PasswordValidationError } from '@common/errors' ;
5
+ import { evaluatePassword , EvaluatePasswordResult } from '@common/utils/password-utils' ;
6
6
import {
7
7
validateEmptyPassword ,
8
8
validateNotMatchConfirmPassword ,
@@ -13,7 +13,7 @@ import { useAdenaContext } from '@hooks/use-context';
13
13
import useIndicatorStep , {
14
14
UseIndicatorStepReturn ,
15
15
} from '@hooks/wallet/broadcast-transaction/use-indicator-step' ;
16
- import { evaluatePassword , EvaluatePasswordResult } from '@common/utils/password-utils ' ;
16
+ import { RoutePath } from '@types ' ;
17
17
18
18
export type UseCreatePasswordScreenReturn = {
19
19
passwordState : {
@@ -41,6 +41,7 @@ export type UseCreatePasswordScreenReturn = {
41
41
} ;
42
42
indicatorInfo : UseIndicatorStepReturn ;
43
43
onKeyDown : ( e : React . KeyboardEvent < HTMLInputElement > ) => void ;
44
+ clearPassword : ( ) => void ;
44
45
} ;
45
46
46
47
export const useCreatePasswordScreen = ( ) : UseCreatePasswordScreenReturn => {
@@ -126,11 +127,16 @@ export const useCreatePasswordScreen = (): UseCreatePasswordScreenReturn => {
126
127
return false ;
127
128
} ;
128
129
130
+ const clearPassword = ( ) : void => {
131
+ setInputs ( { password : '' , confirmPassword : '' } ) ;
132
+ } ;
133
+
129
134
const _saveWalletByPassword = async ( password : string ) : Promise < void > => {
130
135
const { serializedWallet } = params ;
131
136
const wallet = await AdenaWallet . deserialize ( serializedWallet , '' ) ;
132
137
await walletService . saveWallet ( wallet , password ) ;
133
138
await accountService . changeCurrentAccount ( wallet . currentAccount ) ;
139
+ await setInputs ( { password : '' , confirmPassword : '' } ) ;
134
140
} ;
135
141
136
142
const onChangePassword = useCallback (
@@ -157,14 +163,15 @@ export const useCreatePasswordScreen = (): UseCreatePasswordScreenReturn => {
157
163
} ;
158
164
159
165
const onKeyDownInput = useCallback (
160
- ( ) => ( e : React . KeyboardEvent < HTMLInputElement > ) : void => {
161
- if ( e . key === 'Enter' ) {
162
- if ( disabledCreateButton ) {
163
- return ;
166
+ ( ) =>
167
+ ( e : React . KeyboardEvent < HTMLInputElement > ) : void => {
168
+ if ( e . key === 'Enter' ) {
169
+ if ( disabledCreateButton ) {
170
+ return ;
171
+ }
172
+ onClickCreateButton ( ) ;
164
173
}
165
- onClickCreateButton ( ) ;
166
- }
167
- } ,
174
+ } ,
168
175
[ disabledCreateButton , onClickCreateButton ] ,
169
176
) ;
170
177
@@ -207,5 +214,6 @@ export const useCreatePasswordScreen = (): UseCreatePasswordScreenReturn => {
207
214
disabled : disabledCreateButton ,
208
215
} ,
209
216
onKeyDown : onKeyDownInput ,
217
+ clearPassword,
210
218
} ;
211
219
} ;
0 commit comments