@meshconnect/uwc-injected-connector 0.17.0 → 0.17.1
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;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAkBhE;AAED;;;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;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAkBhE;AAED;;;GAGG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,CAyEhD"}
|
|
@@ -33,12 +33,21 @@ export function parseError(error) {
|
|
|
33
33
|
}
|
|
34
34
|
let message;
|
|
35
35
|
let isRejected = false;
|
|
36
|
+
// Preserve the numeric provider code so the classifier can place it (e.g.
|
|
37
|
+
// -32002 "already pending" → provider_error); it is lost at wrap time otherwise.
|
|
38
|
+
let numericCode;
|
|
36
39
|
// Handle different error formats
|
|
37
40
|
if (error && typeof error === 'object') {
|
|
38
41
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
39
42
|
const errorObj = error;
|
|
43
|
+
// Read once — a wallet-controlled getter/proxy could yield inconsistent
|
|
44
|
+
// values or throw on repeated access.
|
|
45
|
+
const code = errorObj.code;
|
|
46
|
+
if (typeof code === 'number' && Number.isInteger(code)) {
|
|
47
|
+
numericCode = code;
|
|
48
|
+
}
|
|
40
49
|
// Check for EIP-1193 error code
|
|
41
|
-
if (
|
|
50
|
+
if (code === 4001 || code === 'ACTION_REJECTED') {
|
|
42
51
|
isRejected = true;
|
|
43
52
|
}
|
|
44
53
|
// Extract message
|
|
@@ -77,7 +86,8 @@ export function parseError(error) {
|
|
|
77
86
|
}
|
|
78
87
|
const walletError = {
|
|
79
88
|
type: isRejected ? 'rejected' : 'unknown',
|
|
80
|
-
message
|
|
89
|
+
message,
|
|
90
|
+
...(numericCode !== undefined ? { code: numericCode } : {})
|
|
81
91
|
};
|
|
82
92
|
throw new WalletConnectorError(walletError);
|
|
83
93
|
}
|
|
@@ -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;;;;GAIG;AACH,MAAM,UAAU,yBAAyB,CAAC,KAAc;IACtD,MAAM,GAAG,GACP,KAAK,YAAY,KAAK;QACpB,CAAC,CAAC,KAAK,CAAC,OAAO;QACf,CAAC,CAAC,KAAK;YACH,OAAO,KAAK,KAAK,QAAQ;YACzB,SAAS,IAAI,KAAK;YAClB,OAAQ,KAA8B,CAAC,OAAO,KAAK,QAAQ;YAC7D,CAAC,CAAE,KAA6B,CAAC,OAAO;YACxC,CAAC,CAAC,EAAE,CAAA;IAEV,IAAI,CAAC,GAAG;QAAE,OAAO,EAAE,CAAA;IAEnB,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,CAAA;IACtC,IAAI,QAAQ,IAAI,QAAQ,KAAK,GAAG,EAAE,CAAC;QACjC,OAAO,QAAQ,CAAC,IAAI,EAAE,CAAA;IACxB,CAAC;IACD,OAAO,GAAG,CAAA;AACZ,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,UAAU,CAAC,KAAc;IACvC,wEAAwE;IACxE,yEAAyE;IACzE,IAAI,KAAK,YAAY,oBAAoB,EAAE,CAAC;QAC1C,MAAM,KAAK,CAAA;IACb,CAAC;IAED,IAAI,OAAe,CAAA;IACnB,IAAI,U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,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-injected-connector",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.1",
|
|
4
4
|
"description": "Injected connector for Universal Wallet Connector",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -28,10 +28,10 @@
|
|
|
28
28
|
"uuid": "^13.0.0",
|
|
29
29
|
"viem": "^2.54.6",
|
|
30
30
|
"@meshconnect/uwc-bridge-child": "0.3.0",
|
|
31
|
-
"@meshconnect/uwc-constants": "0.6.
|
|
32
|
-
"@meshconnect/uwc-ton-connector": "0.7.
|
|
33
|
-
"@meshconnect/uwc-tron-connector": "0.5.
|
|
34
|
-
"@meshconnect/uwc-types": "0.
|
|
31
|
+
"@meshconnect/uwc-constants": "0.6.13",
|
|
32
|
+
"@meshconnect/uwc-ton-connector": "0.7.5",
|
|
33
|
+
"@meshconnect/uwc-tron-connector": "0.5.3",
|
|
34
|
+
"@meshconnect/uwc-types": "0.22.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"typescript": "^5.9.3"
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { describe, it, expect } from 'vitest'
|
|
2
|
+
import { WalletConnectorError } from '@meshconnect/uwc-types'
|
|
3
|
+
import { parseError, extractTonSdkErrorMessage } from './error-utils'
|
|
4
|
+
|
|
5
|
+
// Capture the thrown error explicitly — parseError is `never`, and a bare
|
|
6
|
+
// try/catch would pass vacuously if it ever stopped throwing.
|
|
7
|
+
const thrownBy = (input: unknown): WalletConnectorError => {
|
|
8
|
+
try {
|
|
9
|
+
parseError(input)
|
|
10
|
+
} catch (err) {
|
|
11
|
+
return err as WalletConnectorError
|
|
12
|
+
}
|
|
13
|
+
throw new Error('parseError did not throw')
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
describe('parseError (injected)', () => {
|
|
17
|
+
it('passes an already-typed WalletConnectorError through unchanged', () => {
|
|
18
|
+
const original = new WalletConnectorError({
|
|
19
|
+
type: 'expired',
|
|
20
|
+
message: 'gone',
|
|
21
|
+
code: 4900
|
|
22
|
+
})
|
|
23
|
+
expect(thrownBy(original)).toBe(original)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
it('marks 4001 / ACTION_REJECTED as rejected', () => {
|
|
27
|
+
expect(thrownBy({ code: 4001, message: 'nope' }).type).toBe('rejected')
|
|
28
|
+
expect(thrownBy({ code: 'ACTION_REJECTED', message: 'nope' }).type).toBe(
|
|
29
|
+
'rejected'
|
|
30
|
+
)
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
it('detects a rejection from the message when no code is present', () => {
|
|
34
|
+
expect(thrownBy(new Error('User denied the request')).type).toBe('rejected')
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
it('falls back to unknown for an unrecognized error', () => {
|
|
38
|
+
const err = thrownBy(new Error('Something odd happened'))
|
|
39
|
+
expect(err.type).toBe('unknown')
|
|
40
|
+
expect(err.message).toBe('Something odd happened')
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
it('extracts a nested error.message', () => {
|
|
44
|
+
expect(thrownBy({ error: { message: 'inner boom' } }).message).toBe(
|
|
45
|
+
'inner boom'
|
|
46
|
+
)
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
describe('numeric code preservation (MFS-667)', () => {
|
|
50
|
+
it('preserves the -32002 "already pending" code so the classifier can place it', () => {
|
|
51
|
+
const err = thrownBy({
|
|
52
|
+
code: -32002,
|
|
53
|
+
message: "Request of type 'wallet_requestPermissions' already pending"
|
|
54
|
+
})
|
|
55
|
+
expect(err.code).toBe(-32002)
|
|
56
|
+
expect(err.type).toBe('unknown')
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it('preserves the code alongside a rejection type', () => {
|
|
60
|
+
expect(thrownBy({ code: 4001, message: 'User rejected' }).code).toBe(4001)
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('leaves code undefined for a string code (numeric-only slot)', () => {
|
|
64
|
+
expect(
|
|
65
|
+
thrownBy({ code: 'SERVER_ERROR', message: 'x' }).code
|
|
66
|
+
).toBeUndefined()
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('leaves code undefined when the source error carries no code', () => {
|
|
70
|
+
expect(thrownBy(new Error('No accounts returned')).code).toBeUndefined()
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
it('leaves code undefined for a non-integer numeric code (NaN/Infinity)', () => {
|
|
74
|
+
expect(thrownBy({ code: NaN, message: 'x' }).code).toBeUndefined()
|
|
75
|
+
expect(thrownBy({ code: Infinity, message: 'x' }).code).toBeUndefined()
|
|
76
|
+
})
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
describe('extractTonSdkErrorMessage', () => {
|
|
81
|
+
it('returns the last line of a multiline TON Connect SDK error', () => {
|
|
82
|
+
expect(
|
|
83
|
+
extractTonSdkErrorMessage(
|
|
84
|
+
new Error('[TON_CONNECT_SDK_ERROR] BadRequest\nActual message')
|
|
85
|
+
)
|
|
86
|
+
).toBe('Actual message')
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('returns the message unchanged when single-line', () => {
|
|
90
|
+
expect(extractTonSdkErrorMessage(new Error('plain'))).toBe('plain')
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('returns empty string for a value with no message', () => {
|
|
94
|
+
expect(extractTonSdkErrorMessage(42)).toBe('')
|
|
95
|
+
})
|
|
96
|
+
})
|
package/src/utils/error-utils.ts
CHANGED
|
@@ -39,14 +39,24 @@ export function parseError(error: unknown): never {
|
|
|
39
39
|
|
|
40
40
|
let message: string
|
|
41
41
|
let isRejected = false
|
|
42
|
+
// Preserve the numeric provider code so the classifier can place it (e.g.
|
|
43
|
+
// -32002 "already pending" → provider_error); it is lost at wrap time otherwise.
|
|
44
|
+
let numericCode: number | undefined
|
|
42
45
|
|
|
43
46
|
// Handle different error formats
|
|
44
47
|
if (error && typeof error === 'object') {
|
|
45
48
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
46
49
|
const errorObj = error as any
|
|
47
50
|
|
|
51
|
+
// Read once — a wallet-controlled getter/proxy could yield inconsistent
|
|
52
|
+
// values or throw on repeated access.
|
|
53
|
+
const code = errorObj.code
|
|
54
|
+
if (typeof code === 'number' && Number.isInteger(code)) {
|
|
55
|
+
numericCode = code
|
|
56
|
+
}
|
|
57
|
+
|
|
48
58
|
// Check for EIP-1193 error code
|
|
49
|
-
if (
|
|
59
|
+
if (code === 4001 || code === 'ACTION_REJECTED') {
|
|
50
60
|
isRejected = true
|
|
51
61
|
}
|
|
52
62
|
|
|
@@ -88,7 +98,8 @@ export function parseError(error: unknown): never {
|
|
|
88
98
|
|
|
89
99
|
const walletError: WalletError = {
|
|
90
100
|
type: isRejected ? 'rejected' : 'unknown',
|
|
91
|
-
message
|
|
101
|
+
message,
|
|
102
|
+
...(numericCode !== undefined ? { code: numericCode } : {})
|
|
92
103
|
}
|
|
93
104
|
|
|
94
105
|
throw new WalletConnectorError(walletError)
|