1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-23 09:52:26 +01:00

Help users avoid insufficient gas prices in swaps (#9624)

* Don't show average (slowest) button in custom gas modal while in swaps

* In swaps, show warning in custom gas modal if price set below average price

* Update ui/app/selectors/custom-gas.js

Co-authored-by: Erik Marks <25517051+rekmarks@users.noreply.github.com>

* Fix typo

Co-authored-by: Erik Marks <25517051+rekmarks@users.noreply.github.com>
This commit is contained in:
Dan J Miller 2020-10-17 06:43:51 -02:30 committed by GitHub
parent e546314e3f
commit 3191d9e014
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 16 deletions

View File

@ -158,7 +158,7 @@ const mapStateToProps = (state, ownProps) => {
newTotalFiat, newTotalFiat,
currentTimeEstimate, currentTimeEstimate,
blockTime: getBasicGasEstimateBlockTime(state), blockTime: getBasicGasEstimateBlockTime(state),
customPriceIsSafe: isCustomPriceSafe(state), customPriceIsSafe: isCustomPriceSafe(state, isSwap),
maxModeOn, maxModeOn,
gasPriceButtonGroupProps: { gasPriceButtonGroupProps: {
buttonDataLoading, buttonDataLoading,

View File

@ -88,16 +88,31 @@ export function getSafeLowEstimate (state) {
return safeLow return safeLow
} }
export function isCustomPriceSafe (state) { export function getAverageEstimate (state) {
const {
gas: {
basicEstimates: {
average,
},
},
} = state
return average
}
export function isCustomPriceSafe (state, averageIsSafe) {
const safeLow = getSafeLowEstimate(state) const safeLow = getSafeLowEstimate(state)
const average = getAverageEstimate(state)
const safeMinimumPrice = averageIsSafe ? average : safeLow
const customGasPrice = getCustomGasPrice(state) const customGasPrice = getCustomGasPrice(state)
if (!customGasPrice) { if (!customGasPrice) {
return true return true
} }
if (safeLow === null) { if (safeMinimumPrice === null) {
return null return false
} }
const customPriceSafe = conversionGreaterThan( const customPriceSafe = conversionGreaterThan(
@ -107,7 +122,7 @@ export function isCustomPriceSafe (state) {
fromDenomination: 'WEI', fromDenomination: 'WEI',
toDenomination: 'GWEI', toDenomination: 'GWEI',
}, },
{ value: safeLow, fromNumericBase: 'dec' }, { value: safeMinimumPrice, fromNumericBase: 'dec' },
) )
return customPriceSafe return customPriceSafe
@ -216,7 +231,7 @@ export function getRenderableBasicEstimateData (state, gasLimit, useFastestButto
}, },
} = state } = state
const slowEstimatData = { const slowEstimateData = {
gasEstimateType: GAS_ESTIMATE_TYPES.SLOW, gasEstimateType: GAS_ESTIMATE_TYPES.SLOW,
feeInPrimaryCurrency: getRenderableEthFee(safeLow, gasLimit), feeInPrimaryCurrency: getRenderableEthFee(safeLow, gasLimit),
feeInSecondaryCurrency: showFiat feeInSecondaryCurrency: showFiat
@ -234,7 +249,7 @@ export function getRenderableBasicEstimateData (state, gasLimit, useFastestButto
timeEstimate: avgWait && getRenderableTimeEstimate(avgWait), timeEstimate: avgWait && getRenderableTimeEstimate(avgWait),
priceInHexWei: getGasPriceInHexWei(average), priceInHexWei: getGasPriceInHexWei(average),
} }
const fastEstimatData = { const fastEstimateData = {
gasEstimateType: GAS_ESTIMATE_TYPES.FAST, gasEstimateType: GAS_ESTIMATE_TYPES.FAST,
feeInPrimaryCurrency: getRenderableEthFee(fast, gasLimit), feeInPrimaryCurrency: getRenderableEthFee(fast, gasLimit),
feeInSecondaryCurrency: showFiat feeInSecondaryCurrency: showFiat
@ -254,8 +269,8 @@ export function getRenderableBasicEstimateData (state, gasLimit, useFastestButto
} }
return useFastestButtons return useFastestButtons
? [averageEstimateData, fastEstimatData, fastestEstimateData] ? [fastEstimateData, fastestEstimateData]
: [slowEstimatData, averageEstimateData, fastEstimatData] : [slowEstimateData, averageEstimateData, fastEstimateData]
} }
export function getRenderableEstimateDataForSmallButtonsFromGWEI (state) { export function getRenderableEstimateDataForSmallButtonsFromGWEI (state) {

View File

@ -346,13 +346,6 @@ describe('custom-gas selectors', function () {
}, },
{ {
expectedResult: [ expectedResult: [
{
gasEstimateType: 'AVERAGE',
feeInPrimaryCurrency: '0.000147 ETH',
feeInSecondaryCurrency: '$0.38',
priceInHexWei: '0x1a13b8600',
timeEstimate: '~10 min 6 sec',
},
{ {
gasEstimateType: 'FAST', gasEstimateType: 'FAST',
feeInSecondaryCurrency: '$0.54', feeInSecondaryCurrency: '$0.54',