-
Notifications
You must be signed in to change notification settings - Fork 8
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
feat: adding TransactionTimeToConfirmation event for confirmations #9
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -24,6 +24,7 @@ import getProvidedUtxos from '../utils/getProvidedUtxos'; | |||||||||||||||||||||||
import { AnalyticsServicePosthog } from '../../analytics/AnalyticsServicePosthog'; | ||||||||||||||||||||||||
import { ChainId } from '@avalabs/core-chains-sdk'; | ||||||||||||||||||||||||
import { openApprovalWindow } from '@src/background/runtime/openApprovalWindow'; | ||||||||||||||||||||||||
import { measureTransactionTime } from '@src/background/services/wallet/utils/measureTransactionTime'; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
type TxParams = { | ||||||||||||||||||||||||
transactionHex: string; | ||||||||||||||||||||||||
|
@@ -231,6 +232,7 @@ export class AvalancheSendTransactionHandler extends DAppRequestHandler< | |||||||||||||||||||||||
const usedNetwork = this.#getChainIdForVM(vm); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
try { | ||||||||||||||||||||||||
measureTransactionTime().startMeasure(); | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔥
Suggested change
|
||||||||||||||||||||||||
// Parse the json into a tx object | ||||||||||||||||||||||||
const unsignedTx = | ||||||||||||||||||||||||
vm === EVM | ||||||||||||||||||||||||
|
@@ -272,6 +274,18 @@ export class AvalancheSendTransactionHandler extends DAppRequestHandler< | |||||||||||||||||||||||
}, | ||||||||||||||||||||||||
}); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
measureTransactionTime().endMeasure(async (duration) => { | ||||||||||||||||||||||||
this.analyticsServicePosthog.captureEvent({ | ||||||||||||||||||||||||
name: 'TransactionTimeToConfirmation', | ||||||||||||||||||||||||
windowId: crypto.randomUUID(), | ||||||||||||||||||||||||
properties: { | ||||||||||||||||||||||||
duration, | ||||||||||||||||||||||||
txType: 'txType', | ||||||||||||||||||||||||
chainId: usedNetwork, | ||||||||||||||||||||||||
}, | ||||||||||||||||||||||||
}); | ||||||||||||||||||||||||
}); | ||||||||||||||||||||||||
Comment on lines
+277
to
+287
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔥
Suggested change
|
||||||||||||||||||||||||
|
||||||||||||||||||||||||
// If we already have the transaction hash (i.e. it was dispatched by WalletConnect), | ||||||||||||||||||||||||
// we just return it to the caller. | ||||||||||||||||||||||||
onSuccess(txHash); | ||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
enum TransactionTimeEvents { | ||
TRANSACTION_TIMED = 'transaction-timed', | ||
TRANSACTION_SUCCEEDED = 'transaction-succeeded', | ||
TRANSACTION_APPROVED = 'transaction-approved', | ||
} | ||
|
||
export const measureTransactionTime = (): { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While this util is handy, it is introducing some issues when there are multiple concurrent transactions waiting for confirmations. Since you are using the same marks for all measurements, the start time can be overwritten or cleared by an upcoming transaction. |
||
startMeasure: () => void; | ||
endMeasure: (callback: (duration: number) => void) => void; | ||
} => { | ||
const startMeasure = () => { | ||
performance.mark(TransactionTimeEvents.TRANSACTION_APPROVED); | ||
}; | ||
|
||
const endMeasure = (callback: (duration: number) => void) => { | ||
performance.mark(TransactionTimeEvents.TRANSACTION_SUCCEEDED); | ||
|
||
const measurement = performance.measure( | ||
TransactionTimeEvents.TRANSACTION_TIMED, | ||
TransactionTimeEvents.TRANSACTION_APPROVED, | ||
TransactionTimeEvents.TRANSACTION_SUCCEEDED | ||
); | ||
|
||
performance.clearMarks(TransactionTimeEvents.TRANSACTION_APPROVED); | ||
performance.clearMarks(TransactionTimeEvents.TRANSACTION_SUCCEEDED); | ||
performance.clearMarks(TransactionTimeEvents.TRANSACTION_TIMED); | ||
|
||
callback(measurement.duration); | ||
}; | ||
|
||
return { startMeasure, endMeasure }; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.