1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-01 21:57:06 +01:00
metamask-extension/ui/pages/settings/experimental-tab/experimental-tab.component.js
Olaf Tomalka 95c37e1ba3
feat: add yaml feature management (#18125)
* feat: add yaml feature management

Add yaml feature file per build type.
Also add method to parse yaml and set
enabled features env to true. The build
process will then replace any process.env[feature]
that exists on the config by its value

* chore: add example for desktop

* Added initial draft of build features

* [TMP] Sync between computers

* Is able to succesfully build stable extension with snaps feature

* Removing var context from builds.yml

* Add asssets to builds.yml

* Minor bug fixes and removing debug logs

* [WIP] Test changes

* Removed TODOs

* Fix regession bug

Also
* remove debug logs
* merge Variables.set and Variables.setMany with an overload

* Fix build, lint and a bunch of issues

* Update LavaMoat policies

* Re-add desktop build type

* Fix some tests

* Fix desktop build

* Define some env variables used by MV3

* Fix lint

* Fix remove-fenced-code tests

* Fix README typo

* Move new code

* Fix missing asset copy

* Move Jest env setup

* Fix path for test after rebase

* Fix code fences

* Fix fencing and LavaMoat policies

* Fix MMI code-fencing after rebase

* Fix MMI code fencing after merge

* Fix more MMI code fencing

---------

Co-authored-by: cryptotavares <joao.tavares@consensys.net>
Co-authored-by: Frederik Bolding <frederik.bolding@gmail.com>
Co-authored-by: Brad Decker <bhdecker84@gmail.com>
2023-04-25 16:32:51 +02:00

275 lines
8.8 KiB
JavaScript

import React, { PureComponent } from 'react';
import PropTypes from 'prop-types';
import ToggleButton from '../../../components/ui/toggle-button';
import {
getNumberOfSettingsInSection,
handleSettingsRefs,
} from '../../../helpers/utils/settings-search';
import { MetaMetricsEventCategory } from '../../../../shared/constants/metametrics';
import Typography from '../../../components/ui/typography/typography';
import { Text } from '../../../components/component-library';
import {
FONT_WEIGHT,
TextColor,
TypographyVariant,
} from '../../../helpers/constants/design-system';
///: BEGIN:ONLY_INCLUDE_IN(desktop)
import DesktopEnableButton from '../../../components/app/desktop-enable-button';
///: END:ONLY_INCLUDE_IN
export default class ExperimentalTab extends PureComponent {
static contextTypes = {
t: PropTypes.func,
trackEvent: PropTypes.func,
};
static propTypes = {
useNftDetection: PropTypes.bool,
setUseNftDetection: PropTypes.func,
setOpenSeaEnabled: PropTypes.func,
openSeaEnabled: PropTypes.bool,
transactionSecurityCheckEnabled: PropTypes.bool,
setTransactionSecurityCheckEnabled: PropTypes.func,
};
settingsRefs = Array(
getNumberOfSettingsInSection(
this.context.t,
this.context.t('experimental'),
),
)
.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);
}
renderOpenSeaEnabledToggle() {
const { t } = this.context;
const {
openSeaEnabled,
setOpenSeaEnabled,
useNftDetection,
setUseNftDetection,
} = this.props;
return (
<>
<div ref={this.settingsRefs[0]} className="settings-page__content-row">
<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) => {
this.context.trackEvent({
category: MetaMetricsEventCategory.Settings,
event: 'Enabled/Disable OpenSea',
properties: {
action: 'Enabled/Disable OpenSea',
legacy_event: true,
},
});
// value is positive when being toggled off
if (value && useNftDetection) {
setUseNftDetection(false);
}
setOpenSeaEnabled(!value);
}}
offLabel={t('off')}
onLabel={t('on')}
/>
</div>
</div>
</div>
<div ref={this.settingsRefs[1]} className="settings-page__content-row">
<div className="settings-page__content-item">
<span>{t('useNftDetection')}</span>
<div className="settings-page__content-description">
<Text color={TextColor.textAlternative}>
{t('useNftDetectionDescription')}
</Text>
<ul className="settings-page__content-unordered-list">
<li>{t('useNftDetectionDescriptionLine2')}</li>
<li>{t('useNftDetectionDescriptionLine3')}</li>
<li>{t('useNftDetectionDescriptionLine4')}</li>
</ul>
<Text color={TextColor.textAlternative} paddingTop={4}>
{t('useNftDetectionDescriptionLine5')}
</Text>
</div>
</div>
<div className="settings-page__content-item">
<div className="settings-page__content-item-col">
<ToggleButton
value={useNftDetection}
onToggle={(value) => {
this.context.trackEvent({
category: MetaMetricsEventCategory.Settings,
event: 'NFT Detected',
properties: {
action: 'NFT Detected',
legacy_event: true,
},
});
if (!value && !openSeaEnabled) {
setOpenSeaEnabled(!value);
}
setUseNftDetection(!value);
}}
offLabel={t('off')}
onLabel={t('on')}
/>
</div>
</div>
</div>
</>
);
}
renderTransactionSecurityCheckToggle() {
const { t } = this.context;
const {
transactionSecurityCheckEnabled,
setTransactionSecurityCheckEnabled,
} = this.props;
return (
<>
<Typography
variant={TypographyVariant.H4}
color={TextColor.textAlternative}
marginBottom={2}
fontWeight={FONT_WEIGHT.BOLD}
>
{t('privacy')}
</Typography>
<div
ref={this.settingsRefs[1]}
className="settings-page__content-row settings-page__content-row-experimental"
>
<div className="settings-page__content-item">
<span>{t('transactionSecurityCheck')}</span>
<div className="settings-page__content-description">
<Typography
variant={TypographyVariant.H6}
color={TextColor.textAlternative}
>
{t('transactionSecurityCheckDescription')}
</Typography>
<Typography
marginTop={3}
marginBottom={1}
variant={TypographyVariant.H6}
color={TextColor.textAlternative}
>
{t('selectProvider')}
</Typography>
<div className="settings-page__content-item-col settings-page__content-item-col-open-sea">
<Typography
variant={TypographyVariant.H5}
color={TextColor.textDefault}
fontWeight={FONT_WEIGHT.MEDIUM}
marginBottom={0}
>
{t('openSea')}
</Typography>
<ToggleButton
value={transactionSecurityCheckEnabled}
onToggle={(value) => {
this.context.trackEvent({
category: MetaMetricsEventCategory.Settings,
event: 'Enabled/Disable TransactionSecurityCheck',
properties: {
action: 'Enabled/Disable TransactionSecurityCheck',
legacy_event: true,
},
});
setTransactionSecurityCheckEnabled(!value);
}}
/>
</div>
<Typography
variant={TypographyVariant.H6}
color={TextColor.textAlternative}
marginTop={0}
>
{t('thisServiceIsExperimental', [
<a
href="http://opensea.io/securityproviderterms"
key="termsOfUse"
rel="noopener noreferrer"
target="_blank"
>
{t('termsOfUse')}
</a>,
])}
</Typography>
<Typography
variant={TypographyVariant.H5}
color={TextColor.textMuted}
fontWeight={FONT_WEIGHT.MEDIUM}
marginTop={2}
>
{t('moreComingSoon')}
</Typography>
</div>
</div>
</div>
</>
);
}
///: BEGIN:ONLY_INCLUDE_IN(desktop)
renderDesktopEnableButton() {
const { t } = this.context;
return (
<div
ref={this.settingsRefs[6]}
className="settings-page__content-row"
data-testid="advanced-setting-desktop-pairing"
>
<div className="settings-page__content-item">
<span>{t('desktopEnableButtonDescription')}</span>
</div>
<div className="settings-page__content-item">
<div className="settings-page__content-item-col">
<DesktopEnableButton />
</div>
</div>
</div>
);
}
///: END:ONLY_INCLUDE_IN
render() {
return (
<div className="settings-page__body">
{this.renderTransactionSecurityCheckToggle()}
{this.renderOpenSeaEnabledToggle()}
{
///: BEGIN:ONLY_INCLUDE_IN(desktop)
this.renderDesktopEnableButton()
///: END:ONLY_INCLUDE_IN
}
</div>
);
}
}