Skip to content

Commit a51325f

Browse files
authored
feat: wallet connect details (#2532)
1 parent e833337 commit a51325f

File tree

2 files changed

+72
-11
lines changed

2 files changed

+72
-11
lines changed

src/components/WalletConnection/ConnectWalletButton.tsx

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import { Trans } from '@lingui/macro';
22
import { Button } from '@mui/material';
33
import { ConnectKitButton } from 'connectkit';
4+
import { useEffect, useRef, useState } from 'react';
45
import { useRootStore } from 'src/store/root';
56
import { AUTH } from 'src/utils/events';
7+
import { useShallow } from 'zustand/shallow';
68

79
import { AvatarSize } from '../Avatar';
810
import { UserDisplay } from '../UserDisplay';
@@ -14,19 +16,75 @@ export interface ConnectWalletProps {
1416
}
1517

1618
export const ConnectWalletButton: React.FC<ConnectWalletProps> = ({ funnel, onClick }) => {
17-
const trackEvent = useRootStore((store) => store.trackEvent);
19+
const [trackEvent, walletType] = useRootStore(
20+
useShallow((store) => [store.trackEvent, store.walletType])
21+
);
22+
23+
// Track connection attempt duration
24+
const [connectionStartTime, setConnectionStartTime] = useState<number | null>(null);
25+
const previousConnectionState = useRef<boolean>(false);
26+
const isConnectingRef = useRef<boolean>(false);
27+
const isConnectedRef = useRef<boolean>(false);
28+
29+
const connectionAttempts = useRef<number>(0);
30+
31+
// Track connection state changes
32+
useEffect(() => {
33+
if (isConnectingRef.current && !previousConnectionState.current) {
34+
// Connection attempt started
35+
setConnectionStartTime(Date.now());
36+
connectionAttempts.current += 1;
37+
trackEvent(AUTH.WALLET_CONNECT_START, {
38+
funnel,
39+
attempt_number: connectionAttempts.current,
40+
previous_wallet_type: walletType,
41+
});
42+
}
43+
44+
if (!isConnectingRef.current && previousConnectionState.current) {
45+
// Connection attempt ended
46+
const duration = connectionStartTime ? Date.now() - connectionStartTime : 0;
47+
if (isConnectedRef.current) {
48+
trackEvent(AUTH.WALLET_CONNECT_SUCCESS, {
49+
funnel,
50+
wallet_type: walletType,
51+
connection_duration_ms: duration,
52+
attempts_until_success: connectionAttempts.current,
53+
});
54+
} else {
55+
trackEvent(AUTH.WALLET_CONNECT_ABORT, {
56+
funnel,
57+
connection_duration_ms: duration,
58+
attempt_number: connectionAttempts.current,
59+
});
60+
}
61+
setConnectionStartTime(null);
62+
}
63+
64+
previousConnectionState.current = isConnectingRef.current;
65+
}, [connectionStartTime, funnel, trackEvent, walletType]);
1866

1967
return (
2068
<>
2169
<ConnectKitButton.Custom>
22-
{({ isConnected, show }) => {
70+
{({ isConnected, show, isConnecting }) => {
71+
// Update refs for tracking
72+
isConnectingRef.current = isConnecting;
73+
isConnectedRef.current = isConnected;
74+
2375
return (
2476
<Button
2577
variant={isConnected ? 'surface' : 'gradient'}
2678
onClick={() => {
79+
// Track initial button click
80+
trackEvent(AUTH.CONNECT_WALLET, {
81+
funnel,
82+
current_url: window.location.pathname,
83+
is_reconnect_attempt: connectionAttempts.current > 0,
84+
});
85+
2786
onClick && onClick();
2887
show && show();
29-
trackEvent(AUTH.CONNECT_WALLET, { funnel: funnel });
3088
}}
3189
>
3290
{isConnected ? (

src/utils/events.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
export const AUTH = {
2-
CONNECT_WALLET: 'Connect wallet', //done
3-
SWITCH_WALLET: 'Switch wallet', //done
4-
MOCK_WALLET: 'Mock wallet', //done
5-
DISCONNECT_WALLET: 'Disconnect wallet', //done
6-
COPY_ADDRESS: 'Copy address', // done
7-
VIEW_EXPLORER: 'View explorer', // done
8-
VIEW_TX_HISTORY: 'View Tx History',
9-
};
2+
CONNECT_WALLET: 'Connect Wallet',
3+
SWITCH_WALLET: 'Switch Wallet',
4+
MOCK_WALLET: 'Mock Wallet',
5+
DISCONNECT_WALLET: 'Disconnect Wallet',
6+
COPY_ADDRESS: 'Copy Address',
7+
VIEW_EXPLORER: 'View Explorer',
8+
VIEW_TX_HISTORY: 'View Transaction History',
9+
WALLET_CONNECT_START: 'Wallet Connect Start',
10+
WALLET_CONNECT_SUCCESS: 'Wallet Connect Success',
11+
WALLET_CONNECT_ABORT: 'Wallet Connect Abort',
12+
} as const;
1013

1114
export const GENERAL = {
1215
SWITCH_NETWORK: 'Switch network',

0 commit comments

Comments
 (0)