mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
1304ec7af5
We want to convert NetworkController to TypeScript in order to be able to compare differences in the controller between in this repo and the core repo. To do this, however, we need to convert the dependencies of the controller to TypeScript. As a part of this effort, this commit converts `shared/constants/metametrics` to TypeScript. Note that simple objects have been largely replaced with enums. There are some cases where I even split up some of these objects into multiple enums. Co-authored-by: Mark Stacey <markjstacey@gmail.com>
172 lines
5.3 KiB
JavaScript
172 lines
5.3 KiB
JavaScript
import EventEmitter from 'events';
|
|
import React, { useState, useEffect, useContext } from 'react';
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
import { useHistory } from 'react-router-dom';
|
|
import { Carousel } from 'react-responsive-carousel';
|
|
import Mascot from '../../../components/ui/mascot';
|
|
import Button from '../../../components/ui/button';
|
|
import { Text } from '../../../components/component-library';
|
|
import {
|
|
FONT_WEIGHT,
|
|
TEXT_ALIGN,
|
|
TextVariant,
|
|
} from '../../../helpers/constants/design-system';
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
|
import { MetaMetricsContext } from '../../../contexts/metametrics';
|
|
import {
|
|
MetaMetricsEventCategory,
|
|
MetaMetricsEventName,
|
|
} from '../../../../shared/constants/metametrics';
|
|
import { setFirstTimeFlowType } from '../../../store/actions';
|
|
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';
|
|
|
|
export default function OnboardingWelcome() {
|
|
const t = useI18nContext();
|
|
const dispatch = useDispatch();
|
|
const history = useHistory();
|
|
const [eventEmitter] = useState(new EventEmitter());
|
|
const currentKeyring = useSelector(getCurrentKeyring);
|
|
const firstTimeFlowType = useSelector(getFirstTimeFlowType);
|
|
|
|
// 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]);
|
|
const trackEvent = useContext(MetaMetricsContext);
|
|
|
|
const onCreateClick = () => {
|
|
dispatch(setFirstTimeFlowType('create'));
|
|
trackEvent({
|
|
category: MetaMetricsEventCategory.Onboarding,
|
|
event: MetaMetricsEventName.OnboardingWalletCreationStarted,
|
|
properties: {
|
|
account_type: 'metamask',
|
|
},
|
|
});
|
|
history.push(ONBOARDING_METAMETRICS);
|
|
};
|
|
|
|
const onImportClick = () => {
|
|
dispatch(setFirstTimeFlowType('import'));
|
|
trackEvent({
|
|
category: MetaMetricsEventCategory.Onboarding,
|
|
event: MetaMetricsEventName.OnboardingWalletImportStarted,
|
|
properties: {
|
|
account_type: 'imported',
|
|
},
|
|
});
|
|
history.push(ONBOARDING_METAMETRICS);
|
|
};
|
|
|
|
trackEvent({
|
|
category: MetaMetricsEventCategory.Onboarding,
|
|
event: MetaMetricsEventName.OnboardingWelcome,
|
|
properties: {
|
|
message_title: t('welcomeToMetaMask'),
|
|
app_version: global?.platform?.getVersion(),
|
|
},
|
|
});
|
|
|
|
return (
|
|
<div className="onboarding-welcome" data-testid="onboarding-welcome">
|
|
<Carousel showThumbs={false} showStatus={false} showArrows>
|
|
<div>
|
|
<Text
|
|
variant={TextVariant.headingLg}
|
|
as="h2"
|
|
textAlign={TEXT_ALIGN.CENTER}
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
>
|
|
{t('welcomeToMetaMask')}
|
|
</Text>
|
|
<Text textAlign={TEXT_ALIGN.CENTER} marginLeft={6} marginRight={6}>
|
|
{t('welcomeToMetaMaskIntro')}
|
|
</Text>
|
|
<div className="onboarding-welcome__mascot">
|
|
<Mascot
|
|
animationEventEmitter={eventEmitter}
|
|
width="250"
|
|
height="250"
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<Text
|
|
variant={TextVariant.headingLg}
|
|
as="h2"
|
|
textAlign={TEXT_ALIGN.CENTER}
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
>
|
|
{t('welcomeExploreTitle')}
|
|
</Text>
|
|
<Text textAlign={TEXT_ALIGN.CENTER}>
|
|
{t('welcomeExploreDescription')}
|
|
</Text>
|
|
<div className="onboarding-welcome__image">
|
|
<img
|
|
src="/images/onboarding-welcome-say-hello.svg"
|
|
width="169"
|
|
height="237"
|
|
alt=""
|
|
/>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<Text
|
|
variant={TextVariant.headingLg}
|
|
as="h2"
|
|
textAlign={TEXT_ALIGN.CENTER}
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
>
|
|
{t('welcomeLoginTitle')}
|
|
</Text>
|
|
<Text textAlign={TEXT_ALIGN.CENTER}>
|
|
{t('welcomeLoginDescription')}
|
|
</Text>
|
|
<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">
|
|
<li>
|
|
<Button
|
|
data-testid="onboarding-create-wallet"
|
|
type="primary"
|
|
onClick={onCreateClick}
|
|
>
|
|
{t('onboardingCreateWallet')}
|
|
</Button>
|
|
</li>
|
|
<li>
|
|
<Button
|
|
data-testid="onboarding-import-wallet"
|
|
type="secondary"
|
|
onClick={onImportClick}
|
|
>
|
|
{t('onboardingImportWallet')}
|
|
</Button>
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
);
|
|
}
|