import React, { useState, useContext } from 'react'; import { useHistory } from 'react-router-dom'; import { useDispatch, useSelector } from 'react-redux'; import Box from '../../../components/ui/box/box'; import Button from '../../../components/ui/button'; import Typography from '../../../components/ui/typography'; import { FONT_WEIGHT, TextColor, TypographyVariant, } from '../../../helpers/constants/design-system'; import { useI18nContext } from '../../../hooks/useI18nContext'; import { addUrlProtocolPrefix } from '../../../helpers/utils/ipfs'; import { setCompletedOnboarding, setFeatureFlag, setUseMultiAccountBalanceChecker, setUsePhishDetect, setUseTokenDetection, showModal, setIpfsGateway, setUseCurrencyRateCheck, toggleNetworkMenu, } from '../../../store/actions'; import { getCurrentNetwork } from '../../../selectors'; import { ONBOARDING_PIN_EXTENSION_ROUTE } from '../../../helpers/constants/routes'; import { TextField, PickerNetwork, } from '../../../components/component-library'; import { COINGECKO_LINK, CRYPTOCOMPARE_LINK, PRIVACY_POLICY_LINK, } from '../../../../shared/lib/ui-utils'; import { MetaMetricsContext } from '../../../contexts/metametrics'; import { MetaMetricsEventCategory, MetaMetricsEventName, } from '../../../../shared/constants/metametrics'; 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 ( <>
{t('advancedConfiguration')} {t('setAdvancedPrivacySettingsDetails')}
{t('etherscan')} , {t('privacyMsg')} , ])} /> {t('jsDeliver')} , {t('privacyMsg')} , ])} /> {t('onboardingAdvancedPrivacyNetworkDescription', [ {t('privacyMsg')} , ])} {currentNetwork ? (
<> dispatch(toggleNetworkMenu())} />
) : ( )}
} /> {t('onboardingAdvancedPrivacyIPFSDescription')} { handleIPFSChange(e.target.value); }} /> {ipfsURL ? ( {ipfsError || t('onboardingAdvancedPrivacyIPFSValid')} ) : null} } /> {t('coingecko')} , {t('cryptoCompare')} , {t('privacyMsg')} , ])} />
); }