Skip to content

Commit daca26b

Browse files
committed
feat: adding TransactionTimeToConfirmation event for confirmations
Signed-off-by: ryanml <[email protected]>
1 parent 85dbef4 commit daca26b

File tree

7 files changed

+77
-7
lines changed

7 files changed

+77
-7
lines changed

src/background/services/wallet/handlers/eth_sendTransaction/models.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export enum TransactionType {
2121
SWAP = 'swap',
2222
ADD_LIQUIDITY = 'add_liquidity',
2323
CALL = 'call',
24+
BRIDGE = 'bridge',
2425
}
2526

2627
export interface TransactionToken {

src/contexts/AnalyticsProvider.tsx

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ import { filter, first, from, merge } from 'rxjs';
1515
import { useConnectionContext } from './ConnectionProvider';
1616
import { useSettingsContext } from './SettingsProvider';
1717
import { AnalyticsConsent } from '@src/background/services/settings/models';
18+
import { TransactionType } from '@src/background/services/wallet/handlers/eth_sendTransaction/models';
19+
20+
export enum TimeMeasureEventNames {
21+
TRANSACTION_SUCCEEDED = 'transaction-succeeded',
22+
TRANSACTION_APPROVED = 'transaction-approved',
23+
}
1824

1925
type CaptureFn = (
2026
eventName: string,
@@ -29,6 +35,13 @@ const AnalyticsContext = createContext<{
2935
stopDataCollection: () => Promise<void>;
3036
capture: CaptureFn;
3137
captureEncrypted: CaptureFn;
38+
captureTime: ({
39+
txType,
40+
chainId,
41+
}: {
42+
txType: TransactionType;
43+
chainId: number | undefined;
44+
}) => void;
3245
}>({} as any);
3346

3447
const windowId = crypto.randomUUID();
@@ -99,6 +112,31 @@ export function AnalyticsContextProvider({ children }: { children: any }) {
99112
});
100113
}, [request]);
101114

