Skip to content

fix: preserve transaction type of batched transactions #6056

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jul 23, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions packages/transaction-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Preserve type of nested transactions in batch if specified in `TransactionBatchSingleRequest` ([#6056](https://github.com/MetaMask/core/pull/6056))

## [58.1.0]

### Added
Expand Down
104 changes: 104 additions & 0 deletions packages/transaction-controller/src/utils/batch.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,110 @@ describe('Batch Utils', () => {
});
});

it('calls publish batch hook with requested transaction type', async () => {
const publishBatchHook: jest.MockedFn<PublishBatchHook> = jest.fn();

addTransactionMock
.mockResolvedValueOnce({
transactionMeta: {
...TRANSACTION_META_MOCK,
id: TRANSACTION_ID_MOCK,
},
result: Promise.resolve(''),
})
.mockResolvedValueOnce({
transactionMeta: {
...TRANSACTION_META_MOCK,
id: TRANSACTION_ID_2_MOCK,
},
result: Promise.resolve(''),
});

publishBatchHook.mockResolvedValue({
results: [
{
transactionHash: TRANSACTION_HASH_MOCK,
},
{
transactionHash: TRANSACTION_HASH_2_MOCK,
},
],
});

addTransactionBatch({
...request,
publishBatchHook,
request: {
...request.request,
transactions: [
{
...request.request.transactions[0],
type: TransactionType.swap,
},
{
...request.request.transactions[1],
type: TransactionType.bridge,
},
],
disable7702: true,
},
}).catch(() => {
// Intentionally empty
});

await flushPromises();

const publishHooks = addTransactionMock.mock.calls.map(
([, options]) => options.publishHook,
);

publishHooks[0]?.(
TRANSACTION_META_MOCK,
TRANSACTION_SIGNATURE_MOCK,
).catch(() => {
// Intentionally empty
});

publishHooks[1]?.(
TRANSACTION_META_MOCK,
TRANSACTION_SIGNATURE_2_MOCK,
).catch(() => {
// Intentionally empty
});

await flushPromises();

expect(publishBatchHook).toHaveBeenCalledTimes(1);
expect(publishBatchHook).toHaveBeenCalledWith({
from: FROM_MOCK,
networkClientId: NETWORK_CLIENT_ID_MOCK,
transactions: [
{
id: TRANSACTION_ID_MOCK,
params: {
...TRANSACTION_BATCH_PARAMS_MOCK,
gas: undefined,
maxFeePerGas: undefined,
maxPriorityFeePerGas: undefined,
},
signedTx: TRANSACTION_SIGNATURE_MOCK,
type: TransactionType.swap,
},
{
id: TRANSACTION_ID_2_MOCK,
params: {
...TRANSACTION_BATCH_PARAMS_MOCK,
gas: undefined,
maxFeePerGas: undefined,
maxPriorityFeePerGas: undefined,
},
signedTx: TRANSACTION_SIGNATURE_2_MOCK,
type: TransactionType.bridge,
},
],
});
});

it('resolves individual publish hooks with transaction hashes from publish batch hook', async () => {
const publishBatchHook: jest.MockedFn<PublishBatchHook> = jest.fn();

Expand Down
14 changes: 10 additions & 4 deletions packages/transaction-controller/src/utils/batch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ async function getNestedTransactionMeta(
ethQuery: EthQuery,
): Promise<NestedTransactionMetadata> {
const { from } = request;
const { params } = singleRequest;
const { params, type: requestType } = singleRequest;

const { type } = await determineTransactionType(
{ from, ...params },
Expand All @@ -255,7 +255,7 @@ async function getNestedTransactionMeta(

return {
...params,
type,
type: requestType ?? type,
};
}

Expand Down Expand Up @@ -544,7 +544,7 @@ async function processTransactionWithHook(
request: AddTransactionBatchRequest,
txBatchMeta?: TransactionBatchMeta,
) {
const { existingTransaction, params } = nestedTransaction;
const { existingTransaction, params, type } = nestedTransaction;

const {
addTransaction,
Expand Down Expand Up @@ -595,6 +595,7 @@ async function processTransactionWithHook(
const { transactionMeta } = await addTransaction(
transactionMetaForGasEstimates.txParams,
{
type,
batchId,
disableGasBuffer: true,
networkClientId,
Expand All @@ -620,11 +621,16 @@ async function processTransactionWithHook(
value,
};

log('Processed new transaction with hook', { id, params: newParams });
log('Processed new transaction with hook', {
id,
params: newParams,
type: nestedTransaction.type,
});

return {
id,
params: newParams,
type: nestedTransaction.type,
};
}

Expand Down
Loading