import React, { useContext } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { useHistory } from 'react-router-dom'; import Typography from '../../../components/ui/typography/typography'; import { TYPOGRAPHY, FONT_WEIGHT, TEXT_ALIGN, COLORS, } from '../../../helpers/constants/design-system'; import Button from '../../../components/ui/button'; import { useI18nContext } from '../../../hooks/useI18nContext'; import { setParticipateInMetaMetrics } from '../../../store/actions'; import { getFirstTimeFlowTypeRoute, getFirstTimeFlowType, getParticipateInMetaMetrics, } from '../../../selectors'; import { EVENT, EVENT_NAMES } from '../../../../shared/constants/metametrics'; import { MetaMetricsContext } from '../../../contexts/metametrics'; export default function OnboardingMetametrics() { const t = useI18nContext(); const dispatch = useDispatch(); const history = useHistory(); const nextRoute = useSelector(getFirstTimeFlowTypeRoute); const firstTimeFlowType = useSelector(getFirstTimeFlowType); const participateInMetaMetrics = useSelector(getParticipateInMetaMetrics); const trackEvent = useContext(MetaMetricsContext); const onConfirm = async () => { const [, metaMetricsId] = await dispatch(setParticipateInMetaMetrics(true)); const isInitiallyNotParticipating = !participateInMetaMetrics; try { if (isInitiallyNotParticipating) { trackEvent( { category: EVENT.CATEGORIES.ONBOARDING, event: EVENT_NAMES.METRICS_OPT_IN, properties: { action: 'Metrics Option', legacy_event: true, }, }, { isOptIn: true, flushImmediately: true, }, ); } trackEvent( { category: EVENT.CATEGORIES.ONBOARDING, event: EVENT_NAMES.WALLET_SETUP_STARTED, properties: { account_type: firstTimeFlowType === 'create' ? EVENT.ACCOUNT_TYPES.DEFAULT : EVENT.ACCOUNT_TYPES.IMPORTED, }, }, { isOptIn: true, metaMetricsId, flushImmediately: true, }, ); } finally { history.push(nextRoute); } }; const onCancel = async () => { await dispatch(setParticipateInMetaMetrics(false)); const isInitiallyParticipatingOrNotSet = participateInMetaMetrics === null || participateInMetaMetrics; try { if (isInitiallyParticipatingOrNotSet) { trackEvent( { category: EVENT.CATEGORIES.ONBOARDING, event: EVENT_NAMES.METRICS_OPT_OUT, properties: { action: 'Metrics Option', legacy_event: true, }, }, { isOptIn: true, flushImmediately: true, }, ); } } finally { history.push(nextRoute); } }; return (
{t('metametricsTitle')} {t('metametricsOptInDescription2')} {t('gdprMessage', [ {t('gdprMessagePrivacyPolicy')} , ])}
); }