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 c02eca852..9e70e3284 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 @@ -28,6 +28,7 @@ import { getIsMainnet, getSendToken, getPreferences, + getIsTestnet, getBasicGasEstimateLoadingStatus, getCustomGasLimit, getCustomGasPrice, @@ -36,6 +37,7 @@ import { isCustomPriceSafe, getTokenBalance, getSendMaxModeState, + isCustomPriceSafeForCustomNetwork, getAveragePriceEstimateInHexWEI, isCustomPriceExcessive, getIsGasEstimatesFetched, @@ -118,6 +120,7 @@ const mapStateToProps = (state, ownProps) => { const showFiat = Boolean(isMainnet || showFiatInTestnets); const isSendTokenSet = Boolean(sendToken); + const isTestnet = getIsTestnet(state); const newTotalEth = maxModeOn && !isSendTokenSet @@ -138,6 +141,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), @@ -147,10 +160,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 041d971d2..4f905a7fe 100644 --- a/ui/selectors/custom-gas.js +++ b/ui/selectors/custom-gas.js @@ -100,6 +100,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);