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,
|
2021-10-18 17:12:57 +02:00
|
|
|
ONBOARDING_WELCOME_ROUTE,
|
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() {
|
|
|
|
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 }} />;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!isInitialized) {
|
2021-10-18 17:12:57 +02:00
|
|
|
return <Redirect to={{ pathname: ONBOARDING_WELCOME_ROUTE }} />;
|
2021-09-30 23:34:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return <Redirect to={{ pathname: ONBOARDING_UNLOCK_ROUTE }} />;
|
|
|
|
}
|