2021-10-13 16:22:51 +02:00
|
|
|
import EventEmitter from 'events';
|
2023-01-13 17:11:27 +01:00
|
|
|
import React, { useState, useEffect, useContext } from 'react';
|
2023-01-09 21:55:48 +01:00
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
2021-10-13 16:22:51 +02:00
|
|
|
import { useHistory } from 'react-router-dom';
|
|
|
|
import { Carousel } from 'react-responsive-carousel';
|
|
|
|
import Mascot from '../../../components/ui/mascot';
|
|
|
|
import Button from '../../../components/ui/button';
|
2023-03-21 19:17:59 +01:00
|
|
|
import { Text } from '../../../components/component-library';
|
2023-04-14 18:51:13 +02:00
|
|
|
import CheckBox from '../../../components/ui/check-box';
|
|
|
|
import Box from '../../../components/ui/box';
|
2021-10-13 16:22:51 +02:00
|
|
|
import {
|
|
|
|
FONT_WEIGHT,
|
|
|
|
TEXT_ALIGN,
|
2023-03-21 19:17:59 +01:00
|
|
|
TextVariant,
|
2023-04-14 18:51:13 +02:00
|
|
|
AlignItems,
|
2021-10-13 16:22:51 +02:00
|
|
|
} from '../../../helpers/constants/design-system';
|
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
2023-01-13 17:11:27 +01:00
|
|
|
import { MetaMetricsContext } from '../../../contexts/metametrics';
|
2023-04-03 17:31:04 +02:00
|
|
|
import {
|
|
|
|
MetaMetricsEventCategory,
|
|
|
|
MetaMetricsEventName,
|
|
|
|
} from '../../../../shared/constants/metametrics';
|
2023-04-14 18:51:13 +02:00
|
|
|
import {
|
|
|
|
setFirstTimeFlowType,
|
|
|
|
setTermsOfUseLastAgreed,
|
|
|
|
} from '../../../store/actions';
|
2023-01-09 21:55:48 +01:00
|
|
|
import {
|
|
|
|
ONBOARDING_METAMETRICS,
|
|
|
|
ONBOARDING_SECURE_YOUR_WALLET_ROUTE,
|
|
|
|
ONBOARDING_COMPLETION_ROUTE,
|
|
|
|
} from '../../../helpers/constants/routes';
|
|
|
|
import { FIRST_TIME_FLOW_TYPES } from '../../../helpers/constants/onboarding';
|
|
|
|
import { getFirstTimeFlowType, getCurrentKeyring } from '../../../selectors';
|
2021-10-13 16:22:51 +02:00
|
|
|
|
|
|
|
export default function OnboardingWelcome() {
|
|
|
|
const t = useI18nContext();
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
const history = useHistory();
|
|
|
|
const [eventEmitter] = useState(new EventEmitter());
|
2023-01-09 21:55:48 +01:00
|
|
|
const currentKeyring = useSelector(getCurrentKeyring);
|
|
|
|
const firstTimeFlowType = useSelector(getFirstTimeFlowType);
|
2023-04-14 18:51:13 +02:00
|
|
|
const [termsChecked, setTermsChecked] = useState(false);
|
2023-01-09 21:55:48 +01:00
|
|
|
|
|
|
|
// Don't allow users to come back to this screen after they
|
|
|
|
// have already imported or created a wallet
|
|
|
|
useEffect(() => {
|
|
|
|
if (currentKeyring) {
|
|
|
|
if (firstTimeFlowType === FIRST_TIME_FLOW_TYPES.IMPORT) {
|
|
|
|
history.replace(ONBOARDING_COMPLETION_ROUTE);
|
|
|
|
} else {
|
|
|
|
history.replace(ONBOARDING_SECURE_YOUR_WALLET_ROUTE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, [currentKeyring, history, firstTimeFlowType]);
|
2023-01-13 17:11:27 +01:00
|
|
|
const trackEvent = useContext(MetaMetricsContext);
|
2021-10-13 16:22:51 +02:00
|
|
|
|
|
|
|
const onCreateClick = () => {
|
|
|
|
dispatch(setFirstTimeFlowType('create'));
|
2023-01-13 17:11:27 +01:00
|
|
|
trackEvent({
|
2023-04-03 17:31:04 +02:00
|
|
|
category: MetaMetricsEventCategory.Onboarding,
|
|
|
|
event: MetaMetricsEventName.OnboardingWalletCreationStarted,
|
2023-01-13 17:11:27 +01:00
|
|
|
properties: {
|
|
|
|
account_type: 'metamask',
|
|
|
|
},
|
|
|
|
});
|
2023-04-14 18:51:13 +02:00
|
|
|
dispatch(setTermsOfUseLastAgreed(new Date().getTime()));
|
2021-10-20 20:55:59 +02:00
|
|
|
history.push(ONBOARDING_METAMETRICS);
|
2021-10-13 16:22:51 +02:00
|
|
|
};
|
2023-04-14 18:51:13 +02:00
|
|
|
const toggleTermsCheck = () => {
|
|
|
|
setTermsChecked((currentTermsChecked) => !currentTermsChecked);
|
|
|
|
};
|
|
|
|
const termsOfUse = t('agreeTermsOfUse', [
|
|
|
|
<a
|
|
|
|
className="create-new-vault__terms-link"
|
|
|
|
key="create-new-vault__link-text"
|
|
|
|
href="https://metamask.io/terms.html"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
|
|
|
{t('terms')}
|
|
|
|
</a>,
|
|
|
|
]);
|
2021-10-13 16:22:51 +02:00
|
|
|
|
|
|
|
const onImportClick = () => {
|
|
|
|
dispatch(setFirstTimeFlowType('import'));
|
2023-01-13 17:11:27 +01:00
|
|
|
trackEvent({
|
2023-04-03 17:31:04 +02:00
|
|
|
category: MetaMetricsEventCategory.Onboarding,
|
|
|
|
event: MetaMetricsEventName.OnboardingWalletImportStarted,
|
2023-01-13 17:11:27 +01:00
|
|
|
properties: {
|
|
|
|
account_type: 'imported',
|
|
|
|
},
|
|
|
|
});
|
2023-04-14 18:51:13 +02:00
|
|
|
dispatch(setTermsOfUseLastAgreed(new Date().getTime()));
|
2021-10-20 20:55:59 +02:00
|
|
|
history.push(ONBOARDING_METAMETRICS);
|
2021-10-13 16:22:51 +02:00
|
|
|
};
|
|
|
|
|
2023-01-13 17:11:27 +01:00
|
|
|
trackEvent({
|
2023-04-03 17:31:04 +02:00
|
|
|
category: MetaMetricsEventCategory.Onboarding,
|
|
|
|
event: MetaMetricsEventName.OnboardingWelcome,
|
2023-01-13 17:11:27 +01:00
|
|
|
properties: {
|
|
|
|
message_title: t('welcomeToMetaMask'),
|
|
|
|
app_version: global?.platform?.getVersion(),
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-10-13 16:22:51 +02:00
|
|
|
return (
|
2022-08-31 01:53:24 +02:00
|
|
|
<div className="onboarding-welcome" data-testid="onboarding-welcome">
|
2021-10-13 16:22:51 +02:00
|
|
|
<Carousel showThumbs={false} showStatus={false} showArrows>
|
|
|
|
<div>
|
2023-03-21 19:17:59 +01:00
|
|
|
<Text
|
|
|
|
variant={TextVariant.headingLg}
|
|
|
|
as="h2"
|
|
|
|
textAlign={TEXT_ALIGN.CENTER}
|
2021-10-13 16:22:51 +02:00
|
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
|
|
>
|
|
|
|
{t('welcomeToMetaMask')}
|
2023-03-21 19:17:59 +01:00
|
|
|
</Text>
|
|
|
|
<Text textAlign={TEXT_ALIGN.CENTER} marginLeft={6} marginRight={6}>
|
2021-10-13 16:22:51 +02:00
|
|
|
{t('welcomeToMetaMaskIntro')}
|
2023-03-21 19:17:59 +01:00
|
|
|
</Text>
|
2021-10-13 16:22:51 +02:00
|
|
|
<div className="onboarding-welcome__mascot">
|
|
|
|
<Mascot
|
|
|
|
animationEventEmitter={eventEmitter}
|
|
|
|
width="250"
|
|
|
|
height="250"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div>
|
2023-03-21 19:17:59 +01:00
|
|
|
<Text
|
|
|
|
variant={TextVariant.headingLg}
|
|
|
|
as="h2"
|
|
|
|
textAlign={TEXT_ALIGN.CENTER}
|
2021-10-13 16:22:51 +02:00
|
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
|
|
>
|
|
|
|
{t('welcomeExploreTitle')}
|
2023-03-21 19:17:59 +01:00
|
|
|
</Text>
|
|
|
|
<Text textAlign={TEXT_ALIGN.CENTER}>
|
2021-10-13 16:22:51 +02:00
|
|
|
{t('welcomeExploreDescription')}
|
2023-03-21 19:17:59 +01:00
|
|
|
</Text>
|
2021-10-13 16:22:51 +02:00
|
|
|
<div className="onboarding-welcome__image">
|
|
|
|
<img
|
|
|
|
src="/images/onboarding-welcome-say-hello.svg"
|
|
|
|
width="169"
|
|
|
|
height="237"
|
|
|
|
alt=""
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div>
|
2023-03-21 19:17:59 +01:00
|
|
|
<Text
|
|
|
|
variant={TextVariant.headingLg}
|
|
|
|
as="h2"
|
|
|
|
textAlign={TEXT_ALIGN.CENTER}
|
2021-10-13 16:22:51 +02:00
|
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
|
|
>
|
|
|
|
{t('welcomeLoginTitle')}
|
2023-03-21 19:17:59 +01:00
|
|
|
</Text>
|
|
|
|
<Text textAlign={TEXT_ALIGN.CENTER}>
|
2021-10-13 16:22:51 +02:00
|
|
|
{t('welcomeLoginDescription')}
|
2023-03-21 19:17:59 +01:00
|
|
|
</Text>
|
2021-10-13 16:22:51 +02:00
|
|
|
<div className="onboarding-welcome__image">
|
|
|
|
<img
|
|
|
|
src="/images/onboarding-welcome-decentralised-apps.svg"
|
|
|
|
width="327"
|
|
|
|
height="256"
|
|
|
|
alt=""
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</Carousel>
|
|
|
|
<ul className="onboarding-welcome__buttons">
|
2023-04-14 18:51:13 +02:00
|
|
|
<li>
|
|
|
|
<Box
|
|
|
|
alignItems={AlignItems.center}
|
|
|
|
className="onboarding__terms-of-use"
|
|
|
|
>
|
|
|
|
<CheckBox
|
|
|
|
id="onboarding__terms-checkbox"
|
|
|
|
className="onboarding__terms-checkbox"
|
|
|
|
dataTestId="onboarding-terms-checkbox"
|
|
|
|
checked={termsChecked}
|
|
|
|
onClick={toggleTermsCheck}
|
|
|
|
/>
|
|
|
|
<label
|
|
|
|
className="onboarding__terms-label"
|
|
|
|
htmlFor="onboarding__terms-checkbox"
|
|
|
|
>
|
|
|
|
<Text variant={TextVariant.bodyMd} marginLeft={2} as="span">
|
|
|
|
{termsOfUse}
|
|
|
|
</Text>
|
|
|
|
</label>
|
|
|
|
</Box>
|
|
|
|
</li>
|
|
|
|
|
2021-10-13 16:22:51 +02:00
|
|
|
<li>
|
2021-11-10 18:27:10 +01:00
|
|
|
<Button
|
|
|
|
data-testid="onboarding-create-wallet"
|
|
|
|
type="primary"
|
|
|
|
onClick={onCreateClick}
|
2023-04-14 18:51:13 +02:00
|
|
|
disabled={!termsChecked}
|
2021-11-10 18:27:10 +01:00
|
|
|
>
|
2021-10-13 16:22:51 +02:00
|
|
|
{t('onboardingCreateWallet')}
|
|
|
|
</Button>
|
|
|
|
</li>
|
|
|
|
<li>
|
2021-11-10 18:27:10 +01:00
|
|
|
<Button
|
|
|
|
data-testid="onboarding-import-wallet"
|
|
|
|
type="secondary"
|
|
|
|
onClick={onImportClick}
|
2023-04-14 18:51:13 +02:00
|
|
|
disabled={!termsChecked}
|
2021-11-10 18:27:10 +01:00
|
|
|
>
|
2021-10-13 16:22:51 +02:00
|
|
|
{t('onboardingImportWallet')}
|
|
|
|
</Button>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|