@txnlab/use-wallet-solid 3.0.0-beta.10

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/index.js ADDED
@@ -0,0 +1,777 @@
1
+ export * from '@txnlab/use-wallet';
2
+ import { useStore } from '@tanstack/solid-store';
3
+
4
+ // src/index.tsx
5
+
6
+ // ../../node_modules/.pnpm/solid-js@1.8.16/node_modules/solid-js/dist/solid.js
7
+ var sharedConfig = {
8
+ context: void 0,
9
+ registry: void 0
10
+ };
11
+ function setHydrateContext(context) {
12
+ sharedConfig.context = context;
13
+ }
14
+ function nextHydrateContext() {
15
+ return {
16
+ ...sharedConfig.context,
17
+ id: `${sharedConfig.context.id}${sharedConfig.context.count++}-`,
18
+ count: 0
19
+ };
20
+ }
21
+ var equalFn = (a, b) => a === b;
22
+ var signalOptions = {
23
+ equals: equalFn
24
+ };
25
+ var ERROR = null;
26
+ var runEffects = runQueue;
27
+ var STALE = 1;
28
+ var PENDING = 2;
29
+ var UNOWNED = {
30
+ owned: null,
31
+ cleanups: null,
32
+ context: null,
33
+ owner: null
34
+ };
35
+ var Owner = null;
36
+ var Transition = null;
37
+ var Scheduler = null;
38
+ var ExternalSourceConfig = null;
39
+ var Listener = null;
40
+ var Updates = null;
41
+ var Effects = null;
42
+ var ExecCount = 0;
43
+ function createSignal(value, options) {
44
+ options = options ? Object.assign({}, signalOptions, options) : signalOptions;
45
+ const s = {
46
+ value,
47
+ observers: null,
48
+ observerSlots: null,
49
+ comparator: options.equals || void 0
50
+ };
51
+ const setter = (value2) => {
52
+ if (typeof value2 === "function") {
53
+ if (Transition && Transition.running && Transition.sources.has(s))
54
+ value2 = value2(s.tValue);
55
+ else
56
+ value2 = value2(s.value);
57
+ }
58
+ return writeSignal(s, value2);
59
+ };
60
+ return [readSignal.bind(s), setter];
61
+ }
62
+ function createRenderEffect(fn, value, options) {
63
+ const c = createComputation(fn, value, false, STALE);
64
+ if (Scheduler && Transition && Transition.running)
65
+ Updates.push(c);
66
+ else
67
+ updateComputation(c);
68
+ }
69
+ function createEffect(fn, value, options) {
70
+ runEffects = runUserEffects;
71
+ const c = createComputation(fn, value, false, STALE), s = SuspenseContext && useContext(SuspenseContext);
72
+ if (s)
73
+ c.suspense = s;
74
+ if (!options || !options.render)
75
+ c.user = true;
76
+ Effects ? Effects.push(c) : updateComputation(c);
77
+ }
78
+ function createMemo(fn, value, options) {
79
+ options = options ? Object.assign({}, signalOptions, options) : signalOptions;
80
+ const c = createComputation(fn, value, true, 0);
81
+ c.observers = null;
82
+ c.observerSlots = null;
83
+ c.comparator = options.equals || void 0;
84
+ if (Scheduler && Transition && Transition.running) {
85
+ c.tState = STALE;
86
+ Updates.push(c);
87
+ } else
88
+ updateComputation(c);
89
+ return readSignal.bind(c);
90
+ }
91
+ function untrack(fn) {
92
+ if (!ExternalSourceConfig && Listener === null)
93
+ return fn();
94
+ const listener = Listener;
95
+ Listener = null;
96
+ try {
97
+ if (ExternalSourceConfig)
98
+ return ExternalSourceConfig.untrack(fn);
99
+ return fn();
100
+ } finally {
101
+ Listener = listener;
102
+ }
103
+ }
104
+ function onMount(fn) {
105
+ createEffect(() => untrack(fn));
106
+ }
107
+ function onCleanup(fn) {
108
+ if (Owner === null)
109
+ ;
110
+ else if (Owner.cleanups === null)
111
+ Owner.cleanups = [fn];
112
+ else
113
+ Owner.cleanups.push(fn);
114
+ return fn;
115
+ }
116
+ function startTransition(fn) {
117
+ if (Transition && Transition.running) {
118
+ fn();
119
+ return Transition.done;
120
+ }
121
+ const l = Listener;
122
+ const o = Owner;
123
+ return Promise.resolve().then(() => {
124
+ Listener = l;
125
+ Owner = o;
126
+ let t;
127
+ if (Scheduler || SuspenseContext) {
128
+ t = Transition || (Transition = {
129
+ sources: /* @__PURE__ */ new Set(),
130
+ effects: [],
131
+ promises: /* @__PURE__ */ new Set(),
132
+ disposed: /* @__PURE__ */ new Set(),
133
+ queue: /* @__PURE__ */ new Set(),
134
+ running: true
135
+ });
136
+ t.done || (t.done = new Promise((res) => t.resolve = res));
137
+ t.running = true;
138
+ }
139
+ runUpdates(fn, false);
140
+ Listener = Owner = null;
141
+ return t ? t.done : void 0;
142
+ });
143
+ }
144
+ var [transPending, setTransPending] = /* @__PURE__ */ createSignal(false);
145
+ function createContext(defaultValue, options) {
146
+ const id = Symbol("context");
147
+ return {
148
+ id,
149
+ Provider: createProvider(id),
150
+ defaultValue
151
+ };
152
+ }
153
+ function useContext(context) {
154
+ return Owner && Owner.context && Owner.context[context.id] !== void 0 ? Owner.context[context.id] : context.defaultValue;
155
+ }
156
+ function children(fn) {
157
+ const children2 = createMemo(fn);
158
+ const memo = createMemo(() => resolveChildren(children2()));
159
+ memo.toArray = () => {
160
+ const c = memo();
161
+ return Array.isArray(c) ? c : c != null ? [c] : [];
162
+ };
163
+ return memo;
164
+ }
165
+ var SuspenseContext;
166
+ function readSignal() {
167
+ const runningTransition = Transition && Transition.running;
168
+ if (this.sources && (runningTransition ? this.tState : this.state)) {
169
+ if ((runningTransition ? this.tState : this.state) === STALE)
170
+ updateComputation(this);
171
+ else {
172
+ const updates = Updates;
173
+ Updates = null;
174
+ runUpdates(() => lookUpstream(this), false);
175
+ Updates = updates;
176
+ }
177
+ }
178
+ if (Listener) {
179
+ const sSlot = this.observers ? this.observers.length : 0;
180
+ if (!Listener.sources) {
181
+ Listener.sources = [this];
182
+ Listener.sourceSlots = [sSlot];
183
+ } else {
184
+ Listener.sources.push(this);
185
+ Listener.sourceSlots.push(sSlot);
186
+ }
187
+ if (!this.observers) {
188
+ this.observers = [Listener];
189
+ this.observerSlots = [Listener.sources.length - 1];
190
+ } else {
191
+ this.observers.push(Listener);
192
+ this.observerSlots.push(Listener.sources.length - 1);
193
+ }
194
+ }
195
+ if (runningTransition && Transition.sources.has(this))
196
+ return this.tValue;
197
+ return this.value;
198
+ }
199
+ function writeSignal(node, value, isComp) {
200
+ let current = Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value;
201
+ if (!node.comparator || !node.comparator(current, value)) {
202
+ if (Transition) {
203
+ const TransitionRunning = Transition.running;
204
+ if (TransitionRunning || !isComp && Transition.sources.has(node)) {
205
+ Transition.sources.add(node);
206
+ node.tValue = value;
207
+ }
208
+ if (!TransitionRunning)
209
+ node.value = value;
210
+ } else
211
+ node.value = value;
212
+ if (node.observers && node.observers.length) {
213
+ runUpdates(() => {
214
+ for (let i = 0; i < node.observers.length; i += 1) {
215
+ const o = node.observers[i];
216
+ const TransitionRunning = Transition && Transition.running;
217
+ if (TransitionRunning && Transition.disposed.has(o))
218
+ continue;
219
+ if (TransitionRunning ? !o.tState : !o.state) {
220
+ if (o.pure)
221
+ Updates.push(o);
222
+ else
223
+ Effects.push(o);
224
+ if (o.observers)
225
+ markDownstream(o);
226
+ }
227
+ if (!TransitionRunning)
228
+ o.state = STALE;
229
+ else
230
+ o.tState = STALE;
231
+ }
232
+ if (Updates.length > 1e6) {
233
+ Updates = [];
234
+ if (false)
235
+ ;
236
+ throw new Error();
237
+ }
238
+ }, false);
239
+ }
240
+ }
241
+ return value;
242
+ }
243
+ function updateComputation(node) {
244
+ if (!node.fn)
245
+ return;
246
+ cleanNode(node);
247
+ const time = ExecCount;
248
+ runComputation(
249
+ node,
250
+ Transition && Transition.running && Transition.sources.has(node) ? node.tValue : node.value,
251
+ time
252
+ );
253
+ if (Transition && !Transition.running && Transition.sources.has(node)) {
254
+ queueMicrotask(() => {
255
+ runUpdates(() => {
256
+ Transition && (Transition.running = true);
257
+ Listener = Owner = node;
258
+ runComputation(node, node.tValue, time);
259
+ Listener = Owner = null;
260
+ }, false);
261
+ });
262
+ }
263
+ }
264
+ function runComputation(node, value, time) {
265
+ let nextValue;
266
+ const owner = Owner, listener = Listener;
267
+ Listener = Owner = node;
268
+ try {
269
+ nextValue = node.fn(value);
270
+ } catch (err) {
271
+ if (node.pure) {
272
+ if (Transition && Transition.running) {
273
+ node.tState = STALE;
274
+ node.tOwned && node.tOwned.forEach(cleanNode);
275
+ node.tOwned = void 0;
276
+ } else {
277
+ node.state = STALE;
278
+ node.owned && node.owned.forEach(cleanNode);
279
+ node.owned = null;
280
+ }
281
+ }
282
+ node.updatedAt = time + 1;
283
+ return handleError(err);
284
+ } finally {
285
+ Listener = listener;
286
+ Owner = owner;
287
+ }
288
+ if (!node.updatedAt || node.updatedAt <= time) {
289
+ if (node.updatedAt != null && "observers" in node) {
290
+ writeSignal(node, nextValue, true);
291
+ } else if (Transition && Transition.running && node.pure) {
292
+ Transition.sources.add(node);
293
+ node.tValue = nextValue;
294
+ } else
295
+ node.value = nextValue;
296
+ node.updatedAt = time;
297
+ }
298
+ }
299
+ function createComputation(fn, init, pure, state = STALE, options) {
300
+ const c = {
301
+ fn,
302
+ state,
303
+ updatedAt: null,
304
+ owned: null,
305
+ sources: null,
306
+ sourceSlots: null,
307
+ cleanups: null,
308
+ value: init,
309
+ owner: Owner,
310
+ context: Owner ? Owner.context : null,
311
+ pure
312
+ };
313
+ if (Transition && Transition.running) {
314
+ c.state = 0;
315
+ c.tState = state;
316
+ }
317
+ if (Owner === null)
318
+ ;
319
+ else if (Owner !== UNOWNED) {
320
+ if (Transition && Transition.running && Owner.pure) {
321
+ if (!Owner.tOwned)
322
+ Owner.tOwned = [c];
323
+ else
324
+ Owner.tOwned.push(c);
325
+ } else {
326
+ if (!Owner.owned)
327
+ Owner.owned = [c];
328
+ else
329
+ Owner.owned.push(c);
330
+ }
331
+ }
332
+ if (ExternalSourceConfig && c.fn) {
333
+ const [track, trigger] = createSignal(void 0, {
334
+ equals: false
335
+ });
336
+ const ordinary = ExternalSourceConfig.factory(c.fn, trigger);
337
+ onCleanup(() => ordinary.dispose());
338
+ const triggerInTransition = () => startTransition(trigger).then(() => inTransition.dispose());
339
+ const inTransition = ExternalSourceConfig.factory(c.fn, triggerInTransition);
340
+ c.fn = (x) => {
341
+ track();
342
+ return Transition && Transition.running ? inTransition.track(x) : ordinary.track(x);
343
+ };
344
+ }
345
+ return c;
346
+ }
347
+ function runTop(node) {
348
+ const runningTransition = Transition && Transition.running;
349
+ if ((runningTransition ? node.tState : node.state) === 0)
350
+ return;
351
+ if ((runningTransition ? node.tState : node.state) === PENDING)
352
+ return lookUpstream(node);
353
+ if (node.suspense && untrack(node.suspense.inFallback))
354
+ return node.suspense.effects.push(node);
355
+ const ancestors = [node];
356
+ while ((node = node.owner) && (!node.updatedAt || node.updatedAt < ExecCount)) {
357
+ if (runningTransition && Transition.disposed.has(node))
358
+ return;
359
+ if (runningTransition ? node.tState : node.state)
360
+ ancestors.push(node);
361
+ }
362
+ for (let i = ancestors.length - 1; i >= 0; i--) {
363
+ node = ancestors[i];
364
+ if (runningTransition) {
365
+ let top = node, prev = ancestors[i + 1];
366
+ while ((top = top.owner) && top !== prev) {
367
+ if (Transition.disposed.has(top))
368
+ return;
369
+ }
370
+ }
371
+ if ((runningTransition ? node.tState : node.state) === STALE) {
372
+ updateComputation(node);
373
+ } else if ((runningTransition ? node.tState : node.state) === PENDING) {
374
+ const updates = Updates;
375
+ Updates = null;
376
+ runUpdates(() => lookUpstream(node, ancestors[0]), false);
377
+ Updates = updates;
378
+ }
379
+ }
380
+ }
381
+ function runUpdates(fn, init) {
382
+ if (Updates)
383
+ return fn();
384
+ let wait = false;
385
+ if (!init)
386
+ Updates = [];
387
+ if (Effects)
388
+ wait = true;
389
+ else
390
+ Effects = [];
391
+ ExecCount++;
392
+ try {
393
+ const res = fn();
394
+ completeUpdates(wait);
395
+ return res;
396
+ } catch (err) {
397
+ if (!wait)
398
+ Effects = null;
399
+ Updates = null;
400
+ handleError(err);
401
+ }
402
+ }
403
+ function completeUpdates(wait) {
404
+ if (Updates) {
405
+ if (Scheduler && Transition && Transition.running)
406
+ scheduleQueue(Updates);
407
+ else
408
+ runQueue(Updates);
409
+ Updates = null;
410
+ }
411
+ if (wait)
412
+ return;
413
+ let res;
414
+ if (Transition) {
415
+ if (!Transition.promises.size && !Transition.queue.size) {
416
+ const sources = Transition.sources;
417
+ const disposed = Transition.disposed;
418
+ Effects.push.apply(Effects, Transition.effects);
419
+ res = Transition.resolve;
420
+ for (const e2 of Effects) {
421
+ "tState" in e2 && (e2.state = e2.tState);
422
+ delete e2.tState;
423
+ }
424
+ Transition = null;
425
+ runUpdates(() => {
426
+ for (const d of disposed)
427
+ cleanNode(d);
428
+ for (const v of sources) {
429
+ v.value = v.tValue;
430
+ if (v.owned) {
431
+ for (let i = 0, len = v.owned.length; i < len; i++)
432
+ cleanNode(v.owned[i]);
433
+ }
434
+ if (v.tOwned)
435
+ v.owned = v.tOwned;
436
+ delete v.tValue;
437
+ delete v.tOwned;
438
+ v.tState = 0;
439
+ }
440
+ setTransPending(false);
441
+ }, false);
442
+ } else if (Transition.running) {
443
+ Transition.running = false;
444
+ Transition.effects.push.apply(Transition.effects, Effects);
445
+ Effects = null;
446
+ setTransPending(true);
447
+ return;
448
+ }
449
+ }
450
+ const e = Effects;
451
+ Effects = null;
452
+ if (e.length)
453
+ runUpdates(() => runEffects(e), false);
454
+ if (res)
455
+ res();
456
+ }
457
+ function runQueue(queue) {
458
+ for (let i = 0; i < queue.length; i++)
459
+ runTop(queue[i]);
460
+ }
461
+ function scheduleQueue(queue) {
462
+ for (let i = 0; i < queue.length; i++) {
463
+ const item = queue[i];
464
+ const tasks = Transition.queue;
465
+ if (!tasks.has(item)) {
466
+ tasks.add(item);
467
+ Scheduler(() => {
468
+ tasks.delete(item);
469
+ runUpdates(() => {
470
+ Transition.running = true;
471
+ runTop(item);
472
+ }, false);
473
+ Transition && (Transition.running = false);
474
+ });
475
+ }
476
+ }
477
+ }
478
+ function runUserEffects(queue) {
479
+ let i, userLength = 0;
480
+ for (i = 0; i < queue.length; i++) {
481
+ const e = queue[i];
482
+ if (!e.user)
483
+ runTop(e);
484
+ else
485
+ queue[userLength++] = e;
486
+ }
487
+ if (sharedConfig.context) {
488
+ if (sharedConfig.count) {
489
+ sharedConfig.effects || (sharedConfig.effects = []);
490
+ sharedConfig.effects.push(...queue.slice(0, userLength));
491
+ return;
492
+ } else if (sharedConfig.effects) {
493
+ queue = [...sharedConfig.effects, ...queue];
494
+ userLength += sharedConfig.effects.length;
495
+ delete sharedConfig.effects;
496
+ }
497
+ setHydrateContext();
498
+ }
499
+ for (i = 0; i < userLength; i++)
500
+ runTop(queue[i]);
501
+ }
502
+ function lookUpstream(node, ignore) {
503
+ const runningTransition = Transition && Transition.running;
504
+ if (runningTransition)
505
+ node.tState = 0;
506
+ else
507
+ node.state = 0;
508
+ for (let i = 0; i < node.sources.length; i += 1) {
509
+ const source = node.sources[i];
510
+ if (source.sources) {
511
+ const state = runningTransition ? source.tState : source.state;
512
+ if (state === STALE) {
513
+ if (source !== ignore && (!source.updatedAt || source.updatedAt < ExecCount))
514
+ runTop(source);
515
+ } else if (state === PENDING)
516
+ lookUpstream(source, ignore);
517
+ }
518
+ }
519
+ }
520
+ function markDownstream(node) {
521
+ const runningTransition = Transition && Transition.running;
522
+ for (let i = 0; i < node.observers.length; i += 1) {
523
+ const o = node.observers[i];
524
+ if (runningTransition ? !o.tState : !o.state) {
525
+ if (runningTransition)
526
+ o.tState = PENDING;
527
+ else
528
+ o.state = PENDING;
529
+ if (o.pure)
530
+ Updates.push(o);
531
+ else
532
+ Effects.push(o);
533
+ o.observers && markDownstream(o);
534
+ }
535
+ }
536
+ }
537
+ function cleanNode(node) {
538
+ let i;
539
+ if (node.sources) {
540
+ while (node.sources.length) {
541
+ const source = node.sources.pop(), index = node.sourceSlots.pop(), obs = source.observers;
542
+ if (obs && obs.length) {
543
+ const n = obs.pop(), s = source.observerSlots.pop();
544
+ if (index < obs.length) {
545
+ n.sourceSlots[s] = index;
546
+ obs[index] = n;
547
+ source.observerSlots[index] = s;
548
+ }
549
+ }
550
+ }
551
+ }
552
+ if (Transition && Transition.running && node.pure) {
553
+ if (node.tOwned) {
554
+ for (i = node.tOwned.length - 1; i >= 0; i--)
555
+ cleanNode(node.tOwned[i]);
556
+ delete node.tOwned;
557
+ }
558
+ reset(node, true);
559
+ } else if (node.owned) {
560
+ for (i = node.owned.length - 1; i >= 0; i--)
561
+ cleanNode(node.owned[i]);
562
+ node.owned = null;
563
+ }
564
+ if (node.cleanups) {
565
+ for (i = node.cleanups.length - 1; i >= 0; i--)
566
+ node.cleanups[i]();
567
+ node.cleanups = null;
568
+ }
569
+ if (Transition && Transition.running)
570
+ node.tState = 0;
571
+ else
572
+ node.state = 0;
573
+ }
574
+ function reset(node, top) {
575
+ if (!top) {
576
+ node.tState = 0;
577
+ Transition.disposed.add(node);
578
+ }
579
+ if (node.owned) {
580
+ for (let i = 0; i < node.owned.length; i++)
581
+ reset(node.owned[i]);
582
+ }
583
+ }
584
+ function castError(err) {
585
+ if (err instanceof Error)
586
+ return err;
587
+ return new Error(typeof err === "string" ? err : "Unknown error", {
588
+ cause: err
589
+ });
590
+ }
591
+ function runErrors(err, fns, owner) {
592
+ try {
593
+ for (const f of fns)
594
+ f(err);
595
+ } catch (e) {
596
+ handleError(e, owner && owner.owner || null);
597
+ }
598
+ }
599
+ function handleError(err, owner = Owner) {
600
+ const fns = ERROR && owner && owner.context && owner.context[ERROR];
601
+ const error = castError(err);
602
+ if (!fns)
603
+ throw error;
604
+ if (Effects)
605
+ Effects.push({
606
+ fn() {
607
+ runErrors(error, fns, owner);
608
+ },
609
+ state: STALE
610
+ });
611
+ else
612
+ runErrors(error, fns, owner);
613
+ }
614
+ function resolveChildren(children2) {
615
+ if (typeof children2 === "function" && !children2.length)
616
+ return resolveChildren(children2());
617
+ if (Array.isArray(children2)) {
618
+ const results = [];
619
+ for (let i = 0; i < children2.length; i++) {
620
+ const result = resolveChildren(children2[i]);
621
+ Array.isArray(result) ? results.push.apply(results, result) : results.push(result);
622
+ }
623
+ return results;
624
+ }
625
+ return children2;
626
+ }
627
+ function createProvider(id, options) {
628
+ return function provider(props) {
629
+ let res;
630
+ createRenderEffect(
631
+ () => res = untrack(() => {
632
+ Owner.context = {
633
+ ...Owner.context,
634
+ [id]: props.value
635
+ };
636
+ return children(() => props.children);
637
+ }),
638
+ void 0
639
+ );
640
+ return res;
641
+ };
642
+ }
643
+ var hydrationEnabled = false;
644
+ function createComponent(Comp, props) {
645
+ if (hydrationEnabled) {
646
+ if (sharedConfig.context) {
647
+ const c = sharedConfig.context;
648
+ setHydrateContext(nextHydrateContext());
649
+ const r = untrack(() => Comp(props || {}));
650
+ setHydrateContext(c);
651
+ return r;
652
+ }
653
+ }
654
+ return untrack(() => Comp(props || {}));
655
+ }
656
+
657
+ // ../../node_modules/.pnpm/solid-js@1.8.16/node_modules/solid-js/web/dist/web.js
658
+ var booleans = [
659
+ "allowfullscreen",
660
+ "async",
661
+ "autofocus",
662
+ "autoplay",
663
+ "checked",
664
+ "controls",
665
+ "default",
666
+ "disabled",
667
+ "formnovalidate",
668
+ "hidden",
669
+ "indeterminate",
670
+ "inert",
671
+ "ismap",
672
+ "loop",
673
+ "multiple",
674
+ "muted",
675
+ "nomodule",
676
+ "novalidate",
677
+ "open",
678
+ "playsinline",
679
+ "readonly",
680
+ "required",
681
+ "reversed",
682
+ "seamless",
683
+ "selected"
684
+ ];
685
+ /* @__PURE__ */ new Set([
686
+ "className",
687
+ "value",
688
+ "readOnly",
689
+ "formNoValidate",
690
+ "isMap",
691
+ "noModule",
692
+ "playsInline",
693
+ ...booleans
694
+ ]);
695
+
696
+ // src/WalletProvider.tsx
697
+ var WalletContext = createContext();
698
+ var WalletProvider = (props) => {
699
+ const store = () => props.manager;
700
+ onMount(async () => {
701
+ try {
702
+ await props.manager.resumeSessions();
703
+ } catch (error) {
704
+ }
705
+ });
706
+ return createComponent(WalletContext.Provider, {
707
+ value: store,
708
+ get children() {
709
+ return props.children;
710
+ }
711
+ });
712
+ };
713
+ var useWalletManager = () => {
714
+ const manager = useContext(WalletContext);
715
+ if (!manager) {
716
+ throw new Error("useWalletManager must be used within a WalletProvider");
717
+ }
718
+ return manager();
719
+ };
720
+ function useWallet() {
721
+ const manager = createMemo(() => useWalletManager());
722
+ const walletStore = useStore(manager().store, (state) => {
723
+ return state.wallets;
724
+ });
725
+ const walletState = (walletId) => walletStore()[walletId] || null;
726
+ const activeWalletId = useStore(manager().store, (state) => {
727
+ return state.activeWallet;
728
+ });
729
+ const activeWallet = () => manager().getWallet(activeWalletId()) || null;
730
+ const activeWalletState = () => walletState(activeWalletId());
731
+ const activeWalletAccounts = () => activeWalletState()?.accounts ?? null;
732
+ const activeWalletAddresses = () => activeWalletAccounts()?.map((account) => account.address) ?? null;
733
+ const activeAccount = () => activeWalletState()?.activeAccount ?? null;
734
+ const activeAddress = () => activeAccount()?.address ?? null;
735
+ const isWalletActive = (walletId) => walletId === activeWalletId();
736
+ const isWalletConnected = (walletId) => !!walletState(walletId)?.accounts.length || false;
737
+ const activeNetworkState = createMemo(() => {
738
+ return useStore(manager().store, (state) => state.activeNetwork);
739
+ });
740
+ const activeNetwork = () => activeNetworkState()();
741
+ const setActiveNetwork = (network) => manager().setActiveNetwork(network);
742
+ const algodClient = createMemo(() => manager().algodClient);
743
+ const signTransactions = (txnGroup, indexesToSign, returnGroup) => {
744
+ const wallet = activeWallet();
745
+ if (!wallet) {
746
+ throw new Error("No active wallet");
747
+ }
748
+ return wallet.signTransactions(txnGroup, indexesToSign, returnGroup);
749
+ };
750
+ const transactionSigner = (txnGroup, indexesToSign) => {
751
+ const wallet = activeWallet();
752
+ if (!wallet) {
753
+ throw new Error("No active wallet");
754
+ }
755
+ return wallet.transactionSigner(txnGroup, indexesToSign);
756
+ };
757
+ return {
758
+ activeWalletId,
759
+ walletStore,
760
+ algodClient,
761
+ activeNetwork,
762
+ activeWallet,
763
+ activeWalletAccounts,
764
+ activeWalletAddresses,
765
+ activeWalletState,
766
+ activeAccount,
767
+ activeAddress,
768
+ isWalletActive,
769
+ isWalletConnected,
770
+ setActiveNetwork,
771
+ signTransactions,
772
+ transactionSigner,
773
+ wallets: manager().wallets
774
+ };
775
+ }
776
+
777
+ export { WalletProvider, useWallet };