2023-01-13 17:11:27 +01:00
|
|
|
import React, { useState, useContext } from 'react';
|
2022-12-08 17:42:23 +01:00
|
|
|
|
2021-10-08 21:50:36 +02:00
|
|
|
import { useHistory } from 'react-router-dom';
|
2022-12-08 17:42:23 +01:00
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
2021-10-08 21:50:36 +02:00
|
|
|
|
2022-12-08 17:42:23 +01:00
|
|
|
import Box from '../../../components/ui/box/box';
|
2021-10-08 21:50:36 +02:00
|
|
|
import Button from '../../../components/ui/button';
|
|
|
|
import Typography from '../../../components/ui/typography';
|
|
|
|
import {
|
|
|
|
FONT_WEIGHT,
|
2023-02-02 21:15:26 +01:00
|
|
|
TextColor,
|
|
|
|
TypographyVariant,
|
2021-10-08 21:50:36 +02:00
|
|
|
} from '../../../helpers/constants/design-system';
|
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
2022-12-08 17:42:23 +01:00
|
|
|
import { addUrlProtocolPrefix } from '../../../helpers/utils/ipfs';
|
2021-10-08 21:50:36 +02:00
|
|
|
import {
|
2021-10-20 20:55:59 +02:00
|
|
|
setCompletedOnboarding,
|
2021-10-08 21:50:36 +02:00
|
|
|
setFeatureFlag,
|
2022-12-01 22:16:04 +01:00
|
|
|
setUseMultiAccountBalanceChecker,
|
2021-10-08 21:50:36 +02:00
|
|
|
setUsePhishDetect,
|
|
|
|
setUseTokenDetection,
|
2022-12-08 17:42:23 +01:00
|
|
|
showModal,
|
|
|
|
setIpfsGateway,
|
|
|
|
showNetworkDropdown,
|
2023-01-17 16:23:04 +01:00
|
|
|
setUseCurrencyRateCheck,
|
2021-10-08 21:50:36 +02:00
|
|
|
} from '../../../store/actions';
|
|
|
|
import { ONBOARDING_PIN_EXTENSION_ROUTE } from '../../../helpers/constants/routes';
|
2022-12-08 17:42:23 +01:00
|
|
|
import { Icon, TextField } from '../../../components/component-library';
|
|
|
|
import NetworkDropdown from '../../../components/app/dropdowns/network-dropdown';
|
|
|
|
import NetworkDisplay from '../../../components/app/network-display/network-display';
|
2023-01-17 16:23:04 +01:00
|
|
|
import {
|
|
|
|
COINGECKO_LINK,
|
|
|
|
CRYPTOCOMPARE_LINK,
|
|
|
|
PRIVACY_POLICY_LINK,
|
|
|
|
} from '../../../../shared/lib/ui-utils';
|
2023-01-13 17:11:27 +01:00
|
|
|
import { MetaMetricsContext } from '../../../contexts/metametrics';
|
|
|
|
import { EVENT_NAMES, EVENT } from '../../../../shared/constants/metametrics';
|
2023-01-17 16:23:04 +01:00
|
|
|
|
2021-10-08 21:50:36 +02:00
|
|
|
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);
|
2023-01-17 16:23:04 +01:00
|
|
|
const [turnOnCurrencyRateCheck, setTurnOnCurrencyRateCheck] = useState(true);
|
2022-07-31 20:26:40 +02:00
|
|
|
const [showIncomingTransactions, setShowIncomingTransactions] =
|
|
|
|
useState(true);
|
2022-12-01 22:16:04 +01:00
|
|
|
const [
|
|
|
|
isMultiAccountBalanceCheckerEnabled,
|
|
|
|
setMultiAccountBalanceCheckerEnabled,
|
|
|
|
] = useState(true);
|
2022-12-08 17:42:23 +01:00
|
|
|
const [ipfsURL, setIPFSURL] = useState('');
|
|
|
|
const [ipfsError, setIPFSError] = useState(null);
|
2023-01-13 17:11:27 +01:00
|
|
|
const trackEvent = useContext(MetaMetricsContext);
|
2022-12-08 17:42:23 +01:00
|
|
|
|
|
|
|
const networks = useSelector(
|
2023-03-09 22:00:28 +01:00
|
|
|
(state) => state.metamask.networkConfigurations || {},
|
2022-12-08 17:42:23 +01:00
|
|
|
);
|
2021-10-08 21:50:36 +02:00
|
|
|
|
|
|
|
const handleSubmit = () => {
|
|
|
|
dispatch(
|
|
|
|
setFeatureFlag('showIncomingTransactions', showIncomingTransactions),
|
|
|
|
);
|
|
|
|
dispatch(setUsePhishDetect(usePhishingDetection));
|
|
|
|
dispatch(setUseTokenDetection(turnOnTokenDetection));
|
2022-12-01 22:16:04 +01:00
|
|
|
dispatch(
|
|
|
|
setUseMultiAccountBalanceChecker(isMultiAccountBalanceCheckerEnabled),
|
|
|
|
);
|
2023-01-17 16:23:04 +01:00
|
|
|
dispatch(setUseCurrencyRateCheck(turnOnCurrencyRateCheck));
|
2021-10-20 20:55:59 +02:00
|
|
|
dispatch(setCompletedOnboarding());
|
2022-12-08 17:42:23 +01:00
|
|
|
|
|
|
|
if (ipfsURL && !ipfsError) {
|
|
|
|
const { host } = new URL(addUrlProtocolPrefix(ipfsURL));
|
|
|
|
dispatch(setIpfsGateway(host));
|
|
|
|
}
|
|
|
|
|
2023-01-13 17:11:27 +01:00
|
|
|
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,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
2021-10-08 21:50:36 +02:00
|
|
|
history.push(ONBOARDING_PIN_EXTENSION_ROUTE);
|
|
|
|
};
|
|
|
|
|
2022-12-08 17:42:23 +01:00
|
|
|
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'));
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2021-10-08 21:50:36 +02:00
|
|
|
return (
|
|
|
|
<>
|
2022-08-31 01:53:24 +02:00
|
|
|
<div className="privacy-settings" data-testid="privacy-settings">
|
2021-10-08 21:50:36 +02:00
|
|
|
<div className="privacy-settings__header">
|
2023-02-02 21:15:26 +01:00
|
|
|
<Typography
|
|
|
|
variant={TypographyVariant.H2}
|
|
|
|
fontWeight={FONT_WEIGHT.BOLD}
|
|
|
|
>
|
2022-12-08 15:20:59 +01:00
|
|
|
{t('advancedConfiguration')}
|
2021-10-08 21:50:36 +02:00
|
|
|
</Typography>
|
2023-02-02 21:15:26 +01:00
|
|
|
<Typography variant={TypographyVariant.H4}>
|
2021-10-08 21:50:36 +02:00
|
|
|
{t('setAdvancedPrivacySettingsDetails')}
|
|
|
|
</Typography>
|
|
|
|
</div>
|
|
|
|
<div
|
|
|
|
className="privacy-settings__settings"
|
|
|
|
data-testid="privacy-settings-settings"
|
|
|
|
>
|
|
|
|
<Setting
|
|
|
|
value={showIncomingTransactions}
|
|
|
|
setValue={setShowIncomingTransactions}
|
|
|
|
title={t('showIncomingTransactions')}
|
|
|
|
description={t('onboardingShowIncomingTransactionsDescription', [
|
|
|
|
<a
|
|
|
|
key="etherscan"
|
|
|
|
href="https://etherscan.io/"
|
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer"
|
|
|
|
>
|
|
|
|
{t('etherscan')}
|
|
|
|
</a>,
|
|
|
|
<a
|
2022-03-07 18:37:54 +01:00
|
|
|
href="https://etherscan.io/privacyPolicy"
|
2021-10-08 21:50:36 +02:00
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer"
|
|
|
|
key="privacyMsg"
|
|
|
|
>
|
|
|
|
{t('privacyMsg')}
|
|
|
|
</a>,
|
|
|
|
])}
|
|
|
|
/>
|
|
|
|
<Setting
|
|
|
|
value={usePhishingDetection}
|
|
|
|
setValue={setUsePhishingDetection}
|
|
|
|
title={t('usePhishingDetection')}
|
|
|
|
description={t('onboardingUsePhishingDetectionDescription', [
|
|
|
|
<a
|
|
|
|
href="https://www.jsdelivr.com"
|
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer"
|
|
|
|
key="jsDeliver"
|
|
|
|
>
|
|
|
|
{t('jsDeliver')}
|
|
|
|
</a>,
|
|
|
|
<a
|
|
|
|
href="https://www.jsdelivr.com/terms/privacy-policy-jsdelivr-com"
|
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer"
|
|
|
|
key="privacyMsg"
|
|
|
|
>
|
|
|
|
{t('privacyMsg')}
|
|
|
|
</a>,
|
|
|
|
])}
|
|
|
|
/>
|
|
|
|
<Setting
|
|
|
|
value={turnOnTokenDetection}
|
|
|
|
setValue={setTurnOnTokenDetection}
|
|
|
|
title={t('turnOnTokenDetection')}
|
2022-03-07 18:37:54 +01:00
|
|
|
description={t('useTokenDetectionPrivacyDesc')}
|
2021-10-08 21:50:36 +02:00
|
|
|
/>
|
2022-12-01 22:16:04 +01:00
|
|
|
<Setting
|
|
|
|
value={isMultiAccountBalanceCheckerEnabled}
|
|
|
|
setValue={setMultiAccountBalanceCheckerEnabled}
|
|
|
|
title={t('useMultiAccountBalanceChecker')}
|
|
|
|
description={t('useMultiAccountBalanceCheckerDescription')}
|
|
|
|
/>
|
2022-12-08 17:42:23 +01:00
|
|
|
<Setting
|
|
|
|
title={t('onboardingAdvancedPrivacyNetworkTitle')}
|
|
|
|
showToggle={false}
|
|
|
|
description={
|
|
|
|
<>
|
|
|
|
{t('onboardingAdvancedPrivacyNetworkDescription', [
|
|
|
|
<a
|
|
|
|
href="https://consensys.net/privacy-policy/"
|
|
|
|
key="link"
|
|
|
|
target="_blank"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
>
|
|
|
|
{t('privacyMsg')}
|
|
|
|
</a>,
|
|
|
|
])}
|
|
|
|
|
|
|
|
<Box paddingTop={2}>
|
2023-03-09 22:00:28 +01:00
|
|
|
{Object.values(networks).length > 1 ? (
|
2022-12-08 17:42:23 +01:00
|
|
|
<div className="privacy-settings__network">
|
|
|
|
<>
|
|
|
|
<NetworkDisplay
|
|
|
|
onClick={() => dispatch(showNetworkDropdown())}
|
|
|
|
/>
|
|
|
|
<NetworkDropdown
|
|
|
|
hideElementsForOnboarding
|
|
|
|
dropdownStyles={{
|
|
|
|
position: 'absolute',
|
|
|
|
top: '40px',
|
|
|
|
left: '0',
|
|
|
|
width: '309px',
|
|
|
|
zIndex: '55',
|
|
|
|
}}
|
|
|
|
onAddClick={() => {
|
|
|
|
dispatch(
|
|
|
|
showModal({ name: 'ONBOARDING_ADD_NETWORK' }),
|
|
|
|
);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
</div>
|
|
|
|
) : null}
|
2023-03-09 22:00:28 +01:00
|
|
|
{Object.values(networks).length === 1 ? (
|
2022-12-08 17:42:23 +01:00
|
|
|
<Button
|
|
|
|
type="secondary"
|
|
|
|
rounded
|
|
|
|
large
|
|
|
|
onClick={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
dispatch(showModal({ name: 'ONBOARDING_ADD_NETWORK' }));
|
|
|
|
}}
|
2023-01-25 19:11:13 +01:00
|
|
|
icon={<Icon name="add" marginRight={2} />}
|
2022-12-08 17:42:23 +01:00
|
|
|
>
|
|
|
|
{t('onboardingAdvancedPrivacyNetworkButton')}
|
|
|
|
</Button>
|
|
|
|
) : null}
|
|
|
|
</Box>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<Setting
|
|
|
|
title={t('onboardingAdvancedPrivacyIPFSTitle')}
|
|
|
|
showToggle={false}
|
|
|
|
description={
|
|
|
|
<>
|
|
|
|
{t('onboardingAdvancedPrivacyIPFSDescription')}
|
|
|
|
<Box paddingTop={2}>
|
|
|
|
<TextField
|
|
|
|
style={{ width: '100%' }}
|
2023-03-31 04:27:36 +02:00
|
|
|
inputProps={{ 'data-testid': 'ipfs-input' }}
|
2022-12-08 17:42:23 +01:00
|
|
|
onChange={(e) => {
|
|
|
|
handleIPFSChange(e.target.value);
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
{ipfsURL ? (
|
|
|
|
<Typography
|
2023-02-02 21:15:26 +01:00
|
|
|
variant={TypographyVariant.H7}
|
2022-12-08 17:42:23 +01:00
|
|
|
color={
|
|
|
|
ipfsError
|
2023-02-02 21:15:26 +01:00
|
|
|
? TextColor.errorDefault
|
|
|
|
: TextColor.successDefault
|
2022-12-08 17:42:23 +01:00
|
|
|
}
|
|
|
|
>
|
|
|
|
{ipfsError || t('onboardingAdvancedPrivacyIPFSValid')}
|
|
|
|
</Typography>
|
|
|
|
) : null}
|
|
|
|
</Box>
|
|
|
|
</>
|
|
|
|
}
|
|
|
|
/>
|
2023-01-17 16:23:04 +01:00
|
|
|
<Setting
|
|
|
|
value={turnOnCurrencyRateCheck}
|
|
|
|
setValue={setTurnOnCurrencyRateCheck}
|
|
|
|
title={t('currencyRateCheckToggle')}
|
|
|
|
description={t('currencyRateCheckToggleDescription', [
|
|
|
|
<a
|
|
|
|
key="coingecko_link"
|
|
|
|
href={COINGECKO_LINK}
|
|
|
|
rel="noreferrer"
|
|
|
|
target="_blank"
|
|
|
|
>
|
|
|
|
{t('coingecko')}
|
|
|
|
</a>,
|
|
|
|
<a
|
|
|
|
key="cryptocompare_link"
|
|
|
|
href={CRYPTOCOMPARE_LINK}
|
|
|
|
rel="noreferrer"
|
|
|
|
target="_blank"
|
|
|
|
>
|
|
|
|
{t('cryptoCompare')}
|
|
|
|
</a>,
|
|
|
|
<a
|
|
|
|
key="privacy_policy_link"
|
|
|
|
href={PRIVACY_POLICY_LINK}
|
|
|
|
rel="noreferrer"
|
|
|
|
target="_blank"
|
|
|
|
>
|
|
|
|
{t('privacyMsg')}
|
|
|
|
</a>,
|
|
|
|
])}
|
|
|
|
/>
|
2021-10-08 21:50:36 +02:00
|
|
|
</div>
|
|
|
|
<Button type="primary" rounded onClick={handleSubmit}>
|
|
|
|
{t('done')}
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|