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

Show warning when network request for fee market estimates fails (#11724)

This commit is contained in:
Dan J Miller 2021-08-02 19:19:07 -02:30 committed by GitHub
parent d34bf92fd0
commit 8481c4b6be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 1 deletions

View File

@ -901,6 +901,9 @@
"message": "This gas fee has been suggested by $1. Overriding this may cause a problem with your transaction. Please reach out to $1 if you have questions.",
"description": "$1 represents the Dapp's origin"
},
"gasEstimatesUnavailableWarning": {
"message": "Our low, medium and high estimates are not available."
},
"gasFee": {
"message": "Gas Fee"
},

View File

@ -5,6 +5,7 @@ import PropTypes from 'prop-types';
import {
GAS_RECOMMENDATIONS,
EDIT_GAS_MODES,
GAS_ESTIMATE_TYPES,
} from '../../../../shared/constants/gas';
import Button from '../../ui/button';
@ -62,6 +63,7 @@ export default function EditGasDisplay({
onManualChange,
minimumGasLimit,
balanceError,
estimatesUnavailableWarning,
}) {
const t = useContext(I18nContext);
const supportsEIP1559 = useSelector(isEIP1559Network);
@ -78,16 +80,19 @@ export default function EditGasDisplay({
);
const networkSupports1559 = useSelector(isEIP1559Network);
const showTopError = balanceError;
const showTopError = balanceError || estimatesUnavailableWarning;
const showRadioButtons =
networkSupports1559 &&
gasEstimateType === GAS_ESTIMATE_TYPES.FEE_MARKET &&
!requireDappAcknowledgement &&
![EDIT_GAS_MODES.SPEED_UP, EDIT_GAS_MODES.CANCEL].includes(mode);
let errorKey;
if (balanceError) {
errorKey = 'insufficientFunds';
} else if (estimatesUnavailableWarning) {
errorKey = 'gasEstimatesUnavailableWarning';
}
return (
@ -275,4 +280,5 @@ EditGasDisplay.propTypes = {
onManualChange: PropTypes.func,
minimumGasLimit: PropTypes.number,
balanceError: PropTypes.bool,
estimatesUnavailableWarning: PropTypes.bool,
};

View File

@ -82,6 +82,7 @@ export default function EditGasPopover({
gasErrors,
onManualChange,
balanceError,
estimatesUnavailableWarning,
} = useGasFeeInputs(defaultEstimateToUse, transaction, minimumGasLimit, mode);
const [showAdvancedForm, setShowAdvancedForm] = useState(
@ -241,6 +242,7 @@ export default function EditGasPopover({
onManualChange={onManualChange}
minimumGasLimit={minimumGasLimitDec}
balanceError={balanceError}
estimatesUnavailableWarning={estimatesUnavailableWarning}
{...editGasDisplayProps}
/>
</>

View File

@ -349,6 +349,8 @@ export function useGasFeeInputs(
},
);
let estimatesUnavailableWarning = null;
// Separating errors from warnings so we can know which value problems
// are blocking or simply useful information for the users
const gasErrors = {};
@ -399,6 +401,13 @@ export function useGasFeeInputs(
gasWarnings.maxFee = GAS_FORM_ERRORS.MAX_FEE_HIGH_WARNING;
}
break;
case GAS_ESTIMATE_TYPES.LEGACY:
case GAS_ESTIMATE_TYPES.ETH_GASPRICE:
case GAS_ESTIMATE_TYPES.NONE:
if (networkSupportsEIP1559) {
estimatesUnavailableWarning = true;
}
break;
default:
break;
}
@ -477,5 +486,6 @@ export function useGasFeeInputs(
setMaxPriorityFeePerGas(maxPriorityFeePerGasToUse);
},
balanceError,
estimatesUnavailableWarning,
};
}