diff --git a/packages/hw-wallet-sdk/CHANGELOG.md b/packages/hw-wallet-sdk/CHANGELOG.md index 9cc962f7..86a98024 100644 --- a/packages/hw-wallet-sdk/CHANGELOG.md +++ b/packages/hw-wallet-sdk/CHANGELOG.md @@ -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 diff --git a/packages/hw-wallet-sdk/src/hardware-error-mappings.test.ts b/packages/hw-wallet-sdk/src/hardware-error-mappings.test.ts index cb309531..bed20196 100644 --- a/packages/hw-wallet-sdk/src/hardware-error-mappings.test.ts +++ b/packages/hw-wallet-sdk/src/hardware-error-mappings.test.ts @@ -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'; @@ -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(); diff --git a/packages/hw-wallet-sdk/src/hardware-error-mappings.ts b/packages/hw-wallet-sdk/src/hardware-error-mappings.ts index ca999a4d..a295f237 100644 --- a/packages/hw-wallet-sdk/src/hardware-error-mappings.ts +++ b/packages/hw-wallet-sdk/src/hardware-error-mappings.ts @@ -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 = { + 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. diff --git a/packages/hw-wallet-sdk/src/hardware-errors-enums.ts b/packages/hw-wallet-sdk/src/hardware-errors-enums.ts index 042e9261..38235e9c 100644 --- a/packages/hw-wallet-sdk/src/hardware-errors-enums.ts +++ b/packages/hw-wallet-sdk/src/hardware-errors-enums.ts @@ -58,6 +58,7 @@ export enum ErrorCode { BluetoothConnectionFailed = 7102, MobileNotSupported = 7300, PermissionCameraDenied = 7301, + PermissionCameraPromptDismissed = 7302, // Transaction TxInsufficientFunds = 10000,