Skip to content

Commit adf0b16

Browse files
authored
chore: Revert ConnectWallet analytics (#1956)
1 parent c1b7413 commit adf0b16

File tree

2 files changed

+5
-228
lines changed

2 files changed

+5
-228
lines changed

src/wallet/components/ConnectWallet.test.tsx

+5-175
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import { fireEvent, render, screen } from '@testing-library/react';
33
import type { ReactNode } from 'react';
44
import { beforeEach, describe, expect, it, vi } from 'vitest';
55
import { useAccount, useConnect } from 'wagmi';
6-
import { useAnalytics } from '../../core/analytics/hooks/useAnalytics';
7-
import { WalletEvent } from '../../core/analytics/types';
86
import { useOnchainKit } from '../../useOnchainKit';
97
import { ConnectWallet } from './ConnectWallet';
108
import { ConnectWalletText } from './ConnectWalletText';
@@ -45,13 +43,7 @@ vi.mock('@/useOnchainKit', () => ({
4543
useOnchainKit: vi.fn(),
4644
}));
4745

48-
vi.mock('../../core/analytics/hooks/useAnalytics', () => ({
49-
useAnalytics: vi.fn(),
50-
}));
51-
5246
describe('ConnectWallet', () => {
53-
const mockSendAnalytics = vi.fn();
54-
5547
beforeEach(() => {
5648
Object.defineProperty(window, 'matchMedia', {
5749
writable: true,
@@ -84,9 +76,6 @@ describe('ConnectWallet', () => {
8476
vi.mocked(useOnchainKit).mockReturnValue({
8577
config: { wallet: { display: undefined } },
8678
});
87-
vi.mocked(useAnalytics).mockReturnValue({
88-
sendAnalytics: mockSendAnalytics,
89-
});
9079
});
9180

9281
it('should render connect button when disconnected', () => {
@@ -127,54 +116,22 @@ describe('ConnectWallet', () => {
127116

128117
it('should call connect function when connect button is clicked', () => {
129118
const connectMock = vi.fn();
130-
const mockSendAnalytics = vi.fn();
131-
132119
vi.mocked(useConnect).mockReturnValue({
133-
connectors: [{ name: 'TestConnector', id: 'mockConnector' }],
120+
connectors: [{ id: 'mockConnector' }],
134121
connect: connectMock,
135122
status: 'idle',
136123
});
137-
138-
vi.mocked(useAnalytics).mockReturnValue({
139-
sendAnalytics: mockSendAnalytics,
140-
});
141-
142124
render(<ConnectWallet text="Connect Wallet" />);
143-
144125
const button = screen.getByTestId('ockConnectButton');
145126
fireEvent.click(button);
146-
147-
expect(mockSendAnalytics).toHaveBeenCalledWith(
148-
WalletEvent.ConnectInitiated,
127+
expect(connectMock).toHaveBeenCalledWith(
149128
{
150-
component: 'ConnectWallet',
151-
walletProvider: 'TestConnector',
129+
connector: { id: 'mockConnector' },
152130
},
153-
);
154-
155-
expect(connectMock).toHaveBeenCalledWith(
156-
{ connector: { name: 'TestConnector', id: 'mockConnector' } },
157131
{
158132
onSuccess: expect.any(Function),
159-
onError: expect.any(Function),
160133
},
161134
);
162-
163-
connectMock.mock.calls[0][1].onSuccess();
164-
expect(mockSendAnalytics).toHaveBeenCalledWith(WalletEvent.ConnectSuccess, {
165-
address: '',
166-
walletProvider: 'TestConnector',
167-
});
168-
169-
const error = new Error('Test error');
170-
connectMock.mock.calls[0][1].onError(error);
171-
expect(mockSendAnalytics).toHaveBeenCalledWith(WalletEvent.ConnectError, {
172-
error: 'Test error',
173-
metadata: {
174-
connector: 'TestConnector',
175-
component: 'ConnectWallet',
176-
},
177-
});
178135
});
179136

180137
it('should toggle wallet modal on button click when connected', () => {
@@ -344,10 +301,7 @@ describe('ConnectWallet', () => {
344301

345302
expect(connectMock).toHaveBeenCalledWith(
346303
{ connector: { id: 'mockConnector' } },
347-
{
348-
onSuccess: expect.any(Function),
349-
onError: expect.any(Function),
350-
},
304+
{ onSuccess: expect.any(Function) },
351305
);
352306
});
353307
});
@@ -391,10 +345,7 @@ describe('ConnectWallet', () => {
391345

392346
expect(connectMock).toHaveBeenCalledWith(
393347
{ connector: { id: 'mockConnector' } },
394-
{
395-
onSuccess: expect.any(Function),
396-
onError: expect.any(Function),
397-
},
348+
{ onSuccess: expect.any(Function) },
398349
);
399350

400351
connectMock.mock.calls[0][1].onSuccess();
@@ -592,125 +543,4 @@ describe('ConnectWallet', () => {
592543
expect(onConnectMock).toHaveBeenCalledTimes(1);
593544
});
594545
});
595-
596-
describe('analytics', () => {
597-
it('should send analytics when connect button is clicked in modal mode', () => {
598-
vi.mocked(useOnchainKit).mockReturnValue({
599-
config: { wallet: { display: 'modal' } },
600-
});
601-
602-
vi.mocked(useConnect).mockReturnValue({
603-
connectors: [{ name: 'TestConnector', id: 'mockConnector' }],
604-
connect: vi.fn(),
605-
status: 'idle',
606-
});
607-
608-
render(<ConnectWallet text="Connect Wallet" />);
609-
610-
const button = screen.getByTestId('ockConnectButton');
611-
fireEvent.click(button);
612-
613-
expect(mockSendAnalytics).toHaveBeenCalledWith(
614-
WalletEvent.ConnectInitiated,
615-
{
616-
component: 'ConnectWallet',
617-
walletProvider: 'TestConnector',
618-
},
619-
);
620-
});
621-
622-
it('should send analytics when direct connect is initiated', () => {
623-
const connectMock = vi.fn();
624-
vi.mocked(useConnect).mockReturnValue({
625-
connectors: [{ name: 'TestConnector', id: 'mockConnector' }],
626-
connect: connectMock,
627-
status: 'idle',
628-
});
629-
630-
render(<ConnectWallet text="Connect Wallet" />);
631-
632-
const button = screen.getByTestId('ockConnectButton');
633-
fireEvent.click(button);
634-
635-
expect(mockSendAnalytics).toHaveBeenCalledWith(
636-
WalletEvent.ConnectInitiated,
637-
{
638-
component: 'ConnectWallet',
639-
walletProvider: 'TestConnector',
640-
},
641-
);
642-
});
643-
644-
it('should send analytics on successful connection', () => {
645-
const connectMock = vi.fn();
646-
vi.mocked(useConnect).mockReturnValue({
647-
connectors: [{ name: 'TestConnector', id: 'mockConnector' }],
648-
connect: connectMock,
649-
status: 'idle',
650-
});
651-
652-
render(<ConnectWallet text="Connect Wallet" />);
653-
654-
const button = screen.getByTestId('ockConnectButton');
655-
fireEvent.click(button);
656-
657-
connectMock.mock.calls[0][1].onSuccess();
658-
659-
expect(mockSendAnalytics).toHaveBeenCalledWith(
660-
WalletEvent.ConnectSuccess,
661-
{
662-
address: '',
663-
walletProvider: 'TestConnector',
664-
},
665-
);
666-
});
667-
668-
it('should send analytics on connection error', () => {
669-
const connectMock = vi.fn();
670-
vi.mocked(useConnect).mockReturnValue({
671-
connectors: [{ name: 'TestConnector', id: 'mockConnector' }],
672-
connect: connectMock,
673-
status: 'idle',
674-
});
675-
676-
render(<ConnectWallet text="Connect Wallet" />);
677-
678-
const button = screen.getByTestId('ockConnectButton');
679-
fireEvent.click(button);
680-
681-
connectMock.mock.calls[0][1].onError(new Error('Test error'));
682-
683-
expect(mockSendAnalytics).toHaveBeenCalledWith(WalletEvent.ConnectError, {
684-
error: 'Test error',
685-
metadata: {
686-
connector: 'TestConnector',
687-
component: 'ConnectWallet',
688-
},
689-
});
690-
});
691-
692-
it('should send analytics when account is connected with address', () => {
693-
const mockUseAccount = vi.mocked(useAccount);
694-
vi.mocked(useConnect).mockReturnValue({
695-
connectors: [{ name: 'TestConnector', id: 'mockConnector' }],
696-
connect: vi.fn(),
697-
status: 'idle',
698-
});
699-
700-
mockUseAccount.mockReturnValue({
701-
address: '0x123',
702-
status: 'connected',
703-
});
704-
705-
render(<ConnectWallet text="Connect Wallet" />);
706-
707-
expect(mockSendAnalytics).toHaveBeenCalledWith(
708-
WalletEvent.ConnectSuccess,
709-
{
710-
address: '0x123',
711-
walletProvider: 'TestConnector',
712-
},
713-
);
714-
});
715-
});
716546
});

src/wallet/components/ConnectWallet.tsx

-53
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ import { Children, isValidElement, useCallback, useMemo } from 'react';
44
import type { ReactNode } from 'react';
55
import { useEffect, useState } from 'react';
66
import { useAccount, useConnect } from 'wagmi';
7-
import { useAnalytics } from '../../core/analytics/hooks/useAnalytics';
8-
import { WalletEvent } from '../../core/analytics/types';
97
import { IdentityProvider } from '../../identity/components/IdentityProvider';
108
import { Spinner } from '../../internal/components/Spinner';
119
import { findComponent } from '../../internal/utils/findComponent';
@@ -42,7 +40,6 @@ export function ConnectWallet({
4240
} = useWalletContext();
4341
const { address: accountAddress, status } = useAccount();
4442
const { connectors, connect, status: connectStatus } = useConnect();
45-
const { sendAnalytics } = useAnalytics();
4643

4744
// State
4845
const [hasClickedConnect, setHasClickedConnect] = useState(false);
@@ -91,39 +88,6 @@ export function ConnectWallet({
9188
setHasClickedConnect(true);
9289
}, [setIsConnectModalOpen]);
9390

94-
const handleAnalyticsInitiated = useCallback(
95-
(connectorName: string, component: string) => {
96-
sendAnalytics(WalletEvent.ConnectInitiated, {
97-
component,
98-
walletProvider: connectorName,
99-
});
100-
},
101-
[sendAnalytics],
102-
);
103-
104-
const handleAnalyticsSuccess = useCallback(
105-
(connectorName: string, walletAddress: string | undefined) => {
106-
sendAnalytics(WalletEvent.ConnectSuccess, {
107-
address: walletAddress ?? '',
108-
walletProvider: connectorName,
109-
});
110-
},
111-
[sendAnalytics],
112-
);
113-
114-
const handleAnalyticsError = useCallback(
115-
(connectorName: string, errorMessage: string, component: string) => {
116-
sendAnalytics(WalletEvent.ConnectError, {
117-
error: errorMessage,
118-
metadata: {
119-
connector: connectorName,
120-
component,
121-
},
122-
});
123-
},
124-
[sendAnalytics],
125-
);
126-
12791
// Effects
12892
useEffect(() => {
12993
if (hasClickedConnect && status === 'connected' && onConnect) {
@@ -132,12 +96,6 @@ export function ConnectWallet({
13296
}
13397
}, [status, hasClickedConnect, onConnect]);
13498

135-
useEffect(() => {
136-
if (status === 'connected' && accountAddress && connector) {
137-
handleAnalyticsSuccess(connector.name, accountAddress);
138-
}
139-
}, [status, accountAddress, connector, handleAnalyticsSuccess]);
140-
14199
if (status === 'disconnected') {
142100
if (config?.wallet?.display === 'modal') {
143101
return (
@@ -148,7 +106,6 @@ export function ConnectWallet({
148106
onClick={() => {
149107
handleOpenConnectModal();
150108
setHasClickedConnect(true);
151-
handleAnalyticsInitiated(connector.name, 'ConnectWallet');
152109
}}
153110
text={text}
154111
/>
@@ -162,21 +119,11 @@ export function ConnectWallet({
162119
className={className}
163120
connectWalletText={connectWalletText}
164121
onClick={() => {
165-
handleAnalyticsInitiated(connector.name, 'ConnectWallet');
166-
167122
connect(
168123
{ connector },
169124
{
170125
onSuccess: () => {
171126
onConnect?.();
172-
handleAnalyticsSuccess(connector.name, accountAddress);
173-
},
174-
onError: (error) => {
175-
handleAnalyticsError(
176-
connector.name,
177-
error.message,
178-
'ConnectWallet',
179-
);
180127
},
181128
},
182129
);

0 commit comments

Comments
 (0)