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 { MetaMetricsContext } from '../../../contexts/metametrics'; const firstTimeFlowTypeNameMap = { create: 'Selected Create New Wallet', import: 'Selected Import Wallet', }; 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 firstTimeSelectionMetaMetricsName = firstTimeFlowTypeNameMap[firstTimeFlowType]; const metricsEvent = useContext(MetaMetricsContext); const onConfirm = async () => { const [, metaMetricsId] = await dispatch(setParticipateInMetaMetrics(true)); try { if (!participateInMetaMetrics) { metricsEvent({ eventOpts: { category: 'Onboarding', action: 'Metrics Option', name: 'Metrics Opt In', }, isOptIn: true, flushImmediately: true, }); } metricsEvent({ eventOpts: { category: 'Onboarding', action: 'Import or Create', name: firstTimeSelectionMetaMetricsName, }, isOptIn: true, metaMetricsId, flushImmediately: true, }); } finally { history.push(nextRoute); } }; const onCancel = async () => { await dispatch(setParticipateInMetaMetrics(false)); try { if (!participateInMetaMetrics) { metricsEvent({ eventOpts: { category: 'Onboarding', action: 'Metrics Option', name: 'Metrics Opt Out', }, isOptIn: true, flushImmediately: true, }); } } finally { history.push(nextRoute); } }; return (