Skip to content
Merged
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
1 change: 1 addition & 0 deletions packages/transaction-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Add `MantleLayer1GasFeeFlow` with `tokenRatio` conversion for accurate MNT-denominated gas estimates for Mantle and MantleSepolia ([#8386](https://github.com/MetaMask/core/pull/8386))
- Add `musdRelayDeposit` to `TransactionType` enum ([#8469](https://github.com/MetaMask/core/pull/8469))

### Changed

Expand Down
5 changes: 5 additions & 0 deletions packages/transaction-controller/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -801,6 +801,11 @@ export enum TransactionType {
*/
musdConversion = 'musdConversion',

/**
* Deposit funds for a Relay quote when the parent transaction is an mUSD conversion.
*/
musdRelayDeposit = 'musdRelayDeposit',

/**
* Deposit funds for Across quote via Perps.
*/
Expand Down
4 changes: 4 additions & 0 deletions packages/transaction-pay-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

- Resolve the effective transaction type from `nestedTransactions` when the parent is a batch transaction ([#8469](https://github.com/MetaMask/core/pull/8469))

## [19.1.2]

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const RELAY_PENDING_STATUSES: RelayStatus[] = [
];

export const RELAY_DEPOSIT_TYPES: Record<string, TransactionType> = {
[TransactionType.musdConversion]: TransactionType.musdRelayDeposit,
[TransactionType.predictDeposit]: TransactionType.predictRelayDeposit,
[TransactionType.perpsDeposit]: TransactionType.perpsRelayDeposit,
};
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,66 @@ describe('Relay Submit Utils', () => {
);
});

it('uses musdRelayDeposit type when parent transaction is musdConversion', async () => {
request.transaction = {
...request.transaction,
type: TransactionType.musdConversion,
} as TransactionMeta;

await submitRelayQuotes(request);

expect(addTransactionMock).toHaveBeenCalledTimes(1);
expect(addTransactionMock).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
type: TransactionType.musdRelayDeposit,
}),
);
});

it.each([
[TransactionType.predictDeposit, TransactionType.predictRelayDeposit],
[TransactionType.perpsDeposit, TransactionType.perpsRelayDeposit],
[TransactionType.musdConversion, TransactionType.musdRelayDeposit],
])(
'resolves %s from nestedTransactions when type is batch',
async (nestedType, expectedType) => {
request.transaction = {
...request.transaction,
type: TransactionType.batch,
nestedTransactions: [{ type: nestedType }],
} as TransactionMeta;

await submitRelayQuotes(request);

expect(addTransactionMock).toHaveBeenCalledTimes(1);
expect(addTransactionMock).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
type: expectedType,
}),
);
},
);

it('falls back to relayDeposit when type is batch and nestedTransactions have no mapped type', async () => {
request.transaction = {
...request.transaction,
type: TransactionType.batch,
nestedTransactions: [{ type: TransactionType.tokenMethodApprove }],
} as TransactionMeta;

await submitRelayQuotes(request);

expect(addTransactionMock).toHaveBeenCalledTimes(1);
expect(addTransactionMock).toHaveBeenCalledWith(
expect.anything(),
expect.objectContaining({
type: TransactionType.relayDeposit,
}),
);
});

it('adds transaction with gas fee token if isSourceGasFeeToken', async () => {
request.quotes[0].fees.isSourceGasFeeToken = true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ async function submitViaTransactionController(
networkClientId,
origin: ORIGIN_METAMASK,
requireApproval: false,
type: getRelayDepositType(transaction.type),
type: getRelayDepositType(getEffectiveTransactionType(transaction)),
},
);
} else {
Expand All @@ -576,7 +576,7 @@ async function submitViaTransactionController(
type: getTransactionType(
isPostQuote,
index,
transaction.type,
getEffectiveTransactionType(transaction),
normalizedParams.length,
),
};
Expand Down Expand Up @@ -664,3 +664,24 @@ function getRelayDepositType(
TransactionType.relayDeposit
);
}

/**
* Get the effective transaction type, resolving through nested transactions
* when the top-level type is `batch`.
*
* @param transaction - The transaction metadata.
* @returns The resolved type from nested transactions, or the top-level type.
*/
function getEffectiveTransactionType(
transaction: TransactionMeta,
): TransactionMeta['type'] {
if (transaction.type !== TransactionType.batch) {
return transaction.type;
}

const nestedType = transaction.nestedTransactions?.find(
(tx) => tx.type && RELAY_DEPOSIT_TYPES[tx.type] !== undefined,
)?.type;

return nestedType ?? transaction.type;
}
Loading