2021-09-20 18:22:04 +02:00
|
|
|
import React, { PureComponent } from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
import ToggleButton from '../../../components/ui/toggle-button';
|
2022-02-22 21:58:21 +01:00
|
|
|
import {
|
2022-04-06 22:27:08 +02:00
|
|
|
getNumberOfSettingsInSection,
|
2022-02-22 21:58:21 +01:00
|
|
|
handleSettingsRefs,
|
|
|
|
} from '../../../helpers/utils/settings-search';
|
2022-04-22 18:09:10 +02:00
|
|
|
import { EVENT } from '../../../../shared/constants/metametrics';
|
2022-03-07 19:53:19 +01:00
|
|
|
|
2021-09-20 18:22:04 +02:00
|
|
|
export default class ExperimentalTab extends PureComponent {
|
|
|
|
static contextTypes = {
|
|
|
|
t: PropTypes.func,
|
2022-03-29 15:46:24 +02:00
|
|
|
trackEvent: PropTypes.func,
|
2021-09-20 18:22:04 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static propTypes = {
|
2022-11-15 19:49:42 +01:00
|
|
|
useNftDetection: PropTypes.bool,
|
|
|
|
setUseNftDetection: PropTypes.func,
|
2021-12-01 05:12:27 +01:00
|
|
|
setOpenSeaEnabled: PropTypes.func,
|
2022-01-11 20:17:56 +01:00
|
|
|
openSeaEnabled: PropTypes.bool,
|
|
|
|
eip1559V2Enabled: PropTypes.bool,
|
|
|
|
setEIP1559V2Enabled: PropTypes.func,
|
2022-11-08 18:21:38 +01:00
|
|
|
improvedTokenAllowanceEnabled: PropTypes.bool,
|
|
|
|
setImprovedTokenAllowanceEnabled: PropTypes.func,
|
2022-11-17 15:13:02 +01:00
|
|
|
transactionSecurityCheckEnabled: PropTypes.bool,
|
|
|
|
setTransactionSecurityCheckEnabled: PropTypes.func,
|
2021-09-20 18:22:04 +02:00
|
|
|
};
|
|
|
|
|
2022-02-22 21:58:21 +01:00
|
|
|
settingsRefs = Array(
|
2022-04-06 22:27:08 +02:00
|
|
|
getNumberOfSettingsInSection(
|
|
|
|
this.context.t,
|
|
|
|
this.context.t('experimental'),
|
|
|
|
),
|
2022-02-22 21:58:21 +01:00
|
|
|
)
|
|
|
|
.fill(undefined)
|
|
|
|
.map(() => {
|
|
|
|
return React.createRef();
|
|
|
|
});
|
|
|
|
|
|
|
|
componentDidUpdate() {
|
|
|
|
const { t } = this.context;
|
|
|
|
handleSettingsRefs(t, t('experimental'), this.settingsRefs);
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
const { t } = this.context;
|
|
|
|
handleSettingsRefs(t, t('experimental'), this.settingsRefs);
|
|
|
|
}
|
|
|
|
|
2021-11-26 19:54:57 +01:00
|
|
|
renderCollectibleDetectionToggle() {
|
2021-12-01 23:10:24 +01:00
|
|
|
if (!process.env.COLLECTIBLES_V1) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2021-11-26 19:54:57 +01:00
|
|
|
const { t } = this.context;
|
2021-12-01 05:12:27 +01:00
|
|
|
const {
|
2022-11-15 19:49:42 +01:00
|
|
|
useNftDetection,
|
|
|
|
setUseNftDetection,
|
2021-12-01 05:12:27 +01:00
|
|
|
openSeaEnabled,
|
2022-01-27 18:26:33 +01:00
|
|
|
setOpenSeaEnabled,
|
2021-12-01 05:12:27 +01:00
|
|
|
} = this.props;
|
2021-11-26 19:54:57 +01:00
|
|
|
|
|
|
|
return (
|
2022-02-22 21:58:21 +01:00
|
|
|
<div
|
|
|
|
ref={this.settingsRefs[2]}
|
|
|
|
className="settings-page__content-row--dependent"
|
|
|
|
>
|
2021-11-26 19:54:57 +01:00
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<span>{t('useCollectibleDetection')}</span>
|
|
|
|
<div className="settings-page__content-description">
|
|
|
|
{t('useCollectibleDetectionDescription')}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<div className="settings-page__content-item-col">
|
|
|
|
<ToggleButton
|
2022-11-15 19:49:42 +01:00
|
|
|
value={useNftDetection}
|
2021-11-26 19:54:57 +01:00
|
|
|
onToggle={(value) => {
|
2022-03-29 15:46:24 +02:00
|
|
|
this.context.trackEvent({
|
2022-04-22 18:09:10 +02:00
|
|
|
category: EVENT.CATEGORIES.SETTINGS,
|
2022-03-29 15:46:24 +02:00
|
|
|
event: 'Collectible Detection',
|
|
|
|
properties: {
|
2021-11-26 19:54:57 +01:00
|
|
|
action: 'Collectible Detection',
|
2022-03-29 15:46:24 +02:00
|
|
|
legacy_event: true,
|
2021-11-26 19:54:57 +01:00
|
|
|
},
|
|
|
|
});
|
2022-01-27 18:26:33 +01:00
|
|
|
if (!value && !openSeaEnabled) {
|
|
|
|
setOpenSeaEnabled(!value);
|
|
|
|
}
|
2022-11-15 19:49:42 +01:00
|
|
|
setUseNftDetection(!value);
|
2021-11-26 19:54:57 +01:00
|
|
|
}}
|
|
|
|
offLabel={t('off')}
|
|
|
|
onLabel={t('on')}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-12-01 05:12:27 +01:00
|
|
|
renderOpenSeaEnabledToggle() {
|
2021-12-01 23:10:24 +01:00
|
|
|
if (!process.env.COLLECTIBLES_V1) {
|
|
|
|
return null;
|
|
|
|
}
|
2021-12-01 05:12:27 +01:00
|
|
|
const { t } = this.context;
|
2022-01-27 18:26:33 +01:00
|
|
|
const {
|
|
|
|
openSeaEnabled,
|
|
|
|
setOpenSeaEnabled,
|
2022-11-15 19:49:42 +01:00
|
|
|
useNftDetection,
|
|
|
|
setUseNftDetection,
|
2022-01-27 18:26:33 +01:00
|
|
|
} = this.props;
|
2021-12-01 05:12:27 +01:00
|
|
|
|
|
|
|
return (
|
2022-02-22 21:58:21 +01:00
|
|
|
<div
|
|
|
|
ref={this.settingsRefs[1]}
|
|
|
|
className="settings-page__content-row--parent"
|
|
|
|
>
|
2021-12-01 05:12:27 +01:00
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<span>{t('enableOpenSeaAPI')}</span>
|
|
|
|
<div className="settings-page__content-description">
|
|
|
|
{t('enableOpenSeaAPIDescription')}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<div className="settings-page__content-item-col">
|
|
|
|
<ToggleButton
|
|
|
|
value={openSeaEnabled}
|
|
|
|
onToggle={(value) => {
|
2022-03-29 15:46:24 +02:00
|
|
|
this.context.trackEvent({
|
2022-04-22 18:09:10 +02:00
|
|
|
category: EVENT.CATEGORIES.SETTINGS,
|
2022-03-29 15:46:24 +02:00
|
|
|
event: 'Enabled/Disable OpenSea',
|
|
|
|
properties: {
|
2021-12-01 05:12:27 +01:00
|
|
|
action: 'Enabled/Disable OpenSea',
|
2022-03-29 15:46:24 +02:00
|
|
|
legacy_event: true,
|
2021-12-01 05:12:27 +01:00
|
|
|
},
|
|
|
|
});
|
2022-02-10 21:02:06 +01:00
|
|
|
// value is positive when being toggled off
|
2022-11-15 19:49:42 +01:00
|
|
|
if (value && useNftDetection) {
|
|
|
|
setUseNftDetection(false);
|
2022-01-27 18:26:33 +01:00
|
|
|
}
|
2022-02-10 21:02:06 +01:00
|
|
|
setOpenSeaEnabled(!value);
|
2021-12-01 05:12:27 +01:00
|
|
|
}}
|
|
|
|
offLabel={t('off')}
|
|
|
|
onLabel={t('on')}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-01-11 20:17:56 +01:00
|
|
|
renderEIP1559V2EnabledToggle() {
|
|
|
|
const { t } = this.context;
|
|
|
|
const { eip1559V2Enabled, setEIP1559V2Enabled } = this.props;
|
|
|
|
|
|
|
|
return (
|
2022-03-28 16:50:32 +02:00
|
|
|
<div ref={this.settingsRefs[3]} className="settings-page__content-row">
|
2022-01-11 20:17:56 +01:00
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<span>{t('enableEIP1559V2')}</span>
|
|
|
|
<div className="settings-page__content-description">
|
|
|
|
{t('enableEIP1559V2Description', [
|
|
|
|
<a
|
|
|
|
key="eip_page_link"
|
|
|
|
href="https://metamask.io/1559.html"
|
|
|
|
rel="noopener noreferrer"
|
|
|
|
target="_blank"
|
|
|
|
>
|
|
|
|
{t('learnMoreUpperCase')}
|
|
|
|
</a>,
|
|
|
|
])}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<div className="settings-page__content-item-col">
|
|
|
|
<ToggleButton
|
|
|
|
value={eip1559V2Enabled}
|
|
|
|
onToggle={(value) => {
|
2022-03-29 15:46:24 +02:00
|
|
|
this.context.trackEvent({
|
2022-04-22 18:09:10 +02:00
|
|
|
category: EVENT.CATEGORIES.SETTINGS,
|
2022-06-11 01:05:25 +02:00
|
|
|
event: 'Enable/Disable Advanced Gas UI',
|
2022-03-29 15:46:24 +02:00
|
|
|
properties: {
|
2022-06-11 01:05:25 +02:00
|
|
|
action: 'Enable/Disable Advanced Gas UI',
|
2022-03-29 15:46:24 +02:00
|
|
|
legacy_event: true,
|
2022-01-11 20:17:56 +01:00
|
|
|
},
|
|
|
|
});
|
|
|
|
setEIP1559V2Enabled(!value);
|
|
|
|
}}
|
|
|
|
offLabel={t('off')}
|
|
|
|
onLabel={t('on')}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-08 18:21:38 +01:00
|
|
|
renderImprovedTokenAllowanceToggle() {
|
|
|
|
const { t } = this.context;
|
|
|
|
const { improvedTokenAllowanceEnabled, setImprovedTokenAllowanceEnabled } =
|
|
|
|
this.props;
|
|
|
|
|
|
|
|
return (
|
2022-11-17 15:13:02 +01:00
|
|
|
<div ref={this.settingsRefs[2]} className="settings-page__content-row">
|
2022-11-08 18:21:38 +01:00
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<span>{t('improvedTokenAllowance')}</span>
|
|
|
|
<div className="settings-page__content-description">
|
|
|
|
{t('improvedTokenAllowanceDescription')}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<div className="settings-page__content-item-col">
|
|
|
|
<ToggleButton
|
|
|
|
value={improvedTokenAllowanceEnabled}
|
|
|
|
onToggle={(value) => {
|
|
|
|
this.context.trackEvent({
|
|
|
|
category: EVENT.CATEGORIES.SETTINGS,
|
|
|
|
event: 'Enabled/Disable ImprovedTokenAllowance',
|
|
|
|
properties: {
|
|
|
|
action: 'Enabled/Disable ImprovedTokenAllowance',
|
|
|
|
legacy_event: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
setImprovedTokenAllowanceEnabled(!value);
|
|
|
|
}}
|
|
|
|
offLabel={t('off')}
|
|
|
|
onLabel={t('on')}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-11-17 15:13:02 +01:00
|
|
|
renderTransactionSecurityCheckToggle() {
|
|
|
|
const { t } = this.context;
|
|
|
|
|
|
|
|
const {
|
|
|
|
transactionSecurityCheckEnabled,
|
|
|
|
setTransactionSecurityCheckEnabled,
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div ref={this.settingsRefs[1]} className="settings-page__content-row">
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<span>{t('transactionSecurityCheck')}</span>
|
|
|
|
<div className="settings-page__content-description">
|
|
|
|
{t('transactionSecurityCheckDescription')}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="settings-page__content-item">
|
|
|
|
<div className="settings-page__content-item-col">
|
|
|
|
<ToggleButton
|
|
|
|
value={transactionSecurityCheckEnabled}
|
|
|
|
onToggle={(value) => {
|
|
|
|
this.context.trackEvent({
|
|
|
|
category: EVENT.CATEGORIES.SETTINGS,
|
|
|
|
event: 'Enabled/Disable TransactionSecurityCheck',
|
|
|
|
properties: {
|
|
|
|
action: 'Enabled/Disable TransactionSecurityCheck',
|
|
|
|
legacy_event: true,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
setTransactionSecurityCheckEnabled(!value);
|
|
|
|
}}
|
|
|
|
offLabel={t('off')}
|
|
|
|
onLabel={t('on')}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-09-20 18:22:04 +02:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<div className="settings-page__body">
|
2022-11-17 15:13:02 +01:00
|
|
|
{this.renderTransactionSecurityCheckToggle()}
|
2022-11-08 18:21:38 +01:00
|
|
|
{this.renderImprovedTokenAllowanceToggle()}
|
2021-12-01 05:12:27 +01:00
|
|
|
{this.renderOpenSeaEnabledToggle()}
|
2021-11-26 19:54:57 +01:00
|
|
|
{this.renderCollectibleDetectionToggle()}
|
2022-01-11 20:17:56 +01:00
|
|
|
{this.renderEIP1559V2EnabledToggle()}
|
2021-09-20 18:22:04 +02:00
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|