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
0465263d3e
commit
8fa45c5454
@ -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 () => {
|
it('should invoke action updateTransaction with estimate gas values fee when updateTransactionUsingEstimate callback is invoked', async () => {
|
||||||
const mockUpdateGasFees = jest
|
const mockUpdateGasFees = jest
|
||||||
.spyOn(Actions, 'updateTransactionGasFees')
|
.spyOn(Actions, 'updateTransactionGasFees')
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import { useDispatch } from 'react-redux';
|
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 {
|
import {
|
||||||
addTenPercentAndRound,
|
addTenPercentAndRound,
|
||||||
editGasModeIsSpeedUpOrCancel,
|
editGasModeIsSpeedUpOrCancel,
|
||||||
@ -164,17 +169,31 @@ export const useTransactionFunctions = ({
|
|||||||
maxPriorityFeePerGas,
|
maxPriorityFeePerGas,
|
||||||
} = transaction.previousGas || transaction.txParams;
|
} = 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({
|
updateTransaction({
|
||||||
estimateSuggested: initTransaction
|
estimateSuggested: initTransaction
|
||||||
? defaultEstimateToUse
|
? defaultEstimateToUse
|
||||||
: PriorityLevels.tenPercentIncreased,
|
: PriorityLevels.tenPercentIncreased,
|
||||||
estimateUsed: PriorityLevels.tenPercentIncreased,
|
estimateUsed,
|
||||||
gasLimit,
|
gasLimit,
|
||||||
maxFeePerGas: addTenPercentAndRound(maxFeePerGas),
|
maxFeePerGas: addTenPercentAndRound(maxFeePerGas),
|
||||||
maxPriorityFeePerGas: addTenPercentAndRound(maxPriorityFeePerGas),
|
maxPriorityFeePerGas: addTenPercentAndRound(newMaxPriorityFeePerGas),
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
[defaultEstimateToUse, transaction, updateTransaction],
|
[defaultEstimateToUse, gasFeeEstimates, transaction, updateTransaction],
|
||||||
);
|
);
|
||||||
|
|
||||||
const updateTransactionUsingEstimate = useCallback(
|
const updateTransactionUsingEstimate = useCallback(
|
||||||
|
Loading…
Reference in New Issue
Block a user