Skip to content

Commit 47cc59d

Browse files
authored
Revert "Mixpanel tweaks (#971)"
This reverts commit 7536875.
1 parent d9f80f8 commit 47cc59d

File tree

4 files changed

+44
-82
lines changed

4 files changed

+44
-82
lines changed

app/jest.setup.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ jest.mock('react-native-check-version', () => ({
151151

152152
// Mock @react-native-community/netinfo
153153
jest.mock('@react-native-community/netinfo', () => ({
154-
addEventListener: jest.fn(() => jest.fn()),
154+
addEventListener: jest.fn(),
155155
useNetInfo: jest.fn().mockReturnValue({
156156
type: 'wifi',
157157
isConnected: true,
@@ -161,9 +161,7 @@ jest.mock('@react-native-community/netinfo', () => ({
161161
cellularGeneration: '4g',
162162
},
163163
}),
164-
fetch: jest
165-
.fn()
166-
.mockResolvedValue({ isConnected: true, isInternetReachable: true }),
164+
fetch: jest.fn(),
167165
}));
168166

169167
// Mock react-native-nfc-manager
@@ -228,6 +226,11 @@ NativeModules.PassportReader = {
228226
flush: jest.fn(),
229227
};
230228

229+
jest.mock('@react-native-community/netinfo', () => ({
230+
addEventListener: jest.fn(() => jest.fn()),
231+
fetch: jest.fn(() => Promise.resolve({ isConnected: true })),
232+
}));
233+
231234
// Mock @stablelib packages
232235
jest.mock('@stablelib/cbor', () => ({
233236
encode: jest.fn(),

app/src/mocks/react-native-passport-reader.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,6 @@
33
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
44

55
// Web mock for react-native-passport-reader
6-
7-
// Mock PassportReader object with analytics methods
8-
export const PassportReader = {
9-
configure: (
10-
token: string,
11-
enableDebug?: boolean,
12-
flushPolicies?: {
13-
flushInterval?: number;
14-
flushCount?: number;
15-
flushOnBackground?: boolean;
16-
flushOnForeground?: boolean;
17-
flushOnNetworkChange?: boolean;
18-
},
19-
) => {
20-
// No-op for web
21-
return Promise.resolve();
22-
},
23-
trackEvent: (name: string, properties?: Record<string, unknown>) => {
24-
// No-op for web
25-
return Promise.resolve();
26-
},
27-
flush: () => {
28-
// No-op for web
29-
return Promise.resolve();
30-
},
31-
reset: () => {
32-
// No-op for web
33-
return Promise.resolve();
34-
},
35-
scan: async () => {
36-
throw new Error('NFC scanning is not supported on web');
37-
},
38-
};
396
export const reset = async () => {
407
// No-op for web
418
return Promise.resolve();

app/src/utils/analytics.ts

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
44

55
import { AppState, type AppStateStatus } from 'react-native';
6-
import { PassportReader } from 'react-native-passport-reader';
6+
import { NativeModules } from 'react-native';
77
import { ENABLE_DEBUG_LOGS, MIXPANEL_NFC_PROJECT_TOKEN } from '@env';
88
import NetInfo from '@react-native-community/netinfo';
99
import type { JsonMap, JsonValue } from '@segment/analytics-react-native';
@@ -161,32 +161,28 @@ export const cleanupAnalytics = () => {
161161
const setupFlushPolicies = () => {
162162
AppState.addEventListener('change', (state: AppStateStatus) => {
163163
if (state === 'background' || state === 'active') {
164-
flushMixpanelEvents().catch(console.warn);
164+
flushMixpanelEvents();
165165
}
166166
});
167167

168168
NetInfo.addEventListener(state => {
169169
isConnected = state.isConnected ?? true;
170170
if (isConnected) {
171-
flushMixpanelEvents().catch(console.warn);
171+
flushMixpanelEvents();
172172
}
173173
});
174174
};
175175

176-
const flushMixpanelEvents = async () => {
176+
const flushMixpanelEvents = () => {
177177
if (!MIXPANEL_NFC_PROJECT_TOKEN) return;
178178
try {
179179
if (__DEV__) console.log('[Mixpanel] flush');
180180
// Send any queued events before flushing
181181
while (eventQueue.length > 0) {
182182
const evt = eventQueue.shift()!;
183-
if (PassportReader.trackEvent) {
184-
await Promise.resolve(
185-
PassportReader.trackEvent(evt.name, evt.properties),
186-
);
187-
}
183+
NativeModules.PassportReader?.trackEvent?.(evt.name, evt.properties);
188184
}
189-
if (PassportReader.flush) await Promise.resolve(PassportReader.flush());
185+
NativeModules.PassportReader?.flush?.();
190186
eventCount = 0;
191187
} catch (err) {
192188
if (__DEV__) console.warn('Mixpanel flush failed', err);
@@ -198,20 +194,20 @@ const flushMixpanelEvents = async () => {
198194
};
199195

200196
// --- Mixpanel NFC Analytics ---
201-
export const configureNfcAnalytics = async () => {
197+
export const configureNfcAnalytics = () => {
202198
if (!MIXPANEL_NFC_PROJECT_TOKEN || mixpanelConfigured) return;
203199
const enableDebugLogs = JSON.parse(String(ENABLE_DEBUG_LOGS));
204-
if (PassportReader.configure) {
205-
await Promise.resolve(
206-
PassportReader.configure(MIXPANEL_NFC_PROJECT_TOKEN, enableDebugLogs, {
207-
flushInterval: 20,
208-
flushCount: 5,
209-
flushOnBackground: true,
210-
flushOnForeground: true,
211-
flushOnNetworkChange: true,
212-
}),
213-
);
214-
}
200+
NativeModules.PassportReader.configure(
201+
MIXPANEL_NFC_PROJECT_TOKEN,
202+
enableDebugLogs,
203+
{
204+
flushInterval: 20,
205+
flushCount: 5,
206+
flushOnBackground: true,
207+
flushOnForeground: true,
208+
flushOnNetworkChange: true,
209+
},
210+
);
215211
setupFlushPolicies();
216212
mixpanelConfigured = true;
217213
};
@@ -226,30 +222,28 @@ export const flushAllAnalytics = () => {
226222
flushAnalytics();
227223

228224
// Flush Mixpanel events
229-
flushMixpanelEvents().catch(console.warn);
225+
flushMixpanelEvents();
230226
};
231227

232-
export const trackNfcEvent = async (
228+
export const trackNfcEvent = (
233229
name: string,
234230
properties?: Record<string, unknown>,
235231
) => {
236232
if (!MIXPANEL_NFC_PROJECT_TOKEN) return;
237-
if (!mixpanelConfigured) await configureNfcAnalytics();
233+
if (!mixpanelConfigured) configureNfcAnalytics();
238234

239235
if (!isConnected) {
240236
eventQueue.push({ name, properties });
241237
return;
242238
}
243239

244240
try {
245-
if (PassportReader.trackEvent) {
246-
await Promise.resolve(PassportReader.trackEvent(name, properties));
247-
}
241+
NativeModules.PassportReader?.trackEvent?.(name, properties);
248242
eventCount++;
249243
if (eventCount >= 5) {
250-
flushMixpanelEvents().catch(console.warn);
244+
flushMixpanelEvents();
251245
}
252-
} catch {
246+
} catch (err) {
253247
eventQueue.push({ name, properties });
254248
}
255249
};

app/src/utils/nfcScanner.ts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
44

55
import { Buffer } from 'buffer';
6-
import { Platform } from 'react-native';
7-
import {
8-
PassportReader,
9-
reset,
10-
scan as scanDocument,
11-
} from 'react-native-passport-reader';
6+
import { NativeModules, Platform } from 'react-native';
7+
import { reset, scan as scanDocument } from 'react-native-passport-reader';
128

139
import type { PassportData } from '@selfxyz/common/types';
1410

@@ -48,7 +44,7 @@ export const parseScanResponse = (response: unknown) => {
4844
};
4945

5046
export const scan = async (inputs: Inputs) => {
51-
await configureNfcAnalytics();
47+
configureNfcAnalytics();
5248

5349
return Platform.OS === 'android'
5450
? await scanAndroid(inputs)
@@ -67,14 +63,16 @@ const scanAndroid = async (inputs: Inputs) => {
6763
};
6864

6965
const scanIOS = async (inputs: Inputs) => {
70-
return await Promise.resolve(
71-
PassportReader.scan({
72-
documentNumber: inputs.passportNumber,
73-
dateOfBirth: inputs.dateOfBirth,
74-
dateOfExpiry: inputs.dateOfExpiry,
75-
canNumber: inputs.canNumber ?? '',
76-
useCan: inputs.useCan ?? false,
77-
}),
66+
return await NativeModules.PassportReader.scanDocument(
67+
inputs.passportNumber,
68+
inputs.dateOfBirth,
69+
inputs.dateOfExpiry,
70+
inputs.canNumber ?? '',
71+
inputs.useCan ?? false,
72+
inputs.skipPACE ?? false,
73+
inputs.skipCA ?? false,
74+
inputs.extendedMode ?? false,
75+
inputs.usePacePolling ?? false,
7876
);
7977
};
8078

0 commit comments

Comments
 (0)