2021-09-30 23:34:11 +02:00
|
|
|
import React, { useEffect, useState } from 'react';
|
2021-10-11 16:43:25 +02:00
|
|
|
import { Switch, Route, useHistory, useLocation } from 'react-router-dom';
|
2021-09-30 23:34:11 +02:00
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
|
|
import Unlock from '../unlock-page';
|
|
|
|
import {
|
2021-12-01 17:53:30 +01:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
|
|
ONBOARDING_EXPERIMENTAL_AREA,
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
2021-09-30 23:34:11 +02:00
|
|
|
ONBOARDING_CREATE_PASSWORD_ROUTE,
|
|
|
|
ONBOARDING_REVIEW_SRP_ROUTE,
|
|
|
|
ONBOARDING_CONFIRM_SRP_ROUTE,
|
|
|
|
ONBOARDING_UNLOCK_ROUTE,
|
2021-10-18 17:12:57 +02:00
|
|
|
ONBOARDING_WELCOME_ROUTE,
|
2021-09-30 23:34:11 +02:00
|
|
|
DEFAULT_ROUTE,
|
2021-10-06 20:52:25 +02:00
|
|
|
ONBOARDING_SECURE_YOUR_WALLET_ROUTE,
|
2021-10-08 21:50:36 +02:00
|
|
|
ONBOARDING_PRIVACY_SETTINGS_ROUTE,
|
2021-10-11 16:43:25 +02:00
|
|
|
ONBOARDING_COMPLETION_ROUTE,
|
2021-10-13 19:41:24 +02:00
|
|
|
ONBOARDING_IMPORT_WITH_SRP_ROUTE,
|
2021-10-19 00:33:42 +02:00
|
|
|
ONBOARDING_PIN_EXTENSION_ROUTE,
|
2021-10-19 19:01:42 +02:00
|
|
|
ONBOARDING_METAMETRICS,
|
2021-09-30 23:34:11 +02:00
|
|
|
} from '../../helpers/constants/routes';
|
|
|
|
import {
|
|
|
|
getCompletedOnboarding,
|
|
|
|
getSeedPhraseBackedUp,
|
|
|
|
} from '../../ducks/metamask/metamask';
|
|
|
|
import {
|
|
|
|
createNewVaultAndGetSeedPhrase,
|
|
|
|
unlockAndGetSeedPhrase,
|
2021-10-13 19:41:24 +02:00
|
|
|
createNewVaultAndRestore,
|
2021-09-30 23:34:11 +02:00
|
|
|
} from '../../store/actions';
|
|
|
|
import { getFirstTimeFlowTypeRoute } from '../../selectors';
|
2021-10-11 16:43:25 +02:00
|
|
|
import Button from '../../components/ui/button';
|
|
|
|
import { useI18nContext } from '../../hooks/useI18nContext';
|
2021-12-01 17:53:30 +01:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
|
|
import ExperimentalArea from '../../components/app/flask/experimental-area';
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
2021-09-30 23:34:11 +02:00
|
|
|
import OnboardingFlowSwitch from './onboarding-flow-switch/onboarding-flow-switch';
|
2021-10-11 16:43:25 +02:00
|
|
|
import CreatePassword from './create-password/create-password';
|
2021-09-30 23:34:11 +02:00
|
|
|
import ReviewRecoveryPhrase from './recovery-phrase/review-recovery-phrase';
|
2021-10-06 20:52:25 +02:00
|
|
|
import SecureYourWallet from './secure-your-wallet/secure-your-wallet';
|
2021-09-30 23:34:11 +02:00
|
|
|
import ConfirmRecoveryPhrase from './recovery-phrase/confirm-recovery-phrase';
|
2021-10-08 21:50:36 +02:00
|
|
|
import PrivacySettings from './privacy-settings/privacy-settings';
|
2021-10-11 16:43:25 +02:00
|
|
|
import CreationSuccessful from './creation-successful/creation-successful';
|
2021-10-13 16:22:51 +02:00
|
|
|
import OnboardingWelcome from './welcome/welcome';
|
2021-10-13 19:41:24 +02:00
|
|
|
import ImportSRP from './import-srp/import-srp';
|
2021-10-19 00:33:42 +02:00
|
|
|
import OnboardingPinExtension from './pin-extension/pin-extension';
|
2021-10-19 19:01:42 +02:00
|
|
|
import MetaMetricsComponent from './metametrics/metametrics';
|
2021-09-30 23:34:11 +02:00
|
|
|
|
|
|
|
export default function OnboardingFlow() {
|
2021-10-13 19:41:24 +02:00
|
|
|
const [secretRecoveryPhrase, setSecretRecoveryPhrase] = useState('');
|
2021-09-30 23:34:11 +02:00
|
|
|
const dispatch = useDispatch();
|
2021-10-11 16:43:25 +02:00
|
|
|
const currentLocation = useLocation();
|
2021-09-30 23:34:11 +02:00
|
|
|
const history = useHistory();
|
2021-10-11 16:43:25 +02:00
|
|
|
const t = useI18nContext();
|
2021-09-30 23:34:11 +02:00
|
|
|
const completedOnboarding = useSelector(getCompletedOnboarding);
|
|
|
|
const seedPhraseBackedUp = useSelector(getSeedPhraseBackedUp);
|
|
|
|
const nextRoute = useSelector(getFirstTimeFlowTypeRoute);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (completedOnboarding && seedPhraseBackedUp) {
|
|
|
|
history.push(DEFAULT_ROUTE);
|
|
|
|
}
|
2022-03-25 22:03:49 +01:00
|
|
|
}, [history, completedOnboarding, seedPhraseBackedUp]);
|
2021-09-30 23:34:11 +02:00
|
|
|
|
|
|
|
const handleCreateNewAccount = async (password) => {
|
2021-10-13 19:41:24 +02:00
|
|
|
const newSecretRecoveryPhrase = await dispatch(
|
2021-09-30 23:34:11 +02:00
|
|
|
createNewVaultAndGetSeedPhrase(password),
|
|
|
|
);
|
2021-10-13 19:41:24 +02:00
|
|
|
setSecretRecoveryPhrase(newSecretRecoveryPhrase);
|
2021-09-30 23:34:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const handleUnlock = async (password) => {
|
2021-10-13 19:41:24 +02:00
|
|
|
const retrievedSecretRecoveryPhrase = await dispatch(
|
2021-09-30 23:34:11 +02:00
|
|
|
unlockAndGetSeedPhrase(password),
|
|
|
|
);
|
2021-10-13 19:41:24 +02:00
|
|
|
setSecretRecoveryPhrase(retrievedSecretRecoveryPhrase);
|
2021-09-30 23:34:11 +02:00
|
|
|
history.push(nextRoute);
|
|
|
|
};
|
|
|
|
|
2021-10-13 19:41:24 +02:00
|
|
|
const handleImportWithRecoveryPhrase = async (password, srp) => {
|
|
|
|
return await dispatch(createNewVaultAndRestore(password, srp));
|
|
|
|
};
|
|
|
|
|
2021-09-30 23:34:11 +02:00
|
|
|
return (
|
|
|
|
<div className="onboarding-flow">
|
|
|
|
<div className="onboarding-flow__wrapper">
|
|
|
|
<Switch>
|
|
|
|
<Route
|
|
|
|
path={ONBOARDING_CREATE_PASSWORD_ROUTE}
|
|
|
|
render={(routeProps) => (
|
2021-10-11 16:43:25 +02:00
|
|
|
<CreatePassword
|
2021-09-30 23:34:11 +02:00
|
|
|
{...routeProps}
|
|
|
|
createNewAccount={handleCreateNewAccount}
|
2021-10-13 19:41:24 +02:00
|
|
|
importWithRecoveryPhrase={handleImportWithRecoveryPhrase}
|
|
|
|
secretRecoveryPhrase={secretRecoveryPhrase}
|
2021-09-30 23:34:11 +02:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
2021-10-06 20:52:25 +02:00
|
|
|
<Route
|
|
|
|
exact
|
|
|
|
path={ONBOARDING_SECURE_YOUR_WALLET_ROUTE}
|
|
|
|
component={SecureYourWallet}
|
|
|
|
/>
|
2021-09-30 23:34:11 +02:00
|
|
|
<Route
|
|
|
|
path={ONBOARDING_REVIEW_SRP_ROUTE}
|
2021-10-13 19:41:24 +02:00
|
|
|
render={() => (
|
|
|
|
<ReviewRecoveryPhrase
|
|
|
|
secretRecoveryPhrase={secretRecoveryPhrase}
|
|
|
|
/>
|
|
|
|
)}
|
2021-09-30 23:34:11 +02:00
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path={ONBOARDING_CONFIRM_SRP_ROUTE}
|
2021-10-13 19:41:24 +02:00
|
|
|
render={() => (
|
|
|
|
<ConfirmRecoveryPhrase
|
|
|
|
secretRecoveryPhrase={secretRecoveryPhrase}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path={ONBOARDING_IMPORT_WITH_SRP_ROUTE}
|
|
|
|
render={(routeProps) => (
|
|
|
|
<ImportSRP
|
|
|
|
{...routeProps}
|
|
|
|
submitSecretRecoveryPhrase={setSecretRecoveryPhrase}
|
|
|
|
/>
|
|
|
|
)}
|
2021-09-30 23:34:11 +02:00
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path={ONBOARDING_UNLOCK_ROUTE}
|
|
|
|
render={(routeProps) => (
|
|
|
|
<Unlock {...routeProps} onSubmit={handleUnlock} />
|
|
|
|
)}
|
|
|
|
/>
|
2021-10-08 21:50:36 +02:00
|
|
|
<Route
|
|
|
|
path={ONBOARDING_PRIVACY_SETTINGS_ROUTE}
|
|
|
|
component={PrivacySettings}
|
|
|
|
/>
|
2021-10-11 16:43:25 +02:00
|
|
|
<Route
|
|
|
|
path={ONBOARDING_COMPLETION_ROUTE}
|
|
|
|
component={CreationSuccessful}
|
|
|
|
/>
|
2021-10-18 17:12:57 +02:00
|
|
|
<Route
|
|
|
|
path={ONBOARDING_WELCOME_ROUTE}
|
|
|
|
component={OnboardingWelcome}
|
|
|
|
/>
|
2021-10-19 00:33:42 +02:00
|
|
|
<Route
|
|
|
|
path={ONBOARDING_PIN_EXTENSION_ROUTE}
|
|
|
|
component={OnboardingPinExtension}
|
|
|
|
/>
|
2021-10-19 19:01:42 +02:00
|
|
|
<Route
|
|
|
|
path={ONBOARDING_METAMETRICS}
|
|
|
|
component={MetaMetricsComponent}
|
|
|
|
/>
|
2021-12-01 17:53:30 +01:00
|
|
|
{
|
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(flask)
|
|
|
|
}
|
|
|
|
<Route
|
|
|
|
path={ONBOARDING_EXPERIMENTAL_AREA}
|
|
|
|
render={(routeProps) => (
|
|
|
|
<ExperimentalArea
|
|
|
|
{...routeProps}
|
|
|
|
redirectTo={ONBOARDING_WELCOME_ROUTE}
|
|
|
|
/>
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
{
|
|
|
|
///: END:ONLY_INCLUDE_IN
|
|
|
|
}
|
2021-09-30 23:34:11 +02:00
|
|
|
<Route exact path="*" component={OnboardingFlowSwitch} />
|
|
|
|
</Switch>
|
|
|
|
</div>
|
2021-10-11 16:43:25 +02:00
|
|
|
{currentLocation?.pathname === ONBOARDING_COMPLETION_ROUTE && (
|
|
|
|
<Button
|
|
|
|
className="onboarding-flow__twitter-button"
|
|
|
|
type="link"
|
|
|
|
href="https://twitter.com/MetaMask"
|
|
|
|
target="_blank"
|
|
|
|
>
|
|
|
|
<span>{t('followUsOnTwitter')}</span>
|
2022-03-28 16:42:09 +02:00
|
|
|
<i className="fab fa-twitter onboarding-flow__twitter-button__icon" />
|
2021-10-11 16:43:25 +02:00
|
|
|
</Button>
|
|
|
|
)}
|
2021-09-30 23:34:11 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|