mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Add transaction security check toggle (#16271)
Co-authored-by: Brad Decker <bhdecker84@gmail.com>
This commit is contained in:
parent
f7cb1844d6
commit
3746ad9451
6
app/_locales/en/messages.json
generated
6
app/_locales/en/messages.json
generated
@ -4140,6 +4140,12 @@
|
|||||||
"transactionResubmitted": {
|
"transactionResubmitted": {
|
||||||
"message": "Transaction resubmitted with estimated gas fee increased to $1 at $2"
|
"message": "Transaction resubmitted with estimated gas fee increased to $1 at $2"
|
||||||
},
|
},
|
||||||
|
"transactionSecurityCheck": {
|
||||||
|
"message": "Transaction security check"
|
||||||
|
},
|
||||||
|
"transactionSecurityCheckDescription": {
|
||||||
|
"message": "Turn this on to enable a third party (OpenSea) to review all your transactions and signature requests and warn you about known malicious requests."
|
||||||
|
},
|
||||||
"transactionSubmitted": {
|
"transactionSubmitted": {
|
||||||
"message": "Transaction submitted with estimated gas fee of $1 at $2."
|
"message": "Transaction submitted with estimated gas fee of $1 at $2."
|
||||||
},
|
},
|
||||||
|
@ -70,6 +70,7 @@ export default class PreferencesController {
|
|||||||
: LEDGER_TRANSPORT_TYPES.U2F,
|
: LEDGER_TRANSPORT_TYPES.U2F,
|
||||||
theme: 'light',
|
theme: 'light',
|
||||||
improvedTokenAllowanceEnabled: false,
|
improvedTokenAllowanceEnabled: false,
|
||||||
|
transactionSecurityCheckEnabled: false,
|
||||||
...opts.initState,
|
...opts.initState,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -199,6 +200,17 @@ export default class PreferencesController {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setter for the `transactionSecurityCheckEnabled` property
|
||||||
|
*
|
||||||
|
* @param transactionSecurityCheckEnabled
|
||||||
|
*/
|
||||||
|
setTransactionSecurityCheckEnabled(transactionSecurityCheckEnabled) {
|
||||||
|
this.store.updateState({
|
||||||
|
transactionSecurityCheckEnabled,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add new methodData to state, to avoid requesting this information again through Infura
|
* Add new methodData to state, to avoid requesting this information again through Infura
|
||||||
*
|
*
|
||||||
|
@ -1648,6 +1648,10 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
preferencesController.setImprovedTokenAllowanceEnabled.bind(
|
preferencesController.setImprovedTokenAllowanceEnabled.bind(
|
||||||
preferencesController,
|
preferencesController,
|
||||||
),
|
),
|
||||||
|
setTransactionSecurityCheckEnabled:
|
||||||
|
preferencesController.setTransactionSecurityCheckEnabled.bind(
|
||||||
|
preferencesController,
|
||||||
|
),
|
||||||
// AssetsContractController
|
// AssetsContractController
|
||||||
getTokenStandardAndDetails: this.getTokenStandardAndDetails.bind(this),
|
getTokenStandardAndDetails: this.getTokenStandardAndDetails.bind(this),
|
||||||
|
|
||||||
|
@ -343,4 +343,11 @@ export const SETTINGS_CONSTANTS = [
|
|||||||
route: `${EXPERIMENTAL_ROUTE}#improved-token-allowance`,
|
route: `${EXPERIMENTAL_ROUTE}#improved-token-allowance`,
|
||||||
icon: 'fa fa-flask',
|
icon: 'fa fa-flask',
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
tabMessage: (t) => t('experimental'),
|
||||||
|
sectionMessage: (t) => t('transactionSecurityCheck'),
|
||||||
|
descriptionMessage: (t) => t('transactionSecurityCheckDescription'),
|
||||||
|
route: `${EXPERIMENTAL_ROUTE}#transaction-security-check`,
|
||||||
|
icon: 'fa fa-flask',
|
||||||
|
},
|
||||||
];
|
];
|
||||||
|
@ -182,7 +182,7 @@ describe('Settings Search Utils', () => {
|
|||||||
|
|
||||||
it('should get good experimental section number', () => {
|
it('should get good experimental section number', () => {
|
||||||
expect(getNumberOfSettingsInSection(t, t('experimental'))).toStrictEqual(
|
expect(getNumberOfSettingsInSection(t, t('experimental'))).toStrictEqual(
|
||||||
2,
|
3,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -22,6 +22,8 @@ export default class ExperimentalTab extends PureComponent {
|
|||||||
setEIP1559V2Enabled: PropTypes.func,
|
setEIP1559V2Enabled: PropTypes.func,
|
||||||
improvedTokenAllowanceEnabled: PropTypes.bool,
|
improvedTokenAllowanceEnabled: PropTypes.bool,
|
||||||
setImprovedTokenAllowanceEnabled: PropTypes.func,
|
setImprovedTokenAllowanceEnabled: PropTypes.func,
|
||||||
|
transactionSecurityCheckEnabled: PropTypes.bool,
|
||||||
|
setTransactionSecurityCheckEnabled: PropTypes.func,
|
||||||
};
|
};
|
||||||
|
|
||||||
settingsRefs = Array(
|
settingsRefs = Array(
|
||||||
@ -198,7 +200,7 @@ export default class ExperimentalTab extends PureComponent {
|
|||||||
this.props;
|
this.props;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={this.settingsRefs[1]} className="settings-page__content-row">
|
<div ref={this.settingsRefs[2]} className="settings-page__content-row">
|
||||||
<div className="settings-page__content-item">
|
<div className="settings-page__content-item">
|
||||||
<span>{t('improvedTokenAllowance')}</span>
|
<span>{t('improvedTokenAllowance')}</span>
|
||||||
<div className="settings-page__content-description">
|
<div className="settings-page__content-description">
|
||||||
@ -229,9 +231,50 @@ export default class ExperimentalTab extends PureComponent {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="settings-page__body">
|
<div className="settings-page__body">
|
||||||
|
{this.renderTransactionSecurityCheckToggle()}
|
||||||
{this.renderImprovedTokenAllowanceToggle()}
|
{this.renderImprovedTokenAllowanceToggle()}
|
||||||
{this.renderOpenSeaEnabledToggle()}
|
{this.renderOpenSeaEnabledToggle()}
|
||||||
{this.renderCollectibleDetectionToggle()}
|
{this.renderCollectibleDetectionToggle()}
|
||||||
|
@ -6,12 +6,14 @@ import {
|
|||||||
setOpenSeaEnabled,
|
setOpenSeaEnabled,
|
||||||
setEIP1559V2Enabled,
|
setEIP1559V2Enabled,
|
||||||
setImprovedTokenAllowanceEnabled,
|
setImprovedTokenAllowanceEnabled,
|
||||||
|
setTransactionSecurityCheckEnabled,
|
||||||
} from '../../../store/actions';
|
} from '../../../store/actions';
|
||||||
import {
|
import {
|
||||||
getUseNftDetection,
|
getUseNftDetection,
|
||||||
getOpenSeaEnabled,
|
getOpenSeaEnabled,
|
||||||
getEIP1559V2Enabled,
|
getEIP1559V2Enabled,
|
||||||
getIsImprovedTokenAllowanceEnabled,
|
getIsImprovedTokenAllowanceEnabled,
|
||||||
|
getIsTransactionSecurityCheckEnabled,
|
||||||
} from '../../../selectors';
|
} from '../../../selectors';
|
||||||
import ExperimentalTab from './experimental-tab.component';
|
import ExperimentalTab from './experimental-tab.component';
|
||||||
|
|
||||||
@ -21,6 +23,8 @@ const mapStateToProps = (state) => {
|
|||||||
openSeaEnabled: getOpenSeaEnabled(state),
|
openSeaEnabled: getOpenSeaEnabled(state),
|
||||||
eip1559V2Enabled: getEIP1559V2Enabled(state),
|
eip1559V2Enabled: getEIP1559V2Enabled(state),
|
||||||
improvedTokenAllowanceEnabled: getIsImprovedTokenAllowanceEnabled(state),
|
improvedTokenAllowanceEnabled: getIsImprovedTokenAllowanceEnabled(state),
|
||||||
|
transactionSecurityCheckEnabled:
|
||||||
|
getIsTransactionSecurityCheckEnabled(state),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -31,6 +35,8 @@ const mapDispatchToProps = (dispatch) => {
|
|||||||
setEIP1559V2Enabled: (val) => dispatch(setEIP1559V2Enabled(val)),
|
setEIP1559V2Enabled: (val) => dispatch(setEIP1559V2Enabled(val)),
|
||||||
setImprovedTokenAllowanceEnabled: (val) =>
|
setImprovedTokenAllowanceEnabled: (val) =>
|
||||||
dispatch(setImprovedTokenAllowanceEnabled(val)),
|
dispatch(setImprovedTokenAllowanceEnabled(val)),
|
||||||
|
setTransactionSecurityCheckEnabled: (val) =>
|
||||||
|
dispatch(setTransactionSecurityCheckEnabled(val)),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1270,6 +1270,16 @@ export function getIsImprovedTokenAllowanceEnabled(state) {
|
|||||||
return state.metamask.improvedTokenAllowanceEnabled;
|
return state.metamask.improvedTokenAllowanceEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To get the `transactionSecurityCheckEnabled` value which determines whether we use the transaction security check
|
||||||
|
*
|
||||||
|
* @param {*} state
|
||||||
|
* @returns Boolean
|
||||||
|
*/
|
||||||
|
export function getIsTransactionSecurityCheckEnabled(state) {
|
||||||
|
return state.metamask.transactionSecurityCheckEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
export function getIsCustomNetwork(state) {
|
export function getIsCustomNetwork(state) {
|
||||||
const chainId = getCurrentChainId(state);
|
const chainId = getCurrentChainId(state);
|
||||||
|
|
||||||
|
@ -3803,6 +3803,20 @@ export function setImprovedTokenAllowanceEnabled(
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function setTransactionSecurityCheckEnabled(
|
||||||
|
transactionSecurityCheckEnabled,
|
||||||
|
) {
|
||||||
|
return async () => {
|
||||||
|
try {
|
||||||
|
await submitRequestToBackground('setTransactionSecurityCheckEnabled', [
|
||||||
|
transactionSecurityCheckEnabled,
|
||||||
|
]);
|
||||||
|
} catch (error) {
|
||||||
|
log.error(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export function setFirstTimeUsedNetwork(chainId) {
|
export function setFirstTimeUsedNetwork(chainId) {
|
||||||
return submitRequestToBackground('setFirstTimeUsedNetwork', [chainId]);
|
return submitRequestToBackground('setFirstTimeUsedNetwork', [chainId]);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user