mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 01:47:00 +01:00
EIP-1559 V2: Advanced gas fee modal - getting 12 hour ranges of base fee and priority fee (#12996)
This commit is contained in:
parent
73379c528b
commit
7cd11a975c
@ -20,7 +20,13 @@
|
|||||||
"suggestedMaxPriorityFeePerGas": "10",
|
"suggestedMaxPriorityFeePerGas": "10",
|
||||||
"suggestedMaxFeePerGas": "100"
|
"suggestedMaxFeePerGas": "100"
|
||||||
},
|
},
|
||||||
"estimatedBaseFee": "50"
|
"estimatedBaseFee": "50",
|
||||||
|
"networkCongestion": 0.5184,
|
||||||
|
"latestPriorityFeeRange": ["1", "20"],
|
||||||
|
"historicalPriorityFeeRange": ["2", "125"],
|
||||||
|
"historicalBaseFeeRange": ["50", "100"],
|
||||||
|
"priorityFeeTrend": "up",
|
||||||
|
"baseFeeTrend": "down"
|
||||||
},
|
},
|
||||||
"estimatedGasFeeTimeBounds": {}
|
"estimatedGasFeeTimeBounds": {}
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ import {
|
|||||||
import { PRIMARY, SECONDARY } from '../../../../../helpers/constants/common';
|
import { PRIMARY, SECONDARY } from '../../../../../helpers/constants/common';
|
||||||
import { bnGreaterThan, bnLessThan } from '../../../../../helpers/utils/util';
|
import { bnGreaterThan, bnLessThan } from '../../../../../helpers/utils/util';
|
||||||
import { decGWEIToHexWEI } from '../../../../../helpers/utils/conversions.util';
|
import { decGWEIToHexWEI } from '../../../../../helpers/utils/conversions.util';
|
||||||
|
|
||||||
import { getAdvancedGasFeeValues } from '../../../../../selectors';
|
import { getAdvancedGasFeeValues } from '../../../../../selectors';
|
||||||
import { useGasFeeContext } from '../../../../../contexts/gasFee';
|
import { useGasFeeContext } from '../../../../../contexts/gasFee';
|
||||||
import { useI18nContext } from '../../../../../hooks/useI18nContext';
|
import { useI18nContext } from '../../../../../hooks/useI18nContext';
|
||||||
@ -22,6 +23,10 @@ import I18nValue from '../../../../ui/i18n-value';
|
|||||||
|
|
||||||
import { useAdvancedGasFeePopoverContext } from '../../context';
|
import { useAdvancedGasFeePopoverContext } from '../../context';
|
||||||
import AdvancedGasFeeInputSubtext from '../../advanced-gas-fee-input-subtext';
|
import AdvancedGasFeeInputSubtext from '../../advanced-gas-fee-input-subtext';
|
||||||
|
import {
|
||||||
|
roundToDecimalPlacesRemovingExtraZeroes,
|
||||||
|
renderFeeRange,
|
||||||
|
} from '../utils';
|
||||||
|
|
||||||
const divideCurrencyValues = (value, baseFee) => {
|
const divideCurrencyValues = (value, baseFee) => {
|
||||||
if (baseFee === 0) {
|
if (baseFee === 0) {
|
||||||
@ -79,7 +84,7 @@ const BaseFeeInput = () => {
|
|||||||
setMaxFeePerGas,
|
setMaxFeePerGas,
|
||||||
} = useAdvancedGasFeePopoverContext();
|
} = useAdvancedGasFeePopoverContext();
|
||||||
|
|
||||||
const { estimatedBaseFee } = gasFeeEstimates;
|
const { estimatedBaseFee, historicalBaseFeeRange } = gasFeeEstimates;
|
||||||
const [baseFeeError, setBaseFeeError] = useState();
|
const [baseFeeError, setBaseFeeError] = useState();
|
||||||
const {
|
const {
|
||||||
numberOfDecimals: numberOfDecimalsPrimary,
|
numberOfDecimals: numberOfDecimalsPrimary,
|
||||||
@ -198,8 +203,11 @@ const BaseFeeInput = () => {
|
|||||||
numeric
|
numeric
|
||||||
/>
|
/>
|
||||||
<AdvancedGasFeeInputSubtext
|
<AdvancedGasFeeInputSubtext
|
||||||
latest={estimatedBaseFee}
|
latest={`${roundToDecimalPlacesRemovingExtraZeroes(
|
||||||
historical="23-359 GWEI"
|
estimatedBaseFee,
|
||||||
|
2,
|
||||||
|
)} GWEI`}
|
||||||
|
historical={renderFeeRange(historicalBaseFeeRange)}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
@ -113,9 +113,16 @@ describe('BaseFeeInput', () => {
|
|||||||
maxFeePerGas: '0x174876E800',
|
maxFeePerGas: '0x174876E800',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
expect(screen.queryByText('50')).toBeInTheDocument();
|
expect(screen.queryByText('50 GWEI')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
it('should show 12hr range value in subtext', () => {
|
||||||
|
render({
|
||||||
|
txParams: {
|
||||||
|
maxFeePerGas: '0x174876E800',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(screen.queryByText('50 - 100 GWEI')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should show error if base fee is less than suggested low value', () => {
|
it('should show error if base fee is less than suggested low value', () => {
|
||||||
render({
|
render({
|
||||||
txParams: {
|
txParams: {
|
||||||
|
@ -15,6 +15,7 @@ import { bnGreaterThan, bnLessThan } from '../../../../../helpers/utils/util';
|
|||||||
|
|
||||||
import { useAdvancedGasFeePopoverContext } from '../../context';
|
import { useAdvancedGasFeePopoverContext } from '../../context';
|
||||||
import AdvancedGasFeeInputSubtext from '../../advanced-gas-fee-input-subtext';
|
import AdvancedGasFeeInputSubtext from '../../advanced-gas-fee-input-subtext';
|
||||||
|
import { renderFeeRange } from '../utils';
|
||||||
|
|
||||||
const validatePriorityFee = (value, gasFeeEstimates) => {
|
const validatePriorityFee = (value, gasFeeEstimates) => {
|
||||||
if (value <= 0) {
|
if (value <= 0) {
|
||||||
@ -51,6 +52,10 @@ const PriorityFeeInput = () => {
|
|||||||
gasFeeEstimates,
|
gasFeeEstimates,
|
||||||
maxPriorityFeePerGas,
|
maxPriorityFeePerGas,
|
||||||
} = useGasFeeContext();
|
} = useGasFeeContext();
|
||||||
|
const {
|
||||||
|
latestPriorityFeeRange,
|
||||||
|
historicalPriorityFeeRange,
|
||||||
|
} = gasFeeEstimates;
|
||||||
const [priorityFeeError, setPriorityFeeError] = useState();
|
const [priorityFeeError, setPriorityFeeError] = useState();
|
||||||
|
|
||||||
const [priorityFee, setPriorityFee] = useState(() => {
|
const [priorityFee, setPriorityFee] = useState(() => {
|
||||||
@ -101,7 +106,10 @@ const PriorityFeeInput = () => {
|
|||||||
detailText={`≈ ${priorityFeeInFiat}`}
|
detailText={`≈ ${priorityFeeInFiat}`}
|
||||||
numeric
|
numeric
|
||||||
/>
|
/>
|
||||||
<AdvancedGasFeeInputSubtext latest="1-18 GWEI" historical="23-359 GWEI" />
|
<AdvancedGasFeeInputSubtext
|
||||||
|
latest={renderFeeRange(latestPriorityFeeRange)}
|
||||||
|
historical={renderFeeRange(historicalPriorityFeeRange)}
|
||||||
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
@ -68,7 +68,22 @@ describe('PriorityfeeInput', () => {
|
|||||||
});
|
});
|
||||||
expect(document.getElementsByTagName('input')[0]).toHaveValue(2);
|
expect(document.getElementsByTagName('input')[0]).toHaveValue(2);
|
||||||
});
|
});
|
||||||
|
it('should show current priority fee range in subtext', () => {
|
||||||
|
render({
|
||||||
|
txParams: {
|
||||||
|
maxFeePerGas: '0x174876E800',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(screen.queryByText('1 - 20 GWEI')).toBeInTheDocument();
|
||||||
|
});
|
||||||
|
it('should show 12hr range value in subtext', () => {
|
||||||
|
render({
|
||||||
|
txParams: {
|
||||||
|
maxFeePerGas: '0x174876E800',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(screen.queryByText('2 - 125 GWEI')).toBeInTheDocument();
|
||||||
|
});
|
||||||
it('should show error if value entered is 0', () => {
|
it('should show error if value entered is 0', () => {
|
||||||
render({
|
render({
|
||||||
txParams: {
|
txParams: {
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
import { uniq } from 'lodash';
|
||||||
|
import { toBigNumber } from '../../../../../shared/modules/conversion.utils';
|
||||||
|
|
||||||
|
export function roundToDecimalPlacesRemovingExtraZeroes(
|
||||||
|
numberish,
|
||||||
|
numberOfDecimalPlaces,
|
||||||
|
) {
|
||||||
|
if (numberish) {
|
||||||
|
return toBigNumber.dec(
|
||||||
|
toBigNumber.dec(numberish).toFixed(numberOfDecimalPlaces),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const renderFeeRange = (feeRange) => {
|
||||||
|
if (feeRange) {
|
||||||
|
const formattedRange = uniq(
|
||||||
|
feeRange.map((fee) => roundToDecimalPlacesRemovingExtraZeroes(fee, 2)),
|
||||||
|
).join(' - ');
|
||||||
|
return `${formattedRange} GWEI`;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user