diff --git a/app/scripts/lib/transaction/metrics.test.ts b/app/scripts/lib/transaction/metrics.test.ts index d1d3f5e88091..74d5aaa13ca0 100644 --- a/app/scripts/lib/transaction/metrics.test.ts +++ b/app/scripts/lib/transaction/metrics.test.ts @@ -607,7 +607,7 @@ describe('Transaction metrics', () => { mockTransactionMeta.submittedTime = 123; await handleTransactionConfirmed(mockTransactionMetricsRequest, { - transactionMeta: mockTransactionMeta, + ...mockTransactionMeta, actionId: mockActionId, // TODO: Replace `any` with type // eslint-disable-next-line @typescript-eslint/no-explicit-any @@ -665,7 +665,7 @@ describe('Transaction metrics', () => { mockTransactionMetaWithBlockaid.submittedTime = 123; await handleTransactionConfirmed(mockTransactionMetricsRequest, { - transactionMeta: mockTransactionMetaWithBlockaid, + ...mockTransactionMetaWithBlockaid, actionId: mockActionId, // TODO: Replace `any` with type // eslint-disable-next-line @typescript-eslint/no-explicit-any diff --git a/app/scripts/lib/transaction/metrics.ts b/app/scripts/lib/transaction/metrics.ts index fa0a1469578e..667643bd8408 100644 --- a/app/scripts/lib/transaction/metrics.ts +++ b/app/scripts/lib/transaction/metrics.ts @@ -102,6 +102,11 @@ export type TransactionEventPayload = { error?: string; }; +export type TransactionMetaEventPayload = TransactionMeta & { + actionId?: string; + error?: string; +}; + /** * This function is called when a transaction is added to the controller. * @@ -197,16 +202,16 @@ export const handleTransactionFailed = async ( */ export const handleTransactionConfirmed = async ( transactionMetricsRequest: TransactionMetricsRequest, - transactionEventPayload: TransactionEventPayload, + transactionEventPayload: TransactionMetaEventPayload, ) => { - if (!transactionEventPayload.transactionMeta) { + if (Object.keys(transactionEventPayload).length === 0) { return; } // TODO: Replace `any` with type // eslint-disable-next-line @typescript-eslint/no-explicit-any const extraParams = {} as Record; - const { transactionMeta } = transactionEventPayload; + const transactionMeta = { ...transactionEventPayload }; const { txReceipt } = transactionMeta; extraParams.gas_used = txReceipt?.gasUsed; @@ -223,7 +228,10 @@ export const handleTransactionConfirmed = async ( await createUpdateFinalizeTransactionEventFragment({ eventName: TransactionMetaMetricsEvent.finalized, extraParams, - transactionEventPayload, + transactionEventPayload: { + actionId: transactionMeta.actionId, + transactionMeta, + }, transactionMetricsRequest, }); };