Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: "Transaction Finalized" metrics event on transaction confirmation #24338

Merged
merged 4 commits into from
May 2, 2024
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
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 @@ -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
Expand Down Expand Up @@ -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
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 @@ -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.
*
Expand Down Expand Up @@ -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<string, any>;
const { transactionMeta } = transactionEventPayload;
const transactionMeta = { ...transactionEventPayload };
const { txReceipt } = transactionMeta;

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