1
0
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 ()

This commit is contained in:
Filip Sekulic 2022-12-07 16:10:10 +01:00 committed by GitHub
parent 36ba4bc8a7
commit ddcaaf3e8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 28 additions and 19 deletions
ui
components/app/advanced-gas-fee-popover
hooks/gasFeeInput

View File

@ -21,7 +21,7 @@ import { useAdvancedGasFeePopoverContext } from '../../context';
import AdvancedGasFeeInputSubtext from '../../advanced-gas-fee-input-subtext'; import AdvancedGasFeeInputSubtext from '../../advanced-gas-fee-input-subtext';
const validatePriorityFee = (value, gasFeeEstimates) => { const validatePriorityFee = (value, gasFeeEstimates) => {
if (value <= 0) { if (value < 0) {
return 'editGasMaxPriorityFeeBelowMinimumV2'; return 'editGasMaxPriorityFeeBelowMinimumV2';
} }
if ( if (

View File

@ -111,7 +111,7 @@ describe('PriorityfeeInput', () => {
expect(screen.queryByText('2 - 125 GWEI')).toBeInTheDocument(); 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({ render({
txParams: { txParams: {
maxPriorityFeePerGas: '0x174876E800', maxPriorityFeePerGas: '0x174876E800',
@ -125,6 +125,17 @@ describe('PriorityfeeInput', () => {
}); });
expect( expect(
screen.queryByText('Priority fee must be greater than 0.'), 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();
}); });
}); });

View File

@ -63,12 +63,12 @@ describe('AdvancedGasFeePopover', () => {
expect(screen.queryByRole('button', { name: 'Save' })).not.toBeDisabled(); 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(); render();
fireEvent.change(document.getElementsByTagName('input')[1], { fireEvent.change(document.getElementsByTagName('input')[1], {
target: { value: 0 }, 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', () => { it('should disable save button if priority fee entered is greater than base fee', () => {

View File

@ -11,11 +11,7 @@ import {
} from '../../selectors'; } from '../../selectors';
import { addHexes } from '../../helpers/utils/conversions.util'; import { addHexes } from '../../helpers/utils/conversions.util';
import { isLegacyTransaction } from '../../helpers/utils/transactions.util'; import { isLegacyTransaction } from '../../helpers/utils/transactions.util';
import { import { bnGreaterThan, bnLessThan } from '../../helpers/utils/util';
bnGreaterThan,
bnLessThan,
bnLessThanEqualTo,
} from '../../helpers/utils/util';
import { GAS_FORM_ERRORS } from '../../helpers/constants/gas'; import { GAS_FORM_ERRORS } from '../../helpers/constants/gas';
const HIGH_FEE_WARNING_MULTIPLIER = 1.5; const HIGH_FEE_WARNING_MULTIPLIER = 1.5;
@ -36,7 +32,7 @@ const validateMaxPriorityFee = (maxPriorityFeePerGas, supportsEIP1559) => {
if (!supportsEIP1559) { if (!supportsEIP1559) {
return undefined; return undefined;
} }
if (bnLessThanEqualTo(maxPriorityFeePerGas, 0)) { if (bnLessThan(maxPriorityFeePerGas, 0)) {
return GAS_FORM_ERRORS.MAX_PRIORITY_FEE_BELOW_MINIMUM; return GAS_FORM_ERRORS.MAX_PRIORITY_FEE_BELOW_MINIMUM;
} }
return undefined; return undefined;
@ -68,7 +64,7 @@ const validateGasPrice = (
} }
if ( if (
(!supportsEIP1559 || transaction?.txParams?.gasPrice) && (!supportsEIP1559 || transaction?.txParams?.gasPrice) &&
bnLessThanEqualTo(gasPrice, 0) bnLessThan(gasPrice, 0)
) { ) {
return GAS_FORM_ERRORS.GAS_PRICE_TOO_LOW; return GAS_FORM_ERRORS.GAS_PRICE_TOO_LOW;
} }

View File

@ -80,14 +80,14 @@ describe('useGasFeeErrors', () => {
expect(result.current.gasErrors.maxPriorityFee).toBeUndefined(); expect(result.current.gasErrors.maxPriorityFee).toBeUndefined();
expect(result.current.hasGasErrors).toBe(false); 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({ const { result } = renderUseGasFeeErrorsHook({
maxPriorityFeePerGas: '0', maxPriorityFeePerGas: '0',
}); });
expect(result.current.gasErrors.maxPriorityFee).toBe( expect(result.current.gasErrors.maxPriorityFee).not.toBe(
GAS_FORM_ERRORS.MAX_PRIORITY_FEE_BELOW_MINIMUM, GAS_FORM_ERRORS.MAX_PRIORITY_FEE_BELOW_MINIMUM,
); );
expect(result.current.hasGasErrors).toBe(true); expect(result.current.hasGasErrors).toBe(false);
}); });
}); });
describe('Legacy estimates', () => { describe('Legacy estimates', () => {
@ -129,7 +129,9 @@ describe('useGasFeeErrors', () => {
maxFeePerGas: '1', maxFeePerGas: '1',
maxPriorityFeePerGas: '0', maxPriorityFeePerGas: '0',
}); });
expect(result.current.gasErrors.maxFee).toBeUndefined(); expect(result.current.gasErrors.maxFee).not.toBe(
GAS_FORM_ERRORS.MAX_FEE_IMBALANCE,
);
}); });
}); });
describe('Legacy estimates', () => { describe('Legacy estimates', () => {
@ -163,15 +165,15 @@ describe('useGasFeeErrors', () => {
beforeEach(() => { beforeEach(() => {
configureLegacy(); configureLegacy();
}); });
it('returns gasPriceError if gasPrice is 0', () => { it('does not return gasPriceError if gasPrice is 0', () => {
const { result } = renderUseGasFeeErrorsHook({ const { result } = renderUseGasFeeErrorsHook({
gasPrice: '0', gasPrice: '0',
...LEGACY_GAS_ESTIMATE_RETURN_VALUE, ...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, 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', () => { it('does not return gasPriceError if gasPrice is > 0', () => {
const { result } = renderUseGasFeeErrorsHook( const { result } = renderUseGasFeeErrorsHook(