@meshconnect/uwc-wallet-connect-connector 0.11.2 → 0.11.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-utils.d.ts","sourceRoot":"","sources":["../../src/utils/error-utils.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,
|
|
1
|
+
{"version":3,"file":"error-utils.d.ts","sourceRoot":"","sources":["../../src/utils/error-utils.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAwFhD"}
|
|
@@ -4,15 +4,30 @@ import { WalletConnectorError } from '@meshconnect/uwc-types';
|
|
|
4
4
|
* Detects if the error is a user rejection, expired proposal, or unknown error
|
|
5
5
|
*/
|
|
6
6
|
export function parseError(error) {
|
|
7
|
+
// Already-typed connector errors (e.g. the `expired` timeout) must pass through —
|
|
8
|
+
// re-deriving here would double-wrap and downgrade the type/code. Matches the
|
|
9
|
+
// injected and tron parseError guards.
|
|
10
|
+
if (error instanceof WalletConnectorError) {
|
|
11
|
+
throw error;
|
|
12
|
+
}
|
|
7
13
|
let message;
|
|
8
14
|
let isRejected = false;
|
|
9
15
|
let isExpired = false;
|
|
16
|
+
// Preserve the numeric provider code so the classifier can place it (e.g.
|
|
17
|
+
// -32002 "resource unavailable" → provider_error); lost at wrap time otherwise.
|
|
18
|
+
let numericCode;
|
|
10
19
|
// Handle different error formats
|
|
11
20
|
if (error && typeof error === 'object') {
|
|
12
21
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
13
22
|
const errorObj = error;
|
|
23
|
+
// Read once — a wallet-controlled getter/proxy could yield inconsistent
|
|
24
|
+
// values or throw on repeated access.
|
|
25
|
+
const code = errorObj.code;
|
|
26
|
+
if (typeof code === 'number' && Number.isInteger(code)) {
|
|
27
|
+
numericCode = code;
|
|
28
|
+
}
|
|
14
29
|
// Check for EIP-1193 error code
|
|
15
|
-
if (
|
|
30
|
+
if (code === 4001 || code === 'ACTION_REJECTED') {
|
|
16
31
|
isRejected = true;
|
|
17
32
|
}
|
|
18
33
|
// Extract message
|
|
@@ -61,7 +76,8 @@ export function parseError(error) {
|
|
|
61
76
|
}
|
|
62
77
|
const walletError = {
|
|
63
78
|
type: isExpired ? 'expired' : isRejected ? 'rejected' : 'unknown',
|
|
64
|
-
message
|
|
79
|
+
message,
|
|
80
|
+
...(numericCode !== undefined ? { code: numericCode } : {})
|
|
65
81
|
};
|
|
66
82
|
throw new WalletConnectorError(walletError);
|
|
67
83
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-utils.js","sourceRoot":"","sources":["../../src/utils/error-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAE7D;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,IAAI,OAAe,CAAA;IACnB,IAAI,UAAU,GAAG,KAAK,CAAA;IACtB,IAAI,SAAS,GAAG,KAAK,CAAA;
|
|
1
|
+
{"version":3,"file":"error-utils.js","sourceRoot":"","sources":["../../src/utils/error-utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAA;AAE7D;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,kFAAkF;IAClF,8EAA8E;IAC9E,uCAAuC;IACvC,IAAI,KAAK,YAAY,oBAAoB,EAAE,CAAC;QAC1C,MAAM,KAAK,CAAA;IACb,CAAC;IAED,IAAI,OAAe,CAAA;IACnB,IAAI,UAAU,GAAG,KAAK,CAAA;IACtB,IAAI,SAAS,GAAG,KAAK,CAAA;IACrB,0EAA0E;IAC1E,gFAAgF;IAChF,IAAI,WAA+B,CAAA;IAEnC,iCAAiC;IACjC,IAAI,KAAK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AAS,EAAE,CAAC;QAC9B,MAAM,iBAAiB,GAAG;YACxB,eAAe;YACf,aAAa;YACb,gBAAgB;YAChB,eAAe;YACf,kBAAkB;YAClB,gBAAgB;YAChB,mBAAmB;YACnB,kBAAkB;YAClB,kBAAkB;YAClB,eAAe;YACf,iBAAiB;SAClB,CAAA;QAED,UAAU,GAAG,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAC5C,YAAY,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,CAC7C,CAAA;IACH,CAAC;IAED,MAAM,WAAW,GAAgB;QAC/B,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,SAAS;QACjE,OAAO;QACP,GAAG,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC5D,CAAA;IAED,MAAM,IAAI,oBAAoB,CAAC,WAAW,CAAC,CAAA;AAC7C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshconnect/uwc-wallet-connect-connector",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.3",
|
|
4
4
|
"description": "WalletConnect connector for Universal Wallet Connector",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"bs58": "6.0.0",
|
|
26
26
|
"buffer": "^6.0.3",
|
|
27
27
|
"viem": "^2.54.6",
|
|
28
|
-
"@meshconnect/uwc-types": "0.
|
|
28
|
+
"@meshconnect/uwc-types": "0.22.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"typescript": "^5.9.3"
|
|
@@ -543,5 +543,54 @@ describe('error-utils', () => {
|
|
|
543
543
|
expect(() => parseError(error)).toThrow()
|
|
544
544
|
})
|
|
545
545
|
})
|
|
546
|
+
|
|
547
|
+
describe('numeric code preservation (MFS-667)', () => {
|
|
548
|
+
// Capture the thrown error explicitly — a bare try/catch passes vacuously if
|
|
549
|
+
// parseError ever stopped throwing.
|
|
550
|
+
const thrownBy = (input: unknown): WalletConnectorError => {
|
|
551
|
+
try {
|
|
552
|
+
parseError(input)
|
|
553
|
+
} catch (err) {
|
|
554
|
+
return err as WalletConnectorError
|
|
555
|
+
}
|
|
556
|
+
throw new Error('parseError did not throw')
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
it('preserves a numeric provider code so the classifier can place it', () => {
|
|
560
|
+
const err = thrownBy({ code: -32002, message: 'resource unavailable' })
|
|
561
|
+
expect(err.code).toBe(-32002)
|
|
562
|
+
expect(err.type).toBe('unknown')
|
|
563
|
+
})
|
|
564
|
+
|
|
565
|
+
it('preserves the code alongside a rejection type', () => {
|
|
566
|
+
const err = thrownBy({ code: 4001, message: 'User rejected' })
|
|
567
|
+
expect(err.code).toBe(4001)
|
|
568
|
+
expect(err.type).toBe('rejected')
|
|
569
|
+
})
|
|
570
|
+
|
|
571
|
+
it('leaves code undefined for a string code (numeric-only slot)', () => {
|
|
572
|
+
const err = thrownBy({ code: 'ACTION_REJECTED', message: 'x' })
|
|
573
|
+
expect(err.code).toBeUndefined()
|
|
574
|
+
})
|
|
575
|
+
|
|
576
|
+
it('leaves code undefined when the source error has no code', () => {
|
|
577
|
+
const err = thrownBy(new Error('Failed to fetch'))
|
|
578
|
+
expect(err.code).toBeUndefined()
|
|
579
|
+
})
|
|
580
|
+
|
|
581
|
+
it('passes an already-typed WalletConnectorError through unchanged (no double-wrap)', () => {
|
|
582
|
+
// A deeper layer already classified this; re-processing would downgrade
|
|
583
|
+
// type/code. Matches injected/tron behavior.
|
|
584
|
+
const original = new WalletConnectorError({
|
|
585
|
+
type: 'expired',
|
|
586
|
+
message: 'Proposal expired',
|
|
587
|
+
code: 4900
|
|
588
|
+
})
|
|
589
|
+
const thrown = thrownBy(original)
|
|
590
|
+
expect(thrown).toBe(original)
|
|
591
|
+
expect(thrown.type).toBe('expired')
|
|
592
|
+
expect(thrown.code).toBe(4900)
|
|
593
|
+
})
|
|
594
|
+
})
|
|
546
595
|
})
|
|
547
596
|
})
|
package/src/utils/error-utils.ts
CHANGED
|
@@ -6,17 +6,34 @@ import { WalletConnectorError } from '@meshconnect/uwc-types'
|
|
|
6
6
|
* Detects if the error is a user rejection, expired proposal, or unknown error
|
|
7
7
|
*/
|
|
8
8
|
export function parseError(error: unknown): never {
|
|
9
|
+
// Already-typed connector errors (e.g. the `expired` timeout) must pass through —
|
|
10
|
+
// re-deriving here would double-wrap and downgrade the type/code. Matches the
|
|
11
|
+
// injected and tron parseError guards.
|
|
12
|
+
if (error instanceof WalletConnectorError) {
|
|
13
|
+
throw error
|
|
14
|
+
}
|
|
15
|
+
|
|
9
16
|
let message: string
|
|
10
17
|
let isRejected = false
|
|
11
18
|
let isExpired = false
|
|
19
|
+
// Preserve the numeric provider code so the classifier can place it (e.g.
|
|
20
|
+
// -32002 "resource unavailable" → provider_error); lost at wrap time otherwise.
|
|
21
|
+
let numericCode: number | undefined
|
|
12
22
|
|
|
13
23
|
// Handle different error formats
|
|
14
24
|
if (error && typeof error === 'object') {
|
|
15
25
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
26
|
const errorObj = error as any
|
|
17
27
|
|
|
28
|
+
// Read once — a wallet-controlled getter/proxy could yield inconsistent
|
|
29
|
+
// values or throw on repeated access.
|
|
30
|
+
const code = errorObj.code
|
|
31
|
+
if (typeof code === 'number' && Number.isInteger(code)) {
|
|
32
|
+
numericCode = code
|
|
33
|
+
}
|
|
34
|
+
|
|
18
35
|
// Check for EIP-1193 error code
|
|
19
|
-
if (
|
|
36
|
+
if (code === 4001 || code === 'ACTION_REJECTED') {
|
|
20
37
|
isRejected = true
|
|
21
38
|
}
|
|
22
39
|
|
|
@@ -71,7 +88,8 @@ export function parseError(error: unknown): never {
|
|
|
71
88
|
|
|
72
89
|
const walletError: WalletError = {
|
|
73
90
|
type: isExpired ? 'expired' : isRejected ? 'rejected' : 'unknown',
|
|
74
|
-
message
|
|
91
|
+
message,
|
|
92
|
+
...(numericCode !== undefined ? { code: numericCode } : {})
|
|
75
93
|
}
|
|
76
94
|
|
|
77
95
|
throw new WalletConnectorError(walletError)
|