1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-12-22 17:33:23 +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:
Dan J Miller 2023-02-03 03:27:32 -08:00 committed by GitHub
parent 0465263d3e
commit 8fa45c5454
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 4 deletions

View File

@ -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')

View File

@ -1,7 +1,12 @@
import { useCallback } from 'react';
import { useDispatch } from 'react-redux';
import { EditGasModes, PriorityLevels } from '../../../shared/constants/gas';
import BigNumber from 'bignumber.js';
import {
EditGasModes,
PriorityLevels,
CUSTOM_GAS_ESTIMATE,
} from '../../../shared/constants/gas';
import {
addTenPercentAndRound,
editGasModeIsSpeedUpOrCancel,
@ -164,17 +169,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
: PriorityLevels.tenPercentIncreased;
updateTransaction({
estimateSuggested: initTransaction
? defaultEstimateToUse
: PriorityLevels.tenPercentIncreased,
estimateUsed: PriorityLevels.tenPercentIncreased,
estimateUsed,
gasLimit,
maxFeePerGas: addTenPercentAndRound(maxFeePerGas),
maxPriorityFeePerGas: addTenPercentAndRound(maxPriorityFeePerGas),
maxPriorityFeePerGas: addTenPercentAndRound(newMaxPriorityFeePerGas),
});
},
[defaultEstimateToUse, transaction, updateTransaction],
[defaultEstimateToUse, gasFeeEstimates, transaction, updateTransaction],
);
const updateTransactionUsingEstimate = useCallback(