-
Notifications
You must be signed in to change notification settings - Fork 5.4k
feat: Gas modals refactor I #38624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
feat: Gas modals refactor I #38624
Conversation
✨ Files requiring CODEOWNER review ✨✅ @MetaMask/confirmations (28 files, +2179 -11)
|
Builds ready [dbbcef8]
UI Startup Metrics (1260 ± 98 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
ui/pages/confirmations/components/confirm/info/hooks/useFeeCalculations.ts
Outdated
Show resolved
Hide resolved
ui/pages/confirmations/components/confirm/info/hooks/useFeeCalculations.ts
Outdated
Show resolved
Hide resolved
| // Note: feePerGas and priorityFeePerGas are hex strings from txParams/gasFeeEstimates | ||
| let minimumFeePerGas = addHexes( | ||
| decGWEIToHexWEI(estimatedBaseFee) || HEX_ZERO, | ||
| feePerGas ? (priorityFeePerGas as Hex) : HEX_ZERO, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Wrong variable checked in gas fee conditional logic
The calculateGasEstimateCallback function checks feePerGas to decide whether to add priorityFeePerGas to the calculation, but this is the wrong variable to check. The condition feePerGas ? (priorityFeePerGas as Hex) : HEX_ZERO should check priorityFeePerGas directly since that's the value being conditionally added. While current callers happen to set both values together (either both valid or both HEX_ZERO), this logic is confusing and could cause incorrect gas estimates if a caller ever passes a valid priorityFeePerGas with an empty/undefined feePerGas.
| priorityFeePerGas = dappSuggestedGasFees?.maxPriorityFeePerGas; | ||
| } else if (dappSuggestedGasFees?.gasPrice) { | ||
| gasPrice = dappSuggestedGasFees?.gasPrice; | ||
| gas = dappSuggestedGasFees?.gas || HEX_ZERO; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Legacy gas option loses gas limit fallback
When a dapp suggests legacy gas pricing, the code sets gas = dappSuggestedGasFees?.gas || HEX_ZERO, falling back to HEX_ZERO if the dapp doesn't provide a gas value. This loses the transactionMeta.gasLimitNoBuffer fallback that was set on line 57. For EIP-1559 suggestions, gasLimitNoBuffer is used, but for legacy suggestions without a gas value, the estimate would incorrectly use zero gas, resulting in a zero fee estimate rather than using the transaction's actual gas limit.
Builds ready [e3526c8]
UI Startup Metrics (1210 ± 89 ms)
📊 Page Load Benchmark ResultsCurrent Commit: 📄 Localhost MetaMask Test DappSamples: 100 Summary
📈 Detailed Results
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
| import { useSelector } from 'react-redux'; | ||
| import { TransactionMeta } from '@metamask/transaction-controller'; | ||
| import { useConfirmContext } from '../../context/confirm'; | ||
| import { getNetworkConfigurationsByChainId } from '../../../../../shared/modules/selectors/networks'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: sort imports
| } else { | ||
| gasPropertiesToUpdate = { | ||
| maxFeePerGas: transactionGasFeeEstimates?.gasPrice, | ||
| maxPriorityFeePerGas: transactionGasFeeEstimates?.gasPrice, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gasPrice only is assigned above to maxFeePerGas and maxPriorityFeePerGas
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes because estimation is done via gasPrice meaning only maxFeePerGas and maxPriorityFeePerGas should be defined if EIP1559
| isSelected: isGasPriceEstimateSelected, | ||
| key: 'gasPrice', | ||
| name: t('networkSuggested'), | ||
| onSelect: () => onGasPriceEstimateLevelClick(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Creating new fn here does not look like is needed () => onGasPriceEstimateLevelClick(), instead we can just use onGasPriceEstimateLevelClick.
| </ModalContent> | ||
| </Modal> | ||
| ); | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This modal does not seems to have any content.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I will implement details in step II as mentioned here
Description
This PR implements the first step of https://github.com/MetaMask/MetaMask-planning/issues/6067
Note that new gas modal UI is not enabled yet until very last step. Hence no changelog included.
The recording is manually enabled on local.
Changelog
CHANGELOG entry:
Related issues
Fixes: Step I of https://github.com/MetaMask/MetaMask-planning/issues/6067
Manual testing steps
N/A
Screenshots/Recordings
Before
After
Step.I.gas.modals.mov
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Adds a new gas fee modal stack (Estimates, Advanced EIP-1559/Legacy) with option hooks, UI list items, time utils, and a
calculateGasEstimateAPI, plus i18n and tests.GasFeeModalorchestrator withEstimatesModal,AdvancedEIP1559Modal, andAdvancedGasPriceModal.NetworkStatisticsupdated to support a redesigned header viauseRedesigned.useGasOptionsto compose options from:useGasFeeEstimateLevelOptions(low/medium/high; EIP-1559/legacy aware)useGasPriceEstimateOption(network suggested gas price)useDappSuggestedGasFeeOption(site-suggested)useAdvancedGasFeeOption(opens advanced modals)useFeeCalculationsnow exposescalculateGasEstimatefor computing totals (incl. optional L1 fees) and precise native amounts.GasEstimateListHeaderandGasEstimateListItemwith optional tooltip details.toHumanEstimatedTimeRange/toHumanSeconds.useTransactionNativeTickerto resolve native ticker by chain.networkSuggestedtoenanden_GBlocales.useFeeCalculationsupdates.Written by Cursor Bugbot for commit e3526c8. This will update automatically on new commits. Configure here.