From 2d9f5f779421aed5cbf1a315de6acab1d0e46339 Mon Sep 17 00:00:00 2001 From: Dan J Miller Date: Thu, 2 May 2024 15:43:40 -0230 Subject: [PATCH] fix (cherry-pick): "Transaction Finalized" metrics event on transaction confirmation (#24338) (#24353) Cherry-picks 9a7f82a036 (#24338) to v11.14.5 --- app/scripts/lib/transaction/metrics.test.ts | 4 ++-- app/scripts/lib/transaction/metrics.ts | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/app/scripts/lib/transaction/metrics.test.ts b/app/scripts/lib/transaction/metrics.test.ts index a4eb13918d7d..acf82095ed24 100644 --- a/app/scripts/lib/transaction/metrics.test.ts +++ b/app/scripts/lib/transaction/metrics.test.ts @@ -571,7 +571,7 @@ describe('Transaction metrics', () => { mockTransactionMeta.submittedTime = 123; await handleTransactionConfirmed(mockTransactionMetricsRequest, { - transactionMeta: mockTransactionMeta, + ...mockTransactionMeta, actionId: mockActionId, } as any); @@ -627,7 +627,7 @@ describe('Transaction metrics', () => { mockTransactionMetaWithBlockaid.submittedTime = 123; await handleTransactionConfirmed(mockTransactionMetricsRequest, { - transactionMeta: mockTransactionMetaWithBlockaid, + ...mockTransactionMetaWithBlockaid, actionId: mockActionId, } as any); diff --git a/app/scripts/lib/transaction/metrics.ts b/app/scripts/lib/transaction/metrics.ts index 1335878393a9..108a60557855 100644 --- a/app/scripts/lib/transaction/metrics.ts +++ b/app/scripts/lib/transaction/metrics.ts @@ -92,6 +92,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. * @@ -185,14 +190,14 @@ export const handleTransactionFailed = async ( */ export const handleTransactionConfirmed = async ( transactionMetricsRequest: TransactionMetricsRequest, - transactionEventPayload: TransactionEventPayload, + transactionEventPayload: TransactionMetaEventPayload, ) => { - if (!transactionEventPayload.transactionMeta) { + if (Object.keys(transactionEventPayload).length === 0) { return; } const extraParams = {} as Record; - const { transactionMeta } = transactionEventPayload; + const transactionMeta = { ...transactionEventPayload }; const { txReceipt } = transactionMeta; extraParams.gas_used = txReceipt?.gasUsed; @@ -209,7 +214,10 @@ export const handleTransactionConfirmed = async ( await createUpdateFinalizeTransactionEventFragment({ eventName: TransactionMetaMetricsEvent.finalized, extraParams, - transactionEventPayload, + transactionEventPayload: { + actionId: transactionMeta.actionId, + transactionMeta, + }, transactionMetricsRequest, }); };