aboutsummaryrefslogtreecommitdiffstats
path: root/ui/app/selectors
diff options
context:
space:
mode:
authorDan Miller <danjm.com@gmail.com>2018-11-28 01:30:41 +0800
committerDan Miller <danjm.com@gmail.com>2018-12-04 11:36:22 +0800
commitd8e41a6aa5a4c64538063c6dde7afdf77b0e5793 (patch)
treee03f9f43682cf687d81e93185cd2edcdb57fb0b2 /ui/app/selectors
parent75d75454374d98bf904b817bc2dd2b81b9e97a9d (diff)
downloadtangerine-wallet-browser-d8e41a6aa5a4c64538063c6dde7afdf77b0e5793.tar.gz
tangerine-wallet-browser-d8e41a6aa5a4c64538063c6dde7afdf77b0e5793.tar.zst
tangerine-wallet-browser-d8e41a6aa5a4c64538063c6dde7afdf77b0e5793.zip
Final gas customization fixes
Diffstat (limited to 'ui/app/selectors')
-rw-r--r--ui/app/selectors/custom-gas.js61
-rw-r--r--ui/app/selectors/tests/custom-gas.test.js12
2 files changed, 32 insertions, 41 deletions
diff --git a/ui/app/selectors/custom-gas.js b/ui/app/selectors/custom-gas.js
index ec234500d..59f240f9c 100644
--- a/ui/app/selectors/custom-gas.js
+++ b/ui/app/selectors/custom-gas.js
@@ -85,9 +85,9 @@ function getAveragePriceEstimateInHexWEI (state) {
return getGasPriceInHexWei(averagePriceEstimate || '0x0')
}
-function getFastPriceEstimateInHexWEI (state, convertFromDecGWEI) {
+function getFastPriceEstimateInHexWEI (state) {
const fastPriceEstimate = state.gas.basicEstimates.fast
- return getGasPriceInHexWei(fastPriceEstimate || '0x0', convertFromDecGWEI)
+ return getGasPriceInHexWei(fastPriceEstimate || '0x0')
}
function getDefaultActiveButtonIndex (gasButtonInfo, customGasPriceInHex, gasPrice) {
@@ -100,15 +100,6 @@ function getBasicGasEstimateBlockTime (state) {
return state.gas.basicEstimates.blockTime
}
-function apiEstimateModifiedToGWEI (estimate) {
- return multiplyCurrencies(estimate, 0.10, {
- toNumericBase: 'hex',
- multiplicandBase: 10,
- multiplierBase: 10,
- numberOfDecimals: 9,
- })
-}
-
function basicPriceEstimateToETHTotal (estimate, gasLimit, numberOfDecimals = 9) {
return conversionUtil(calcGasTotal(gasLimit, estimate), {
fromNumericBase: 'hex',
@@ -118,26 +109,18 @@ function basicPriceEstimateToETHTotal (estimate, gasLimit, numberOfDecimals = 9)
})
}
-function getRenderableEthFee (estimate, gasLimit, numberOfDecimals = 9, convertFromDecGWEI) {
- const initialConversion = convertFromDecGWEI
- ? x => conversionUtil(x, { fromNumericBase: 'dec', toNumericBase: 'hex' })
- : apiEstimateModifiedToGWEI
-
+function getRenderableEthFee (estimate, gasLimit, numberOfDecimals = 9) {
return pipe(
- initialConversion,
+ x => conversionUtil(x, { fromNumericBase: 'dec', toNumericBase: 'hex' }),
partialRight(basicPriceEstimateToETHTotal, [gasLimit, numberOfDecimals]),
formatETHFee
)(estimate, gasLimit)
}
-function getRenderableConvertedCurrencyFee (estimate, gasLimit, convertedCurrency, conversionRate, convertFromDecGWEI) {
- const initialConversion = convertFromDecGWEI
- ? x => conversionUtil(x, { fromNumericBase: 'dec', toNumericBase: 'hex' })
- : apiEstimateModifiedToGWEI
-
+function getRenderableConvertedCurrencyFee (estimate, gasLimit, convertedCurrency, conversionRate) {
return pipe(
- initialConversion,
+ x => conversionUtil(x, { fromNumericBase: 'dec', toNumericBase: 'hex' }),
partialRight(basicPriceEstimateToETHTotal, [gasLimit]),
partialRight(ethTotalToConvertedCurrency, [convertedCurrency, conversionRate]),
partialRight(formatCurrency, [convertedCurrency])
@@ -153,14 +136,26 @@ function getTimeEstimateInSeconds (blockWaitEstimate) {
})
}
-function formatTimeEstimate (totalSeconds) {
+function formatTimeEstimate (totalSeconds, greaterThanMax, lessThanMin) {
const minutes = Math.floor(totalSeconds / 60)
const seconds = Math.floor(totalSeconds % 60)
+
+ if (!minutes && !seconds) {
+ return '...'
+ }
+
+ let symbol = '~'
+ if (greaterThanMax) {
+ symbol = '< '
+ } else if (lessThanMin) {
+ symbol = '> '
+ }
+
const formattedMin = `${minutes ? minutes + ' min' : ''}`
const formattedSec = `${seconds ? seconds + ' sec' : ''}`
const formattedCombined = formattedMin && formattedSec
- ? `~${formattedMin} ${formattedSec}`
- : '~' + [formattedMin, formattedSec].find(t => t)
+ ? `${symbol}${formattedMin} ${formattedSec}`
+ : symbol + [formattedMin, formattedSec].find(t => t)
return formattedCombined
}
@@ -182,13 +177,9 @@ function priceEstimateToWei (priceEstimate) {
})
}
-function getGasPriceInHexWei (price, convertFromDecGWEI) {
- const initialConversion = convertFromDecGWEI
- ? x => conversionUtil(x, { fromNumericBase: 'dec', toNumericBase: 'hex' })
- : apiEstimateModifiedToGWEI
-
+function getGasPriceInHexWei (price) {
return pipe(
- initialConversion,
+ x => conversionUtil(x, { fromNumericBase: 'dec', toNumericBase: 'hex' }),
priceEstimateToWei,
addHexPrefix
)(price)
@@ -259,19 +250,19 @@ function getRenderableEstimateDataForSmallButtonsFromGWEI (state) {
return [
{
labelKey: 'fastest',
- feeInSecondaryCurrency: getRenderableConvertedCurrencyFee(fastest, gasLimit, currentCurrency, conversionRate, true),
+ feeInSecondaryCurrency: getRenderableConvertedCurrencyFee(fastest, gasLimit, currentCurrency, conversionRate),
feeInPrimaryCurrency: getRenderableEthFee(fastest, gasLimit, NUMBER_OF_DECIMALS_SM_BTNS, true),
priceInHexWei: getGasPriceInHexWei(fastest, true),
},
{
labelKey: 'fast',
- feeInSecondaryCurrency: getRenderableConvertedCurrencyFee(fast, gasLimit, currentCurrency, conversionRate, true),
+ feeInSecondaryCurrency: getRenderableConvertedCurrencyFee(fast, gasLimit, currentCurrency, conversionRate),
feeInPrimaryCurrency: getRenderableEthFee(fast, gasLimit, NUMBER_OF_DECIMALS_SM_BTNS, true),
priceInHexWei: getGasPriceInHexWei(fast, true),
},
{
labelKey: 'slow',
- feeInSecondaryCurrency: getRenderableConvertedCurrencyFee(safeLow, gasLimit, currentCurrency, conversionRate, true),
+ feeInSecondaryCurrency: getRenderableConvertedCurrencyFee(safeLow, gasLimit, currentCurrency, conversionRate),
feeInPrimaryCurrency: getRenderableEthFee(safeLow, gasLimit, NUMBER_OF_DECIMALS_SM_BTNS, true),
priceInHexWei: getGasPriceInHexWei(safeLow, true),
},
diff --git a/ui/app/selectors/tests/custom-gas.test.js b/ui/app/selectors/tests/custom-gas.test.js
index 037b1e86e..ebc300160 100644
--- a/ui/app/selectors/tests/custom-gas.test.js
+++ b/ui/app/selectors/tests/custom-gas.test.js
@@ -109,11 +109,11 @@ describe('custom-gas selectors', () => {
gas: {
basicEstimates: {
blockTime: 14.16326530612245,
- safeLow: 25,
+ safeLow: 2.5,
safeLowWait: 6.6,
- fast: 50,
+ fast: 5,
fastWait: 3.3,
- fastest: 100,
+ fastest: 10,
fastestWait: 0.5,
},
},
@@ -154,11 +154,11 @@ describe('custom-gas selectors', () => {
gas: {
basicEstimates: {
blockTime: 14.16326530612245,
- safeLow: 50,
+ safeLow: 5,
safeLowWait: 13.2,
- fast: 100,
+ fast: 10,
fastWait: 6.6,
- fastest: 200,
+ fastest: 20,
fastestWait: 1.0,
},
},