2021-09-30 23:34:11 +02:00
|
|
|
import React from 'react';
|
|
|
|
import { useSelector } from 'react-redux';
|
|
|
|
import { Redirect } from 'react-router-dom';
|
|
|
|
import {
|
|
|
|
DEFAULT_ROUTE,
|
|
|
|
ONBOARDING_COMPLETION_ROUTE,
|
|
|
|
ONBOARDING_UNLOCK_ROUTE,
|
|
|
|
LOCK_ROUTE,
|
2023-04-25 16:32:51 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-flask)
|
2021-12-01 17:53:30 +01:00
|
|
|
ONBOARDING_EXPERIMENTAL_AREA, // eslint-disable-line no-unused-vars
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
2023-04-25 16:32:51 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-main,build-beta,build-mmi)
|
2021-12-01 17:53:30 +01:00
|
|
|
ONBOARDING_WELCOME_ROUTE, // eslint-disable-line no-unused-vars
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
2021-09-30 23:34:11 +02:00
|
|
|
} from '../../../helpers/constants/routes';
|
|
|
|
import {
|
|
|
|
getCompletedOnboarding,
|
|
|
|
getIsInitialized,
|
|
|
|
getIsUnlocked,
|
|
|
|
getSeedPhraseBackedUp,
|
|
|
|
} from '../../../ducks/metamask/metamask';
|
|
|
|
|
|
|
|
export default function OnboardingFlowSwitch() {
|
2021-12-01 17:53:30 +01:00
|
|
|
/* eslint-disable prefer-const */
|
2021-09-30 23:34:11 +02:00
|
|
|
const completedOnboarding = useSelector(getCompletedOnboarding);
|
|
|
|
const isInitialized = useSelector(getIsInitialized);
|
|
|
|
const seedPhraseBackedUp = useSelector(getSeedPhraseBackedUp);
|
|
|
|
const isUnlocked = useSelector(getIsUnlocked);
|
|
|
|
|
|
|
|
if (completedOnboarding) {
|
|
|
|
return <Redirect to={{ pathname: DEFAULT_ROUTE }} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (seedPhraseBackedUp !== null) {
|
|
|
|
return <Redirect to={{ pathname: ONBOARDING_COMPLETION_ROUTE }} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isUnlocked) {
|
|
|
|
return <Redirect to={{ pathname: LOCK_ROUTE }} />;
|
|
|
|
}
|
|
|
|
|
2023-04-25 16:32:51 +02:00
|
|
|
// TODO(ritave): Remove allow-list and only leave experimental_area exception
|
2021-09-30 23:34:11 +02:00
|
|
|
if (!isInitialized) {
|
2021-12-01 17:53:30 +01:00
|
|
|
let redirect;
|
2023-04-25 16:32:51 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-flask)
|
2021-12-01 17:53:30 +01:00
|
|
|
redirect = <Redirect to={{ pathname: ONBOARDING_EXPERIMENTAL_AREA }} />;
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
2023-04-25 16:32:51 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-main,build-beta,build-mmi)
|
2021-12-01 17:53:30 +01:00
|
|
|
redirect = <Redirect to={{ pathname: ONBOARDING_WELCOME_ROUTE }} />;
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
return redirect;
|
2021-09-30 23:34:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return <Redirect to={{ pathname: ONBOARDING_UNLOCK_ROUTE }} />;
|
|
|
|
}
|