Skip to content

Commit 9e80e46

Browse files
committed
refactor: move mapping type
1 parent 85b4f75 commit 9e80e46

3 files changed

Lines changed: 18 additions & 35 deletions

File tree

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
11
import { ErrorCode, Severity, Category } from './hardware-errors-enums';
22

3-
export const LEDGER_ERROR_MAPPINGS = {
3+
export type ErrorMapping = {
4+
code: ErrorCode;
5+
message: string;
6+
severity: Severity;
7+
category: Category;
8+
userMessage?: string;
9+
};
10+
11+
export const LEDGER_ERROR_MAPPINGS: Record<string, ErrorMapping> = {
412
'0x9000': {
513
code: ErrorCode.Success,
614
message: 'Operation successful',

packages/keyring-eth-ledger-bridge/src/errors.ts

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
11
import {
2-
type ErrorCode,
3-
type Severity,
4-
type Category,
2+
ErrorMapping,
3+
ErrorCode,
4+
Severity,
5+
Category,
56
HardwareWalletError,
67
LEDGER_ERROR_MAPPINGS,
7-
ErrorCode as ErrorCodeEnum,
8-
Severity as SeverityEnum,
9-
Category as CategoryEnum,
108
} from '@metamask/hw-wallet-sdk';
119

12-
type LedgerErrorMapping = {
13-
code: ErrorCode;
14-
message: string;
15-
severity: Severity;
16-
category: Category;
17-
userMessage?: string;
18-
};
19-
2010
/**
2111
* Factory function to create a HardwareWalletError from a Ledger error code.
2212
*
@@ -49,9 +39,9 @@ export function createLedgerError(
4939
: `Unknown Ledger error: ${ledgerErrorCode}`;
5040

5141
return new HardwareWalletError(fallbackMessage, {
52-
code: ErrorCodeEnum.Unknown,
53-
severity: SeverityEnum.Err,
54-
category: CategoryEnum.Unknown,
42+
code: ErrorCode.Unknown,
43+
severity: Severity.Err,
44+
category: Category.Unknown,
5545
userMessage: fallbackMessage,
5646
});
5747
}
@@ -74,9 +64,6 @@ export function isKnownLedgerError(ledgerErrorCode: string): boolean {
7464
*/
7565
export function getLedgerErrorMapping(
7666
ledgerErrorCode: string,
77-
): LedgerErrorMapping | undefined {
78-
const mappings = LEDGER_ERROR_MAPPINGS as {
79-
[key: string]: LedgerErrorMapping;
80-
};
81-
return mappings[ledgerErrorCode];
67+
): ErrorMapping | undefined {
68+
return LEDGER_ERROR_MAPPINGS[ledgerErrorCode];
8269
}

packages/keyring-eth-ledger-bridge/src/index.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,3 @@ export type * from './type';
88
export * from './ledger-hw-app';
99
export * from './errors';
1010
export * from './ledger-error-handler';
11-
12-
// Re-export HardwareWalletError and related types from hw-wallet-sdk for convenience
13-
export {
14-
HardwareWalletError,
15-
ErrorCode,
16-
Severity,
17-
Category,
18-
LEDGER_ERROR_MAPPINGS,
19-
BLE_ERROR_MAPPINGS,
20-
MOBILE_ERROR_MAPPINGS,
21-
} from '@metamask/hw-wallet-sdk';
22-
export type { HardwareWalletErrorOptions } from '@metamask/hw-wallet-sdk';

0 commit comments

Comments
 (0)