mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 18:00:18 +01:00
Fix speed up of 0 max priority fee transactions (#17547)
* Fix speed up of 0 max priority fee transactions * Update ui/hooks/gasFeeInput/useTransactionFunction.test.js Co-authored-by: Brad Decker <bhdecker84@gmail.com> * Use bignumber for comparison to zero --------- Co-authored-by: Brad Decker <bhdecker84@gmail.com> Co-authored-by: Pedro Figueiredo <pedro.figueiredo@consensys.net>
This commit is contained in:
parent
222a7dd881
commit
9ecf5d2d4e
@ -90,6 +90,31 @@ describe('useMaxPriorityFeePerGasInput', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('invokes action updateTransaction with 10% increased max priority fee and medium fee + 10% when updateTransactionToTenPercentIncreasedGasFee callback is invoked while original priority fee is 0', async () => {
|
||||
const mockUpdateGasFees = jest
|
||||
.spyOn(Actions, 'updateTransactionGasFees')
|
||||
.mockImplementation(() => ({ type: '' }));
|
||||
|
||||
const { result } = renderUseTransactionFunctions({
|
||||
transaction: {
|
||||
userFeeLevel: CUSTOM_GAS_ESTIMATE,
|
||||
txParams: { maxFeePerGas: '0x5028', maxPriorityFeePerGas: '0x0' },
|
||||
},
|
||||
});
|
||||
await result.current.updateTransactionToTenPercentIncreasedGasFee();
|
||||
expect(mockUpdateGasFees).toHaveBeenCalledTimes(1);
|
||||
expect(mockUpdateGasFees).toHaveBeenCalledWith(undefined, {
|
||||
estimateSuggested: 'tenPercentIncreased',
|
||||
estimateUsed: 'custom',
|
||||
gas: '5208',
|
||||
gasLimit: '5208',
|
||||
maxFeePerGas: '0x582c',
|
||||
maxPriorityFeePerGas: '0x1caf4ad00',
|
||||
userEditedGasLimit: undefined,
|
||||
userFeeLevel: 'custom',
|
||||
});
|
||||
});
|
||||
|
||||
it('should invoke action updateTransaction with estimate gas values fee when updateTransactionUsingEstimate callback is invoked', async () => {
|
||||
const mockUpdateGasFees = jest
|
||||
.spyOn(Actions, 'updateTransactionGasFees')
|
||||
|
@ -1,8 +1,12 @@
|
||||
import { useCallback } from 'react';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import BigNumber from 'bignumber.js';
|
||||
import { decimalToHex } from '../../../shared/lib/transactions-controller-utils';
|
||||
|
||||
import { EDIT_GAS_MODES, PRIORITY_LEVELS } from '../../../shared/constants/gas';
|
||||
import {
|
||||
EDIT_GAS_MODES,
|
||||
PRIORITY_LEVELS,
|
||||
CUSTOM_GAS_ESTIMATE,
|
||||
} from '../../../shared/constants/gas';
|
||||
import { decGWEIToHexWEI } from '../../helpers/utils/conversions.util';
|
||||
import {
|
||||
addTenPercentAndRound,
|
||||
@ -162,17 +166,31 @@ export const useTransactionFunctions = ({
|
||||
maxPriorityFeePerGas,
|
||||
} = transaction.previousGas || transaction.txParams;
|
||||
|
||||
const newMaxPriorityFeePerGas = new BigNumber(
|
||||
maxPriorityFeePerGas,
|
||||
16,
|
||||
).isZero()
|
||||
? decGWEIToHexWEI(
|
||||
gasFeeEstimates[defaultEstimateToUse].suggestedMaxPriorityFeePerGas,
|
||||
)
|
||||
: maxPriorityFeePerGas;
|
||||
|
||||
const estimateUsed =
|
||||
maxPriorityFeePerGas === '0x0'
|
||||
? CUSTOM_GAS_ESTIMATE
|
||||
: PRIORITY_LEVELS.TEN_PERCENT_INCREASED;
|
||||
|
||||
updateTransaction({
|
||||
estimateSuggested: initTransaction
|
||||
? defaultEstimateToUse
|
||||
: PRIORITY_LEVELS.TEN_PERCENT_INCREASED,
|
||||
estimateUsed: PRIORITY_LEVELS.TEN_PERCENT_INCREASED,
|
||||
estimateUsed,
|
||||
gasLimit,
|
||||
maxFeePerGas: addTenPercentAndRound(maxFeePerGas),
|
||||
maxPriorityFeePerGas: addTenPercentAndRound(maxPriorityFeePerGas),
|
||||
maxPriorityFeePerGas: addTenPercentAndRound(newMaxPriorityFeePerGas),
|
||||
});
|
||||
},
|
||||
[defaultEstimateToUse, transaction, updateTransaction],
|
||||
[defaultEstimateToUse, gasFeeEstimates, transaction, updateTransaction],
|
||||
);
|
||||
|
||||
const updateTransactionUsingEstimate = useCallback(
|
||||
|
Loading…
Reference in New Issue
Block a user