|
|
@ -51,6 +51,7 @@ import { |
|
|
|
calcGasTotal, |
|
|
|
calcGasTotal, |
|
|
|
} from '../../send/send.utils' |
|
|
|
} from '../../send/send.utils' |
|
|
|
import { addHexPrefix } from 'ethereumjs-util' |
|
|
|
import { addHexPrefix } from 'ethereumjs-util' |
|
|
|
|
|
|
|
import { getAdjacentGasPrices, extrapolateY } from '../gas-price-chart/gas-price-chart.utils' |
|
|
|
|
|
|
|
|
|
|
|
const mapStateToProps = state => { |
|
|
|
const mapStateToProps = state => { |
|
|
|
const buttonDataLoading = getBasicGasEstimateLoadingStatus(state) |
|
|
|
const buttonDataLoading = getBasicGasEstimateLoadingStatus(state) |
|
|
@ -83,7 +84,7 @@ const mapStateToProps = state => { |
|
|
|
customGasPrice, |
|
|
|
customGasPrice, |
|
|
|
customGasLimit: calcCustomGasLimit(customModalGasLimitInHex), |
|
|
|
customGasLimit: calcCustomGasLimit(customModalGasLimitInHex), |
|
|
|
newTotalFiat, |
|
|
|
newTotalFiat, |
|
|
|
currentTimeEstimate: getRenderableTimeEstimate(customGasPrice, getPriceAndTimeEstimates(state)), |
|
|
|
currentTimeEstimate: getRenderableTimeEstimate(customGasPrice, gasPrices, estimatedTimes), |
|
|
|
gasPriceButtonGroupProps: { |
|
|
|
gasPriceButtonGroupProps: { |
|
|
|
buttonDataLoading, |
|
|
|
buttonDataLoading, |
|
|
|
defaultActiveButtonIndex: getDefaultActiveButtonIndex(gasButtonInfo, customModalGasPriceInHex), |
|
|
|
defaultActiveButtonIndex: getDefaultActiveButtonIndex(gasButtonInfo, customModalGasPriceInHex), |
|
|
@ -93,7 +94,7 @@ const mapStateToProps = state => { |
|
|
|
currentPrice: customGasPrice, |
|
|
|
currentPrice: customGasPrice, |
|
|
|
gasPrices, |
|
|
|
gasPrices, |
|
|
|
estimatedTimes, |
|
|
|
estimatedTimes, |
|
|
|
gasPricesMax: gasPrices[gasPrices.length - 1] + 1, |
|
|
|
gasPricesMax: gasPrices[gasPrices.length - 1], |
|
|
|
estimatedTimesMax: estimatedTimes[0], |
|
|
|
estimatedTimesMax: estimatedTimes[0], |
|
|
|
}, |
|
|
|
}, |
|
|
|
infoRowProps: { |
|
|
|
infoRowProps: { |
|
|
@ -173,7 +174,6 @@ function calcCustomGasLimit (customGasLimitInHex) { |
|
|
|
|
|
|
|
|
|
|
|
function getTxParams (state) { |
|
|
|
function getTxParams (state) { |
|
|
|
const { confirmTransaction: { txData }, metamask: { send } } = state |
|
|
|
const { confirmTransaction: { txData }, metamask: { send } } = state |
|
|
|
console.log('txData', txData) |
|
|
|
|
|
|
|
return txData.txParams || { |
|
|
|
return txData.txParams || { |
|
|
|
from: send.from, |
|
|
|
from: send.from, |
|
|
|
gas: send.gasLimit, |
|
|
|
gas: send.gasLimit, |
|
|
@ -198,24 +198,21 @@ function addHexWEIsToRenderableFiat (aHexWEI, bHexWEI, convertedCurrency, conver |
|
|
|
)(aHexWEI, bHexWEI) |
|
|
|
)(aHexWEI, bHexWEI) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
function getRenderableTimeEstimate (currentGasPrice, priceAndTimeEstimates) { |
|
|
|
function getRenderableTimeEstimate (currentGasPrice, gasPrices, estimatedTimes) { |
|
|
|
const gasPrices = priceAndTimeEstimates.map(({ gasprice }) => gasprice) |
|
|
|
const { |
|
|
|
const estimatedTimes = priceAndTimeEstimates.map(({ expectedTime }) => expectedTime) |
|
|
|
closestLowerValueIndex, |
|
|
|
|
|
|
|
closestHigherValueIndex, |
|
|
|
const closestLowerValueIndex = gasPrices.findIndex((e, i, a) => { |
|
|
|
closestHigherValue, |
|
|
|
return e <= currentGasPrice && a[i + 1] >= currentGasPrice |
|
|
|
closestLowerValue, |
|
|
|
}) |
|
|
|
} = getAdjacentGasPrices({ gasPrices, priceToPosition: currentGasPrice }) |
|
|
|
const closestHigherValueIndex = gasPrices.findIndex((e, i, a) => { |
|
|
|
|
|
|
|
return e > 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) |
|
|
|
return formatTimeEstimate(newTimeEstimate) |
|
|
|
} |
|
|
|
} |
|
|
|