import React, { useContext, useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { useHistory } from 'react-router-dom'; import { addUrlProtocolPrefix } from '../../../../app/scripts/lib/util'; import { MetaMetricsEventCategory, MetaMetricsEventName, } from '../../../../shared/constants/metametrics'; import { COINGECKO_LINK, CRYPTOCOMPARE_LINK, PRIVACY_POLICY_LINK, } from '../../../../shared/lib/ui-utils'; import { PickerNetwork, TextField, } from '../../../components/component-library'; import Box from '../../../components/ui/box/box'; import Button from '../../../components/ui/button'; import Typography from '../../../components/ui/typography'; import { MetaMetricsContext } from '../../../contexts/metametrics'; import { FONT_WEIGHT, TextColor, TypographyVariant, } from '../../../helpers/constants/design-system'; import { ONBOARDING_PIN_EXTENSION_ROUTE } from '../../../helpers/constants/routes'; import { useI18nContext } from '../../../hooks/useI18nContext'; import { getCurrentNetwork } from '../../../selectors'; import { setCompletedOnboarding, setFeatureFlag, setIpfsGateway, setUseCurrencyRateCheck, setUseMultiAccountBalanceChecker, setUsePhishDetect, setUseTokenDetection, showModal, toggleNetworkMenu, } from '../../../store/actions'; import { Setting } from './setting'; export default function PrivacySettings() { const t = useI18nContext(); const dispatch = useDispatch(); const history = useHistory(); const [usePhishingDetection, setUsePhishingDetection] = useState(true); const [turnOnTokenDetection, setTurnOnTokenDetection] = useState(true); const [turnOnCurrencyRateCheck, setTurnOnCurrencyRateCheck] = useState(true); const [showIncomingTransactions, setShowIncomingTransactions] = useState(true); const [ isMultiAccountBalanceCheckerEnabled, setMultiAccountBalanceCheckerEnabled, ] = useState(true); const [ipfsURL, setIPFSURL] = useState(''); const [ipfsError, setIPFSError] = useState(null); const trackEvent = useContext(MetaMetricsContext); const currentNetwork = useSelector(getCurrentNetwork); const handleSubmit = () => { dispatch( setFeatureFlag('showIncomingTransactions', showIncomingTransactions), ); dispatch(setUsePhishDetect(usePhishingDetection)); dispatch(setUseTokenDetection(turnOnTokenDetection)); dispatch( setUseMultiAccountBalanceChecker(isMultiAccountBalanceCheckerEnabled), ); dispatch(setUseCurrencyRateCheck(turnOnCurrencyRateCheck)); dispatch(setCompletedOnboarding()); if (ipfsURL && !ipfsError) { const { host } = new URL(addUrlProtocolPrefix(ipfsURL)); dispatch(setIpfsGateway(host)); } trackEvent({ category: MetaMetricsEventCategory.Onboarding, event: MetaMetricsEventName.OnboardingWalletAdvancedSettings, properties: { show_incoming_tx: showIncomingTransactions, use_phising_detection: usePhishingDetection, turnon_token_detection: turnOnTokenDetection, }, }); history.push(ONBOARDING_PIN_EXTENSION_ROUTE); }; const handleIPFSChange = (url) => { setIPFSURL(url); try { const { host } = new URL(addUrlProtocolPrefix(url)); if (!host || host === 'gateway.ipfs.io') { throw new Error(); } setIPFSError(null); } catch (error) { setIPFSError(t('onboardingAdvancedPrivacyIPFSInvalid')); } }; return ( <>