@rango-dev/wallets-react 0.0.0-experimental-99f1781b-20260920 → 0.0.0-experimental-a84f27a7-20260921

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/errors.d.ts DELETED
@@ -1,60 +0,0 @@
1
- import type { NamespaceInputForConnect } from './legacy/types.js';
2
- import type { Option, Result } from 'ts-results';
3
- import { WalletConnectionError } from '@hub3js/std/utils';
4
- export type WalletConnectionAttemptErrorOptions = {
5
- errors: unknown[];
6
- requestedNamespaces: NamespaceInputForConnect[];
7
- message?: string;
8
- };
9
- /**
10
- * A connection attempt that failed.
11
- *
12
- * - `errors` holds every failed namespace's `WalletConnectionError`, in request order,
13
- * followed by any other value thrown during the attempt.
14
- * - `requestedNamespaces` lists every namespace the attempt requested, in request
15
- * order, cancelled ones included, with the network and derivation path passed for it.
16
- * - `message` is the `message` passed in, or else the first entry's.
17
- *
18
- * It has no `code` and no `cause`: read them from each entry.
19
- */
20
- export declare class WalletConnectionAttemptError extends AggregateError {
21
- name: string;
22
- errors: unknown[];
23
- readonly requestedNamespaces: NamespaceInputForConnect[];
24
- constructor(options: WalletConnectionAttemptErrorOptions);
25
- }
26
- /**
27
- * An auto-connect attempt that failed. Auto-connect sends it with
28
- * `Events.AUTO_CONNECT_FAILED`.
29
- */
30
- export declare class AutoConnectionAttemptError extends WalletConnectionAttemptError {
31
- name: string;
32
- }
33
- export type NamespaceConnectAttempt<T = unknown> = {
34
- input: NamespaceInputForConnect;
35
- result: Result<T, unknown>;
36
- cancelled?: boolean;
37
- };
38
- /**
39
- * Lists each failed namespace's `WalletConnectionError` in request order, leaving
40
- * cancelled namespaces out. A failure that isn't one yet (e.g. from an integrator's
41
- * provider, or a before-hook) is wrapped in one for its namespace.
42
- */
43
- export declare function collectConnectionFailures(attempts: NamespaceConnectAttempt[]): WalletConnectionError[];
44
- /**
45
- * Builds the error `connect` throws, or returns `undefined` when every namespace
46
- * connected and nothing else was thrown. `nonNamespaceError` holds the value thrown
47
- * outside any namespace, if any, such as a config error; it's added after the
48
- * namespace failures, unchanged.
49
- */
50
- export declare function buildConnectionAttemptError(params: {
51
- requestedNamespaces: NamespaceInputForConnect[];
52
- attempts: NamespaceConnectAttempt[];
53
- nonNamespaceError: Option<unknown>;
54
- }): WalletConnectionAttemptError | undefined;
55
- /**
56
- * Builds the value of `Events.AUTO_CONNECT_FAILED` from the namespaces auto-connect
57
- * tried to connect for a wallet. Returns `undefined` when none of them failed.
58
- */
59
- export declare function buildAutoConnectionAttemptError(attempts: NamespaceConnectAttempt[]): AutoConnectionAttemptError | undefined;
60
- //# sourceMappingURL=errors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,mBAAmB,CAAC;AAClE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,MAAM,MAAM,mCAAmC,GAAG;IAChD,MAAM,EAAE,OAAO,EAAE,CAAC;IAClB,mBAAmB,EAAE,wBAAwB,EAAE,CAAC;IAChD,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAcF;;;;;;;;;;GAUG;AACH,qBAAa,4BAA6B,SAAQ,cAAc;IAC9D,IAAI,SAAkC;IAC9B,MAAM,EAAE,OAAO,EAAE,CAAC;IAC1B,QAAQ,CAAC,mBAAmB,EAAE,wBAAwB,EAAE,CAAC;gBAE7C,OAAO,EAAE,mCAAmC;CAKzD;AAED;;;GAGG;AACH,qBAAa,0BAA2B,SAAQ,4BAA4B;IAC1E,IAAI,SAAgC;CACrC;AAED,MAAM,MAAM,uBAAuB,CAAC,CAAC,GAAG,OAAO,IAAI;IACjD,KAAK,EAAE,wBAAwB,CAAC;IAChC,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC;IAE3B,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,uBAAuB,EAAE,GAClC,qBAAqB,EAAE,CAczB;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE;IAClD,mBAAmB,EAAE,wBAAwB,EAAE,CAAC;IAChD,QAAQ,EAAE,uBAAuB,EAAE,CAAC;IACpC,iBAAiB,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC;CACpC,GAAG,4BAA4B,GAAG,SAAS,CAW3C;AAED;;;GAGG;AACH,wBAAgB,+BAA+B,CAC7C,QAAQ,EAAE,uBAAuB,EAAE,GAClC,0BAA0B,GAAG,SAAS,CAUxC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=errors.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"errors.test.d.ts","sourceRoot":"","sources":["../src/errors.test.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=autoConnect.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"autoConnect.test.d.ts","sourceRoot":"","sources":["../../src/hub/autoConnect.test.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=helpers.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.test.d.ts","sourceRoot":"","sources":["../../src/hub/helpers.test.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=useHubAdapter.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useHubAdapter.test.d.ts","sourceRoot":"","sources":["../../src/hub/useHubAdapter.test.ts"],"names":[],"mappings":""}
@@ -1,349 +0,0 @@
1
- import type { NamespaceInputForConnect } from './legacy/types.js';
2
-
3
- import {
4
- USER_REJECTION_ERROR_CODE,
5
- WalletConnectionError,
6
- } from '@hub3js/std/utils';
7
- import { Err, None, Ok, Some } from 'ts-results';
8
- import { describe, expect, it } from 'vitest';
9
-
10
- import {
11
- AutoConnectionAttemptError,
12
- buildAutoConnectionAttemptError,
13
- buildConnectionAttemptError,
14
- WalletConnectionAttemptError,
15
- } from './errors.js';
16
-
17
- const connected = new Ok({ accounts: [], network: null });
18
-
19
- const SOLANA_DERIVATION_PATH = "m/44'/501'/0'/0'";
20
- const evm: NamespaceInputForConnect = { namespace: 'EVM', network: 'ETH' };
21
- const solana: NamespaceInputForConnect = {
22
- namespace: 'Solana',
23
- network: undefined,
24
- derivationPath: SOLANA_DERIVATION_PATH,
25
- };
26
- const sui: NamespaceInputForConnect = { namespace: 'Sui', network: undefined };
27
- const requestedNamespaces = [evm, solana, sui];
28
-
29
- function rejection() {
30
- return Object.assign(new Error('User rejected the request.'), {
31
- code: USER_REJECTION_ERROR_CODE,
32
- });
33
- }
34
-
35
- describe('WalletConnectionAttemptError', () => {
36
- it('keep its entries and requested namespaces', () => {
37
- const entry = new Error('EVM failed');
38
-
39
- const error = new WalletConnectionAttemptError({
40
- errors: [entry],
41
- requestedNamespaces,
42
- });
43
-
44
- expect(error).toBeInstanceOf(AggregateError);
45
- expect(error.errors).toEqual([entry]);
46
- expect(error.errors[0]).toBe(entry);
47
- expect(error.requestedNamespaces).toEqual(requestedNamespaces);
48
- });
49
-
50
- it('take its message from the first entry', () => {
51
- const error = new WalletConnectionAttemptError({
52
- errors: [new Error('first'), new Error('second')],
53
- requestedNamespaces: [],
54
- });
55
-
56
- expect(error.message).toBe('first');
57
- });
58
-
59
- it('use the string form of a first entry without a string message', () => {
60
- expect(
61
- new WalletConnectionAttemptError({
62
- errors: ['thrown string'],
63
- requestedNamespaces: [],
64
- }).message
65
- ).toBe('thrown string');
66
- expect(
67
- new WalletConnectionAttemptError({
68
- errors: [{ message: 123 }],
69
- requestedNamespaces: [],
70
- }).message
71
- ).toBe('[object Object]');
72
- expect(
73
- new WalletConnectionAttemptError({
74
- errors: [undefined],
75
- requestedNamespaces: [],
76
- }).message
77
- ).toBe('undefined');
78
- });
79
-
80
- it('prefer a message passed in over the first entry', () => {
81
- const error = new WalletConnectionAttemptError({
82
- errors: [new Error('first')],
83
- requestedNamespaces: [],
84
- message: 'Wallet connection still pending after 3 minutes',
85
- });
86
-
87
- expect(error.message).toBe(
88
- 'Wallet connection still pending after 3 minutes'
89
- );
90
- });
91
-
92
- it('have an empty message with no entries and no message passed in', () => {
93
- const error = new WalletConnectionAttemptError({
94
- errors: [],
95
- requestedNamespaces: [],
96
- });
97
-
98
- expect(error.message).toBe('');
99
- });
100
-
101
- it('have its own name instead of the aggregate error name', () => {
102
- const error = new WalletConnectionAttemptError({
103
- errors: [rejection()],
104
- requestedNamespaces: [],
105
- });
106
-
107
- expect(error.name).toBe('WalletConnectionAttemptError');
108
- });
109
-
110
- it('have no code even when an entry has one', () => {
111
- const error = new WalletConnectionAttemptError({
112
- errors: [rejection()],
113
- requestedNamespaces: [],
114
- });
115
-
116
- expect(error).not.toHaveProperty('code');
117
- });
118
-
119
- it('have no cause even when it has an entry', () => {
120
- const error = new WalletConnectionAttemptError({
121
- errors: [rejection()],
122
- requestedNamespaces: [],
123
- });
124
-
125
- expect(error).not.toHaveProperty('cause');
126
- });
127
- });
128
-
129
- describe('AutoConnectionAttemptError', () => {
130
- it('extend the wallet connection attempt error with its own name', () => {
131
- const entry = new Error('EVM failed');
132
-
133
- const error = new AutoConnectionAttemptError({
134
- errors: [entry],
135
- requestedNamespaces: [{ namespace: 'EVM', network: 'ETH' }],
136
- });
137
-
138
- expect(error).toBeInstanceOf(WalletConnectionAttemptError);
139
- expect(error.name).toBe('AutoConnectionAttemptError');
140
- expect(error.message).toBe('EVM failed');
141
- expect(error.errors).toEqual([entry]);
142
- expect(error.requestedNamespaces).toEqual([
143
- { namespace: 'EVM', network: 'ETH' },
144
- ]);
145
- });
146
- });
147
-
148
- describe('buildConnectionAttemptError', () => {
149
- it('list every failed namespace in request order', () => {
150
- const evmError = new WalletConnectionError({
151
- namespace: 'EVM',
152
- cause: new Error('EVM failed'),
153
- });
154
- const suiError = new WalletConnectionError({
155
- namespace: 'Sui',
156
- cause: new Error('Sui failed'),
157
- });
158
-
159
- const error = buildConnectionAttemptError({
160
- requestedNamespaces,
161
- attempts: [
162
- { input: evm, result: new Err(evmError) },
163
- { input: solana, result: connected },
164
- { input: sui, result: new Err(suiError) },
165
- ],
166
- nonNamespaceError: None,
167
- });
168
-
169
- expect(error).toBeInstanceOf(WalletConnectionAttemptError);
170
- expect(error?.errors).toEqual([evmError, suiError]);
171
- expect(error?.errors[0]).toBe(evmError);
172
- expect(error?.errors[1]).toBe(suiError);
173
- expect(error?.message).toBe('EVM failed');
174
- });
175
-
176
- it('leave namespaces marked as cancelled out of errors', () => {
177
- const rejectionError = rejection();
178
-
179
- const error = buildConnectionAttemptError({
180
- requestedNamespaces,
181
- attempts: [
182
- { input: evm, result: new Err(rejectionError) },
183
- { input: solana, result: new Err(rejectionError), cancelled: true },
184
- { input: sui, result: new Err(rejectionError), cancelled: true },
185
- ],
186
- nonNamespaceError: None,
187
- });
188
-
189
- expect(error?.errors).toHaveLength(1);
190
- expect(error?.errors[0]).toMatchObject({ namespace: 'EVM' });
191
- });
192
-
193
- it('keep a failure that shares its error object with an earlier one when it is not cancelled', () => {
194
- const sharedError = new Error('Wallet is not available');
195
-
196
- const error = buildConnectionAttemptError({
197
- requestedNamespaces,
198
- attempts: [
199
- { input: evm, result: new Err(sharedError) },
200
- { input: solana, result: new Err(sharedError) },
201
- ],
202
- nonNamespaceError: None,
203
- });
204
-
205
- expect(error?.errors).toHaveLength(2);
206
- expect(error?.errors[0]).toMatchObject({ namespace: 'EVM' });
207
- expect(error?.errors[1]).toMatchObject({ namespace: 'Solana' });
208
- });
209
-
210
- it('wrap a failure that is not a wallet connection error in one for its namespace', () => {
211
- const error = buildConnectionAttemptError({
212
- requestedNamespaces,
213
- attempts: [{ input: solana, result: new Err(rejection()) }],
214
- nonNamespaceError: None,
215
- });
216
-
217
- const [entry] = error?.errors ?? [];
218
- expect(entry).toBeInstanceOf(WalletConnectionError);
219
- expect(entry).toMatchObject({
220
- name: 'WalletConnectionError',
221
- namespace: 'Solana',
222
- message: 'User rejected the request.',
223
- });
224
- });
225
-
226
- it('keep the raw failure as the cause of its wrapper and copy its code', () => {
227
- const rawError = rejection();
228
-
229
- const error = buildConnectionAttemptError({
230
- requestedNamespaces,
231
- attempts: [{ input: solana, result: new Err(rawError) }],
232
- nonNamespaceError: None,
233
- });
234
-
235
- const [entry] = error?.errors ?? [];
236
- expect((entry as WalletConnectionError).cause).toBe(rawError);
237
- expect(entry).toMatchObject({ code: USER_REJECTION_ERROR_CODE });
238
- });
239
-
240
- it('wrap a thrown value that is not an error object for its namespace', () => {
241
- const error = buildConnectionAttemptError({
242
- requestedNamespaces,
243
- attempts: [{ input: evm, result: new Err('User closed the popup') }],
244
- nonNamespaceError: None,
245
- });
246
-
247
- const [entry] = error?.errors ?? [];
248
- expect(entry).toBeInstanceOf(WalletConnectionError);
249
- expect(entry).toMatchObject({
250
- namespace: 'EVM',
251
- message: 'User closed the popup',
252
- });
253
- expect((entry as WalletConnectionError).cause).toBe(
254
- 'User closed the popup'
255
- );
256
- });
257
-
258
- it('add a value thrown outside any namespace after the namespace failures unchanged', () => {
259
- const storageError = new Error('QuotaExceededError');
260
-
261
- const error = buildConnectionAttemptError({
262
- requestedNamespaces,
263
- attempts: [
264
- { input: evm, result: new Err(new Error('EVM failed')) },
265
- { input: solana, result: connected },
266
- ],
267
- nonNamespaceError: new Some(storageError),
268
- });
269
-
270
- expect(error?.errors).toHaveLength(2);
271
- expect(error?.errors[0]).toMatchObject({ namespace: 'EVM' });
272
- expect(error?.errors[1]).toBe(storageError);
273
- });
274
-
275
- it('add a thrown undefined as an entry', () => {
276
- const error = buildConnectionAttemptError({
277
- requestedNamespaces,
278
- attempts: [],
279
- nonNamespaceError: new Some(undefined),
280
- });
281
-
282
- expect(error).toBeInstanceOf(WalletConnectionAttemptError);
283
- expect(error?.errors).toEqual([undefined]);
284
- });
285
-
286
- it('return nothing when every namespace connected', () => {
287
- expect(
288
- buildConnectionAttemptError({
289
- requestedNamespaces,
290
- attempts: [
291
- { input: evm, result: connected },
292
- { input: solana, result: connected },
293
- ],
294
- nonNamespaceError: None,
295
- })
296
- ).toBeUndefined();
297
- });
298
-
299
- it('return an error with no entries when every namespace that did not connect was cancelled', () => {
300
- const error = buildConnectionAttemptError({
301
- requestedNamespaces,
302
- attempts: [{ input: evm, result: new Err(rejection()), cancelled: true }],
303
- nonNamespaceError: None,
304
- });
305
-
306
- expect(error).toBeInstanceOf(WalletConnectionAttemptError);
307
- expect(error?.errors).toEqual([]);
308
- });
309
- });
310
-
311
- describe('buildAutoConnectionAttemptError', () => {
312
- it('return nothing when every attempted namespace connected', () => {
313
- expect(
314
- buildAutoConnectionAttemptError([
315
- { input: evm, result: connected },
316
- { input: sui, result: connected },
317
- ])
318
- ).toBeUndefined();
319
- });
320
-
321
- it('list the attempted namespaces with their networks', () => {
322
- const error = buildAutoConnectionAttemptError([
323
- { input: evm, result: connected },
324
- { input: sui, result: new Err(new Error('Sui failed')) },
325
- ]);
326
-
327
- expect(error).toBeInstanceOf(AutoConnectionAttemptError);
328
- expect(error?.requestedNamespaces).toEqual([
329
- { namespace: 'EVM', network: 'ETH' },
330
- { namespace: 'Sui', network: undefined },
331
- ]);
332
- });
333
-
334
- it('wrap each failure in a wallet connection error for its namespace', () => {
335
- const rawError = new Error('Sui failed');
336
-
337
- const error = buildAutoConnectionAttemptError([
338
- { input: evm, result: connected },
339
- { input: sui, result: new Err(rawError) },
340
- ]);
341
-
342
- expect(error?.errors).toHaveLength(1);
343
- expect(error?.errors[0]).toBeInstanceOf(WalletConnectionError);
344
- expect(error?.errors[0]).toMatchObject({
345
- namespace: 'Sui',
346
- cause: rawError,
347
- });
348
- });
349
- });
package/src/errors.ts DELETED
@@ -1,124 +0,0 @@
1
- import type { NamespaceInputForConnect } from './legacy/types.js';
2
- import type { Option, Result } from 'ts-results';
3
-
4
- import { WalletConnectionError } from '@hub3js/std/utils';
5
-
6
- export type WalletConnectionAttemptErrorOptions = {
7
- errors: unknown[];
8
- requestedNamespaces: NamespaceInputForConnect[];
9
- message?: string;
10
- };
11
-
12
- function messageOf(value: unknown): string {
13
- if (
14
- typeof value === 'object' &&
15
- value !== null &&
16
- 'message' in value &&
17
- typeof value.message === 'string'
18
- ) {
19
- return value.message;
20
- }
21
- return String(value);
22
- }
23
-
24
- /**
25
- * A connection attempt that failed.
26
- *
27
- * - `errors` holds every failed namespace's `WalletConnectionError`, in request order,
28
- * followed by any other value thrown during the attempt.
29
- * - `requestedNamespaces` lists every namespace the attempt requested, in request
30
- * order, cancelled ones included, with the network and derivation path passed for it.
31
- * - `message` is the `message` passed in, or else the first entry's.
32
- *
33
- * It has no `code` and no `cause`: read them from each entry.
34
- */
35
- export class WalletConnectionAttemptError extends AggregateError {
36
- name = 'WalletConnectionAttemptError';
37
- declare errors: unknown[];
38
- readonly requestedNamespaces: NamespaceInputForConnect[];
39
-
40
- constructor(options: WalletConnectionAttemptErrorOptions) {
41
- const { errors, requestedNamespaces, message } = options;
42
- super(errors, message ?? (errors.length > 0 ? messageOf(errors[0]) : ''));
43
- this.requestedNamespaces = requestedNamespaces;
44
- }
45
- }
46
-
47
- /**
48
- * An auto-connect attempt that failed. Auto-connect sends it with
49
- * `Events.AUTO_CONNECT_FAILED`.
50
- */
51
- export class AutoConnectionAttemptError extends WalletConnectionAttemptError {
52
- name = 'AutoConnectionAttemptError';
53
- }
54
-
55
- export type NamespaceConnectAttempt<T = unknown> = {
56
- input: NamespaceInputForConnect;
57
- result: Result<T, unknown>;
58
- // The connect queue abandoned the namespace after another one was rejected.
59
- cancelled?: boolean;
60
- };
61
-
62
- /**
63
- * Lists each failed namespace's `WalletConnectionError` in request order, leaving
64
- * cancelled namespaces out. A failure that isn't one yet (e.g. from an integrator's
65
- * provider, or a before-hook) is wrapped in one for its namespace.
66
- */
67
- export function collectConnectionFailures(
68
- attempts: NamespaceConnectAttempt[]
69
- ): WalletConnectionError[] {
70
- return attempts.flatMap(({ input, result, cancelled }) => {
71
- if (cancelled || result.ok) {
72
- return [];
73
- }
74
- return result.val instanceof WalletConnectionError
75
- ? [result.val]
76
- : [
77
- new WalletConnectionError({
78
- namespace: input.namespace,
79
- cause: result.val,
80
- }),
81
- ];
82
- });
83
- }
84
-
85
- /**
86
- * Builds the error `connect` throws, or returns `undefined` when every namespace
87
- * connected and nothing else was thrown. `nonNamespaceError` holds the value thrown
88
- * outside any namespace, if any, such as a config error; it's added after the
89
- * namespace failures, unchanged.
90
- */
91
- export function buildConnectionAttemptError(params: {
92
- requestedNamespaces: NamespaceInputForConnect[];
93
- attempts: NamespaceConnectAttempt[];
94
- nonNamespaceError: Option<unknown>;
95
- }): WalletConnectionAttemptError | undefined {
96
- const { requestedNamespaces, attempts, nonNamespaceError } = params;
97
- if (attempts.every(({ result }) => result.ok) && nonNamespaceError.none) {
98
- return undefined;
99
- }
100
-
101
- const errors: unknown[] = collectConnectionFailures(attempts);
102
- if (nonNamespaceError.some) {
103
- errors.push(nonNamespaceError.val);
104
- }
105
- return new WalletConnectionAttemptError({ errors, requestedNamespaces });
106
- }
107
-
108
- /**
109
- * Builds the value of `Events.AUTO_CONNECT_FAILED` from the namespaces auto-connect
110
- * tried to connect for a wallet. Returns `undefined` when none of them failed.
111
- */
112
- export function buildAutoConnectionAttemptError(
113
- attempts: NamespaceConnectAttempt[]
114
- ): AutoConnectionAttemptError | undefined {
115
- const errors = collectConnectionFailures(attempts);
116
- if (!errors.length) {
117
- return undefined;
118
- }
119
-
120
- return new AutoConnectionAttemptError({
121
- errors,
122
- requestedNamespaces: attempts.map(({ input }) => input),
123
- });
124
- }