Skip to content

Commit 94aa0d5

Browse files
Merge branch 'release/13.9.0' into runway-cherry-pick-13.9.0-1762779144
2 parents 668a33e + 4dd36e7 commit 94aa0d5

File tree

4 files changed

+38
-14
lines changed

4 files changed

+38
-14
lines changed

app/scripts/services/oauth/oauth-service.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { AuthConnection } from '@metamask/seedless-onboarding-controller';
22
import log from 'loglevel';
3-
import { OAuthErrorMessages } from '../../../../shared/modules/error';
3+
import {
4+
isUserCancelledLoginError,
5+
OAuthErrorMessages,
6+
} from '../../../../shared/modules/error';
47
import { checkForLastError } from '../../../../shared/modules/browser-runtime.utils';
58
import { TraceName, TraceOperation } from '../../../../shared/lib/trace';
69
import { BaseLoginHandler } from './base-login-handler';
@@ -204,12 +207,13 @@ export default class OAuthService {
204207
reject(error);
205208
}
206209
} else {
207-
if (this.#isUserCancelledLoginError()) {
208-
reject(
209-
new Error(OAuthErrorMessages.USER_CANCELLED_LOGIN_ERROR),
210-
);
210+
const userCancelledLoginError =
211+
this.#getUserCancelledLoginError();
212+
if (userCancelledLoginError) {
213+
reject(userCancelledLoginError);
211214
return;
212215
}
216+
// Throw default error for no redirect URL found
213217
reject(
214218
new Error(OAuthErrorMessages.NO_REDIRECT_URL_FOUND_ERROR),
215219
);
@@ -357,9 +361,12 @@ export default class OAuthService {
357361
return url.searchParams.get('code');
358362
}
359363

360-
#isUserCancelledLoginError(): boolean {
364+
#getUserCancelledLoginError(): Error | undefined {
361365
const error = checkForLastError();
362-
return error?.message === OAuthErrorMessages.USER_CANCELLED_LOGIN_ERROR;
366+
if (isUserCancelledLoginError(error)) {
367+
return error;
368+
}
369+
return undefined;
363370
}
364371

365372
async setMarketingConsent(

shared/modules/error.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ export enum OAuthErrorMessages {
3939
USER_CANCELLED_LOGIN_ERROR = 'The user did not approve access.',
4040
// TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31860
4141
// eslint-disable-next-line @typescript-eslint/naming-convention
42+
USER_CANCELLED_LOGIN_ERROR_FIREFOX = 'User cancelled or denied access.',
43+
// TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31860
44+
// eslint-disable-next-line @typescript-eslint/naming-convention
4245
NO_REDIRECT_URL_FOUND_ERROR = 'No redirect URL found',
4346
// TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31860
4447
// eslint-disable-next-line @typescript-eslint/naming-convention
@@ -47,3 +50,17 @@ export enum OAuthErrorMessages {
4750
// eslint-disable-next-line @typescript-eslint/naming-convention
4851
INVALID_OAUTH_STATE_ERROR = 'Invalid OAuth state',
4952
}
53+
54+
/**
55+
* Checks if the Web Authentication error is a user cancelled error.
56+
*
57+
* @param error - The error to check.
58+
* @returns True if the error is a user cancelled login error, false otherwise.
59+
*/
60+
export function isUserCancelledLoginError(error: Error | undefined): boolean {
61+
// NOTE: Firefox and chrome have different error messages for user cancelled the social login window.
62+
return (
63+
error?.message === OAuthErrorMessages.USER_CANCELLED_LOGIN_ERROR ||
64+
error?.message === OAuthErrorMessages.USER_CANCELLED_LOGIN_ERROR_FIREFOX
65+
);
66+
}

ui/pages/onboarding-flow/welcome/welcome.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import React, {
88
} from 'react';
99
import { useDispatch, useSelector } from 'react-redux';
1010
import { useNavigate } from 'react-router-dom-v5-compat';
11-
import log from 'loglevel';
1211
import { Box } from '../../../components/component-library';
1312
import {
1413
ONBOARDING_COMPLETION_ROUTE,
@@ -41,7 +40,10 @@ import {
4140
import { getIsSeedlessOnboardingFeatureEnabled } from '../../../../shared/modules/environment';
4241
import { getBrowserName } from '../../../../shared/modules/browser-runtime.utils';
4342
import { PLATFORM_FIREFOX } from '../../../../shared/constants/app';
44-
import { OAuthErrorMessages } from '../../../../shared/modules/error';
43+
import {
44+
isUserCancelledLoginError,
45+
OAuthErrorMessages,
46+
} from '../../../../shared/modules/error';
4547
import { TraceName, TraceOperation } from '../../../../shared/lib/trace';
4648
import {
4749
AlignItems,
@@ -214,7 +216,7 @@ export default function OnboardingWelcome() {
214216
error instanceof Error ? error.message : 'Unknown error';
215217

216218
// Map raw OAuth error messages to UI modal-friendly constants
217-
if (errorMessage === OAuthErrorMessages.USER_CANCELLED_LOGIN_ERROR) {
219+
if (isUserCancelledLoginError(error)) {
218220
setLoginError(null);
219221
return;
220222
}
@@ -354,9 +356,7 @@ export default function OnboardingWelcome() {
354356
);
355357

356358
const handleLoginError = useCallback((error) => {
357-
log.error('handleLoginError::error', error);
358-
const errorMessage = error.message;
359-
if (errorMessage === OAuthErrorMessages.USER_CANCELLED_LOGIN_ERROR) {
359+
if (isUserCancelledLoginError(error)) {
360360
setLoginError(null);
361361
} else {
362362
setLoginError(LOGIN_ERROR.GENERIC);

ui/selectors/assets.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export function getAssetsMetadata(state: AssetsState) {
111111
* @returns An object containing all ignored assets.
112112
*/
113113
export function getAllIgnoredAssets(state: AssetsState) {
114-
return state.metamask.allIgnoredAssets;
114+
return state.metamask.allIgnoredAssets ?? EMPTY_OBJECT;
115115
}
116116

117117
/**

0 commit comments

Comments
 (0)