@meshconnect/uwc-injected-connector 0.28.3 → 0.29.0
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.
- package/dist/injected-connector.d.ts.map +1 -1
- package/dist/injected-connector.js +27 -2
- package/dist/injected-connector.js.map +1 -1
- package/dist/services/connection-manager.d.ts +16 -1
- package/dist/services/connection-manager.d.ts.map +1 -1
- package/dist/services/connection-manager.js +49 -5
- package/dist/services/connection-manager.js.map +1 -1
- package/dist/utils/error-utils.d.ts +19 -0
- package/dist/utils/error-utils.d.ts.map +1 -1
- package/dist/utils/error-utils.js +34 -0
- package/dist/utils/error-utils.js.map +1 -1
- package/package.json +6 -6
- package/src/injected-connector.test.ts +293 -1
- package/src/injected-connector.ts +40 -9
- package/src/services/connection-manager.test.ts +146 -0
- package/src/services/connection-manager.ts +56 -6
- package/src/utils/error-utils.test.ts +96 -1
- package/src/utils/error-utils.ts +34 -0
|
@@ -9,7 +9,8 @@ import {
|
|
|
9
9
|
parseError,
|
|
10
10
|
extractTonSdkErrorMessage,
|
|
11
11
|
classifyWalletError,
|
|
12
|
-
isRequestAlreadyPending
|
|
12
|
+
isRequestAlreadyPending,
|
|
13
|
+
isUnsupportedAccountError
|
|
13
14
|
} from './error-utils'
|
|
14
15
|
|
|
15
16
|
// Capture the thrown error explicitly — parseError is `never`, and a bare
|
|
@@ -615,3 +616,97 @@ describe('the wallet code below the top', () => {
|
|
|
615
616
|
})
|
|
616
617
|
})
|
|
617
618
|
})
|
|
619
|
+
|
|
620
|
+
describe('isUnsupportedAccountError', () => {
|
|
621
|
+
const err = (code: unknown, message: string, extra: object = {}) =>
|
|
622
|
+
Object.assign(new Error(message), { code }, extra)
|
|
623
|
+
const PHANTOM = 'Requested resource not available.'
|
|
624
|
+
|
|
625
|
+
// Every -32002 message production recorded (CUS-173), plus the shapes the
|
|
626
|
+
// bridge and viem give them.
|
|
627
|
+
it.each([
|
|
628
|
+
['Phantom, as an Error', err(-32002, PHANTOM), true],
|
|
629
|
+
['Phantom, as a plain object', { code: -32002, message: PHANTOM }, true],
|
|
630
|
+
[
|
|
631
|
+
'Phantom, without the trailing dot',
|
|
632
|
+
err(-32002, PHANTOM.slice(0, -1)),
|
|
633
|
+
true
|
|
634
|
+
],
|
|
635
|
+
[
|
|
636
|
+
'Phantom, code only in cause',
|
|
637
|
+
Object.assign(new Error(PHANTOM), { cause: { code: -32002 } }),
|
|
638
|
+
true
|
|
639
|
+
],
|
|
640
|
+
// BridgeParent < 1.7.4 drops an Error rejection's code: only the message survives.
|
|
641
|
+
['Phantom, no code (old bridge), as an Error', new Error(PHANTOM), true],
|
|
642
|
+
[
|
|
643
|
+
'Phantom, no code (old bridge), as a plain object',
|
|
644
|
+
{ message: PHANTOM },
|
|
645
|
+
true
|
|
646
|
+
],
|
|
647
|
+
[
|
|
648
|
+
'MetaMask "already pending"',
|
|
649
|
+
err(
|
|
650
|
+
-32002,
|
|
651
|
+
"Request of type 'wallet_requestPermissions' already pending for origin https://example.com. Please wait."
|
|
652
|
+
),
|
|
653
|
+
false
|
|
654
|
+
],
|
|
655
|
+
[
|
|
656
|
+
'Trust "already pending"',
|
|
657
|
+
err(
|
|
658
|
+
-32002,
|
|
659
|
+
"Request of type 'PUBLIC_requestAccounts' already pending for origin https://example.com. Please wait."
|
|
660
|
+
),
|
|
661
|
+
false
|
|
662
|
+
],
|
|
663
|
+
[
|
|
664
|
+
'Bitget "already pending"',
|
|
665
|
+
err(
|
|
666
|
+
-32002,
|
|
667
|
+
"Request of type 'eth_requestAccounts' already pending for origin https://example.com. Please wait. "
|
|
668
|
+
),
|
|
669
|
+
false
|
|
670
|
+
],
|
|
671
|
+
[
|
|
672
|
+
'MetaMask "already pending", no code',
|
|
673
|
+
new Error(
|
|
674
|
+
"Request of type 'wallet_requestPermissions' already pending for origin https://example.com. Please wait."
|
|
675
|
+
),
|
|
676
|
+
false
|
|
677
|
+
],
|
|
678
|
+
[
|
|
679
|
+
'viem-wrapped transaction carrying "already pending"',
|
|
680
|
+
err(
|
|
681
|
+
-32002,
|
|
682
|
+
`${PHANTOM}\n\nRequest Arguments:\n from: 0x1\n\nDetails: Request of type 'PUBLIC_requestAccounts' already pending`
|
|
683
|
+
),
|
|
684
|
+
false
|
|
685
|
+
],
|
|
686
|
+
['the message with another code', err(-32603, PHANTOM), false],
|
|
687
|
+
[
|
|
688
|
+
"the message with viem's -1 placeholder",
|
|
689
|
+
Object.assign(new Error(PHANTOM), { code: -1, name: 'UnknownRpcError' }),
|
|
690
|
+
false
|
|
691
|
+
],
|
|
692
|
+
['-32002 with another message', err(-32002, 'Resource unavailable'), false],
|
|
693
|
+
['another message, no code', new Error('Resource unavailable'), false],
|
|
694
|
+
['a user rejection', err(4001, 'User rejected the request.'), false],
|
|
695
|
+
['null', null, false],
|
|
696
|
+
['a bare string', PHANTOM, false]
|
|
697
|
+
])('%s', (_, error, expected) => {
|
|
698
|
+
expect(isUnsupportedAccountError(error)).toBe(expected)
|
|
699
|
+
})
|
|
700
|
+
|
|
701
|
+
it('never throws on a hostile error', () => {
|
|
702
|
+
const hostile = new Proxy(
|
|
703
|
+
{},
|
|
704
|
+
{
|
|
705
|
+
get() {
|
|
706
|
+
throw new Error('boom')
|
|
707
|
+
}
|
|
708
|
+
}
|
|
709
|
+
)
|
|
710
|
+
expect(isUnsupportedAccountError(hostile)).toBe(false)
|
|
711
|
+
})
|
|
712
|
+
})
|
package/src/utils/error-utils.ts
CHANGED
|
@@ -257,3 +257,37 @@ export function isRequestAlreadyPending(error: unknown): boolean {
|
|
|
257
257
|
return false
|
|
258
258
|
}
|
|
259
259
|
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* True when a wallet refused an EVM connect because its ACTIVE account cannot
|
|
263
|
+
* hold an EVM address: Phantom with a Solana-only account (an imported Solana
|
|
264
|
+
* private key, a Solana-only Ledger) shows "Unsupported account" and answers
|
|
265
|
+
* `eth_requestAccounts` with -32002 and EIP-1474's default message, whatever
|
|
266
|
+
* the user clicks. Matched on the exact default message, with code -32002 or
|
|
267
|
+
* no code at all: a host page's BridgeParent older than 1.7.4 (every client
|
|
268
|
+
* Web SDK before it) drops the code of an Error rejection and keeps only the
|
|
269
|
+
* message. Every other wallet's -32002 seen in production says "already
|
|
270
|
+
* pending" (see {@link isRequestAlreadyPending}), which this never matches.
|
|
271
|
+
*
|
|
272
|
+
* Not tied to Phantom by design: any wallet whose active account cannot hold
|
|
273
|
+
* EVM may answer this way, and the fallback is the right outcome for it too.
|
|
274
|
+
* The fallback ASSUMES no wallet answers a request that is really still pending
|
|
275
|
+
* with this bare default message: one that did, and also exposes Solana, would
|
|
276
|
+
* get a Solana prompt on top of its open EVM one. Production data (the
|
|
277
|
+
* `namespaceFallback` step, `fallbackFrom`) is what shows that still holds.
|
|
278
|
+
*/
|
|
279
|
+
export function isUnsupportedAccountError(error: unknown): boolean {
|
|
280
|
+
try {
|
|
281
|
+
const { code } = (error ?? {}) as { code?: unknown }
|
|
282
|
+
const walletCode = extractWalletErrorCode(error, code)
|
|
283
|
+
if (walletCode !== undefined && walletCode !== -32002) return false
|
|
284
|
+
if (isRequestAlreadyPending(error)) return false
|
|
285
|
+
const { message } = (error ?? {}) as { message?: unknown }
|
|
286
|
+
return (
|
|
287
|
+
typeof message === 'string' &&
|
|
288
|
+
/^requested resource not available\.?$/i.test(message.trim())
|
|
289
|
+
)
|
|
290
|
+
} catch {
|
|
291
|
+
return false
|
|
292
|
+
}
|
|
293
|
+
}
|