Skip to content

Commit 433b130

Browse files
authored
fix: new user email uses onboarding data cache (#1921)
1 parent 0b0b8a4 commit 433b130

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

src/providers/TurnkeyAuthProvider.tsx

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import { appQueryClient } from '@/state/appQueryClient';
2727
import { useAppDispatch, useAppSelector } from '@/state/appTypes';
2828
import { forceOpenDialog, openDialog } from '@/state/dialogs';
2929
import {
30-
clearTurnkeyEmailOnboardingData,
3130
setRequiresAddressUpload,
3231
setTurnkeyEmailOnboardingData,
3332
setWalletInfo,
@@ -163,12 +162,12 @@ const useTurnkeyAuthContext = () => {
163162
throw new Error('Current unsupported login method');
164163
}
165164
},
166-
onError: (error, variables) => {
165+
onError: async (error, variables) => {
167166
selectWallet(undefined);
168167
setEmailSignInStatus('error');
169168
const { errorMessage, shouldLog } = parseTurnkeyError(error.message, stringGetter);
170169
setEmailSignInError(errorMessage);
171-
endTurnkeySession();
170+
await endTurnkeySession();
172171

173172
if (shouldLog) {
174173
logBonsaiError('TurnkeyOnboarding', 'Error during sign-in', { error });
@@ -366,16 +365,14 @@ const useTurnkeyAuthContext = () => {
366365
})
367366
);
368367

369-
endTurnkeySession();
368+
await endTurnkeySession();
370369
setEmailSignInStatus('error');
371370
} finally {
372371
// Clear token from state after it has been consumed
373372
setEmailToken(undefined);
374373
// Remove the token from the search params after it has been saved to state
375374
searchParams.delete('token');
376375
setSearchParams(searchParams);
377-
// Clear email sign in data
378-
dispatch(clearTurnkeyEmailOnboardingData());
379376
}
380377
},
381378
[
@@ -387,7 +384,6 @@ const useTurnkeyAuthContext = () => {
387384
setWalletFromSignature,
388385
searchParams,
389386
setSearchParams,
390-
dispatch,
391387
stringGetter,
392388
endTurnkeySession,
393389
]

src/views/dialogs/EmailSignInStatusDialog.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import { useCallback, useMemo } from 'react';
1+
import { useCallback, useMemo, useRef } from 'react';
22

33
import { ButtonAction, ButtonShape, ButtonSize, ButtonType } from '@/constants/buttons';
44
import { DialogTypes } from '@/constants/dialogs';
55
import { STRING_KEYS } from '@/constants/localization';
66
import { ConnectorType } from '@/constants/wallets';
7+
import { LoginMethod } from '@/types/turnkey';
78

89
import { useStringGetter } from '@/hooks/useStringGetter';
910
import { useTurnkeyAuth } from '@/providers/TurnkeyAuthProvider';
@@ -18,7 +19,7 @@ import { useAppDispatch, useAppSelector } from '@/state/appTypes';
1819
import { AppTheme } from '@/state/appUiConfigs';
1920
import { getAppTheme, getChartDotBackground } from '@/state/appUiConfigsSelectors';
2021
import { openDialog } from '@/state/dialogs';
21-
import { getSourceAccount } from '@/state/walletSelectors';
22+
import { getSourceAccount, getTurnkeyEmailOnboardingData } from '@/state/walletSelectors';
2223

2324
import { calc } from '@/lib/do';
2425
import { 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

Comments
 (0)