Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions packages/transaction-controller/src/TransactionController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1276,6 +1276,7 @@ export class TransactionController extends BaseController<
deviceConfirmedOn,
disableGasBuffer,
gasFeeToken,
excludeNativeTokenForFee,
isGasFeeIncluded,
isGasFeeSponsored,
isStateOnly,
Expand Down Expand Up @@ -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)
Expand All @@ -1375,9 +1380,10 @@ export class TransactionController extends BaseController<
deviceConfirmedOn,
disableGasBuffer,
id: random(),
isGasFeeTokenIgnoredIfBalance: Boolean(gasFeeToken),
isGasFeeTokenIgnoredIfBalance,
isGasFeeIncluded,
isGasFeeSponsored,
excludeNativeTokenForFee,
isFirstTimeInteraction: undefined,
isStateOnly,
nestedTransactions,
Expand Down
18 changes: 18 additions & 0 deletions packages/transaction-controller/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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.
*
Expand Down
3 changes: 3 additions & 0 deletions packages/transaction-controller/src/utils/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ async function addTransactionBatchWith7702(
gasLimit7702,
networkClientId,
origin,
actionId,
overwriteUpgrade,
requestId,
requiredAssets,
Expand Down Expand Up @@ -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,
Expand Down
Loading