From 87166afb6b732d27e4471ffb7db2040fb8bd0c26 Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Thu, 24 Jun 2021 14:29:47 -0230 Subject: [PATCH] Use eth_gasPrice result for setting too low warning on custom networks (#11370) * Use eth_gasPrice result for setting too low warning on custom networks * Assume CustomPriceSafeForCustomNetwork when there is no custom price set (it will default to recommended) --- .../gas-modal-page-container.container.js | 18 +++++++++++---- ui/selectors/custom-gas.js | 22 +++++++++++++++++++ 2 files changed, 36 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 513b4dc86..b2f619ac7 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 @@ -29,12 +29,14 @@ import { getCurrentCurrency, getCurrentEthBalance, getIsMainnet, + getIsTestnet, getBasicGasEstimateLoadingStatus, getCustomGasLimit, getCustomGasPrice, getDefaultActiveButtonIndex, getRenderableBasicEstimateData, isCustomPriceSafe, + isCustomPriceSafeForCustomNetwork, getAveragePriceEstimateInHexWEI, isCustomPriceExcessive, getIsGasEstimatesFetched, @@ -113,6 +115,7 @@ const mapStateToProps = (state, ownProps) => { const balance = getCurrentEthBalance(state); const isMainnet = getIsMainnet(state); + const isTestnet = getIsTestnet(state); const showFiat = getShouldShowFiat(state); const newTotalEth = @@ -134,6 +137,16 @@ const mapStateToProps = (state, ownProps) => { conversionRate, }); const isGasEstimate = getIsGasEstimatesFetched(state); + + let customPriceIsSafe; + if ((isMainnet || process.env.IN_TEST) && isGasEstimate) { + customPriceIsSafe = isCustomPriceSafe(state); + } else if (isTestnet) { + customPriceIsSafe = true; + } else { + customPriceIsSafe = isCustomPriceSafeForCustomNetwork(state); + } + return { hideBasic, isConfirm: isConfirm(state), @@ -143,10 +156,7 @@ const mapStateToProps = (state, ownProps) => { customGasLimit: calcCustomGasLimit(customModalGasLimitInHex), customGasTotal, newTotalFiat, - customPriceIsSafe: - (isMainnet || process.env.IN_TEST) && isGasEstimate - ? isCustomPriceSafe(state) - : true, + customPriceIsSafe, customPriceIsExcessive: isCustomPriceExcessive(state), maxModeOn, gasPriceButtonGroupProps: { diff --git a/ui/selectors/custom-gas.js b/ui/selectors/custom-gas.js index 0e275764f..a357bf758 100644 --- a/ui/selectors/custom-gas.js +++ b/ui/selectors/custom-gas.js @@ -96,6 +96,28 @@ export function isCustomPriceSafe(state) { return customPriceSafe; } +export function isCustomPriceSafeForCustomNetwork(state) { + const estimatedPrice = state.gas.basicEstimates.average; + + const customGasPrice = getCustomGasPrice(state); + + if (!customGasPrice) { + return true; + } + + const customPriceSafe = conversionGreaterThan( + { + value: customGasPrice, + fromNumericBase: 'hex', + fromDenomination: 'WEI', + toDenomination: 'GWEI', + }, + { value: estimatedPrice, fromNumericBase: 'dec' }, + ); + + return customPriceSafe; +} + export function isCustomPriceExcessive(state, checkSend = false) { const customPrice = checkSend ? getGasPrice(state) : getCustomGasPrice(state); const fastPrice = getFastPriceEstimate(state);