aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/components/gas-customization/gas-modal-page-container/gas-modal-page-container.container.js
diff options
context:
space:
mode:
authorDan Miller <danjm.com@gmail.com>2018-10-25 08:53:12 +0800
committerDan Miller <danjm.com@gmail.com>2018-12-04 11:36:05 +0800
commit3ced3c9b2ab75038163f82eb77fbf97ea78d2342 (patch)
treeb16818f06358ffdd4faee14ce6a1badea395ed9f /ui/app/components/gas-customization/gas-modal-page-container/gas-modal-page-container.container.js
parentd14af8346af2517db2e50f142377948c9f2ae5e9 (diff)
downloadtangerine-wallet-browser-3ced3c9b2ab75038163f82eb77fbf97ea78d2342.tar
tangerine-wallet-browser-3ced3c9b2ab75038163f82eb77fbf97ea78d2342.tar.gz
tangerine-wallet-browser-3ced3c9b2ab75038163f82eb77fbf97ea78d2342.tar.bz2
tangerine-wallet-browser-3ced3c9b2ab75038163f82eb77fbf97ea78d2342.tar.lz
tangerine-wallet-browser-3ced3c9b2ab75038163f82eb77fbf97ea78d2342.tar.xz
tangerine-wallet-browser-3ced3c9b2ab75038163f82eb77fbf97ea78d2342.tar.zst
tangerine-wallet-browser-3ced3c9b2ab75038163f82eb77fbf97ea78d2342.zip
Clean up for mmui-i11-custom-gas-price-chart branch
Diffstat (limited to 'ui/app/components/gas-customization/gas-modal-page-container/gas-modal-page-container.container.js')
-rw-r--r--ui/app/components/gas-customization/gas-modal-page-container/gas-modal-page-container.container.js37
1 files changed, 17 insertions, 20 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)
}