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, showNetworkDropdown, setUseCurrencyRateCheck, } from '../../../store/actions'; import { ONBOARDING_PIN_EXTENSION_ROUTE } from '../../../helpers/constants/routes'; import { Icon, TextField } from '../../../components/component-library'; import NetworkDropdown from '../../../components/app/dropdowns/network-dropdown'; import NetworkDisplay from '../../../components/app/network-display/network-display'; import { COINGECKO_LINK, CRYPTOCOMPARE_LINK, PRIVACY_POLICY_LINK, } from '../../../../shared/lib/ui-utils'; import { MetaMetricsContext } from '../../../contexts/metametrics'; import { EVENT_NAMES, EVENT } 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 networks = useSelector( (state) => state.metamask.networkConfigurations || {}, ); 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: EVENT.CATEGORIES.ONBOARDING, event: EVENT_NAMES.ONBOARDING_WALLET_ADVANCED_SETTINGS, 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')} , ])} {Object.values(networks).length > 1 ? (
<> dispatch(showNetworkDropdown())} /> { dispatch( showModal({ name: 'ONBOARDING_ADD_NETWORK' }), ); }} />
) : null} {Object.values(networks).length === 1 ? ( ) : null}
} /> {t('onboardingAdvancedPrivacyIPFSDescription')} { handleIPFSChange(e.target.value); }} /> {ipfsURL ? ( {ipfsError || t('onboardingAdvancedPrivacyIPFSValid')} ) : null} } /> {t('coingecko')} , {t('cryptoCompare')} , {t('privacyMsg')} , ])} />
); }