From 18464793f50f9388894b706c686720de8f02cee9 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 b2f619ac7..a0e399dc6 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 { isCustomPriceExcessive, getIsGasEstimatesFetched, getShouldShowFiat, + getIsCustomNetworkGasPriceFetched, } from '../../../../selectors'; import { @@ -137,13 +138,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 a357bf758..c36742204 100644 --- a/ui/selectors/custom-gas.js +++ b/ui/selectors/custom-gas.js @@ -105,6 +105,10 @@ export function isCustomPriceSafeForCustomNetwork(state) { return true; } + if (!estimatedPrice) { + return false; + } + const customPriceSafe = conversionGreaterThan( { value: customGasPrice, @@ -382,6 +386,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);