2023-06-20 20:27:10 +02:00
|
|
|
import React, { useContext, useState } from 'react';
|
2022-12-08 17:42:23 +01:00
|
|
|
import { useDispatch, useSelector } from 'react-redux';
|
2023-06-20 20:27:10 +02:00
|
|
|
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';
|
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';
|
2023-06-20 20:27:10 +02:00
|
|
|
import { MetaMetricsContext } from '../../../contexts/metametrics';
|
2021-10-08 21:50:36 +02:00
|
|
|
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';
|
2023-06-20 20:27:10 +02:00
|
|
|
import { ONBOARDING_PIN_EXTENSION_ROUTE } from '../../../helpers/constants/routes';
|
2021-10-08 21:50:36 +02:00
|
|
|
import { useI18nContext } from '../../../hooks/useI18nContext';
|
2023-06-20 20:27:10 +02:00
|
|
|
import { getCurrentNetwork } from '../../../selectors';
|
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,
|
2023-06-20 20:27:10 +02:00
|
|
|
setIpfsGateway,
|
|
|
|
setUseCurrencyRateCheck,
|
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,
|
2023-06-01 23:14:38 +02:00
|
|
|
toggleNetworkMenu,
|
2021-10-08 21:50:36 +02:00
|
|
|
} 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);
|
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
|
|
|
|
2023-06-01 23:14:38 +02:00
|
|
|
const currentNetwork = useSelector(getCurrentNetwork);
|
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({
|
2023-04-03 17:31:04 +02:00
|
|
|
category: MetaMetricsEventCategory.Onboarding,
|
|
|
|
event: MetaMetricsEventName.OnboardingWalletAdvancedSettings,
|
2023-01-13 17:11:27 +01:00
|
|
|
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-06-01 23:14:38 +02:00
|
|
|
{currentNetwork ? (
|
2022-12-08 17:42:23 +01:00
|
|
|
<div className="privacy-settings__network">
|
|
|
|
<>
|
2023-06-01 23:14:38 +02:00
|
|
|
<PickerNetwork
|
|
|
|
label={currentNetwork?.nickname}
|
|
|
|
src={currentNetwork?.rpcPrefs?.imageUrl}
|
|
|
|
onClick={() => dispatch(toggleNetworkMenu())}
|
2022-12-08 17:42:23 +01:00
|
|
|
/>
|
|
|
|
</>
|
|
|
|
</div>
|
2023-06-01 23:14:38 +02:00
|
|
|
) : (
|
2022-12-08 17:42:23 +01:00
|
|
|
<Button
|
|
|
|
type="secondary"
|
|
|
|
rounded
|
|
|
|
large
|
|
|
|
onClick={(e) => {
|
|
|
|
e.preventDefault();
|
|
|
|
dispatch(showModal({ name: 'ONBOARDING_ADD_NETWORK' }));
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{t('onboardingAdvancedPrivacyNetworkButton')}
|
|
|
|
</Button>
|
2023-06-01 23:14:38 +02:00
|
|
|
)}
|
2022-12-08 17:42:23 +01:00
|
|
|
</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>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
}
|