Skip to content

Commit 89a4cc7

Browse files
authored
fix: quiet expected errors (#1917)
1 parent a665b18 commit 89a4cc7

File tree

3 files changed

+44
-12
lines changed

3 files changed

+44
-12
lines changed

src/lib/turnkey/turnkeyUtils.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,18 @@ export async function getWalletsWithAccountsFromClient(
3333
return walletWithAccounts;
3434
}
3535

36-
export const parseTurnkeyError = (message: string, stringGetter: StringGetterFunction): string => {
36+
export const parseTurnkeyError = (
37+
message: string,
38+
stringGetter: StringGetterFunction
39+
): {
40+
errorMessage: string;
41+
shouldLog: boolean;
42+
} => {
3743
if (message.includes('User has already registered using this email')) {
38-
return stringGetter({ key: STRING_KEYS.USER_ALREADY_HAS_TURNKEY });
44+
return {
45+
errorMessage: stringGetter({ key: STRING_KEYS.USER_ALREADY_HAS_TURNKEY }),
46+
shouldLog: false,
47+
};
3948
}
4049

4150
if (
@@ -44,11 +53,17 @@ export const parseTurnkeyError = (message: string, stringGetter: StringGetterFun
4453
message.includes('Unauthenticated desc') ||
4554
message.includes('Organization ID was not found')
4655
) {
47-
return stringGetter({ key: STRING_KEYS.INVALID_TURNKEY_EMAIL_LINK });
56+
return {
57+
errorMessage: stringGetter({ key: STRING_KEYS.INVALID_TURNKEY_EMAIL_LINK }),
58+
shouldLog: false,
59+
};
4860
}
4961

50-
return stringGetter({
51-
key: STRING_KEYS.SOMETHING_WENT_WRONG_WITH_MESSAGE,
52-
params: { ERROR_MESSAGE: message },
53-
});
62+
return {
63+
errorMessage: stringGetter({
64+
key: STRING_KEYS.SOMETHING_WENT_WRONG_WITH_MESSAGE,
65+
params: { ERROR_MESSAGE: message },
66+
}),
67+
shouldLog: true,
68+
};
5469
};

src/providers/TurnkeyAuthProvider.tsx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ const useTurnkeyAuthContext = () => {
8585

8686
const {
8787
embeddedPublicKey,
88+
endTurnkeySession,
8889
setIsNewTurnkeyUser,
8990
onboardDydx,
9091
targetPublicKeys,
@@ -164,9 +165,14 @@ const useTurnkeyAuthContext = () => {
164165
},
165166
onError: (error, variables) => {
166167
selectWallet(undefined);
167-
logBonsaiError('TurnkeyOnboarding', 'Error during sign-in', { error });
168168
setEmailSignInStatus('error');
169-
setEmailSignInError(parseTurnkeyError(error.message, stringGetter));
169+
const { errorMessage, shouldLog } = parseTurnkeyError(error.message, stringGetter);
170+
setEmailSignInError(errorMessage);
171+
endTurnkeySession();
172+
173+
if (shouldLog) {
174+
logBonsaiError('TurnkeyOnboarding', 'Error during sign-in', { error });
175+
}
170176

171177
if (variables.loginMethod === LoginMethod.OAuth) {
172178
const providerName = variables.providerName;
@@ -336,8 +342,16 @@ const useTurnkeyAuthContext = () => {
336342
let errorMessage: string | undefined;
337343

338344
if (error instanceof Error) {
339-
errorMessage = parseTurnkeyError(error.message, stringGetter);
340-
logBonsaiError('TurnkeyOnboarding', 'error handling email magic link', { error });
345+
const { errorMessage: message, shouldLog } = parseTurnkeyError(
346+
error.message,
347+
stringGetter
348+
);
349+
350+
if (shouldLog) {
351+
logBonsaiError('TurnkeyOnboarding', 'error handling email magic link', { error });
352+
}
353+
354+
errorMessage = message;
341355
} else {
342356
logBonsaiError('TurnkeyOnboarding', 'error handling email magic link - unknown', {
343357
error,
@@ -351,6 +365,8 @@ const useTurnkeyAuthContext = () => {
351365
params: { ERROR_MESSAGE: stringGetter({ key: STRING_KEYS.UNKNOWN_ERROR }) },
352366
})
353367
);
368+
369+
endTurnkeySession();
354370
setEmailSignInStatus('error');
355371
} finally {
356372
// Clear token from state after it has been consumed
@@ -373,6 +389,7 @@ const useTurnkeyAuthContext = () => {
373389
setSearchParams,
374390
dispatch,
375391
stringGetter,
392+
endTurnkeySession,
376393
]
377394
);
378395

src/views/dialogs/ManageAccountDialog/RevealPhrase.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export const RevealPhrase = ({
235235
);
236236

237237
const iframeCss = `
238-
iframe {
238+
#${TurnkeyExportIframeContainerId} > iframe {
239239
padding: 0.75rem;
240240
width: 100%;
241241
height: 100%;

0 commit comments

Comments
 (0)