Fix nfc configuration scanning issue (#978)

* fix nfc scanning on ios and android

* save test

* fix tests

* fix lint
This commit is contained in:
Justin Hernandez
2025-08-28 11:12:41 -07:00
committed by GitHub
parent d9f80f8c13
commit 0e3e5de1b0
10 changed files with 354 additions and 61 deletions

View File

@@ -200,18 +200,24 @@ const flushMixpanelEvents = async () => {
// --- Mixpanel NFC Analytics ---
export const configureNfcAnalytics = async () => {
if (!MIXPANEL_NFC_PROJECT_TOKEN || mixpanelConfigured) return;
const enableDebugLogs = JSON.parse(String(ENABLE_DEBUG_LOGS));
if (PassportReader.configure) {
await Promise.resolve(
PassportReader.configure(MIXPANEL_NFC_PROJECT_TOKEN, enableDebugLogs, {
flushInterval: 20,
flushCount: 5,
flushOnBackground: true,
flushOnForeground: true,
flushOnNetworkChange: true,
}),
);
const enableDebugLogs =
String(ENABLE_DEBUG_LOGS ?? '')
.trim()
.toLowerCase() === 'true';
// Check if PassportReader and configure method exist (Android doesn't have configure)
if (PassportReader && typeof PassportReader.configure === 'function') {
try {
// iOS configure method only accepts token and enableDebugLogs
// Android doesn't have this method at all
await Promise.resolve(
PassportReader.configure(MIXPANEL_NFC_PROJECT_TOKEN, enableDebugLogs),
);
} catch (error) {
console.warn('Failed to configure NFC analytics:', error);
}
}
setupFlushPolicies();
mixpanelConfigured = true;
};

View File

@@ -68,13 +68,17 @@ const scanAndroid = async (inputs: Inputs) => {
const scanIOS = async (inputs: Inputs) => {
return await Promise.resolve(
PassportReader.scan({
documentNumber: inputs.passportNumber,
dateOfBirth: inputs.dateOfBirth,
dateOfExpiry: inputs.dateOfExpiry,
canNumber: inputs.canNumber ?? '',
useCan: inputs.useCan ?? false,
}),
PassportReader.scanPassport(
inputs.passportNumber,
inputs.dateOfBirth,
inputs.dateOfExpiry,
inputs.canNumber ?? '',
inputs.useCan ?? false,
inputs.skipPACE ?? false,
inputs.skipCA ?? false,
inputs.extendedMode ?? false,
inputs.usePacePolling ?? false,
),
);
};

View File

@@ -183,6 +183,7 @@ interface ProvingState {
endpointType: EndpointType | null;
fcmToken: string | null;
env: 'prod' | 'stg' | null;
selfClient: SelfClient | null;
setFcmToken: (token: string) => void;
init: (
selfClient: SelfClient,
@@ -330,6 +331,7 @@ export const useProvingStore = create<ProvingState>((set, get) => {
reason: null,
endpointType: null,
fcmToken: null,
selfClient: null,
setFcmToken: (token: string) => {
set({ fcmToken: token });
trackEvent(ProofEvents.FCM_TOKEN_STORED);
@@ -632,6 +634,7 @@ export const useProvingStore = create<ProvingState>((set, get) => {
circuitType,
endpointType: null,
env: null,
selfClient,
});
actor = createActor(provingMachine);
@@ -649,7 +652,7 @@ export const useProvingStore = create<ProvingState>((set, get) => {
const { data: passportData } = selectedDocument;
const secret = await selfClient.getPrivateKey();
const secret = await get().selfClient?.getPrivateKey();
if (!secret) {
console.error('Could not load secret');
trackEvent(ProofEvents.LOAD_SECRET_FAILED);