aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/selectors/custom-gas.js
diff options
context:
space:
mode:
Diffstat (limited to 'ui/app/selectors/custom-gas.js')
-rw-r--r--ui/app/selectors/custom-gas.js57
1 files changed, 53 insertions, 4 deletions
diff --git a/ui/app/selectors/custom-gas.js b/ui/app/selectors/custom-gas.js
index 61c0525df..f023b03b8 100644
--- a/ui/app/selectors/custom-gas.js
+++ b/ui/app/selectors/custom-gas.js
@@ -25,6 +25,7 @@ const selectors = {
getCustomGasLimit,
getCustomGasPrice,
getCustomGasTotal,
+ getRenderableEstimateDataForSmallButtons,
getRenderableBasicEstimateData,
getBasicGasEstimateLoadingStatus,
getAveragePriceEstimateInHexWEI,
@@ -34,6 +35,8 @@ const selectors = {
module.exports = selectors
+const NUMBER_OF_DECIMALS_SM_BTNS = 5
+
function getCustomGasErrors (state) {
return state.gas.errors
}
@@ -60,7 +63,9 @@ function getAveragePriceEstimateInHexWEI (state) {
}
function getDefaultActiveButtonIndex (gasButtonInfo, customGasPriceInHex, gasPrice) {
+ console.log('gasButtonInfo', gasButtonInfo)
return gasButtonInfo.findIndex(({ priceInHexWei }) => {
+ console.log('priceInHexWei', priceInHexWei, '|', customGasPriceInHex)
return priceInHexWei === addHexPrefix(customGasPriceInHex || gasPrice)
})
}
@@ -74,23 +79,24 @@ function apiEstimateModifiedToGWEI (estimate) {
})
}
-function basicPriceEstimateToETHTotal (estimate, gasLimit) {
+function basicPriceEstimateToETHTotal (estimate, gasLimit, numberOfDecimals = 9) {
return conversionUtil(calcGasTotal(gasLimit, estimate), {
fromNumericBase: 'hex',
toNumericBase: 'dec',
fromDenomination: 'GWEI',
- numberOfDecimals: 9,
+ numberOfDecimals,
})
}
-function getRenderableEthFee (estimate, gasLimit) {
+function getRenderableEthFee (estimate, gasLimit, numberOfDecimals = 9) {
return pipe(
apiEstimateModifiedToGWEI,
- partialRight(basicPriceEstimateToETHTotal, [gasLimit]),
+ partialRight(basicPriceEstimateToETHTotal, [gasLimit, numberOfDecimals]),
formatETHFee
)(estimate, gasLimit)
}
+
function getRenderableConvertedCurrencyFee (estimate, gasLimit, convertedCurrency, conversionRate) {
return pipe(
apiEstimateModifiedToGWEI,
@@ -188,3 +194,46 @@ function getRenderableBasicEstimateData (state) {
},
]
}
+
+function getRenderableEstimateDataForSmallButtons (state) {
+ if (getBasicGasEstimateLoadingStatus(state)) {
+ return []
+ }
+ const gasLimit = state.metamask.send.gasLimit || getCustomGasLimit(state)
+ const conversionRate = state.metamask.conversionRate
+ const currentCurrency = getCurrentCurrency(state)
+ const {
+ gas: {
+ basicEstimates: {
+ safeLow,
+ average,
+ fast,
+ blockTime,
+ safeLowWait,
+ avgWait,
+ fastWait,
+ },
+ },
+ } = state
+
+ return [
+ {
+ labelKey: 'fast',
+ feeInSecondaryCurrency: getRenderableConvertedCurrencyFee(fast, gasLimit, currentCurrency, conversionRate),
+ feeInPrimaryCurrency: getRenderableEthFee(fast, gasLimit, NUMBER_OF_DECIMALS_SM_BTNS),
+ priceInHexWei: getGasPriceInHexWei(fast),
+ },
+ {
+ labelKey: 'average',
+ feeInSecondaryCurrency: getRenderableConvertedCurrencyFee(average, gasLimit, currentCurrency, conversionRate),
+ feeInPrimaryCurrency: getRenderableEthFee(average, gasLimit, NUMBER_OF_DECIMALS_SM_BTNS),
+ priceInHexWei: getGasPriceInHexWei(average),
+ },
+ {
+ labelKey: 'slow',
+ feeInSecondaryCurrency: getRenderableConvertedCurrencyFee(safeLow, gasLimit, currentCurrency, conversionRate),
+ feeInPrimaryCurrency: getRenderableEthFee(safeLow, gasLimit, NUMBER_OF_DECIMALS_SM_BTNS),
+ priceInHexWei: getGasPriceInHexWei(safeLow),
+ },
+ ]
+}