Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,14 @@ describe('OptinMetrics — interest questionnaire navigation branching', () => {
await waitFor(() => {
expect(Logger.error).toHaveBeenCalledWith(
expect.objectContaining({ message: 'provisioning failed' }),
'OptinMetrics: provisionFromMetadata failed',
expect.objectContaining({
tags: expect.objectContaining({
feature: 'qr-sync',
surface: 'import',
operation: 'provision_from_metadata',
source: 'OptinMetrics',
}),
}),
);
});
});
Expand Down
22 changes: 12 additions & 10 deletions app/components/Views/AddDeviceToWallet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import { showAddDeviceVerificationSheet } from '../../../core/QrSync/showAddDevi
import { useAddDeviceResetToInstructionsListener } from '../../../core/QrSync/useAddDeviceResetToInstructionsListener';
import { useIsQrTabSwitcherOpen } from '../../../core/QrSync/useIsQrTabSwitcherOpen';
import { useQrSyncImportNavigation } from '../../../core/QrSync/useQrSyncImportNavigation';
import { reportQrSyncFailure } from '../../../core/QrSync/qrSyncTelemetry';
import type { AppNavigationProp } from '../../../core/NavigationService/types';
import Logger from '../../../util/Logger';
import {
selectQrSyncError,
selectQrSyncIsBusy,
Expand Down Expand Up @@ -119,10 +119,11 @@ const AddDeviceToWallet = () => {
const scannedQrPayload = content ?? data.content ?? '';

submitQrPayload(scannedQrPayload).catch((err: unknown) => {
Logger.error(
err as Error,
'AddDeviceToWallet: failed to submit scanned QR payload',
);
reportQrSyncFailure(err, {
surface: 'scanner',
Comment thread
grvgoel81 marked this conversation as resolved.
Outdated
operation: 'submit_scanned_payload',
source: 'AddDeviceToWallet.onScanSuccess',
});
});
},
[submitQrPayload],
Expand Down Expand Up @@ -150,11 +151,12 @@ const AddDeviceToWallet = () => {
}, [manualQrPayload, submitQrPayload]);

const triggerManualQrSubmit = useCallback(() => {
handleManualQrSubmit().catch((error: unknown) => {
Logger.error(
error as Error,
'AddDeviceToWallet: failed to submit manual QR payload',
);
handleManualQrSubmit().catch((submitError: unknown) => {
reportQrSyncFailure(submitError, {
surface: 'scanner',
operation: 'submit_manual_payload',
source: 'AddDeviceToWallet.triggerManualQrSubmit',
});
});
}, [handleManualQrSubmit]);

Expand Down
13 changes: 13 additions & 0 deletions app/components/Views/QRScanner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import AddDeviceScannerRecovery, {
AddDeviceScannerPermissionDenied,
} from './AddDeviceScannerRecovery';
import { EXTENSION_ACCOUNT_SYNC_CONNECTION_FAILED_EVENT } from '../../../core/ExtensionAccountSync/types';
import { reportQrSyncFailure } from '../../../core/QrSync/qrSyncTelemetry';

const sleep = (ms: number) =>
new Promise<void>((resolve) => {
Expand Down Expand Up @@ -258,6 +259,18 @@ const QRScanner = ({
if (classification !== 'valid') {
shouldReadBarCodeRef.current = false;
setIsCameraActive(false);
reportQrSyncFailure(
new Error(`Add-device QR scan classified as ${classification}`),
{
surface: 'scanner',
operation: 'classify_scan_content',
errorCode:
classification === 'expired'
Comment thread
grvgoel81 marked this conversation as resolved.
Outdated
? 'SESSION_EXPIRED'
: 'INVALID_PAYLOAD',
source: 'QRScanner.addDevice',
},
);
trackEvent(
createEventBuilder(MetaMetricsEvents.QR_SCANNED)
.addProperties({
Expand Down
44 changes: 44 additions & 0 deletions app/core/QrSync/QrSyncController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,50 @@ describe('QrSyncController', () => {
expect(walletClient.client.sendResponse).toHaveBeenCalledTimes(1);
});

it('terminates with GRANT_WAIT_TIMEOUT when the OTP grant deadline elapses', async () => {
jest.useFakeTimers();
const controller = buildController();
const walletClient = buildMockWalletClient({ deferOtpAck: true });

mockCreateQrSyncWalletClient.mockResolvedValue({
sessionId: VALID_SESSION_ID,
client: walletClient.client,
});

const scanPromise = controller.handleScannedQrPayload(
buildValidScanPayload(),
);
await flushPromises();

expect(controller.state.phase).toBe(QrSyncPhases.DISPLAYING_OTP);

jest.advanceTimersByTime(30_000);
await flushPromises();

expect(controller.state.phase).toBe(QrSyncPhases.FAILED);
expect(controller.state.error).toEqual({
code: 'GRANT_WAIT_TIMEOUT',
message: 'QR sync OTP grant wait timed out before handshake completed.',
});

walletClient.completeOtpHandshake();
await scanPromise;
await flushPromises();

expect(controller.state.phase).toBe(QrSyncPhases.FAILED);
expect(controller.state.error?.code).toBe('GRANT_WAIT_TIMEOUT');
expect(walletClient.client.sendResponse).toHaveBeenCalledWith(
expect.objectContaining({
type: QrSyncActionTypes.SYNC_ERROR,
data: expect.objectContaining({ code: 'GRANT_WAIT_TIMEOUT' }),
}),
);
expect(walletClient.client.sendResponse).not.toHaveBeenCalledWith(
expect.objectContaining({ type: QrSyncActionTypes.SYNC_OFFER }),
);
jest.useRealTimers();
});

it('sends sync-offer once after connect completes the OTP handshake', async () => {
const controller = buildController();
const walletClient = buildMockWalletClient();
Expand Down
Loading
Loading