mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
Allow transactions with gas price or priority fee 0 (#16651)
This commit is contained in:
parent
36ba4bc8a7
commit
ddcaaf3e8d
@ -21,7 +21,7 @@ import { useAdvancedGasFeePopoverContext } from '../../context';
|
||||
import AdvancedGasFeeInputSubtext from '../../advanced-gas-fee-input-subtext';
|
||||
|
||||
const validatePriorityFee = (value, gasFeeEstimates) => {
|
||||
if (value <= 0) {
|
||||
if (value < 0) {
|
||||
return 'editGasMaxPriorityFeeBelowMinimumV2';
|
||||
}
|
||||
if (
|
||||
|
@ -111,7 +111,7 @@ describe('PriorityfeeInput', () => {
|
||||
expect(screen.queryByText('2 - 125 GWEI')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should show error if value entered is 0', () => {
|
||||
it('should not show error if value entered is 0', () => {
|
||||
render({
|
||||
txParams: {
|
||||
maxPriorityFeePerGas: '0x174876E800',
|
||||
@ -125,6 +125,17 @@ describe('PriorityfeeInput', () => {
|
||||
});
|
||||
expect(
|
||||
screen.queryByText('Priority fee must be greater than 0.'),
|
||||
).toBeInTheDocument();
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('should not show the error if priority fee is 0', () => {
|
||||
render({
|
||||
txParams: {
|
||||
maxPriorityFeePerGas: '0x0',
|
||||
},
|
||||
});
|
||||
expect(
|
||||
screen.queryByText('Priority fee must be greater than 0.'),
|
||||
).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
@ -63,12 +63,12 @@ describe('AdvancedGasFeePopover', () => {
|
||||
expect(screen.queryByRole('button', { name: 'Save' })).not.toBeDisabled();
|
||||
});
|
||||
|
||||
it('should disable save button if priority fee 0 is entered', () => {
|
||||
it('should enable save button if priority fee 0 is entered', () => {
|
||||
render();
|
||||
fireEvent.change(document.getElementsByTagName('input')[1], {
|
||||
target: { value: 0 },
|
||||
});
|
||||
expect(screen.queryByRole('button', { name: 'Save' })).toBeDisabled();
|
||||
expect(screen.queryByRole('button', { name: 'Save' })).toBeEnabled();
|
||||
});
|
||||
|
||||
it('should disable save button if priority fee entered is greater than base fee', () => {
|
||||
|
@ -11,11 +11,7 @@ import {
|
||||
} from '../../selectors';
|
||||
import { addHexes } from '../../helpers/utils/conversions.util';
|
||||
import { isLegacyTransaction } from '../../helpers/utils/transactions.util';
|
||||
import {
|
||||
bnGreaterThan,
|
||||
bnLessThan,
|
||||
bnLessThanEqualTo,
|
||||
} from '../../helpers/utils/util';
|
||||
import { bnGreaterThan, bnLessThan } from '../../helpers/utils/util';
|
||||
import { GAS_FORM_ERRORS } from '../../helpers/constants/gas';
|
||||
|
||||
const HIGH_FEE_WARNING_MULTIPLIER = 1.5;
|
||||
@ -36,7 +32,7 @@ const validateMaxPriorityFee = (maxPriorityFeePerGas, supportsEIP1559) => {
|
||||
if (!supportsEIP1559) {
|
||||
return undefined;
|
||||
}
|
||||
if (bnLessThanEqualTo(maxPriorityFeePerGas, 0)) {
|
||||
if (bnLessThan(maxPriorityFeePerGas, 0)) {
|
||||
return GAS_FORM_ERRORS.MAX_PRIORITY_FEE_BELOW_MINIMUM;
|
||||
}
|
||||
return undefined;
|
||||
@ -68,7 +64,7 @@ const validateGasPrice = (
|
||||
}
|
||||
if (
|
||||
(!supportsEIP1559 || transaction?.txParams?.gasPrice) &&
|
||||
bnLessThanEqualTo(gasPrice, 0)
|
||||
bnLessThan(gasPrice, 0)
|
||||
) {
|
||||
return GAS_FORM_ERRORS.GAS_PRICE_TOO_LOW;
|
||||
}
|
||||
|
@ -80,14 +80,14 @@ describe('useGasFeeErrors', () => {
|
||||
expect(result.current.gasErrors.maxPriorityFee).toBeUndefined();
|
||||
expect(result.current.hasGasErrors).toBe(false);
|
||||
});
|
||||
it('return maxPriorityFeeError if maxPriorityFee is 0', () => {
|
||||
it('does not return maxPriorityFeeError if maxPriorityFee is 0', () => {
|
||||
const { result } = renderUseGasFeeErrorsHook({
|
||||
maxPriorityFeePerGas: '0',
|
||||
});
|
||||
expect(result.current.gasErrors.maxPriorityFee).toBe(
|
||||
expect(result.current.gasErrors.maxPriorityFee).not.toBe(
|
||||
GAS_FORM_ERRORS.MAX_PRIORITY_FEE_BELOW_MINIMUM,
|
||||
);
|
||||
expect(result.current.hasGasErrors).toBe(true);
|
||||
expect(result.current.hasGasErrors).toBe(false);
|
||||
});
|
||||
});
|
||||
describe('Legacy estimates', () => {
|
||||
@ -129,7 +129,9 @@ describe('useGasFeeErrors', () => {
|
||||
maxFeePerGas: '1',
|
||||
maxPriorityFeePerGas: '0',
|
||||
});
|
||||
expect(result.current.gasErrors.maxFee).toBeUndefined();
|
||||
expect(result.current.gasErrors.maxFee).not.toBe(
|
||||
GAS_FORM_ERRORS.MAX_FEE_IMBALANCE,
|
||||
);
|
||||
});
|
||||
});
|
||||
describe('Legacy estimates', () => {
|
||||
@ -163,15 +165,15 @@ describe('useGasFeeErrors', () => {
|
||||
beforeEach(() => {
|
||||
configureLegacy();
|
||||
});
|
||||
it('returns gasPriceError if gasPrice is 0', () => {
|
||||
it('does not return gasPriceError if gasPrice is 0', () => {
|
||||
const { result } = renderUseGasFeeErrorsHook({
|
||||
gasPrice: '0',
|
||||
...LEGACY_GAS_ESTIMATE_RETURN_VALUE,
|
||||
});
|
||||
expect(result.current.gasErrors.gasPrice).toBe(
|
||||
expect(result.current.gasErrors.gasPrice).not.toBe(
|
||||
GAS_FORM_ERRORS.GAS_PRICE_TOO_LOW,
|
||||
);
|
||||
expect(result.current.hasGasErrors).toBe(true);
|
||||
expect(result.current.hasGasErrors).toBe(false);
|
||||
});
|
||||
it('does not return gasPriceError if gasPrice is > 0', () => {
|
||||
const { result } = renderUseGasFeeErrorsHook(
|
||||
|
Loading…
Reference in New Issue
Block a user