1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Implement Dapp Acknowledgement screen for editing gas (#11424)

This commit is contained in:
David Walsh 2021-07-01 09:36:48 -05:00 committed by GitHub
parent 43b7eab46a
commit 64644ad380
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 85 additions and 12 deletions

View File

@ -837,6 +837,13 @@
"functionType": { "functionType": {
"message": "Function Type" "message": "Function Type"
}, },
"gasDisplayAcknowledgeDappButtonText": {
"message": "Edit app suggestion"
},
"gasDisplayDappWarning": {
"message": "This gas fee has been suggested by the app $1. Its using legacy gas estimation which may be inaccurate. However, editing this gas fee may cause unintended consequences. Please reach out to the app team if you have questions.",
"description": "$1 represents the Dapp's origin"
},
"gasFee": { "gasFee": {
"message": "Gas Fee" "message": "Gas Fee"
}, },

View File

@ -1,6 +1,7 @@
import React, { useState, useContext } from 'react'; import React, { useState, useContext } from 'react';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import Button from '../../ui/button';
import Typography from '../../ui/typography/typography'; import Typography from '../../ui/typography/typography';
import { import {
COLORS, COLORS,
@ -21,11 +22,20 @@ export default function EditGasDisplay({
type, type,
showEducationButton, showEducationButton,
onEducationClick, onEducationClick,
dappSuggestedGasFee,
dappOrigin,
}) { }) {
const t = useContext(I18nContext); const t = useContext(I18nContext);
const [warning] = useState(null); const [warning] = useState(null);
const [showAdvancedForm, setShowAdvancedForm] = useState(false); const [showAdvancedForm, setShowAdvancedForm] = useState(false);
const [
dappSuggestedGasFeeAcknowledged,
setDappSuggestedGasFeeAcknowledged,
] = useState(false);
const requireDappAcknowledgement =
dappSuggestedGasFee && !dappSuggestedGasFeeAcknowledged;
return ( return (
<div className="edit-gas-display"> <div className="edit-gas-display">
@ -38,6 +48,15 @@ export default function EditGasDisplay({
/> />
</div> </div>
)} )}
{requireDappAcknowledgement && (
<div className="edit-gas-display__dapp-acknowledgement-warning">
<ActionableMessage
className="actionable-message--warning"
message={t('gasDisplayDappWarning', [dappOrigin])}
useIcon
/>
</div>
)}
{type === 'speed-up' && ( {type === 'speed-up' && (
<div className="edit-gas-display__top-tooltip"> <div className="edit-gas-display__top-tooltip">
<Typography <Typography
@ -53,17 +72,34 @@ export default function EditGasDisplay({
</Typography> </Typography>
</div> </div>
)} )}
<TransactionTotalBanner total="" detail="" timing="" /> <TransactionTotalBanner total="" detail="" timing="" />
{requireDappAcknowledgement && (
<Button
className="edit-gas-display__dapp-acknowledgement-button"
onClick={() => setDappSuggestedGasFeeAcknowledged(true)}
>
{t('gasDisplayAcknowledgeDappButtonText')}
</Button>
)}
{!requireDappAcknowledgement && (
<RadioGroup <RadioGroup
name="gas-recommendation" name="gas-recommendation"
options={[ options={[
{ value: 'low', label: t('editGasLow'), recommended: false }, { value: 'low', label: t('editGasLow'), recommended: false },
{ value: 'medium', label: t('editGasMedium'), recommended: false }, {
value: 'medium',
label: t('editGasMedium'),
recommended: false,
},
{ value: 'high', label: t('editGasHigh'), recommended: true }, { value: 'high', label: t('editGasHigh'), recommended: true },
]} ]}
selectedValue="high" selectedValue="high"
/> />
{!alwaysShowForm && ( )}
{!requireDappAcknowledgement && !alwaysShowForm && (
<button <button
className="edit-gas-display__advanced-button" className="edit-gas-display__advanced-button"
onClick={() => setShowAdvancedForm(!showAdvancedForm)} onClick={() => setShowAdvancedForm(!showAdvancedForm)}
@ -76,9 +112,10 @@ export default function EditGasDisplay({
)} )}
</button> </button>
)} )}
{(alwaysShowForm || showAdvancedForm) && <AdvancedGasControls />} {((!requireDappAcknowledgement && alwaysShowForm) ||
showAdvancedForm) && <AdvancedGasControls />}
</div> </div>
{showEducationButton && ( {!requireDappAcknowledgement && showEducationButton && (
<div className="edit-gas-display__education"> <div className="edit-gas-display__education">
<button onClick={onEducationClick}> <button onClick={onEducationClick}>
{t('editGasEducationButtonText')} {t('editGasEducationButtonText')}
@ -94,6 +131,8 @@ EditGasDisplay.propTypes = {
type: PropTypes.oneOf(['customize-gas', 'speed-up']), type: PropTypes.oneOf(['customize-gas', 'speed-up']),
showEducationButton: PropTypes.bool, showEducationButton: PropTypes.bool,
onEducationClick: PropTypes.func, onEducationClick: PropTypes.func,
dappSuggestedGasFee: PropTypes.number,
dappOrigin: PropTypes.string,
}; };
EditGasDisplay.defaultProps = { EditGasDisplay.defaultProps = {
@ -101,4 +140,6 @@ EditGasDisplay.defaultProps = {
type: 'customize-gas', type: 'customize-gas',
showEducationButton: false, showEducationButton: false,
onEducationClick: undefined, onEducationClick: undefined,
dappSuggestedGasFee: 0,
dappOrigin: '',
}; };

View File

@ -20,3 +20,14 @@ export const withEducation = () => {
</div> </div>
); );
}; };
export const withDappSuggestedGas = () => {
return (
<div style={{ width: '600px' }}>
<EditGasDisplay
dappSuggestedGasFee="100000"
dappOrigin="davidwalsh.name"
/>
</div>
);
};

View File

@ -16,6 +16,20 @@
} }
} }
&__dapp-acknowledgement-warning {
margin-bottom: 20px;
}
button.edit-gas-display__dapp-acknowledgement-button {
margin: 0 auto;
display: block;
color: $secondary-1;
border: 1px solid $secondary-1;
text-transform: unset;
width: auto;
background: transparent;
}
.radio-group { .radio-group {
margin: 20px auto; margin: 20px auto;
} }