diff options
Clean up for mmui-i11-custom-gas-price-chart branch
Diffstat (limited to 'ui/app/components/gas-customization/gas-modal-page-container')
2 files changed, 18 insertions, 21 deletions
diff --git a/ui/app/components/gas-customization/gas-modal-page-container/gas-modal-page-container.container.js b/ui/app/components/gas-customization/gas-modal-page-container/gas-modal-page-container.container.js index 64b94e66c..426f940d1 100644 --- a/ui/app/components/gas-customization/gas-modal-page-container/gas-modal-page-container.container.js +++ b/ui/app/components/gas-customization/gas-modal-page-container/gas-modal-page-container.container.js @@ -51,6 +51,7 @@ import { calcGasTotal, } from '../../send/send.utils' import { addHexPrefix } from 'ethereumjs-util' +import { getAdjacentGasPrices, extrapolateY } from '../gas-price-chart/gas-price-chart.utils' const mapStateToProps = state => { const buttonDataLoading = getBasicGasEstimateLoadingStatus(state) @@ -83,7 +84,7 @@ const mapStateToProps = state => { customGasPrice, customGasLimit: calcCustomGasLimit(customModalGasLimitInHex), newTotalFiat, - currentTimeEstimate: getRenderableTimeEstimate(customGasPrice, getPriceAndTimeEstimates(state)), + currentTimeEstimate: getRenderableTimeEstimate(customGasPrice, gasPrices, estimatedTimes), gasPriceButtonGroupProps: { buttonDataLoading, defaultActiveButtonIndex: getDefaultActiveButtonIndex(gasButtonInfo, customModalGasPriceInHex), @@ -93,7 +94,7 @@ const mapStateToProps = state => { currentPrice: customGasPrice, gasPrices, estimatedTimes, - gasPricesMax: gasPrices[gasPrices.length - 1] + 1, + gasPricesMax: gasPrices[gasPrices.length - 1], estimatedTimesMax: estimatedTimes[0], }, infoRowProps: { @@ -173,7 +174,6 @@ function calcCustomGasLimit (customGasLimitInHex) { function getTxParams (state) { const { confirmTransaction: { txData }, metamask: { send } } = state - console.log('txData', txData) return txData.txParams || { from: send.from, gas: send.gasLimit, @@ -198,24 +198,21 @@ function addHexWEIsToRenderableFiat (aHexWEI, bHexWEI, convertedCurrency, conver )(aHexWEI, bHexWEI) } -function getRenderableTimeEstimate (currentGasPrice, priceAndTimeEstimates) { - const gasPrices = priceAndTimeEstimates.map(({ gasprice }) => gasprice) - const estimatedTimes = priceAndTimeEstimates.map(({ expectedTime }) => expectedTime) - - const closestLowerValueIndex = gasPrices.findIndex((e, i, a) => { - return e <= currentGasPrice && a[i + 1] >= currentGasPrice - }) - const closestHigherValueIndex = gasPrices.findIndex((e, i, a) => { - return e > currentGasPrice +function getRenderableTimeEstimate (currentGasPrice, gasPrices, estimatedTimes) { + const { + closestLowerValueIndex, + closestHigherValueIndex, + closestHigherValue, + closestLowerValue, + } = getAdjacentGasPrices({ gasPrices, priceToPosition: currentGasPrice }) + + const newTimeEstimate = extrapolateY({ + higherY: estimatedTimes[closestHigherValueIndex], + lowerY: estimatedTimes[closestLowerValueIndex], + higherX: closestHigherValue, + lowerX: closestLowerValue, + xForExtrapolation: currentGasPrice, }) - const closestLowerValue = gasPrices[closestLowerValueIndex] - const closestHigherValue = gasPrices[closestHigherValueIndex] - const estimatedClosestLowerTimeEstimate = estimatedTimes[closestLowerValueIndex] - const estimatedClosestHigherTimeEstimate = estimatedTimes[closestHigherValueIndex] - - const slope = (estimatedClosestHigherTimeEstimate - estimatedClosestLowerTimeEstimate) / (closestHigherValue - closestLowerValue) - const newTimeEstimate = -1 * (slope * (closestHigherValue - currentGasPrice) - estimatedClosestHigherTimeEstimate) - return formatTimeEstimate(newTimeEstimate) } diff --git a/ui/app/components/gas-customization/gas-modal-page-container/tests/gas-modal-page-container-container.test.js b/ui/app/components/gas-customization/gas-modal-page-container/tests/gas-modal-page-container-container.test.js index 2170c242d..54fbfb66c 100644 --- a/ui/app/components/gas-customization/gas-modal-page-container/tests/gas-modal-page-container-container.test.js +++ b/ui/app/components/gas-customization/gas-modal-page-container/tests/gas-modal-page-container-container.test.js @@ -107,7 +107,7 @@ describe('gas-modal-page-container container', () => { estimatedTimes: ['31', '62', '93', '124'], estimatedTimesMax: '31', gasPrices: [3, 4, 5, 6], - gasPricesMax: 7, + gasPricesMax: 6, }, gasPriceButtonGroupProps: { buttonDataLoading: 'mockBasicGasEstimateLoadingStatus:4', |