Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
TransactionController,
TransactionControllerMessenger,
TransactionMeta,
TransactionStatus,
TransactionType,
} from '@metamask/transaction-controller';
import {
Expand Down Expand Up @@ -300,7 +301,23 @@ function addTransactionControllerListeners(
'TransactionController:transactionApproved',
// TODO: Fix in https://github.com/MetaMask/metamask-extension/issues/31879
// eslint-disable-next-line @typescript-eslint/no-misused-promises
handleTransactionApproved.bind(null, transactionMetricsRequest),
async ({ transactionMeta }) => {
// when hardware wallet failed or rejected, due to user already click the confirm, then the flow will come to here.
// but because hardware wallet need double confirm in device, so we need to handle the transaction rejected here.
// if status is failed or rejected, then we need to handle the transaction rejected
if (
transactionMeta.status === TransactionStatus.failed ||
transactionMeta.status === TransactionStatus.rejected
) {
await handleTransactionRejected(transactionMetricsRequest, {
transactionMeta,
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Duplicate metrics and incorrect event classification

Manually calling handleTransactionRejected here causes duplicate metrics, as the TransactionController emits separate transactionRejected and transactionFailed events that already trigger their own listeners. Additionally, treating TransactionStatus.failed as a user rejection (calling handleTransactionRejected) is semantically incorrect and will result in conflicting event data (both "rejected" and "failed" events for the same transaction). The handler should only skip the approved event logic when the status indicates failure.

Fix in Cursor Fix in Web

} else {
await handleTransactionApproved(transactionMetricsRequest, {
transactionMeta,
});
}
},
);

initMessenger.subscribe(
Expand Down
Loading