feat(transaction-controller): prepare transactions for approval - #10109
Open
pedronfigueiredo wants to merge 3 commits into
Open
feat(transaction-controller): prepare transactions for approval#10109pedronfigueiredo wants to merge 3 commits into
pedronfigueiredo wants to merge 3 commits into
Conversation
jpuri
approved these changes
Sep 4, 2026
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.
Related pull requests
Summary
prepareTransactionForApprovalAPI to@metamask/transaction-controllerisGasFeeSponsoredandisExternalSignfrom explicit sponsorship and publication-path facts without mutating the inputcheckGasFeeTokenBeforePublishbehavior unchangedPublic API
The package also exports:
PrepareTransactionForApprovalRequestPrepareTransactionForApprovalResultTransactionApprovalSponsorshipFactsTransactionApprovalSigningFactsTransactionApprovalSigningModeBehavior decisions
isExternalSigndescribes the selected publication path, not the account alone. When true, TransactionController skips local keyring signing.TransactionType.checkGasFeeTokenBeforePublishremains authoritative for final native-balance validation, token-quote refresh, fee-token selection fallback, nonce removal, and publication-time external-signing selection.Client integration
Extension and Mobile adapters should provide final publication-path capability rather than only lower-level account capability:
available: current simulation/caller sponsorship resultsupported: whether optional sponsorship works for the actual account and selected pathrequired: explicit product-domain requirementexternalSigningSupported: whether the selected sponsored path publishes without local keyring signingThis PR intentionally does not move gas-fee-token batch construction, UI, navigation, hardware transport, approval dispatch, or publication behavior into Core.
Validation
yarn workspace @metamask/transaction-controller run jest --no-coverage src/utils/prepare-transaction-for-approval.test.ts src/utils/gas-fee-tokens.test.ts src/TransactionController.test.ts— 306 tests passed, 4 snapshots passedyarn build— passedyarn workspace @metamask/transaction-controller run build— passedyarn lint:tsc— passedyarn lint:misc --check— passedyarn workspace @metamask/transaction-controller run changelog:validate— passedNote
Medium Risk
The helper directly drives execution-sensitive approval flags (sponsorship and local vs external signing); incorrect caller-supplied facts or integration mistakes could mis-publish transactions, though required-path failures fail closed with an error.
Overview
Adds a pure, exported
prepareTransactionForApprovalAPI (plus request/result and sponsorship/signing fact types) so clients can normalize approval-timeisGasFeeSponsoredandisExternalSignfrom explicit simulation and publication-path facts without mutating the inputTransactionMeta.Sponsorship is enabled when it is available, the user has not opted out, and either optional sponsorship is supported or a required flow can use an externally signable sponsored path; external signing is chosen only when sponsorship is enabled and the path supports it (sponsored local signing remains possible). If sponsorship is required, not opted out, and no valid sponsored path exists, preparation throws instead of falling back to unsponsored publication.
Tests cover the full boolean decision matrix, required-path rejection, immutability, unrelated field preservation, and idempotence. Gas-fee token handling and
checkGasFeeTokenBeforePublishare unchanged and stay outside this helper.Reviewed by Cursor Bugbot for commit d03969e. Bugbot is set up for automated code reviews on this repo. Configure here.