@rango-dev/wallets-react 0.0.0-experimental-c6bea4d8-20260930 → 0.0.0-experimental-767249ce-20261007

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,70 +0,0 @@
1
- import {
2
- CONNECTION_ERROR_MESSAGES,
3
- ConnectionErrorType,
4
- WalletConnectionError,
5
- } from '@hub3js/std/utils';
6
- import { error as logError } from '@rango-dev/logging-core';
7
- import { beforeEach, describe, expect, it, vi } from 'vitest';
8
-
9
- import { reportConnectionFailure } from './errors.js';
10
-
11
- vi.mock('@rango-dev/logging-core', () => ({
12
- error: vi.fn(),
13
- }));
14
-
15
- describe('reportConnectionFailure', () => {
16
- const options = {
17
- walletType: 'metamask',
18
- namespace: 'EVM',
19
- origin: 'manual',
20
- } as const;
21
-
22
- beforeEach(() => {
23
- vi.mocked(logError).mockClear();
24
- });
25
-
26
- it.each([ConnectionErrorType.Rejected, ConnectionErrorType.Locked])(
27
- 'drop a %s connection error',
28
- (type) => {
29
- reportConnectionFailure(
30
- new WalletConnectionError(CONNECTION_ERROR_MESSAGES[type], { type }),
31
- options
32
- );
33
-
34
- expect(logError).not.toHaveBeenCalled();
35
- }
36
- );
37
-
38
- it('log an unknown connection error tagged only with its name, type, wallet, namespace and origin', () => {
39
- const error = new WalletConnectionError('Something went wrong', {
40
- type: ConnectionErrorType.Unknown,
41
- cause: new Error('Something went wrong'),
42
- });
43
-
44
- reportConnectionFailure(error, options);
45
-
46
- expect(logError).toHaveBeenCalledOnce();
47
- expect(logError).toHaveBeenCalledWith(error, {
48
- tags: {
49
- name: 'WalletConnectionError',
50
- type: ConnectionErrorType.Unknown,
51
- walletType: 'metamask',
52
- namespace: 'EVM',
53
- origin: 'manual',
54
- },
55
- });
56
- });
57
-
58
- it('drop a plain error', () => {
59
- reportConnectionFailure(new Error('Something went wrong'), options);
60
-
61
- expect(logError).not.toHaveBeenCalled();
62
- });
63
-
64
- it('drop a thrown value that is not an error', () => {
65
- reportConnectionFailure({ code: 4001, message: 'rejected' }, options);
66
- reportConnectionFailure('Something went wrong', options);
67
-
68
- expect(logError).not.toHaveBeenCalled();
69
- });
70
- });
package/src/hub/errors.ts DELETED
@@ -1,39 +0,0 @@
1
- import type { WalletType } from '@hub3js/core';
2
- import type { Namespace } from '@hub3js/namespaces';
3
-
4
- import { ConnectionErrorType, WalletConnectionError } from '@hub3js/std/utils';
5
- import { error as logError } from '@rango-dev/logging-core';
6
-
7
- type ConnectionOrigin = 'manual' | 'auto';
8
-
9
- // The user caused these failures. It's a drop list, so a type added later is reported.
10
- const UNREPORTED_CONNECTION_ERROR_TYPES: ConnectionErrorType[] = [
11
- ConnectionErrorType.Rejected,
12
- ConnectionErrorType.Locked,
13
- ];
14
-
15
- export function reportConnectionFailure(
16
- error: unknown,
17
- options: {
18
- walletType: WalletType;
19
- namespace: Namespace;
20
- origin: ConnectionOrigin;
21
- }
22
- ): void {
23
- if (
24
- !(error instanceof WalletConnectionError) ||
25
- UNREPORTED_CONNECTION_ERROR_TYPES.includes(error.type)
26
- ) {
27
- return;
28
- }
29
-
30
- logError(error, {
31
- tags: {
32
- name: error.name,
33
- type: error.type,
34
- walletType: options.walletType,
35
- namespace: options.namespace,
36
- origin: options.origin,
37
- },
38
- });
39
- }
@@ -1,86 +0,0 @@
1
- import {
2
- CONNECTION_ERROR_MESSAGES,
3
- ConnectionErrorType,
4
- WalletConnectionError,
5
- } from '@hub3js/std/utils';
6
- import { describe, expect, it, vi } from 'vitest';
7
-
8
- import { createQueue, removeQueuedNamespacesOnRejection } from './helpers.js';
9
-
10
- const WALLET = 'wallet';
11
-
12
- function queueNamespaces(firstError: unknown) {
13
- const queueTask = createQueue({
14
- onError: removeQueuedNamespacesOnRejection,
15
- });
16
- const second = vi.fn(async () => 'second');
17
- const third = vi.fn(async () => 'third');
18
-
19
- const results = Promise.all([
20
- queueTask(async () => Promise.reject(firstError), WALLET),
21
- queueTask(second, WALLET),
22
- queueTask(third, WALLET),
23
- ]);
24
-
25
- return { results, second, third };
26
- }
27
-
28
- describe('connect queue', () => {
29
- it('abandon the queued namespaces after a rejected connection error', async () => {
30
- const error = new WalletConnectionError('User rejected the request.', {
31
- type: ConnectionErrorType.Rejected,
32
- cause: { code: 4001, message: 'User rejected the request.' },
33
- });
34
-
35
- const { results, second, third } = queueNamespaces(error);
36
- const [first, ...rest] = await results;
37
-
38
- expect(first.err && first.val).toBe(error);
39
- expect(rest.every((result) => result.err && result.val === error)).toBe(
40
- true
41
- );
42
- expect(second).not.toHaveBeenCalled();
43
- expect(third).not.toHaveBeenCalled();
44
- });
45
-
46
- it('abandon the queued namespaces after a rejection whose cause has no code', async () => {
47
- const error = new WalletConnectionError(
48
- CONNECTION_ERROR_MESSAGES[ConnectionErrorType.Rejected],
49
- {
50
- type: ConnectionErrorType.Rejected,
51
- cause: 'User Rejected Request: The user rejected the request.',
52
- }
53
- );
54
-
55
- const { results, second, third } = queueNamespaces(error);
56
- await results;
57
-
58
- expect(second).not.toHaveBeenCalled();
59
- expect(third).not.toHaveBeenCalled();
60
- });
61
-
62
- it('keep the queued namespaces after an unknown connection error', async () => {
63
- const error = new WalletConnectionError('Something went wrong', {
64
- type: ConnectionErrorType.Unknown,
65
- cause: new Error('Something went wrong'),
66
- });
67
-
68
- const { results, second, third } = queueNamespaces(error);
69
- const [, secondResult, thirdResult] = await results;
70
-
71
- expect(second).toHaveBeenCalledOnce();
72
- expect(third).toHaveBeenCalledOnce();
73
- expect(secondResult.ok && secondResult.val).toBe('second');
74
- expect(thirdResult.ok && thirdResult.val).toBe('third');
75
- });
76
-
77
- it('keep the queued namespaces after a raw 4001 error', async () => {
78
- const { results, second } = queueNamespaces({
79
- code: 4001,
80
- message: 'User rejected the request.',
81
- });
82
- await results;
83
-
84
- expect(second).toHaveBeenCalledOnce();
85
- });
86
- });