feat: save custom gas settings#31649
Conversation
|
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
PR template — items to address before "Ready for review"Warnings — informational, address before merging:
See docs/readme/ready-for-review.md for the full Definition of Ready for Review. |
54d7046 to
3cfc658
Compare
|
Can you please add screenshots / video with it and resolve failing checks? |
3cfc658 to
8bde3a5
Compare
8c22fab to
2e7f7a6
Compare
2e7f7a6 to
43769f1
Compare
mobile-save-gas-settings.mov |
…8993) ## Explanation This expands transaction-controller saved gas fee handling so clients can resolve saved preferences with full transaction metadata instead of only a chain ID. That lets consumers key saved gas settings by both chain and account while keeping the controller API responsible for applying saved fees. The saved gas payload now supports gas fee estimate levels (`low`, `medium`, `high`) and legacy custom `gasPrice` values in addition to EIP-1559 custom fee values. Saved estimate levels reuse the current gas fee flow estimate for the saved level; custom values override only the specific saved fields. Transactions that already include gas fee params continue to use those initial params, so dapp-proposed fees keep precedence over saved preferences. Swap transaction types continue to skip saved gas fees. ## References Related PRs: - MetaMask/metamask-extension#43317 - MetaMask/metamask-mobile#31649 ## Checklist - [x] I’ve updated the test suite for new or updated code as appropriate - [x] I’ve updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I’ve communicated my changes to consumers by updating changelogs for packages I’ve changed - [x] I’ve introduced breaking changes in this PR and have prepared client adoption work to resolve them <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Breaking callback signature and changed gas-fee precedence logic can misprice dApp txs or break extension/mobile until consumers update; changes are confined to gas fee application paths with substantial test coverage. > > **Overview** > **Breaking change:** `getSavedGasFees` now receives full `TransactionMeta` instead of chain ID so clients can key saved preferences by chain and account. The `SavedGasFees` shape adds optional estimate `level`, legacy `gasPrice`, and makes EIP-1559 fields optional. > > Gas fee application in `updateGasFees` now skips saved lookup when the tx already has initial gas params (dapp fees win), still skips internal txs, and can pick **low/medium/high** from the current gas fee flow when only a level is saved. Custom `maxBaseFee` / `priorityFee` / `gasPrice` override specific fields; `userFeeLevel` stays on the saved level only when pricing is truly level-derived (otherwise `custom`). > > Deprecated **incoming transaction** constructor options and restored **no-op** `startIncomingTransactionPolling` / `stopIncomingTransactionPolling` for backward compatibility, with tests. > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit a173b00. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
All alerts resolved. Learn more about Socket for GitHub. This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored. Ignoring alerts on:
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 0799ea2. Configure here.
|
@SocketSecurity ignore npm/@metamask/transaction-controller@69.0.0 |
TransactionController's getSavedGasFees hook only ever supported
(chainId) => {maxBaseFee, priorityFee}, with no account context and no
level/gasPrice fields, even at the version pinned before this branch's
rebase onto main. Resolve the account via AccountsController's selected
account instead of the (unavailable) transaction account, and only
auto-restore complete custom EIP-1559 overrides, since that's what the
real API can express.
useSendActions.ts and send.ts had leftover diffs from an earlier draft that are unrelated to the save-custom-gas-settings feature: - Re-added an 'await' before submitEvmTransaction that was deliberately removed in #30088 because it blocks navigation until addTransaction resolves, delaying the confirmation skeleton loader mount. - Made submitEvmTransaction return an unused transactionMeta. Neither is used by the gas-fee persistence feature (usePersistGasFeePreference is only wired into the advanced gas modals / estimate option hooks), so restore both files to match main.
…init SonarCloud flagged new_coverage at 78.7% (below the 80% gate), all attributable to preferences-controller-init.ts, where setAdvancedGasFee's update callback (clear preference, merge preference, account normalization) was never invoked by any test - only its existence was asserted indirectly via controller construction. Add direct tests that call setAdvancedGasFee and execute the captured update callback against a fake state, covering: - persisting a normalized (lowercased) account key - merging with existing preferences for other accounts on the chain - clearing a preference when gasFeePreferences is undefined 100% line/branch coverage locally for this file.
The new setAdvancedGasFee tests failed yarn lint:tsc: - accessed controller.update directly, which is protected on BaseController; cast through MutablePreferencesControllerWithSavedGasFees (same pattern used in preferences-controller-init.ts itself) instead. - cast partial fake state objects directly to PreferencesStateWithSavedGasFees, which doesn't sufficiently overlap (missing most PreferencesState properties); route through 'as unknown as' since only advancedGasFee is exercised by the code under test.
76cf2ee to
a9bcd3d
Compare
🧪 Flaky unit test detectionRun history flaky detectionHistorical failure rate is a hint, not proof — review each suggestion in context. See the flaky-test-detection skill for the full pattern reference and manual audit workflow. Failures / runs sampled per window:
AI-detected flaky patterns
|
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsE2E Test Selection: Performance Test Selection: |
|




Summary
Related PRs
Testing
yarn jest app/components/Views/confirmations/components/modals/advanced-eip1559-modal/advanced-eip1559-modal.test.tsx app/components/Views/confirmations/components/modals/advanced-gas-price-modal/advanced-gas-price-modal.test.tsx app/components/Views/confirmations/hooks/gas/useGasFeeEstimateLevelOptions.test.ts app/components/Views/confirmations/hooks/gas/useGasPriceEstimateOption.test.ts app/components/Views/confirmations/hooks/gas/usePersistGasFeePreference.test.ts app/core/Engine/controllers/preferences-controller-init.test.ts app/core/Engine/controllers/transaction-controller/metrics_properties/gas.test.ts app/core/Engine/controllers/transaction-controller/transaction-controller-init.test.ts(8 suites, 78 tests).Note
Medium Risk
Changes how default and custom gas fees are stored and applied for sends; incorrect lookup or validation could affect fee defaults, though saves are gated on complete custom values and covered by new tests.
Overview
Adds per-account, per-chain persistence for gas choices so confirmations can reuse the user’s last fee level or custom values.
On save, confirmation gas flows call
usePersistGasFeePreference, which writes toPreferencesController.setAdvancedGasFee(advancedGasFeeis persisted state). Advanced EIP-1559 and legacy gas price modals shareuseAdvancedGasFeeModal, which blocks save when custom fees are incomplete and persists mapped preferences (e.g. max base / priority fee). Preset estimate levels and gas-price estimate options persist the selecteduserFeeLevelas well.TransactionControlleris upgraded to 69.0.0 and receives agetSavedGasFeeshook that reads those preferences for the transaction’sfromaddress and chain. Gas metrics now reportdapp_proposedwhenUserFeeLevel.DAPP_SUGGESTEDis selected.Reviewed by Cursor Bugbot for commit 3041ea6. Bugbot is set up for automated code reviews on this repo. Configure here.