mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Improve data management and tests for gas-modal-page-container price estimates.
This commit is contained in:
parent
d0619b024f
commit
d14af8346a
@ -24,13 +24,16 @@ import {
|
|||||||
getSelectedToken,
|
getSelectedToken,
|
||||||
} from '../../../selectors.js'
|
} from '../../../selectors.js'
|
||||||
import {
|
import {
|
||||||
getCustomGasPrice,
|
|
||||||
getCustomGasLimit,
|
|
||||||
getRenderableBasicEstimateData,
|
|
||||||
getBasicGasEstimateLoadingStatus,
|
|
||||||
getAveragePriceEstimateInHexWEI,
|
|
||||||
getDefaultActiveButtonIndex,
|
|
||||||
formatTimeEstimate,
|
formatTimeEstimate,
|
||||||
|
getAveragePriceEstimateInHexWEI,
|
||||||
|
getBasicGasEstimateLoadingStatus,
|
||||||
|
getCustomGasLimit,
|
||||||
|
getCustomGasPrice,
|
||||||
|
getDefaultActiveButtonIndex,
|
||||||
|
getEstimatedGasPrices,
|
||||||
|
getEstimatedGasTimes,
|
||||||
|
getPriceAndTimeEstimates,
|
||||||
|
getRenderableBasicEstimateData,
|
||||||
} from '../../../selectors/custom-gas'
|
} from '../../../selectors/custom-gas'
|
||||||
import {
|
import {
|
||||||
formatCurrency,
|
formatCurrency,
|
||||||
@ -69,9 +72,8 @@ const mapStateToProps = state => {
|
|||||||
|
|
||||||
const customGasPrice = calcCustomGasPrice(customModalGasPriceInHex)
|
const customGasPrice = calcCustomGasPrice(customModalGasPriceInHex)
|
||||||
|
|
||||||
const priceAndTimeEstimates = state.gas.priceAndTimeEstimates
|
const gasPrices = getEstimatedGasPrices(state)
|
||||||
const gasPrices = priceAndTimeEstimates.map(({ gasprice }) => gasprice)
|
const estimatedTimes = getEstimatedGasTimes(state)
|
||||||
const estimatedTimes = priceAndTimeEstimates.map(({ expectedTime }) => expectedTime)
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
hideBasic,
|
hideBasic,
|
||||||
@ -81,7 +83,7 @@ const mapStateToProps = state => {
|
|||||||
customGasPrice,
|
customGasPrice,
|
||||||
customGasLimit: calcCustomGasLimit(customModalGasLimitInHex),
|
customGasLimit: calcCustomGasLimit(customModalGasLimitInHex),
|
||||||
newTotalFiat,
|
newTotalFiat,
|
||||||
currentTimeEstimate: getRenderableTimeEstimate(customGasPrice, priceAndTimeEstimates),
|
currentTimeEstimate: getRenderableTimeEstimate(customGasPrice, getPriceAndTimeEstimates(state)),
|
||||||
gasPriceButtonGroupProps: {
|
gasPriceButtonGroupProps: {
|
||||||
buttonDataLoading,
|
buttonDataLoading,
|
||||||
defaultActiveButtonIndex: getDefaultActiveButtonIndex(gasButtonInfo, customModalGasPriceInHex),
|
defaultActiveButtonIndex: getDefaultActiveButtonIndex(gasButtonInfo, customModalGasPriceInHex),
|
||||||
|
@ -104,12 +104,10 @@ describe('gas-modal-page-container container', () => {
|
|||||||
customModalGasPriceInHex: 'ffffffff',
|
customModalGasPriceInHex: 'ffffffff',
|
||||||
gasChartProps: {
|
gasChartProps: {
|
||||||
'currentPrice': 4.294967295,
|
'currentPrice': 4.294967295,
|
||||||
priceAndTimeEstimates: [
|
estimatedTimes: ['31', '62', '93', '124'],
|
||||||
{ gasprice: 3, expectedTime: '31' },
|
estimatedTimesMax: '31',
|
||||||
{ gasprice: 4, expectedTime: '62' },
|
gasPrices: [3, 4, 5, 6],
|
||||||
{ gasprice: 5, expectedTime: '93' },
|
gasPricesMax: 7,
|
||||||
{ gasprice: 6, expectedTime: '124' },
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
gasPriceButtonGroupProps: {
|
gasPriceButtonGroupProps: {
|
||||||
buttonDataLoading: 'mockBasicGasEstimateLoadingStatus:4',
|
buttonDataLoading: 'mockBasicGasEstimateLoadingStatus:4',
|
||||||
|
@ -21,17 +21,20 @@ import {
|
|||||||
import { addHexPrefix } from 'ethereumjs-util'
|
import { addHexPrefix } from 'ethereumjs-util'
|
||||||
|
|
||||||
const selectors = {
|
const selectors = {
|
||||||
|
formatTimeEstimate,
|
||||||
|
getAveragePriceEstimateInHexWEI,
|
||||||
|
getBasicGasEstimateLoadingStatus,
|
||||||
getCustomGasErrors,
|
getCustomGasErrors,
|
||||||
getCustomGasLimit,
|
getCustomGasLimit,
|
||||||
getCustomGasPrice,
|
getCustomGasPrice,
|
||||||
getCustomGasTotal,
|
getCustomGasTotal,
|
||||||
getRenderableEstimateDataForSmallButtons,
|
|
||||||
getRenderableBasicEstimateData,
|
|
||||||
getBasicGasEstimateLoadingStatus,
|
|
||||||
getAveragePriceEstimateInHexWEI,
|
|
||||||
getDefaultActiveButtonIndex,
|
getDefaultActiveButtonIndex,
|
||||||
|
getEstimatedGasPrices,
|
||||||
|
getEstimatedGasTimes,
|
||||||
|
getPriceAndTimeEstimates,
|
||||||
|
getRenderableBasicEstimateData,
|
||||||
|
getRenderableEstimateDataForSmallButtons,
|
||||||
priceEstimateToWei,
|
priceEstimateToWei,
|
||||||
formatTimeEstimate,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = selectors
|
module.exports = selectors
|
||||||
@ -58,6 +61,18 @@ function getBasicGasEstimateLoadingStatus (state) {
|
|||||||
return state.gas.basicEstimateIsLoading
|
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) {
|
function getAveragePriceEstimateInHexWEI (state) {
|
||||||
const averagePriceEstimate = state.gas.basicEstimates.average
|
const averagePriceEstimate = state.gas.basicEstimates.average
|
||||||
return getGasPriceInHexWei(averagePriceEstimate || '0x0')
|
return getGasPriceInHexWei(averagePriceEstimate || '0x0')
|
||||||
|
@ -6,6 +6,9 @@ const {
|
|||||||
getCustomGasLimit,
|
getCustomGasLimit,
|
||||||
getCustomGasPrice,
|
getCustomGasPrice,
|
||||||
getCustomGasTotal,
|
getCustomGasTotal,
|
||||||
|
getEstimatedGasPrices,
|
||||||
|
getEstimatedGasTimes,
|
||||||
|
getPriceAndTimeEstimates,
|
||||||
getRenderableBasicEstimateData,
|
getRenderableBasicEstimateData,
|
||||||
getRenderableEstimateDataForSmallButtons,
|
getRenderableEstimateDataForSmallButtons,
|
||||||
} = proxyquire('../custom-gas', {})
|
} = 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()', () => {
|
describe('getRenderableBasicEstimateData()', () => {
|
||||||
const tests = [
|
const tests = [
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user