1+ import { Identify , identify , setUserId } from '@amplitude/analytics-browser' ;
12import { Trans } from '@lingui/macro' ;
23import { Button } from '@mui/material' ;
34import { ConnectKitButton } from 'connectkit' ;
@@ -16,8 +17,8 @@ export interface ConnectWalletProps {
1617}
1718
1819export const ConnectWalletButton : React . FC < ConnectWalletProps > = ( { funnel, onClick } ) => {
19- const [ trackEvent , walletType ] = useRootStore (
20- useShallow ( ( store ) => [ store . trackEvent , store . walletType ] )
20+ const [ trackEvent , walletType , account ] = useRootStore (
21+ useShallow ( ( store ) => [ store . trackEvent , store . walletType , store . account ] )
2122 ) ;
2223
2324 // Track connection attempt duration
@@ -44,6 +45,18 @@ export const ConnectWalletButton: React.FC<ConnectWalletProps> = ({ funnel, onCl
4445 if ( ! isConnectingRef . current && previousConnectionState . current ) {
4546 // Connection attempt ended
4647 const duration = connectionStartTime ? Date . now ( ) - connectionStartTime : 0 ;
48+
49+ const walletAddress = account ;
50+ if ( walletAddress ) {
51+ setUserId ( walletAddress ) ;
52+
53+ const identifyObj = new Identify ( )
54+ . set ( 'wallet_connected' , true )
55+ . set ( 'wallet_type' , walletType || 'unknown' ) ;
56+
57+ identify ( identifyObj ) ;
58+ }
59+
4760 if ( isConnectedRef . current ) {
4861 trackEvent ( AUTH . WALLET_CONNECT_SUCCESS , {
4962 funnel,
@@ -62,7 +75,20 @@ export const ConnectWalletButton: React.FC<ConnectWalletProps> = ({ funnel, onCl
6275 }
6376
6477 previousConnectionState . current = isConnectingRef . current ;
65- } , [ connectionStartTime , funnel , trackEvent , walletType ] ) ;
78+ } , [ connectionStartTime , funnel , trackEvent , walletType , account ] ) ;
79+
80+ useEffect ( ( ) => {
81+ if ( ! account && walletType === undefined ) {
82+ // Wallet disconnected - clear identity
83+ const identifyObj = new Identify ( ) . set ( 'wallet_connected' , false ) . unset ( 'wallet_type' ) ;
84+
85+ identify ( identifyObj ) ;
86+
87+ trackEvent ( AUTH . DISCONNECT_WALLET , {
88+ funnel,
89+ } ) ;
90+ }
91+ } , [ account , walletType , funnel , trackEvent ] ) ;
6692
6793 return (
6894 < >
0 commit comments