Skip to content

Commit

Permalink
Add new completion_time_onchain property to Transaction Finalized events
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronfigueiredo committed Jan 7, 2025
1 parent 47fdbe4 commit 673ca86
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion app/scripts/lib/transaction/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
TRANSACTION_ENVELOPE_TYPE_NAMES,
} from '../../../../shared/lib/transactions-controller-utils';
import {
hexToDecimal,
hexWEIToDecETH,
hexWEIToDecGWEI,
} from '../../../../shared/modules/conversion.utils';
Expand Down Expand Up @@ -229,12 +230,19 @@ export const handleTransactionConfirmed = async (

extraParams.gas_used = txReceipt?.gasUsed;

const { submittedTime } = transactionMeta;
const { submittedTime, blockTimestamp } = transactionMeta;

if (submittedTime) {
extraParams.completion_time = getTransactionCompletionTime(submittedTime);
}

if (submittedTime && blockTimestamp) {
extraParams.completion_time_onchain = getTransactionOnchainCompletionTime(
submittedTime,
blockTimestamp,
);
}

if (txReceipt?.status === '0x0') {
extraParams.status = METRICS_STATUS_FAILED;
}
Expand Down Expand Up @@ -1133,6 +1141,25 @@ function getTransactionCompletionTime(submittedTime: number) {
return Math.round((Date.now() - submittedTime) / 1000).toString();
}

/**

Check failure on line 1144 in app/scripts/lib/transaction/metrics.ts

View workflow job for this annotation

GitHub Actions / Test lint / Test lint

Missing JSDoc @param "submittedTime" declaration

Check failure on line 1144 in app/scripts/lib/transaction/metrics.ts

View workflow job for this annotation

GitHub Actions / Test lint / Test lint

Missing JSDoc @param "blockTimestamp" declaration
* Returns number of seconds (rounded to the hundredths) between submitted time
* and the block timestamp.
*/
function getTransactionOnchainCompletionTime(
submittedTime: number,
blockTimestamp: string,
): string {
const DECIMAL_DIGITS = 2;

return (
Math.round(
(Number(hexToDecimal(blockTimestamp)) - submittedTime / 1000) *
10 ** DECIMAL_DIGITS,
) /
10 ** DECIMAL_DIGITS
).toString();
}

/**
* The allowance amount in relation to the dapp proposed amount for specific token
*
Expand Down

0 comments on commit 673ca86

Please sign in to comment.