aboutsummaryrefslogtreecommitdiffstats
path: root/ui
diff options
context:
space:
mode:
authorDan Miller <danjm.com@gmail.com>2018-10-24 12:22:22 +0800
committerDan Miller <danjm.com@gmail.com>2018-12-04 11:36:05 +0800
commitd14af8346af2517db2e50f142377948c9f2ae5e9 (patch)
treeccdfe345dd000b44c0eedfbee0037969ff2d6f38 /ui
parentd0619b024fb092182e77e16c6742e157c89b2dc9 (diff)
downloadtangerine-wallet-browser-d14af8346af2517db2e50f142377948c9f2ae5e9.tar
tangerine-wallet-browser-d14af8346af2517db2e50f142377948c9f2ae5e9.tar.gz
tangerine-wallet-browser-d14af8346af2517db2e50f142377948c9f2ae5e9.tar.bz2
tangerine-wallet-browser-d14af8346af2517db2e50f142377948c9f2ae5e9.tar.lz
tangerine-wallet-browser-d14af8346af2517db2e50f142377948c9f2ae5e9.tar.xz
tangerine-wallet-browser-d14af8346af2517db2e50f142377948c9f2ae5e9.tar.zst
tangerine-wallet-browser-d14af8346af2517db2e50f142377948c9f2ae5e9.zip
Improve data management and tests for gas-modal-page-container price estimates.
Diffstat (limited to 'ui')
-rw-r--r--ui/app/components/gas-customization/gas-modal-page-container/gas-modal-page-container.container.js20
-rw-r--r--ui/app/components/gas-customization/gas-modal-page-container/tests/gas-modal-page-container-container.test.js10
-rw-r--r--ui/app/selectors/custom-gas.js25
-rw-r--r--ui/app/selectors/tests/custom-gas.test.js32
4 files changed, 67 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 67c1ff2e3..64b94e66c 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
@@ -24,13 +24,16 @@ import {
getSelectedToken,
} from '../../../selectors.js'
import {
- getCustomGasPrice,
- getCustomGasLimit,
- getRenderableBasicEstimateData,
- getBasicGasEstimateLoadingStatus,
+ formatTimeEstimate,
getAveragePriceEstimateInHexWEI,
+ getBasicGasEstimateLoadingStatus,
+ getCustomGasLimit,
+ getCustomGasPrice,
getDefaultActiveButtonIndex,
- formatTimeEstimate,
+ getEstimatedGasPrices,
+ getEstimatedGasTimes,
+ getPriceAndTimeEstimates,
+ getRenderableBasicEstimateData,
} from '../../../selectors/custom-gas'
import {
formatCurrency,
@@ -69,9 +72,8 @@ const mapStateToProps = state => {
const customGasPrice = calcCustomGasPrice(customModalGasPriceInHex)
- const priceAndTimeEstimates = state.gas.priceAndTimeEstimates
- const gasPrices = priceAndTimeEstimates.map(({ gasprice }) => gasprice)
- const estimatedTimes = priceAndTimeEstimates.map(({ expectedTime }) => expectedTime)
+ const gasPrices = getEstimatedGasPrices(state)
+ const estimatedTimes = getEstimatedGasTimes(state)
return {
hideBasic,
@@ -81,7 +83,7 @@ const mapStateToProps = state => {
customGasPrice,
customGasLimit: calcCustomGasLimit(customModalGasLimitInHex),
newTotalFiat,
- currentTimeEstimate: getRenderableTimeEstimate(customGasPrice, priceAndTimeEstimates),
+ currentTimeEstimate: getRenderableTimeEstimate(customGasPrice, getPriceAndTimeEstimates(state)),
gasPriceButtonGroupProps: {
buttonDataLoading,
defaultActiveButtonIndex: getDefaultActiveButtonIndex(gasButtonInfo, customModalGasPriceInHex),
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 3f3be8d0c..2170c242d 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
@@ -104,12 +104,10 @@ describe('gas-modal-page-container container', () => {
customModalGasPriceInHex: 'ffffffff',
gasChartProps: {
'currentPrice': 4.294967295,
- priceAndTimeEstimates: [
- { gasprice: 3, expectedTime: '31' },
- { gasprice: 4, expectedTime: '62' },
- { gasprice: 5, expectedTime: '93' },
- { gasprice: 6, expectedTime: '124' },
- ],
+ estimatedTimes: ['31', '62', '93', '124'],
+ estimatedTimesMax: '31',
+ gasPrices: [3, 4, 5, 6],
+ gasPricesMax: 7,
},
gasPriceButtonGroupProps: {
buttonDataLoading: 'mockBasicGasEstimateLoadingStatus:4',
diff --git a/ui/app/selectors/custom-gas.js b/ui/app/selectors/custom-gas.js
index abc8ba191..46bf06efc 100644
--- a/ui/app/selectors/custom-gas.js
+++ b/ui/app/selectors/custom-gas.js
@@ -21,17 +21,20 @@ import {
import { addHexPrefix } from 'ethereumjs-util'
const selectors = {
+ formatTimeEstimate,
+ getAveragePriceEstimateInHexWEI,
+ getBasicGasEstimateLoadingStatus,
getCustomGasErrors,
getCustomGasLimit,
getCustomGasPrice,
getCustomGasTotal,
- getRenderableEstimateDataForSmallButtons,
- getRenderableBasicEstimateData,
- getBasicGasEstimateLoadingStatus,
- getAveragePriceEstimateInHexWEI,
getDefaultActiveButtonIndex,
+ getEstimatedGasPrices,
+ getEstimatedGasTimes,
+ getPriceAndTimeEstimates,
+ getRenderableBasicEstimateData,
+ getRenderableEstimateDataForSmallButtons,
priceEstimateToWei,
- formatTimeEstimate,
}
module.exports = selectors
@@ -58,6 +61,18 @@ function getBasicGasEstimateLoadingStatus (state) {
return state.gas.basicEstimateIsLoading
}
+function getPriceAndTimeEstimates (state) {
+ return state.gas.priceAndTimeEstimates
+}
+
+function getEstimatedGasPrices (state) {
+ return getPriceAndTimeEstimates(state).map(({ gasprice }) => gasprice)
+}
+
+function getEstimatedGasTimes (state) {
+ return getPriceAndTimeEstimates(state).map(({ expectedTime }) => expectedTime)
+}
+
function getAveragePriceEstimateInHexWEI (state) {
const averagePriceEstimate = state.gas.basicEstimates.average
return getGasPriceInHexWei(averagePriceEstimate || '0x0')
diff --git a/ui/app/selectors/tests/custom-gas.test.js b/ui/app/selectors/tests/custom-gas.test.js
index 5fde61c9b..1099670f2 100644
--- a/ui/app/selectors/tests/custom-gas.test.js
+++ b/ui/app/selectors/tests/custom-gas.test.js
@@ -6,6 +6,9 @@ const {
getCustomGasLimit,
getCustomGasPrice,
getCustomGasTotal,
+ getEstimatedGasPrices,
+ getEstimatedGasTimes,
+ getPriceAndTimeEstimates,
getRenderableBasicEstimateData,
getRenderableEstimateDataForSmallButtons,
} = proxyquire('../custom-gas', {})
@@ -40,6 +43,35 @@ describe('custom-gas selectors', () => {
})
})
+ describe('getPriceAndTimeEstimates', () => {
+ it('should return price and time estimates', () => {
+ const mockState = { gas: { priceAndTimeEstimates: 'mockPriceAndTimeEstimates' } }
+ assert.equal(getPriceAndTimeEstimates(mockState), 'mockPriceAndTimeEstimates')
+ })
+ })
+
+ describe('getEstimatedGasPrices', () => {
+ it('should return price and time estimates', () => {
+ const mockState = { gas: { priceAndTimeEstimates: [
+ { gasprice: 12, somethingElse: 20 },
+ { gasprice: 22, expectedTime: 30 },
+ { gasprice: 32, somethingElse: 40 },
+ ] } }
+ assert.deepEqual(getEstimatedGasPrices(mockState), [12, 22, 32])
+ })
+ })
+
+ describe('getEstimatedGasTimes', () => {
+ it('should return price and time estimates', () => {
+ const mockState = { gas: { priceAndTimeEstimates: [
+ { somethingElse: 12, expectedTime: 20 },
+ { gasPrice: 22, expectedTime: 30 },
+ { somethingElse: 32, expectedTime: 40 },
+ ] } }
+ assert.deepEqual(getEstimatedGasTimes(mockState), [20, 30, 40])
+ })
+ })
+
describe('getRenderableBasicEstimateData()', () => {
const tests = [
{