1- import { useCallback , useMemo } from 'react' ;
1+ import { useCallback , useMemo , useRef } from 'react' ;
22
33import { ButtonAction , ButtonShape , ButtonSize , ButtonType } from '@/constants/buttons' ;
44import { DialogTypes } from '@/constants/dialogs' ;
55import { STRING_KEYS } from '@/constants/localization' ;
66import { ConnectorType } from '@/constants/wallets' ;
7+ import { LoginMethod } from '@/types/turnkey' ;
78
89import { useStringGetter } from '@/hooks/useStringGetter' ;
910import { useTurnkeyAuth } from '@/providers/TurnkeyAuthProvider' ;
@@ -18,7 +19,7 @@ import { useAppDispatch, useAppSelector } from '@/state/appTypes';
1819import { AppTheme } from '@/state/appUiConfigs' ;
1920import { getAppTheme , getChartDotBackground } from '@/state/appUiConfigsSelectors' ;
2021import { openDialog } from '@/state/dialogs' ;
21- import { getSourceAccount } from '@/state/walletSelectors' ;
22+ import { getSourceAccount , getTurnkeyEmailOnboardingData } from '@/state/walletSelectors' ;
2223
2324import { calc } from '@/lib/do' ;
2425import { sleep } from '@/lib/timeUtils' ;
@@ -38,6 +39,16 @@ export const EmailSignInStatusDialog = ({
3839 const isLightMode = appTheme === AppTheme . Light ;
3940 const isTurnkey = walletInfo ?. connectorType === ConnectorType . Turnkey ;
4041 const chartDotBackground = useAppSelector ( getChartDotBackground ) ;
42+ const turnkeyEmailOnboardingData = useAppSelector ( getTurnkeyEmailOnboardingData ) ;
43+ const hasNoUploadedAddress =
44+ walletInfo ?. connectorType === ConnectorType . Turnkey &&
45+ walletInfo . loginMethod === LoginMethod . Email &&
46+ ! turnkeyEmailOnboardingData ?. dydxAddress ;
47+
48+ // Use cached turnkeyEmailOnboardingData to determine if we should show the welcome content
49+ // turnkeyEmailOnboardingData is cleared after handling, so we only want initial state
50+ const showWelcomeContentRef = useRef ( hasNoUploadedAddress || isNewTurnkeyUser ) ;
51+ const showWelcomeContent = showWelcomeContentRef . current ;
4152
4253 const setIsOpenInner = useCallback (
4354 ( isOpen : boolean ) => {
@@ -173,7 +184,7 @@ export const EmailSignInStatusDialog = ({
173184 backgroundClip : 'text' ,
174185 } }
175186 >
176- { isNewTurnkeyUser
187+ { showWelcomeContent
177188 ? stringGetter ( { key : STRING_KEYS . WELCOME_DYDX } )
178189 : stringGetter ( { key : STRING_KEYS . WELCOME_BACK } ) }
179190 </ span >
@@ -191,13 +202,13 @@ export const EmailSignInStatusDialog = ({
191202 onClick = { async ( ) => {
192203 setIsOpen ( false ) ;
193204
194- if ( isNewTurnkeyUser ) {
205+ if ( showWelcomeContent ) {
195206 await sleep ( 0 ) ;
196207 dispatch ( openDialog ( DialogTypes . Deposit2 ( { } ) ) ) ;
197208 }
198209 } }
199210 >
200- { isNewTurnkeyUser
211+ { showWelcomeContent
201212 ? `${ stringGetter ( { key : STRING_KEYS . DEPOSIT_AND_TRADE } ) } →`
202213 : stringGetter ( { key : STRING_KEYS . CONTINUE } ) }
203214 </ Button >
0 commit comments