From 520fbcdd033efaedac39f809b88a81eb240bf40c Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Wed, 30 Jun 2021 15:56:34 -0230 Subject: [PATCH] Fix gas-modal-page-container.container check for custom gas price safety (#11426) * Fix gas-modal-page-container.container check for custom gas price safety * Ensure gas price has been fetch before checking for price safety on testnets --- .../gas-modal-page-container.container.js | 13 +++++++++---- ui/selectors/custom-gas.js | 13 +++++++++++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/ui/components/app/gas-customization/gas-modal-page-container/gas-modal-page-container.container.js b/ui/components/app/gas-customization/gas-modal-page-container/gas-modal-page-container.container.js index 9e70e3284..fc94176a0 100644 --- a/ui/components/app/gas-customization/gas-modal-page-container/gas-modal-page-container.container.js +++ b/ui/components/app/gas-customization/gas-modal-page-container/gas-modal-page-container.container.js @@ -41,6 +41,7 @@ import { getAveragePriceEstimateInHexWEI, isCustomPriceExcessive, getIsGasEstimatesFetched, + getIsCustomNetworkGasPriceFetched, } from '../../../../selectors'; import { @@ -141,13 +142,17 @@ const mapStateToProps = (state, ownProps) => { conversionRate, }); const isGasEstimate = getIsGasEstimatesFetched(state); + const customNetworkEstimateWasFetched = getIsCustomNetworkGasPriceFetched( + state, + ); - let customPriceIsSafe; + let customPriceIsSafe = true; if ((isMainnet || process.env.IN_TEST) && isGasEstimate) { customPriceIsSafe = isCustomPriceSafe(state); - } else if (isTestnet) { - customPriceIsSafe = true; - } else { + } else if ( + !(isMainnet || process.env.IN_TEST || isTestnet) && + customNetworkEstimateWasFetched + ) { customPriceIsSafe = isCustomPriceSafeForCustomNetwork(state); } diff --git a/ui/selectors/custom-gas.js b/ui/selectors/custom-gas.js index 4f905a7fe..4a3cbdf1e 100644 --- a/ui/selectors/custom-gas.js +++ b/ui/selectors/custom-gas.js @@ -109,6 +109,10 @@ export function isCustomPriceSafeForCustomNetwork(state) { return true; } + if (!estimatedPrice) { + return false; + } + const customPriceSafe = conversionGreaterThan( { value: customGasPrice, @@ -391,6 +395,15 @@ export function getIsEthGasPriceFetched(state) { ); } +export function getIsCustomNetworkGasPriceFetched(state) { + const gasState = state.gas; + return Boolean( + gasState.estimateSource === GAS_SOURCE.ETHGASPRICE && + gasState.basicEstimateStatus === BASIC_ESTIMATE_STATES.READY && + !getIsMainnet(state), + ); +} + export function getNoGasPriceFetched(state) { const gasState = state.gas; return Boolean(gasState.basicEstimateStatus === BASIC_ESTIMATE_STATES.FAILED);