fix(transaction-controller): harden gas fee token preflight - #10071
Open
jpuri wants to merge 4 commits into
Open
fix(transaction-controller): harden gas fee token preflight#10071jpuri wants to merge 4 commits into
jpuri wants to merge 4 commits into
Conversation
Avoid treating native balance as sufficient when gas estimates are still pending, and do not leave isExternalSign enabled when the selected gas fee token fails preflight validation.
jpuri
marked this pull request as draft
September 2, 2026 04:58
jpuri
marked this pull request as ready for review
September 2, 2026 05:06
jpuri
enabled auto-merge
September 2, 2026 05:06
10 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Explanation
Predict claim on Mobile (Polygon Safe wallets) can fail during gas-station preflight when a gas fee token (e.g. pUSD) is pre-selected but Sentinel returns an empty
gasFeeTokenslist and native POL is insufficient.Two controller bugs contribute to confusing failures and bad publish fallbacks:
isNativeBalanceSufficientForGastreated missingmaxFeePerGas/gasPriceas zero, sogas × 0 = 0made every wallet look able to pay native gas. That could clearselectedGasFeeTokenwhile gas estimates were still in flight (common withskipInitialGasEstimate), leading to publishes withintrinsic gas too low: gas 0.checkGasFeeTokenBeforePublishsetisExternalSign: trueand cleared nonce before validating the selected token. When validation failed (Gas fee token not found and insufficient native balance), transaction metadata could remain in external-sign mode even though signing was never completed.This PR hardens both paths:
balance.ts: return insufficient whengasor fee fields are unset, so pre-selected gas fee tokens are not cleared prematurely.gas-fee-tokens.ts: only enable external sign after the selected token is confirmed in freshly fetchedgasFeeTokens; on failure, persist refreshed tokens but resetisExternalSigntofalsebefore throwing.No breaking API changes. Scope is limited to
@metamask/transaction-controllerpublish-time gas-fee-token gating.References
https://consensyssoftware.atlassian.net/browse/CONF-1725
Checklist
Note
Medium Risk
Changes transaction publish gating and native-balance checks; behavior shifts from false positives (premature token clearing, stuck external sign) to stricter failures when fees or tokens are unavailable.
Overview
Hardens publish-time gas fee token checks so pending or missing gas estimates no longer look like zero-cost native gas, and failed preflight no longer leaves transactions stuck in external-sign mode.
isNativeBalanceSufficientForGasnow returns insufficient whengasor fee fields (maxFeePerGas/gasPrice) are unset, instead of multiplying by zero and incorrectly clearing a pre-selected gas fee token while estimates are still loading.checkGasFeeTokenBeforePublishnow confirms the selected token exists in freshly fetchedgasFeeTokensbefore settingisExternalSignand clearing nonce. On validation failure it persists the refreshed token list, resetsisExternalSigntofalse, then throws—rather than leaving external-sign metadata after an error.Reviewed by Cursor Bugbot for commit 447935c. Bugbot is set up for automated code reviews on this repo. Configure here.