115+
const captureTime = useCallback(
116+
({
117+
txType,
118+
chainId,
119+
}: {
120+
txType: TransactionType;
121+
chainId: number | undefined;
122+
}) => {
123+
try {
124+
const measurement = performance.measure(
125+
TimeMeasureEventNames.TRANSACTION_SUCCEEDED,
126+
TimeMeasureEventNames.TRANSACTION_APPROVED
127+
);
128+
capture('TransactionTimeToConfirmation', {
129+
chainId: chainId,
130+
time: measurement.duration,
131+
txOrigin: txType,
132+
});
133+
} catch (e) {
134+
console.error(e);
135+
}
136+
},
137+
[capture]
138+
);
139+
102140
useEffect(() => {
103141
const subscription = merge(
104142
from(
@@ -131,6 +169,7 @@ export function AnalyticsContextProvider({ children }: { children: any }) {
131169
isInitialized,
132170
initAnalyticsIds,
133171
stopDataCollection,
172+
captureTime,
134173
}}
135174
>
136175
{children}

src/pages/Bridge/Bridge.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ import { CustomFees, GasFeeModifier } from '@src/components/common/CustomFees';
8080
import { CustomGasSettings } from '@src/background/services/bridge/models';
8181
import { isBitcoinNetwork } from '@src/background/services/network/utils/isBitcoinNetwork';
8282
import { useNetworkFeeContext } from '@src/contexts/NetworkFeeProvider';
83+
import { TransactionType } from '@src/background/services/wallet/handlers/eth_sendTransaction/models';
8384

8485
function formatBalance(balance: Big | undefined) {
8586
return balance ? formatTokenAmount(balance, 6) : '-';
@@ -143,7 +144,7 @@ export function Bridge() {
143144
const history = useHistory();
144145
const [isTokenSelectOpen, setIsTokenSelectOpen] = useState(false);
145146
const [isSwitched, setIsSwitched] = useState(false);
146-
const { capture, captureEncrypted } = useAnalyticsContext();
147+
const { capture, captureEncrypted, captureTime } = useAnalyticsContext();
147148
const { getPageHistoryData, setNavigationHistoryData } = usePageHistory();
148149
const { sendTokenSelectedAnalytics, sendAmountEnteredAnalytics } =
149150
useSendAnalyticsData();
@@ -605,12 +606,22 @@ export function Bridge() {
605606
return;
606607
}
607608

609+
const blockChainNetwork = blockchainToNetwork(
610+
currentBlockchain,
611+
networks,
612+
bridgeConfig
613+
);
614+
608615
captureEncrypted('BridgeTransferRequestSucceeded', {
609616
address: activeAddress,
610617
txHash: hash,
611618
sourceBlockchain: currentBlockchain,
612619
targetBlockchain,
613620
});
621+
captureTime({
622+
txType: TransactionType.BRIDGE,
623+
chainId: blockChainNetwork?.chainId,
624+
});
614625

615626
const timestamp = Date.now();
616627

@@ -623,7 +634,10 @@ export function Bridge() {
623634
bridgeFee,
624635
gasSettings,
625636
captureEncrypted,
637+
captureTime,
626638
currentBlockchain,
639+
networks,
640+
bridgeConfig,
627641
targetBlockchain,
628642
activeAddress,
629643
transfer,

src/pages/Collectibles/CollectibleSend.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import { useNetworkFeeContext } from '@src/contexts/NetworkFeeProvider';
3030
import { LoadingSendForm } from '../Send/components/LoadingSendForm';
3131
import { useCollectibleFromParams } from './hooks/useCollectibleFromParams';
3232
import { SendEVMCollectible } from './SendEVMCollectible';
33+
import { TransactionType } from '@src/background/services/wallet/handlers/eth_sendTransaction/models';
3334

3435
export function CollectibleSend() {
3536
const { t } = useTranslation();
@@ -39,7 +40,7 @@ export function CollectibleSend() {
3940
const {
4041
accounts: { active },
4142
} = useAccountsContext();
42-
const { captureEncrypted } = useAnalyticsContext();
43+
const { captureEncrypted, captureTime } = useAnalyticsContext();
4344
const tokens = useTokensWithBalances();
4445
const { nft } = useCollectibleFromParams();
4546

@@ -69,7 +70,10 @@ export function CollectibleSend() {
6970
chainId: network?.chainId,
7071
type: nft?.type,
7172
});
72-
73+
captureTime({
74+
txType: TransactionType.SEND_NFT,
75+
chainId: network?.chainId,
76+
});
7377
toastCardWithLink({
7478
title: t('Send Successful'),
7579
url: getExplorerAddressByNetwork(network as Network, txHash),
@@ -78,7 +82,7 @@ export function CollectibleSend() {
7882

7983
history.push('/home');
8084
},
81-
[fromAddress, network, captureEncrypted, history, t, nft?.type]
85+
[fromAddress, network, captureEncrypted, captureTime, history, t, nft?.type]
8286
);
8387

8488
const onFailure = useCallback(() => {

src/pages/Send/Send.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import {
4343
isAvmCapableAccount,
4444
isPvmCapableAccount,
4545
} from './hooks/useSend/models';
46+
import { TransactionType } from '@src/background/services/wallet/handlers/eth_sendTransaction/models';
4647

4748
export function SendPage() {
4849
const { t } = useTranslation();
@@ -52,7 +53,7 @@ export function SendPage() {
5253
const {
5354
accounts: { active },
5455
} = useAccountsContext();
55-
const { captureEncrypted } = useAnalyticsContext();
56+
const { captureEncrypted, captureTime } = useAnalyticsContext();
5657
const tokens = useTokensWithBalances();
5758

5859
const { isFunctionAvailable, isFunctionSupported } = useIsFunctionAvailable(
@@ -92,6 +93,10 @@ export function SendPage() {
9293
txHash,
9394
chainId: network?.chainId,
9495
});
96+
captureTime({
97+
txType: TransactionType.SEND_TOKEN,
98+
chainId: network?.chainId,
99+
});
95100

96101
toastCardWithLink({
97102
title: t('Send Successful'),
@@ -101,7 +106,7 @@ export function SendPage() {
101106

102107
history.push('/home');
103108
},
104-
[fromAddress, network, captureEncrypted, history, t]
109+
[captureEncrypted, fromAddress, network, captureTime, t, history]
105110
);
106111

107112
const onFailure = useCallback(() => {

src/pages/SignTransaction/SignTransaction.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import { SpendLimitInfo } from './components/SpendLimitInfo/SpendLimitInfo';
4747
import { ActionStatus } from '@src/background/services/actions/models';
4848
import { MaliciousTxAlert } from '@src/components/common/MaliciousTxAlert';
4949
import { TxWarningBox } from '@src/components/common/TxWarningBox';
50+
import { TimeMeasureEventNames } from '@src/contexts/AnalyticsProvider';
5051

5152
export function SignTransactionPage() {
5253
const { t } = useTranslation();
@@ -120,6 +121,7 @@ export function SignTransactionPage() {
120121

121122
const submit = useCallback(async () => {
122123
setTransactionProgressState(TransactionProgressState.PENDING);
124+
performance.mark(TimeMeasureEventNames.TRANSACTION_APPROVED);
123125
await updateTransaction(
124126
{
125127
status: ActionStatus.SUBMITTING,

src/pages/Swap/Swap.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { useAccountsContext } from '@src/contexts/AccountsProvider';
3737
import { isBitcoinNetwork } from '@src/background/services/network/utils/isBitcoinNetwork';
3838
import { isUserRejectionError } from '@src/utils/errors';
3939
import { DISALLOWED_SWAP_ASSETS } from '@src/contexts/SwapProvider/models';
40+
import { TransactionType } from '@src/background/services/wallet/handlers/eth_sendTransaction/models';
4041

4142
const ReviewOrderButtonContainer = styled('div')<{
4243
isTransactionDetailsOpen: boolean;
@@ -50,7 +51,7 @@ const ReviewOrderButtonContainer = styled('div')<{
5051

5152
export function Swap() {
5253
const { t } = useTranslation();
53-
const { capture, captureEncrypted } = useAnalyticsContext();
54+
const { capture, captureEncrypted, captureTime } = useAnalyticsContext();
5455
const { network } = useNetworkContext();
5556
const { swap } = useSwapContext();
5657
const { networkFee } = useNetworkFeeContext();
@@ -180,6 +181,10 @@ export function Swap() {
180181
address: activeAddress,
181182
chainId: network?.chainId,
182183
});
184+
captureTime({
185+
txType: TransactionType.SWAP,
186+
chainId: network?.chainId,
187+
});
183188
}
184189

185190
if (error && !isUserRejectionError(error)) {

0 commit comments

Comments
 (0)