Skip to content

Commit

Permalink
fix (cherry-pick): "Transaction Finalized" metrics event on transacti…
Browse files Browse the repository at this point in the history
…on confirmation (#24338) (#24353)

Cherry-picks 9a7f82a (#24338) to v11.14.5
  • Loading branch information
danjm authored May 2, 2024
1 parent 8c9ed8f commit 2d9f5f7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/scripts/lib/transaction/metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,7 @@ describe('Transaction metrics', () => {
mockTransactionMeta.submittedTime = 123;

await handleTransactionConfirmed(mockTransactionMetricsRequest, {
transactionMeta: mockTransactionMeta,
...mockTransactionMeta,
actionId: mockActionId,
} as any);

Expand Down Expand Up @@ -627,7 +627,7 @@ describe('Transaction metrics', () => {
mockTransactionMetaWithBlockaid.submittedTime = 123;

await handleTransactionConfirmed(mockTransactionMetricsRequest, {
transactionMeta: mockTransactionMetaWithBlockaid,
...mockTransactionMetaWithBlockaid,
actionId: mockActionId,
} as any);

Expand Down
16 changes: 12 additions & 4 deletions app/scripts/lib/transaction/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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<string, any>;
const { transactionMeta } = transactionEventPayload;
const transactionMeta = { ...transactionEventPayload };
const { txReceipt } = transactionMeta;

extraParams.gas_used = txReceipt?.gasUsed;
Expand All @@ -209,7 +214,10 @@ export const handleTransactionConfirmed = async (
await createUpdateFinalizeTransactionEventFragment({
eventName: TransactionMetaMetricsEvent.finalized,
extraParams,
transactionEventPayload,
transactionEventPayload: {
actionId: transactionMeta.actionId,
transactionMeta,
},
transactionMetricsRequest,
});
};
Expand Down

0 comments on commit 2d9f5f7

Please sign in to comment.