1- import React , { useCallback , useMemo , useState } from 'react' ;
1+ import React , { useCallback , useEffect , useMemo , useState } from 'react' ;
22
33import { useForm } from 'react-hook-form' ;
44import { useTranslation } from 'react-i18next' ;
@@ -58,6 +58,22 @@ const EncryptedWalletFileWalletPassword: React.FC<EncryptedWalletFileWalletPassw
5858 const onPasswordVisibilityToggle = useCallback ( ( ) => {
5959 setIsPasswordVisible ( prev => ! prev ) ;
6060 } , [ ] ) ;
61+ const [ loading , setLoading ] = useState ( true ) ;
62+ const [ showPassword , setShowPassword ] = useState ( false ) ;
63+
64+ useEffect ( ( ) => {
65+ const checkIfPasswordShouldBeShown = async ( ) => {
66+ try {
67+ const { Vault } = await import ( 'lib/miden/back/vault' ) ;
68+ setShowPassword ( await Vault . hasPasswordProtector ( ) ) ;
69+ } catch ( e ) {
70+ console . error ( 'Error checking vault password protector:' , e ) ;
71+ } finally {
72+ setLoading ( false ) ;
73+ }
74+ } ;
75+ checkIfPasswordShouldBeShown ( ) ;
76+ } , [ ] ) ;
6177
6278 const [ timeleft , setTimeleft ] = useState ( getTimeLeft ( timelock , lockLevel ) ) ;
6379
@@ -69,7 +85,7 @@ const EncryptedWalletFileWalletPassword: React.FC<EncryptedWalletFileWalletPassw
6985 clearErrors ( 'password' ) ;
7086 try {
7187 if ( attempt > LAST_ATTEMPT ) await new Promise ( res => setTimeout ( res , Math . random ( ) * 2000 + 1000 ) ) ;
72- await unlock ( walletPassword ! ) ;
88+ await unlock ( walletPassword ) ;
7389
7490 setAttempt ( 1 ) ;
7591 onGoNext ( ) ;
@@ -100,49 +116,59 @@ const EncryptedWalletFileWalletPassword: React.FC<EncryptedWalletFileWalletPassw
100116 < div className = "flex-1 flex flex-col" >
101117 < NavigationHeader title = { t ( 'encryptedWalletFile' ) } onBack = { goBack } mode = "back" />
102118 < div className = "flex flex-col flex-1 p-4 md:w-[460px] md:mx-auto" >
103- < div className = "flex-1 flex flex-col justify-stretch gap-y-4" >
104- < p className = "text-sm" > { t ( 'encryptedWalletFileDescription' ) } </ p >
105- < div className = "flex flex-col gap-y-2" >
106- < Input
107- type = { isPasswordVisible ? 'text' : 'password' }
108- label = { t ( 'password' ) }
109- value = { walletPassword }
110- disabled = { isDisabled }
111- placeholder = { t ( 'enterPassword' ) }
112- icon = {
113- < button className = "flex-1" onClick = { onPasswordVisibilityToggle } >
114- < Icon name = { isPasswordVisible ? IconName . EyeOff : IconName . Eye } fill = "black" />
115- </ button >
116- }
117- onChange = { onPasswordChange }
118- onKeyDown = { handleEnterKey }
119- autoFocus
120- />
121- { errors . password && < p className = "h-4 text-red-500 text-xs" > { errors . password . message } </ p > }
119+ { loading ? (
120+ < div className = "flex-1 flex items-center justify-center" >
121+ < div className = "animate-spin rounded-full h-8 w-8 border-b-2 border-gray-900" > </ div >
122122 </ div >
123- < div className = "flex gap-x-2 text-sm text-left" >
124- < button className = "flex mt-3 gap-x-2 text-left" onClick = { ( ) => setConfirmed ( ! confirmed ) } >
125- < Checkbox id = "help-us" value = { confirmed } />
126- < span className = "text-black cursor-pointer text-left mt-[-4px]" >
127- { t ( 'encryptedWalletFileConfirmation' ) }
128- </ span >
129- </ button >
123+ ) : (
124+ < div className = "flex-1 flex flex-col justify-stretch gap-y-4" >
125+ < p className = "text-sm" > { t ( 'encryptedWalletFileDescription' ) } </ p >
126+ < div className = "flex flex-col gap-y-2" >
127+ { showPassword && (
128+ < >
129+ < Input
130+ type = { isPasswordVisible ? 'text' : 'password' }
131+ label = { t ( 'password' ) }
132+ value = { walletPassword }
133+ disabled = { isDisabled }
134+ placeholder = { t ( 'enterPassword' ) }
135+ icon = {
136+ < button className = "flex-1" onClick = { onPasswordVisibilityToggle } >
137+ < Icon name = { isPasswordVisible ? IconName . EyeOff : IconName . Eye } fill = "black" />
138+ </ button >
139+ }
140+ onChange = { onPasswordChange }
141+ onKeyDown = { handleEnterKey }
142+ autoFocus
143+ />
144+ { errors . password && < p className = "h-4 text-red-500 text-xs" > { errors . password . message } </ p > }
145+ </ >
146+ ) }
147+ </ div >
148+ < div className = "flex gap-x-2 text-sm text-left" >
149+ < button className = "flex mt-3 gap-x-2 text-left" onClick = { ( ) => setConfirmed ( ! confirmed ) } >
150+ < Checkbox id = "help-us" value = { confirmed } />
151+ < span className = "text-black cursor-pointer text-left mt-[-4px]" >
152+ { t ( 'encryptedWalletFileConfirmation' ) }
153+ </ span >
154+ </ button >
155+ </ div >
156+ { isDisabled && (
157+ < Alert
158+ type = "error"
159+ title = { t ( 'error' ) }
160+ description = { `${ t ( 'unlockPasswordErrorDelay' ) } ${ timeleft } ` }
161+ className = "mt-8 rounded-lg text-black mx-auto"
162+ style = { { width : '80%' } }
163+ />
164+ ) }
130165 </ div >
131- { isDisabled && (
132- < Alert
133- type = "error"
134- title = { t ( 'error' ) }
135- description = { `${ t ( 'unlockPasswordErrorDelay' ) } ${ timeleft } ` }
136- className = "mt-8 rounded-lg text-black mx-auto"
137- style = { { width : '80%' } }
138- />
139- ) }
140- </ div >
166+ ) }
141167 < Button
142168 className = "w-full justify-center mt-6"
143169 variant = { ButtonVariant . Primary }
144170 title = { t ( 'continue' ) }
145- disabled = { isDisabled || ! confirmed }
171+ disabled = { isDisabled || ! confirmed || loading }
146172 onClick = { onSubmit }
147173 isLoading = { isSubmitting }
148174 />
0 commit comments