11import { openUrl } from '@tauri-apps/plugin-opener' ;
2- import { useEffect , useRef , useState } from 'react' ;
2+ import { useState } from 'react' ;
33import { useTranslation } from 'react-i18next' ;
44import { invoke } from '@tauri-apps/api/core' ;
55import { useNavigate } from 'react-router' ;
@@ -9,6 +9,7 @@ import { useDeepLink } from '../../hooks';
99import { routes } from '../../router' ;
1010import { CCache } from '../../cache' ;
1111import { StateDispatch , TAccountMode } from '../../types' ;
12+ import { DeeplinkTimeout } from '../../errors' ;
1213
1314function PrivyButton ( ) {
1415 const { t, i18n } = useTranslation ( 'login' ) ;
@@ -20,16 +21,6 @@ function PrivyButton() {
2021 const dispatch = useMainDispatch ( ) as StateDispatch ;
2122
2223 const [ loading , setLoading ] = useState ( false ) ;
23- const timeoutIdRef = useRef < ReturnType < typeof setTimeout > | null > ( null ) ;
24-
25- useEffect ( ( ) => {
26- return ( ) => {
27- if ( timeoutIdRef . current !== null ) {
28- clearTimeout ( timeoutIdRef . current ) ;
29- timeoutIdRef . current = null ;
30- }
31- } ;
32- } , [ ] ) ;
3324
3425 const refreshAccountMode = async ( ) => {
3526 const accountMode = await invoke < TAccountMode > ( 'get_account_mode' ) ;
@@ -46,17 +37,7 @@ function PrivyButton() {
4637 openUrl ( loginUrl ) ;
4738
4839 try {
49- const timeoutPromise = new Promise < never > ( ( _ , reject ) => {
50- timeoutIdRef . current = setTimeout (
51- ( ) => reject ( new Error ( 'Login timeout' ) ) ,
52- 300000 ,
53- ) ;
54- } ) ;
55-
56- const deeplinkurl = await Promise . race ( [
57- startListening ( ) ,
58- timeoutPromise ,
59- ] ) ;
40+ const deeplinkurl = await startListening ( 300000 ) ;
6041
6142 await invoke ( 'store_deeplink_account' , {
6243 callbackUrl : deeplinkurl ,
@@ -75,7 +56,7 @@ function PrivyButton() {
7556 dispatch ( { type : 'reset-error' } ) ;
7657 } catch ( error ) {
7758 console . error ( 'Privy login error: ' , error ) ;
78- if ( error instanceof Error && error . message === 'Login timeout' ) {
59+ if ( error instanceof DeeplinkTimeout ) {
7960 push ( {
8061 message : t ( 'privy.error.timeout' ) ,
8162 type : 'error' ,
@@ -91,10 +72,6 @@ function PrivyButton() {
9172 } ) ;
9273 }
9374 } finally {
94- if ( timeoutIdRef . current !== null ) {
95- clearTimeout ( timeoutIdRef . current ) ;
96- timeoutIdRef . current = null ;
97- }
9875 setLoading ( false ) ;
9976 }
10077 } ;
0 commit comments