Skip to content

Commit b761789

Browse files
authored
feat: add QR hardware wallet error mappings for extension (#490)
This PR adds QR hardware wallet error mappings (see change log and code changes). Fixes: https://consensyssoftware.atlassian.net/browse/MUL-1446 <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Low Risk** > Additive enum/mapping/test updates only; primary risk is downstream consumers needing to handle the new `ErrorCode` value. > > **Overview** > Adds QR hardware wallet–specific error handling by introducing `QR_WALLET_ERROR_MAPPINGS` with camera-permission states for extension QR scanning (prompt dismissed vs. browser-blocked). > > Extends `ErrorCode` with `PermissionCameraPromptDismissed`, adds corresponding unit tests, and documents the addition in the changelog. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit a0902aa. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 63d5928 commit b761789

4 files changed

Lines changed: 69 additions & 0 deletions

File tree

packages/hw-wallet-sdk/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- 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))
13+
1014
## [0.7.0]
1115

1216
### Added

packages/hw-wallet-sdk/src/hardware-error-mappings.test.ts

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
LEDGER_ERROR_MAPPINGS,
33
BLE_ERROR_MAPPINGS,
44
MOBILE_ERROR_MAPPINGS,
5+
QR_WALLET_ERROR_MAPPINGS,
56
TREZOR_ERROR_MAPPINGS,
67
} from './hardware-error-mappings';
78
import type { ErrorMapping } from './hardware-error-mappings';
@@ -254,6 +255,48 @@ describe('HARDWARE_ERROR_MAPPINGS', () => {
254255
});
255256
});
256257

258+
describe('QR wallet mappings', () => {
259+
const errorMappings = QR_WALLET_ERROR_MAPPINGS;
260+
261+
it('has errorMappings object', () => {
262+
expect(errorMappings).toBeDefined();
263+
expect(typeof errorMappings).toBe('object');
264+
});
265+
266+
it('maps CAMERA_PERMISSION_PROMPT_DISMISSED for State 1 (dialog dismissed)', () => {
267+
const mapping = errorMappings.CAMERA_PERMISSION_PROMPT_DISMISSED;
268+
expect(mapping).toBeDefined();
269+
expect(mapping?.code).toBe(ErrorCode.PermissionCameraPromptDismissed);
270+
expect(mapping?.severity).toBe(Severity.Warning);
271+
expect(mapping?.userMessage).toContain('QR code');
272+
});
273+
274+
it('maps CAMERA_PERMISSION_BLOCKED for State 2 (persistent block)', () => {
275+
const mapping = errorMappings.CAMERA_PERMISSION_BLOCKED;
276+
expect(mapping).toBeDefined();
277+
expect(mapping?.code).toBe(ErrorCode.PermissionCameraDenied);
278+
expect(mapping?.severity).toBe(Severity.Err);
279+
expect(mapping?.userMessage).toContain('browser settings');
280+
});
281+
282+
it('has valid structure for all mappings', () => {
283+
Object.values(errorMappings).forEach((mapping) => {
284+
expect(mapping).toHaveProperty('code');
285+
expect(mapping).toHaveProperty('message');
286+
expect(mapping).toHaveProperty('severity');
287+
expect(mapping).toHaveProperty('category');
288+
289+
const numericErrorCodes = Object.values(ErrorCode).filter(
290+
(value): value is number => typeof value === 'number',
291+
);
292+
expect(numericErrorCodes).toContain(mapping.code);
293+
expect(Object.values(Severity)).toContain(mapping.severity);
294+
expect(Object.values(Category)).toContain(mapping.category);
295+
expect(typeof mapping.message).toBe('string');
296+
});
297+
});
298+
});
299+
257300
describe('Trezor mappings', () => {
258301
it('has TREZOR_ERROR_MAPPINGS object', () => {
259302
expect(TREZOR_ERROR_MAPPINGS).toBeDefined();

packages/hw-wallet-sdk/src/hardware-error-mappings.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,27 @@ export const MOBILE_ERROR_MAPPINGS = {
229229
},
230230
};
231231

232+
/**
233+
* QR error mappings - static error data for QR hardware wallets and their related flows.
234+
*/
235+
export const QR_WALLET_ERROR_MAPPINGS: Record<string, ErrorMapping> = {
236+
CAMERA_PERMISSION_PROMPT_DISMISSED: {
237+
code: ErrorCode.PermissionCameraPromptDismissed,
238+
message: 'Camera permission prompt dismissed without granting access',
239+
severity: Severity.Warning,
240+
category: Category.Configuration,
241+
userMessage:
242+
'MetaMask needs camera access to scan the QR code on your device.',
243+
},
244+
CAMERA_PERMISSION_BLOCKED: {
245+
code: ErrorCode.PermissionCameraDenied,
246+
message: 'Camera permission blocked by the browser',
247+
severity: Severity.Err,
248+
category: Category.Configuration,
249+
userMessage: 'To continue, allow camera access in your browser settings.',
250+
},
251+
};
252+
232253
/* eslint-disable @typescript-eslint/naming-convention */
233254
/**
234255
* Trezor error mappings - static error data for Trezor hardware wallets.

packages/hw-wallet-sdk/src/hardware-errors-enums.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ export enum ErrorCode {
5858
BluetoothConnectionFailed = 7102,
5959
MobileNotSupported = 7300,
6060
PermissionCameraDenied = 7301,
61+
PermissionCameraPromptDismissed = 7302,
6162

6263
// Transaction
6364
TxInsufficientFunds = 10000,

0 commit comments

Comments
 (0)