Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions ui/pages/onboarding-flow/account-exist/account-exist.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,6 @@ describe('Account Exist Seedless Onboarding View', () => {
});

it('should navigate to the unlock page when the button is clicked', async () => {
const setFirstTimeFlowTypeSpy = jest
.spyOn(Actions, 'setFirstTimeFlowType')
.mockReturnValue(jest.fn().mockResolvedValueOnce(null));

const { getByText } = renderWithProvider(<AccountExist />, customMockStore);
const loginButton = getByText('Log in');
fireEvent.click(loginButton);
Expand All @@ -58,18 +54,15 @@ describe('Account Exist Seedless Onboarding View', () => {
expect(mockUseNavigate).toHaveBeenCalledWith(ONBOARDING_UNLOCK_ROUTE, {
replace: true,
});
expect(setFirstTimeFlowTypeSpy).toHaveBeenCalledWith(
FirstTimeFlowType.socialImport,
);
});
});

it('should navigate to the welcome page when the firstTimeFlowType is not socialCreate', () => {
it('should navigate to the welcome page when the firstTimeFlowType is not socialImport', () => {
const store = configureMockStore([thunk])({
...mockState,
metamask: {
...mockState.metamask,
firstTimeFlowType: FirstTimeFlowType.socialImport,
firstTimeFlowType: FirstTimeFlowType.socialCreate,
},
});

Expand Down
11 changes: 4 additions & 7 deletions ui/pages/onboarding-flow/account-exist/account-exist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { FirstTimeFlowType } from '../../../../shared/constants/onboarding';
import {
forceUpdateMetamaskState,
resetOnboarding,
setFirstTimeFlowType,
} from '../../../store/actions';
import { MetaMetricsContext } from '../../../contexts/metametrics';
import {
Expand Down Expand Up @@ -80,15 +79,11 @@ export default function AccountExist() {
tags: { source: 'account_status_redirect' },
parentContext: onboardingParentContext?.current,
});
await dispatch(setFirstTimeFlowType(FirstTimeFlowType.socialImport));
navigate(ONBOARDING_UNLOCK_ROUTE, { replace: true });
};

useEffect(() => {
if (firstTimeFlowType !== FirstTimeFlowType.socialCreate) {
navigate(ONBOARDING_WELCOME_ROUTE, { replace: true });
}
if (firstTimeFlowType === FirstTimeFlowType.socialCreate) {
if (firstTimeFlowType === FirstTimeFlowType.socialImport) {
// Track page view event for account already exists page
trackEvent({
category: MetaMetricsEventCategory.Onboarding,
Expand All @@ -99,9 +94,11 @@ export default function AccountExist() {
op: TraceOperation.OnboardingUserJourney,
parentContext: onboardingParentContext?.current,
});
} else {
navigate(ONBOARDING_WELCOME_ROUTE, { replace: true });
}
return () => {
if (firstTimeFlowType === FirstTimeFlowType.socialCreate) {
if (firstTimeFlowType === FirstTimeFlowType.socialImport) {
bufferedEndTrace?.({
name: TraceName.OnboardingNewSocialAccountExists,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ describe('Account Not Found Seedless Onboarding View', () => {
});

it('should navigate to the create-password route when the button is clicked', async () => {
const setFirstTimeFlowTypeSpy = jest
.spyOn(Actions, 'setFirstTimeFlowType')
.mockReturnValue(jest.fn().mockResolvedValueOnce(null));

const { getByText } = renderWithProvider(
<AccountNotFound />,
customMockStore,
Expand All @@ -66,9 +62,6 @@ describe('Account Not Found Seedless Onboarding View', () => {
fireEvent.click(loginButton);

await waitFor(() => {
expect(setFirstTimeFlowTypeSpy).toHaveBeenCalledWith(
FirstTimeFlowType.socialCreate,
);
expect(mockUseNavigate).toHaveBeenCalledWith(
ONBOARDING_CREATE_PASSWORD_ROUTE,
{
Expand All @@ -78,12 +71,12 @@ describe('Account Not Found Seedless Onboarding View', () => {
});
});

it('should navigate to the welcome page when the firstTimeFlowType is not socialImport', () => {
it('should navigate to the welcome page when the firstTimeFlowType is not socialCreate', () => {
const store = configureMockStore([thunk])({
...mockState,
metamask: {
...mockState.metamask,
firstTimeFlowType: FirstTimeFlowType.socialCreate,
firstTimeFlowType: FirstTimeFlowType.socialImport,
},
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import { FirstTimeFlowType } from '../../../../shared/constants/onboarding';
import {
forceUpdateMetamaskState,
resetOnboarding,
setFirstTimeFlowType,
} from '../../../store/actions';
import {
MetaMetricsEventAccountType,
Expand Down Expand Up @@ -74,16 +73,11 @@ export default function AccountNotFound() {
tags: { source: 'account_status_redirect' },
parentContext: onboardingParentContext?.current,
});
dispatch(setFirstTimeFlowType(FirstTimeFlowType.socialCreate));
navigate(ONBOARDING_CREATE_PASSWORD_ROUTE, { replace: true });
};

useEffect(() => {
if (firstTimeFlowType !== FirstTimeFlowType.socialImport) {
// if the onboarding flow is not social import, redirect to the welcome page
navigate(ONBOARDING_WELCOME_ROUTE, { replace: true });
}
if (firstTimeFlowType === FirstTimeFlowType.socialImport) {
if (firstTimeFlowType === FirstTimeFlowType.socialCreate) {
trackEvent({
category: MetaMetricsEventCategory.Onboarding,
event: MetaMetricsEventName.AccountNotFoundPageViewed,
Expand All @@ -93,9 +87,11 @@ export default function AccountNotFound() {
op: TraceOperation.OnboardingUserJourney,
parentContext: onboardingParentContext?.current,
});
} else {
navigate(ONBOARDING_WELCOME_ROUTE, { replace: true });
}
return () => {
if (firstTimeFlowType === FirstTimeFlowType.socialImport) {
if (firstTimeFlowType === FirstTimeFlowType.socialCreate) {
bufferedEndTrace?.({
name: TraceName.OnboardingExistingSocialAccountNotFound,
});
Expand Down
55 changes: 40 additions & 15 deletions ui/pages/onboarding-flow/welcome/welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ import {
getCurrentKeyring,
getFirstTimeFlowType,
getIsParticipateInMetaMetricsSet,
getIsSocialLoginUserAuthenticated,
getIsSocialLoginFlow,
} from '../../../selectors';
import { FirstTimeFlowType } from '../../../../shared/constants/onboarding';
import { MetaMetricsContext } from '../../../contexts/metametrics';
import {
setFirstTimeFlowType,
startOAuthLogin,
setParticipateInMetaMetrics,
getIsSeedlessOnboardingUserAuthenticated,
} from '../../../store/actions';
import {
MetaMetricsEventAccountType,
Expand Down Expand Up @@ -72,9 +73,7 @@ export default function OnboardingWelcome() {
getIsSeedlessOnboardingFeatureEnabled();
const firstTimeFlowType = useSelector(getFirstTimeFlowType);
const isWalletResetInProgress = useSelector(getIsWalletResetInProgress);
const isUserAuthenticatedWithSocialLogin = useSelector(
getIsSocialLoginUserAuthenticated,
);
const isSocialLoginFLow = useSelector(getIsSocialLoginFlow);
const isParticipateInMetaMetricsSet = useSelector(
getIsParticipateInMetaMetricsSet,
);
Expand All @@ -94,9 +93,23 @@ export default function OnboardingWelcome() {
useState(shouldSkipAnimation);

const isFireFox = getBrowserName() === PLATFORM_FIREFOX;

const getIsUserAuthenticatedWithSocialLogin = useCallback(async () => {
if (!isSocialLoginFLow) {
return true;
}

const isSeedlessOnboardingUserAuthenticated = await dispatch(
getIsSeedlessOnboardingUserAuthenticated(),
);
return isSeedlessOnboardingUserAuthenticated;
}, [dispatch, isSocialLoginFLow]);

// Don't allow users to come back to this screen after they
// have already imported or created a wallet
useEffect(() => {
let isMounted = true;

if (
currentKeyring &&
!newAccountCreationInProgress &&
Expand All @@ -117,22 +130,33 @@ export default function OnboardingWelcome() {
} else {
navigate(ONBOARDING_REVIEW_SRP_ROUTE, { replace: true });
}
} else if (isUserAuthenticatedWithSocialLogin) {
if (firstTimeFlowType === FirstTimeFlowType.socialCreate) {
navigate(ONBOARDING_CREATE_PASSWORD_ROUTE, { replace: true });
} else {
navigate(ONBOARDING_UNLOCK_ROUTE, { replace: true });
}
} else if (isSocialLoginFLow) {
(async () => {
const isUserAuthenticatedWithSocialLogin =
await getIsUserAuthenticatedWithSocialLogin();
if (isMounted && isUserAuthenticatedWithSocialLogin) {
if (firstTimeFlowType === FirstTimeFlowType.socialCreate) {
navigate(ONBOARDING_CREATE_PASSWORD_ROUTE, { replace: true });
} else {
navigate(ONBOARDING_UNLOCK_ROUTE, { replace: true });
}
}
})();
}

return () => {
isMounted = false;
};
}, [
currentKeyring,
navigate,
firstTimeFlowType,
newAccountCreationInProgress,
isParticipateInMetaMetricsSet,
isUserAuthenticatedWithSocialLogin,
getIsUserAuthenticatedWithSocialLogin,
isFireFox,
isWalletResetInProgress,
isSocialLoginFLow,
]);

const trackEvent = useContext(MetaMetricsContext);
Expand Down Expand Up @@ -255,7 +279,6 @@ export default function OnboardingWelcome() {
async (socialConnectionType) => {
setIsLoggingIn(true);
setNewAccountCreationInProgress(true);
await dispatch(setFirstTimeFlowType(FirstTimeFlowType.socialCreate));

trackEvent({
category: MetaMetricsEventCategory.Onboarding,
Expand All @@ -282,8 +305,10 @@ export default function OnboardingWelcome() {
op: TraceOperation.OnboardingUserJourney,
parentContext: onboardingParentContext.current,
});
await dispatch(setFirstTimeFlowType(FirstTimeFlowType.socialCreate));
navigate(ONBOARDING_CREATE_PASSWORD_ROUTE, { replace: true });
} else {
await dispatch(setFirstTimeFlowType(FirstTimeFlowType.socialImport));
navigate(ONBOARDING_ACCOUNT_EXIST, { replace: true });
}
} catch (error) {
Expand All @@ -306,8 +331,6 @@ export default function OnboardingWelcome() {
const onSocialLoginImportClick = useCallback(
async (socialConnectionType) => {
setIsLoggingIn(true);
dispatch(setFirstTimeFlowType(FirstTimeFlowType.socialImport));

trackEvent({
category: MetaMetricsEventCategory.Onboarding,
event: MetaMetricsEventName.WalletImportStarted,
Expand All @@ -329,13 +352,15 @@ export default function OnboardingWelcome() {
});

if (isNewUser) {
await dispatch(setFirstTimeFlowType(FirstTimeFlowType.socialCreate));
navigate(ONBOARDING_ACCOUNT_NOT_FOUND);
} else {
bufferedTrace?.({
name: TraceName.OnboardingExistingSocialLogin,
op: TraceOperation.OnboardingUserJourney,
parentContext: onboardingParentContext.current,
});
await dispatch(setFirstTimeFlowType(FirstTimeFlowType.socialImport));
navigate(ONBOARDING_UNLOCK_ROUTE);
}
} catch (error) {
Expand All @@ -345,13 +370,13 @@ export default function OnboardingWelcome() {
}
},
[
dispatch,
handleSocialLogin,
trackEvent,
navigate,
onboardingParentContext,
handleSocialLoginError,
bufferedTrace,
dispatch,
],
);

Expand Down
Loading