From 8481c4b6be31a8abb56805e7dbe46f1fecdf5967 Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Mon, 2 Aug 2021 19:19:07 -0230 Subject: [PATCH] Show warning when network request for fee market estimates fails (#11724) --- app/_locales/en/messages.json | 3 +++ .../app/edit-gas-display/edit-gas-display.component.js | 8 +++++++- .../app/edit-gas-popover/edit-gas-popover.component.js | 2 ++ ui/hooks/useGasFeeInputs.js | 10 ++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/app/_locales/en/messages.json b/app/_locales/en/messages.json index c491d9936..6d5f24176 100644 --- a/app/_locales/en/messages.json +++ b/app/_locales/en/messages.json @@ -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" }, diff --git a/ui/components/app/edit-gas-display/edit-gas-display.component.js b/ui/components/app/edit-gas-display/edit-gas-display.component.js index eee8904cc..db3788033 100644 --- a/ui/components/app/edit-gas-display/edit-gas-display.component.js +++ b/ui/components/app/edit-gas-display/edit-gas-display.component.js @@ -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, }; diff --git a/ui/components/app/edit-gas-popover/edit-gas-popover.component.js b/ui/components/app/edit-gas-popover/edit-gas-popover.component.js index ed86d4b3a..259f831b1 100644 --- a/ui/components/app/edit-gas-popover/edit-gas-popover.component.js +++ b/ui/components/app/edit-gas-popover/edit-gas-popover.component.js @@ -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} /> diff --git a/ui/hooks/useGasFeeInputs.js b/ui/hooks/useGasFeeInputs.js index 669eb36ae..c5bc7dde9 100644 --- a/ui/hooks/useGasFeeInputs.js +++ b/ui/hooks/useGasFeeInputs.js @@ -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, }; }