From b3bd9f54976d67ff103893c0b1c9065fd5af28e6 Mon Sep 17 00:00:00 2001 From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com> Date: Sun, 16 May 2021 18:28:39 -0400 Subject: [PATCH 1/3] calling isCustomPriceSafe() only for mainnet or IN_TEST --- .../gas-modal-page-container.container.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 d85d07c72618..b4af9397ef07 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 @@ -142,7 +142,8 @@ const mapStateToProps = (state, ownProps) => { customGasLimit: calcCustomGasLimit(customModalGasLimitInHex), customGasTotal, newTotalFiat, - customPriceIsSafe: isCustomPriceSafe(state), + customPriceIsSafe: + isMainnet || process.env.IN_TEST ? isCustomPriceSafe(state) : true, customPriceIsExcessive: isCustomPriceExcessive(state), maxModeOn, gasPriceButtonGroupProps: { From 6d11781a78cade333aa84f622d965a5db03a13db Mon Sep 17 00:00:00 2001 From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com> Date: Mon, 17 May 2021 18:56:25 -0400 Subject: [PATCH 2/3] handling the gasmodal sidebar while api service fails --- .../gas-modal-page-container.container.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 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 b4af9397ef07..0157f007336a 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 @@ -38,6 +38,7 @@ import { getSendMaxModeState, getAveragePriceEstimateInHexWEI, isCustomPriceExcessive, + getIsEthGasPriceFetched, } from '../../../../selectors'; import { @@ -132,7 +133,7 @@ const mapStateToProps = (state, ownProps) => { balance, conversionRate, }); - + const isEthGasPrice = getIsEthGasPriceFetched(state); return { hideBasic, isConfirm: isConfirm(state), @@ -143,7 +144,9 @@ const mapStateToProps = (state, ownProps) => { customGasTotal, newTotalFiat, customPriceIsSafe: - isMainnet || process.env.IN_TEST ? isCustomPriceSafe(state) : true, + (isMainnet || process.env.IN_TEST) && !isEthGasPrice + ? isCustomPriceSafe(state) + : true, customPriceIsExcessive: isCustomPriceExcessive(state), maxModeOn, gasPriceButtonGroupProps: { From b8d37a50a7eeec55fba90a50fdc87e70730d2684 Mon Sep 17 00:00:00 2001 From: Niranjana Binoy <43930900+NiranjanaBinoy@users.noreply.github.com> Date: Wed, 19 May 2021 11:27:46 -0400 Subject: [PATCH 3/3] handling api service failure --- .../gas-modal-page-container.container.js | 6 +++--- ui/ducks/gas/gas.duck.js | 4 ++-- ui/selectors/custom-gas.js | 15 ++++++++++++--- 3 files changed, 17 insertions(+), 8 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 0157f007336a..4dbbeec22256 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 @@ -38,7 +38,7 @@ import { getSendMaxModeState, getAveragePriceEstimateInHexWEI, isCustomPriceExcessive, - getIsEthGasPriceFetched, + getIsGasEstimatesFetched, } from '../../../../selectors'; import { @@ -133,7 +133,7 @@ const mapStateToProps = (state, ownProps) => { balance, conversionRate, }); - const isEthGasPrice = getIsEthGasPriceFetched(state); + const isGasEstimate = getIsGasEstimatesFetched(state); return { hideBasic, isConfirm: isConfirm(state), @@ -144,7 +144,7 @@ const mapStateToProps = (state, ownProps) => { customGasTotal, newTotalFiat, customPriceIsSafe: - (isMainnet || process.env.IN_TEST) && !isEthGasPrice + (isMainnet || process.env.IN_TEST) && isGasEstimate ? isCustomPriceSafe(state) : true, customPriceIsExcessive: isCustomPriceExcessive(state), diff --git a/ui/ducks/gas/gas.duck.js b/ui/ducks/gas/gas.duck.js index 863d726faca2..e991e5e73ca1 100644 --- a/ui/ducks/gas/gas.duck.js +++ b/ui/ducks/gas/gas.duck.js @@ -11,13 +11,13 @@ import { import { getIsMainnet, getCurrentChainId } from '../../selectors'; import fetchWithCache from '../../helpers/utils/fetch-with-cache'; -const BASIC_ESTIMATE_STATES = { +export const BASIC_ESTIMATE_STATES = { LOADING: 'LOADING', FAILED: 'FAILED', READY: 'READY', }; -const GAS_SOURCE = { +export const GAS_SOURCE = { METASWAPS: 'MetaSwaps', ETHGASPRICE: 'eth_gasprice', }; diff --git a/ui/selectors/custom-gas.js b/ui/selectors/custom-gas.js index ea64bcbe6a89..4485c2086bed 100644 --- a/ui/selectors/custom-gas.js +++ b/ui/selectors/custom-gas.js @@ -9,6 +9,7 @@ import { formatETHFee } from '../helpers/utils/formatters'; import { calcGasTotal } from '../pages/send/send.utils'; import { GAS_ESTIMATE_TYPES } from '../helpers/constants/common'; +import { BASIC_ESTIMATE_STATES, GAS_SOURCE } from '../ducks/gas/gas.duck'; import { getCurrentCurrency, getIsMainnet, @@ -361,13 +362,21 @@ export function getRenderableEstimateDataForSmallButtonsFromGWEI(state) { export function getIsEthGasPriceFetched(state) { const gasState = state.gas; return Boolean( - gasState.estimateSource === 'eth_gasprice' && - gasState.basicEstimateStatus === 'READY' && + 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 === 'FAILED'); + return Boolean(gasState.basicEstimateStatus === BASIC_ESTIMATE_STATES.FAILED); +} + +export function getIsGasEstimatesFetched(state) { + const gasState = state.gas; + return Boolean( + gasState.estimateSource === GAS_SOURCE.METASWAPS && + gasState.basicEstimateStatus === BASIC_ESTIMATE_STATES.READY, + ); }