From c64b46dbbbb10de8d5f66a3239370770b50f5c0f Mon Sep 17 00:00:00 2001 From: Maxime OUAIRY Date: Thu, 26 Feb 2026 17:53:35 +0100 Subject: [PATCH] feat: tx-ctrl add forceGasFeeToken param --- .../src/TransactionController.ts | 10 ++++++++-- packages/transaction-controller/src/types.ts | 18 ++++++++++++++++++ .../transaction-controller/src/utils/batch.ts | 3 +++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/packages/transaction-controller/src/TransactionController.ts b/packages/transaction-controller/src/TransactionController.ts index ae8572b6822..07ca1986923 100644 --- a/packages/transaction-controller/src/TransactionController.ts +++ b/packages/transaction-controller/src/TransactionController.ts @@ -1276,6 +1276,7 @@ export class TransactionController extends BaseController< deviceConfirmedOn, disableGasBuffer, gasFeeToken, + excludeNativeTokenForFee, isGasFeeIncluded, isGasFeeSponsored, isStateOnly, @@ -1361,7 +1362,11 @@ export class TransactionController extends BaseController< type ?? (await determineTransactionType(txParams, ethQuery)).type; const existingTransactionMeta = this.#getTransactionWithActionId(actionId); - + // Original behavior was that this was set to 'true' whenever a gasFeeToken was passed. + // 'excludeNativeTokenForFee' optionnally overrides this behavior to prevent native token from + // being used when another gasFeeToken is set. + const isGasFeeTokenIgnoredIfBalance = + Boolean(gasFeeToken) && !excludeNativeTokenForFee; // If a request to add a transaction with the same actionId is submitted again, a new transaction will not be created for it. let addedTransactionMeta: TransactionMeta = existingTransactionMeta ? cloneDeep(existingTransactionMeta) @@ -1375,9 +1380,10 @@ export class TransactionController extends BaseController< deviceConfirmedOn, disableGasBuffer, id: random(), - isGasFeeTokenIgnoredIfBalance: Boolean(gasFeeToken), + isGasFeeTokenIgnoredIfBalance, isGasFeeIncluded, isGasFeeSponsored, + excludeNativeTokenForFee, isFirstTimeInteraction: undefined, isStateOnly, nestedTransactions, diff --git a/packages/transaction-controller/src/types.ts b/packages/transaction-controller/src/types.ts index ae992a298d5..2242a4db2a7 100644 --- a/packages/transaction-controller/src/types.ts +++ b/packages/transaction-controller/src/types.ts @@ -278,6 +278,11 @@ export type TransactionMeta = { /** Whether the `selectedGasFeeToken` is only used if the user has insufficient native balance. */ isGasFeeTokenIgnoredIfBalance?: boolean; + /** When set to `true` and if gasFeeToken is set, use gasFeeToken regardless of user native balance. */ + /** Unless true, gasFeeToken is only taken as a suggestion and native balance will be used in batch 7702 transactions */ + /** This was first implemented for Tempo, since Tempo doesn't have the notion of native token at all */ + excludeNativeTokenForFee?: boolean; + /** Whether the intent of the transaction was achieved via an alternate route or chain. */ isIntentComplete?: boolean; @@ -1777,6 +1782,9 @@ export type TransactionBatchSingleRequest = { export type TransactionBatchRequest = { batchId?: Hex; + /** Added for tx to appear in Activity tab */ + actionId?: string; + /** Whether to disable batch transaction processing via an EIP-7702 upgraded account. */ disable7702?: boolean; @@ -1795,6 +1803,11 @@ export type TransactionBatchRequest = { /** Address of an ERC-20 token to pay for the gas fee, if the user has insufficient native balance. */ gasFeeToken?: Hex; + /** When set to `true` and if gasFeeToken is set, use gasFeeToken regardless of user native balance. */ + /** Unless true, gasFeeToken is only taken as a suggestion and native balance will be used in batch 7702 transactions */ + /** This was first implemented for Tempo, since Tempo doesn't have the notion of native token at all */ + excludeNativeTokenForFee?: boolean; + /** Gas limit for the transaction batch if submitted via EIP-7702. */ gasLimit7702?: Hex; @@ -2166,6 +2179,11 @@ export type AddTransactionOptions = { /** Whether MetaMask will sponsor the gas fee for the transaction. */ isGasFeeSponsored?: boolean; + /** When set to `true` and if gasFeeToken is set, use gasFeeToken regardless of user native balance. */ + /** Unless true, gasFeeToken is only taken as a suggestion and native balance will be used in batch 7702 transactions */ + /** This was first implemented for Tempo, since Tempo doesn't have the notion of native token at all */ + excludeNativeTokenForFee?: boolean; + /** * Whether the transaction has no lifecycle and is not signed or published. * diff --git a/packages/transaction-controller/src/utils/batch.ts b/packages/transaction-controller/src/utils/batch.ts index eb75a97e200..2937b3324e0 100644 --- a/packages/transaction-controller/src/utils/batch.ts +++ b/packages/transaction-controller/src/utils/batch.ts @@ -301,6 +301,7 @@ async function addTransactionBatchWith7702( gasLimit7702, networkClientId, origin, + actionId, overwriteUpgrade, requestId, requiredAssets, @@ -428,8 +429,10 @@ async function addTransactionBatchWith7702( } const { result } = await addTransaction(txParams, { + actionId, batchId, gasFeeToken, + excludeNativeTokenForFee: userRequest.excludeNativeTokenForFee, isGasFeeIncluded: userRequest.isGasFeeIncluded, isGasFeeSponsored: userRequest.isGasFeeSponsored, nestedTransactions,