File tree Expand file tree Collapse file tree 3 files changed +16
-2
lines changed
packages/transaction-controller/src Expand file tree Collapse file tree 3 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -1276,6 +1276,7 @@ export class TransactionController extends BaseController<
12761276 deviceConfirmedOn,
12771277 disableGasBuffer,
12781278 gasFeeToken,
1279+ forceGasFeeToken,
12791280 isGasFeeIncluded,
12801281 isGasFeeSponsored,
12811282 isStateOnly,
@@ -1361,7 +1362,11 @@ export class TransactionController extends BaseController<
13611362 type ?? ( await determineTransactionType ( txParams , ethQuery ) ) . type ;
13621363
13631364 const existingTransactionMeta = this . #getTransactionWithActionId( actionId ) ;
1364-
1365+ // Original behavior was that this was set to 'true' whenever a gasFeeToken was passed.
1366+ // 'forceGasFeeToken' optionnally overrides this behavior to prevent native token from
1367+ // being used when another gasFeeToken is set.
1368+ const isGasFeeTokenIgnoredIfBalance =
1369+ Boolean ( gasFeeToken ) && ! forceGasFeeToken ;
13651370 // If a request to add a transaction with the same actionId is submitted again, a new transaction will not be created for it.
13661371 let addedTransactionMeta : TransactionMeta = existingTransactionMeta
13671372 ? cloneDeep ( existingTransactionMeta )
@@ -1375,7 +1380,7 @@ export class TransactionController extends BaseController<
13751380 deviceConfirmedOn,
13761381 disableGasBuffer,
13771382 id : random ( ) ,
1378- isGasFeeTokenIgnoredIfBalance : Boolean ( gasFeeToken ) ,
1383+ isGasFeeTokenIgnoredIfBalance,
13791384 isGasFeeIncluded,
13801385 isGasFeeSponsored,
13811386 isFirstTimeInteraction : undefined ,
Original file line number Diff line number Diff line change @@ -1795,6 +1795,10 @@ export type TransactionBatchRequest = {
17951795 /** Address of an ERC-20 token to pay for the gas fee, if the user has insufficient native balance. */
17961796 gasFeeToken ?: Hex ;
17971797
1798+ /** When set to `true` and if gasFeeToken is set, use gasFeeToken regardless of user native balance. */
1799+ /** Unless true, gasFeeToken is only taken as a suggestion and native balance will be used in batch 7702 transactions */
1800+ forceGasFeeToken ?: boolean ;
1801+
17981802 /** Gas limit for the transaction batch if submitted via EIP-7702. */
17991803 gasLimit7702 ?: Hex ;
18001804
@@ -2166,6 +2170,10 @@ export type AddTransactionOptions = {
21662170 /** Whether MetaMask will sponsor the gas fee for the transaction. */
21672171 isGasFeeSponsored ?: boolean ;
21682172
2173+ /** When set to `true` and if gasFeeToken is set, use gasFeeToken regardless of user native balance. */
2174+ /** Unless true, gasFeeToken is only taken as a suggestion and native balance will be used in batch 7702 transactions */
2175+ forceGasFeeToken ?: boolean ;
2176+
21692177 /**
21702178 * Whether the transaction has no lifecycle and is not signed or published.
21712179 *
Original file line number Diff line number Diff line change @@ -430,6 +430,7 @@ async function addTransactionBatchWith7702(
430430 const { result } = await addTransaction ( txParams , {
431431 batchId,
432432 gasFeeToken,
433+ forceGasFeeToken : userRequest . forceGasFeeToken ,
433434 isGasFeeIncluded : userRequest . isGasFeeIncluded ,
434435 isGasFeeSponsored : userRequest . isGasFeeSponsored ,
435436 nestedTransactions,
You can’t perform that action at this time.
0 commit comments