2023-01-13 17:11:27 +01:00
|
|
|
import React, { useEffect, useState, useContext } 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 {
|
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,
|
|
|
|
///: 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';
|
2022-12-13 19:08:28 +01:00
|
|
|
import { getCompletedOnboarding } from '../../ducks/metamask/metamask';
|
2021-09-30 23:34:11 +02:00
|
|
|
import {
|
|
|
|
createNewVaultAndGetSeedPhrase,
|
|
|
|
unlockAndGetSeedPhrase,
|
2021-10-13 19:41:24 +02:00
|
|
|
createNewVaultAndRestore,
|
2022-12-13 19:08:28 +01:00
|
|
|
verifySeedPhrase,
|
2021-09-30 23:34:11 +02:00
|
|
|
} from '../../store/actions';
|
|
|
|
import { getFirstTimeFlowTypeRoute } from '../../selectors';
|
2023-01-13 17:11:27 +01:00
|
|
|
import { MetaMetricsContext } from '../../contexts/metametrics';
|
2021-10-11 16:43:25 +02:00
|
|
|
import Button from '../../components/ui/button';
|
|
|
|
import { useI18nContext } from '../../hooks/useI18nContext';
|
2023-04-03 17:31:04 +02:00
|
|
|
import {
|
|
|
|
MetaMetricsEventCategory,
|
|
|
|
MetaMetricsEventName,
|
|
|
|
} from '../../../shared/constants/metametrics';
|
2023-04-25 16:32:51 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-flask)
|
2021-12-01 17:53:30 +01:00
|
|
|
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
|
|
|
|
2023-01-13 17:11:27 +01:00
|
|
|
const TWITTER_URL = 'https://twitter.com/MetaMask';
|
|
|
|
|
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();
|
2022-12-13 19:08:28 +01:00
|
|
|
const { pathName, search } = 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 nextRoute = useSelector(getFirstTimeFlowTypeRoute);
|
2022-12-13 19:08:28 +01:00
|
|
|
const isFromReminder = new URLSearchParams(search).get('isFromReminder');
|
2023-01-13 17:11:27 +01:00
|
|
|
const trackEvent = useContext(MetaMetricsContext);
|
|
|
|
|
2021-09-30 23:34:11 +02:00
|
|
|
useEffect(() => {
|
2022-12-13 19:08:28 +01:00
|
|
|
if (completedOnboarding && !isFromReminder) {
|
2021-09-30 23:34:11 +02:00
|
|
|
history.push(DEFAULT_ROUTE);
|
|
|
|
}
|
2022-12-13 19:08:28 +01:00
|
|
|
}, [history, completedOnboarding, isFromReminder]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const verifyAndSetSeedPhrase = async () => {
|
|
|
|
if (completedOnboarding && !secretRecoveryPhrase) {
|
|
|
|
const verifiedSeedPhrase = await verifySeedPhrase();
|
|
|
|
if (verifiedSeedPhrase) {
|
|
|
|
setSecretRecoveryPhrase(verifiedSeedPhrase);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
verifyAndSetSeedPhrase();
|
|
|
|
}, [completedOnboarding, secretRecoveryPhrase]);
|
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
|
|
|
|
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
|
|
|
{
|
2023-04-25 16:32:51 +02:00
|
|
|
///: BEGIN:ONLY_INCLUDE_IN(build-flask)
|
2021-12-01 17:53:30 +01:00
|
|
|
}
|
|
|
|
<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>
|
2022-12-13 19:08:28 +01:00
|
|
|
{pathName === ONBOARDING_COMPLETION_ROUTE && (
|
2021-10-11 16:43:25 +02:00
|
|
|
<Button
|
|
|
|
className="onboarding-flow__twitter-button"
|
|
|
|
type="link"
|
2023-01-13 17:11:27 +01:00
|
|
|
href={TWITTER_URL}
|
|
|
|
onClick={() => {
|
|
|
|
trackEvent({
|
2023-04-03 17:31:04 +02:00
|
|
|
category: MetaMetricsEventCategory.Onboarding,
|
|
|
|
event: MetaMetricsEventName.OnboardingTwitterClick,
|
2023-01-13 17:11:27 +01:00
|
|
|
properties: {
|
|
|
|
text: t('followUsOnTwitter'),
|
2023-04-03 17:31:04 +02:00
|
|
|
location: MetaMetricsEventName.OnboardingWalletCreationComplete,
|
2023-01-13 17:11:27 +01:00
|
|
|
url: TWITTER_URL,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}}
|
2021-10-11 16:43:25 +02:00
|
|
|
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>
|
|
|
|
);
|
|
|
|
}
|