1
0
mirror of https://github.com/kremalicious/metamask-extension.git synced 2024-11-22 18:00:18 +01:00

EIP-1559 V2: Advanced gas fee modal - base fee and priority fee trends (#13025)

This commit is contained in:
Niranjana Binoy 2021-12-21 14:01:43 -05:00 committed by GitHub
parent d990cb5eeb
commit 3a11800cb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 28 additions and 9 deletions

View File

Before

Width:  |  Height:  |  Size: 358 B

After

Width:  |  Height:  |  Size: 358 B

View File

Before

Width:  |  Height:  |  Size: 347 B

After

Width:  |  Height:  |  Size: 347 B

View File

@ -5,7 +5,7 @@ import Box from '../../../ui/box';
import I18nValue from '../../../ui/i18n-value'; import I18nValue from '../../../ui/i18n-value';
import LoadingHeartBeat from '../../../ui/loading-heartbeat'; import LoadingHeartBeat from '../../../ui/loading-heartbeat';
const AdvancedGasFeeInputSubtext = ({ latest, historical }) => { const AdvancedGasFeeInputSubtext = ({ latest, historical, feeTrend }) => {
return ( return (
<Box className="advanced-gas-fee-input-subtext"> <Box className="advanced-gas-fee-input-subtext">
<Box display="flex" alignItems="center"> <Box display="flex" alignItems="center">
@ -16,7 +16,7 @@ const AdvancedGasFeeInputSubtext = ({ latest, historical }) => {
<LoadingHeartBeat /> <LoadingHeartBeat />
{latest} {latest}
</span> </span>
<img src="./images/high-arrow.svg" alt="" /> <img src={`./images/${feeTrend}-arrow.svg`} alt="feeTrend-arrow" />
</Box> </Box>
<Box> <Box>
<span className="advanced-gas-fee-input-subtext__label"> <span className="advanced-gas-fee-input-subtext__label">
@ -34,6 +34,7 @@ const AdvancedGasFeeInputSubtext = ({ latest, historical }) => {
AdvancedGasFeeInputSubtext.propTypes = { AdvancedGasFeeInputSubtext.propTypes = {
latest: PropTypes.string, latest: PropTypes.string,
historical: PropTypes.string, historical: PropTypes.string,
feeTrend: PropTypes.string.isRequired,
}; };
export default AdvancedGasFeeInputSubtext; export default AdvancedGasFeeInputSubtext;

View File

@ -38,6 +38,7 @@ const render = () => {
<AdvancedGasFeeInputSubtext <AdvancedGasFeeInputSubtext
latest="Latest Value" latest="Latest Value"
historical="Historical value" historical="Historical value"
feeTrend="up"
/>, />,
store, store,
); );
@ -45,14 +46,10 @@ const render = () => {
describe('AdvancedGasFeeInputSubtext', () => { describe('AdvancedGasFeeInputSubtext', () => {
it('should renders latest and historical values passed', () => { it('should renders latest and historical values passed', () => {
render( render();
<AdvancedGasFeeInputSubtext
latest="Latest Value"
historical="Historical value"
/>,
);
expect(screen.queryByText('Latest Value')).toBeInTheDocument(); expect(screen.queryByText('Latest Value')).toBeInTheDocument();
expect(screen.queryByText('Historical value')).toBeInTheDocument(); expect(screen.queryByText('Historical value')).toBeInTheDocument();
expect(screen.queryByAltText('feeTrend-arrow')).toBeInTheDocument();
}); });
}); });

View File

@ -84,7 +84,12 @@ const BaseFeeInput = () => {
setMaxFeePerGas, setMaxFeePerGas,
} = useAdvancedGasFeePopoverContext(); } = useAdvancedGasFeePopoverContext();
const { estimatedBaseFee, historicalBaseFeeRange } = gasFeeEstimates; const {
estimatedBaseFee,
historicalBaseFeeRange,
baseFeeTrend,
} = gasFeeEstimates;
const [feeTrend, setFeeTrend] = useState(baseFeeTrend);
const [baseFeeError, setBaseFeeError] = useState(); const [baseFeeError, setBaseFeeError] = useState();
const { const {
numberOfDecimals: numberOfDecimalsPrimary, numberOfDecimals: numberOfDecimalsPrimary,
@ -169,14 +174,20 @@ const BaseFeeInput = () => {
error === 'editGasMaxBaseFeeGWEIImbalance' || error === 'editGasMaxBaseFeeGWEIImbalance' ||
error === 'editGasMaxBaseFeeMultiplierImbalance', error === 'editGasMaxBaseFeeMultiplierImbalance',
); );
if (baseFeeTrend !== 'level' && baseFeeTrend !== feeTrend) {
setFeeTrend(baseFeeTrend);
}
}, [ }, [
feeTrend,
editingInGwei, editingInGwei,
baseFeeTrend,
gasFeeEstimates, gasFeeEstimates,
maxBaseFeeGWEI, maxBaseFeeGWEI,
maxPriorityFeePerGas, maxPriorityFeePerGas,
setBaseFeeError, setBaseFeeError,
setErrorValue, setErrorValue,
setMaxFeePerGas, setMaxFeePerGas,
setFeeTrend,
]); ]);
return ( return (
@ -208,6 +219,7 @@ const BaseFeeInput = () => {
2, 2,
)} GWEI`} )} GWEI`}
historical={renderFeeRange(historicalBaseFeeRange)} historical={renderFeeRange(historicalBaseFeeRange)}
feeTrend={feeTrend}
/> />
</Box> </Box>
); );

View File

@ -55,7 +55,9 @@ const PriorityFeeInput = () => {
const { const {
latestPriorityFeeRange, latestPriorityFeeRange,
historicalPriorityFeeRange, historicalPriorityFeeRange,
priorityFeeTrend,
} = gasFeeEstimates; } = gasFeeEstimates;
const [feeTrend, setFeeTrend] = useState(priorityFeeTrend);
const [priorityFeeError, setPriorityFeeError] = useState(); const [priorityFeeError, setPriorityFeeError] = useState();
const [priorityFee, setPriorityFee] = useState(() => { const [priorityFee, setPriorityFee] = useState(() => {
@ -86,12 +88,18 @@ const PriorityFeeInput = () => {
error === 'editGasMaxPriorityFeeBelowMinimumV2', error === 'editGasMaxPriorityFeeBelowMinimumV2',
); );
setPriorityFeeError(error); setPriorityFeeError(error);
if (priorityFeeTrend !== 'level' && priorityFeeTrend !== feeTrend) {
setFeeTrend(priorityFeeTrend);
}
}, [ }, [
feeTrend,
priorityFeeTrend,
gasFeeEstimates, gasFeeEstimates,
priorityFee, priorityFee,
setErrorValue, setErrorValue,
setMaxPriorityFeePerGas, setMaxPriorityFeePerGas,
setPriorityFeeError, setPriorityFeeError,
setFeeTrend,
]); ]);
return ( return (
@ -109,6 +117,7 @@ const PriorityFeeInput = () => {
<AdvancedGasFeeInputSubtext <AdvancedGasFeeInputSubtext
latest={renderFeeRange(latestPriorityFeeRange)} latest={renderFeeRange(latestPriorityFeeRange)}
historical={renderFeeRange(historicalPriorityFeeRange)} historical={renderFeeRange(historicalPriorityFeeRange)}
feeTrend={feeTrend}
/> />
</> </>
); );