@@ -53,6 +53,7 @@ export function OTPLoginUI(props: {
53
53
const [ verifyStatus , setVerifyStatus ] = useState < VerificationStatus > ( "idle" ) ;
54
54
const [ error , setError ] = useState < string | undefined > ( ) ;
55
55
const [ accountStatus , setAccountStatus ] = useState < AccountStatus > ( "sending" ) ;
56
+ const [ countdown , setCountdown ] = useState ( 0 ) ;
56
57
const ecosystem = isEcosystemWallet ( wallet )
57
58
? {
58
59
id : wallet . id ,
@@ -76,6 +77,7 @@ export function OTPLoginUI(props: {
76
77
client : props . client ,
77
78
} ) ;
78
79
setAccountStatus ( "sent" ) ;
80
+ setCountdown ( 60 ) ; // Start 60-second countdown
79
81
} else if ( "phone" in userInfo ) {
80
82
await preAuthenticate ( {
81
83
ecosystem,
@@ -84,6 +86,7 @@ export function OTPLoginUI(props: {
84
86
client : props . client ,
85
87
} ) ;
86
88
setAccountStatus ( "sent" ) ;
89
+ setCountdown ( 60 ) ; // Start 60-second countdown
87
90
} else {
88
91
throw new Error ( "Invalid userInfo" ) ;
89
92
}
@@ -184,6 +187,23 @@ export function OTPLoginUI(props: {
184
187
}
185
188
} , [ sendEmailOrSms ] ) ;
186
189
190
+ // Handle countdown timer
191
+ useEffect ( ( ) => {
192
+ if ( countdown <= 0 ) return ;
193
+
194
+ const timer = setInterval ( ( ) => {
195
+ setCountdown ( ( current ) => {
196
+ if ( current <= 1 ) {
197
+ clearInterval ( timer ) ;
198
+ return 0 ;
199
+ }
200
+ return current - 1 ;
201
+ } ) ;
202
+ } , 1000 ) ;
203
+
204
+ return ( ) => clearInterval ( timer ) ;
205
+ } , [ countdown ] ) ;
206
+
187
207
if ( screen === "base" ) {
188
208
return (
189
209
< Container fullHeight flex = "column" animate = "fadein" >
@@ -298,8 +318,17 @@ export function OTPLoginUI(props: {
298
318
) }
299
319
300
320
{ accountStatus !== "sending" && (
301
- < LinkButton onClick = { sendEmailOrSms } type = "button" >
302
- { locale . emailLoginScreen . resendCode }
321
+ < LinkButton
322
+ onClick = { countdown === 0 ? sendEmailOrSms : undefined }
323
+ type = "button"
324
+ style = { {
325
+ opacity : countdown > 0 ? 0.5 : 1 ,
326
+ cursor : countdown > 0 ? "default" : "pointer" ,
327
+ } }
328
+ >
329
+ { countdown > 0
330
+ ? `Resend code in ${ countdown } seconds`
331
+ : locale . emailLoginScreen . resendCode }
303
332
</ LinkButton >
304
333
) }
305
334
</ Container >
0 commit comments