Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions packages/hw-wallet-sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add `PermissionCameraPromptDismissed` error code and `QR_WALLET_ERROR_MAPPINGS` used for extension QR hardware wallet camera flows ([#490](https://github.com/MetaMask/accounts/pull/490))

## [0.7.0]

### Added
Expand Down
43 changes: 43 additions & 0 deletions packages/hw-wallet-sdk/src/hardware-error-mappings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
LEDGER_ERROR_MAPPINGS,
BLE_ERROR_MAPPINGS,
MOBILE_ERROR_MAPPINGS,
QR_WALLET_ERROR_MAPPINGS,
TREZOR_ERROR_MAPPINGS,
} from './hardware-error-mappings';
import type { ErrorMapping } from './hardware-error-mappings';
Expand Down Expand Up @@ -254,6 +255,48 @@ describe('HARDWARE_ERROR_MAPPINGS', () => {
});
});

describe('QR wallet mappings', () => {
const errorMappings = QR_WALLET_ERROR_MAPPINGS;

it('has errorMappings object', () => {
expect(errorMappings).toBeDefined();
expect(typeof errorMappings).toBe('object');
});

it('maps CAMERA_PERMISSION_PROMPT_DISMISSED for State 1 (dialog dismissed)', () => {
const mapping = errorMappings.CAMERA_PERMISSION_PROMPT_DISMISSED;
expect(mapping).toBeDefined();
expect(mapping?.code).toBe(ErrorCode.PermissionCameraPromptDismissed);
expect(mapping?.severity).toBe(Severity.Warning);
expect(mapping?.userMessage).toContain('QR code');
});

it('maps CAMERA_PERMISSION_BLOCKED for State 2 (persistent block)', () => {
const mapping = errorMappings.CAMERA_PERMISSION_BLOCKED;
expect(mapping).toBeDefined();
expect(mapping?.code).toBe(ErrorCode.PermissionCameraDenied);
expect(mapping?.severity).toBe(Severity.Err);
expect(mapping?.userMessage).toContain('browser settings');
});

it('has valid structure for all mappings', () => {
Object.values(errorMappings).forEach((mapping) => {
expect(mapping).toHaveProperty('code');
expect(mapping).toHaveProperty('message');
expect(mapping).toHaveProperty('severity');
expect(mapping).toHaveProperty('category');

const numericErrorCodes = Object.values(ErrorCode).filter(
(value): value is number => typeof value === 'number',
);
expect(numericErrorCodes).toContain(mapping.code);
expect(Object.values(Severity)).toContain(mapping.severity);
expect(Object.values(Category)).toContain(mapping.category);
expect(typeof mapping.message).toBe('string');
});
});
});

describe('Trezor mappings', () => {
it('has TREZOR_ERROR_MAPPINGS object', () => {
expect(TREZOR_ERROR_MAPPINGS).toBeDefined();
Expand Down
21 changes: 21 additions & 0 deletions packages/hw-wallet-sdk/src/hardware-error-mappings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,27 @@ export const MOBILE_ERROR_MAPPINGS = {
},
};

/**
* QR error mappings - static error data for QR hardware wallets and their related flows.
*/
export const QR_WALLET_ERROR_MAPPINGS: Record<string, ErrorMapping> = {
CAMERA_PERMISSION_PROMPT_DISMISSED: {
code: ErrorCode.PermissionCameraPromptDismissed,
message: 'Camera permission prompt dismissed without granting access',
severity: Severity.Warning,
category: Category.Configuration,
userMessage:
'MetaMask needs camera access to scan the QR code on your device.',
},
CAMERA_PERMISSION_BLOCKED: {
code: ErrorCode.PermissionCameraDenied,
message: 'Camera permission blocked by the browser',
severity: Severity.Err,
category: Category.Configuration,
userMessage: 'To continue, allow camera access in your browser settings.',
},
};

/* eslint-disable @typescript-eslint/naming-convention */
/**
* Trezor error mappings - static error data for Trezor hardware wallets.
Expand Down
1 change: 1 addition & 0 deletions packages/hw-wallet-sdk/src/hardware-errors-enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export enum ErrorCode {
BluetoothConnectionFailed = 7102,
MobileNotSupported = 7300,
PermissionCameraDenied = 7301,
PermissionCameraPromptDismissed = 7302,

// Transaction
TxInsufficientFunds = 10000,
Expand Down
Loading