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:
parent
43b7eab46a
commit
64644ad380
@ -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. It’s 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"
|
||||||
},
|
},
|
||||||
|
@ -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: '',
|
||||||
};
|
};
|
||||||
|
@ -20,3 +20,14 @@ export const withEducation = () => {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const withDappSuggestedGas = () => {
|
||||||
|
return (
|
||||||
|
<div style={{ width: '600px' }}>
|
||||||
|
<EditGasDisplay
|
||||||
|
dappSuggestedGasFee="100000"
|
||||||
|
dappOrigin="davidwalsh.name"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user