@xyo-network/react-chain-provider 1.20.1 → 1.20.2

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.
Files changed (94) hide show
  1. package/dist/browser/contexts/gateway/Provider.d.ts +10 -0
  2. package/dist/browser/contexts/gateway/Provider.d.ts.map +1 -0
  3. package/dist/browser/contexts/gateway/context.d.ts +8 -0
  4. package/dist/browser/contexts/gateway/context.d.ts.map +1 -0
  5. package/dist/browser/contexts/gateway/index.d.ts +5 -0
  6. package/dist/browser/contexts/gateway/index.d.ts.map +1 -0
  7. package/dist/browser/contexts/gateway/state.d.ts +14 -0
  8. package/dist/browser/contexts/gateway/state.d.ts.map +1 -0
  9. package/dist/browser/contexts/gateway/story/GatewayStats.d.ts +9 -0
  10. package/dist/browser/contexts/gateway/story/GatewayStats.d.ts.map +1 -0
  11. package/dist/browser/contexts/gateway/story/GatewayStatus.d.ts +3 -0
  12. package/dist/browser/contexts/gateway/story/GatewayStatus.d.ts.map +1 -0
  13. package/dist/browser/contexts/gateway/use.d.ts +4 -0
  14. package/dist/browser/contexts/gateway/use.d.ts.map +1 -0
  15. package/dist/browser/contexts/index.d.ts +1 -0
  16. package/dist/browser/contexts/index.d.ts.map +1 -1
  17. package/dist/browser/hooks/client/helpers/buildGateway.d.ts +4 -0
  18. package/dist/browser/hooks/client/helpers/buildGateway.d.ts.map +1 -0
  19. package/dist/browser/hooks/client/helpers/index.d.ts +1 -0
  20. package/dist/browser/hooks/client/helpers/index.d.ts.map +1 -1
  21. package/dist/browser/hooks/client/index.d.ts +3 -2
  22. package/dist/browser/hooks/client/index.d.ts.map +1 -1
  23. package/dist/browser/hooks/client/{useClient.d.ts → useClientFromWallet.d.ts} +3 -1
  24. package/dist/browser/hooks/client/useClientFromWallet.d.ts.map +1 -0
  25. package/dist/browser/hooks/client/useGatewayFromConfig.d.ts +9 -0
  26. package/dist/browser/hooks/client/useGatewayFromConfig.d.ts.map +1 -0
  27. package/dist/browser/hooks/client/useGatewayFromWallet.d.ts +6 -0
  28. package/dist/browser/hooks/client/useGatewayFromWallet.d.ts.map +1 -0
  29. package/dist/browser/hooks/gateway/index.d.ts +4 -0
  30. package/dist/browser/hooks/gateway/index.d.ts.map +1 -0
  31. package/dist/browser/hooks/gateway/useNetwork.d.ts +2 -0
  32. package/dist/browser/hooks/gateway/useNetwork.d.ts.map +1 -0
  33. package/dist/browser/hooks/gateway/useRunner.d.ts +2 -0
  34. package/dist/browser/hooks/gateway/useRunner.d.ts.map +1 -0
  35. package/dist/browser/hooks/gateway/useViewer.d.ts +2 -0
  36. package/dist/browser/hooks/gateway/useViewer.d.ts.map +1 -0
  37. package/dist/browser/hooks/index.d.ts +1 -0
  38. package/dist/browser/hooks/index.d.ts.map +1 -1
  39. package/dist/browser/hooks/useCurrentBlock.d.ts +33 -0
  40. package/dist/browser/hooks/useCurrentBlock.d.ts.map +1 -1
  41. package/dist/browser/hooks/useHttpRpcRunner.d.ts.map +1 -1
  42. package/dist/browser/hooks/viewer/useCheckRpc.d.ts.map +1 -1
  43. package/dist/browser/hooks/viewer/useHttpRpcViewer.d.ts +1 -0
  44. package/dist/browser/hooks/viewer/useHttpRpcViewer.d.ts.map +1 -1
  45. package/dist/browser/index.mjs +353 -197
  46. package/dist/browser/index.mjs.map +1 -1
  47. package/dist/browser/types/GatewayFromWallet.d.ts +8 -0
  48. package/dist/browser/types/GatewayFromWallet.d.ts.map +1 -0
  49. package/dist/browser/types/index.d.ts +2 -0
  50. package/dist/browser/types/index.d.ts.map +1 -0
  51. package/package.json +20 -18
  52. package/src/contexts/gateway/Provider.tsx +73 -0
  53. package/src/contexts/gateway/context.ts +5 -0
  54. package/src/contexts/gateway/index.ts +4 -0
  55. package/src/contexts/gateway/state.ts +17 -0
  56. package/src/contexts/gateway/story/GatewayStats.tsx +30 -0
  57. package/src/contexts/gateway/story/GatewayStatus.tsx +53 -0
  58. package/src/contexts/gateway/story/Provider.stories.tsx +38 -0
  59. package/src/contexts/gateway/story/ProviderWithWallet.stories.tsx +46 -0
  60. package/src/contexts/gateway/use.ts +5 -0
  61. package/src/contexts/index.ts +1 -0
  62. package/src/hooks/client/helpers/buildGateway.ts +29 -0
  63. package/src/hooks/client/helpers/index.ts +1 -0
  64. package/src/hooks/client/index.ts +3 -2
  65. package/src/hooks/client/permissions/usePermissions.ts +2 -2
  66. package/src/hooks/client/{useClient.ts → useClientFromWallet.ts} +4 -1
  67. package/src/hooks/client/useGatewayFromConfig.ts +43 -0
  68. package/src/hooks/client/{useGateway.ts → useGatewayFromWallet.ts} +7 -3
  69. package/src/hooks/gateway/index.ts +3 -0
  70. package/src/hooks/gateway/useNetwork.ts +6 -0
  71. package/src/hooks/gateway/useRunner.ts +6 -0
  72. package/src/hooks/gateway/useViewer.ts +6 -0
  73. package/src/hooks/index.ts +1 -0
  74. package/src/hooks/useConnectAccount.ts +2 -2
  75. package/src/hooks/useCurrentBlock.ts +13 -0
  76. package/src/hooks/useHttpRpcRunner.ts +1 -0
  77. package/src/hooks/viewer/useCheckRpc.ts +8 -17
  78. package/src/hooks/viewer/useHttpRpcViewer.ts +1 -0
  79. package/src/hooks/viewer/useViewerFromWallet.ts +2 -2
  80. package/src/types/GatewayFromWallet.ts +8 -0
  81. package/src/types/index.ts +1 -0
  82. package/dist/browser/components/connected/ConnectAccountsStack.stories.d.ts +0 -6
  83. package/dist/browser/components/connected/ConnectAccountsStack.stories.d.ts.map +0 -1
  84. package/dist/browser/contexts/current-block/Provider.stories.d.ts +0 -7
  85. package/dist/browser/contexts/current-block/Provider.stories.d.ts.map +0 -1
  86. package/dist/browser/hooks/client/useClient.d.ts.map +0 -1
  87. package/dist/browser/hooks/client/useGateway.d.ts +0 -8
  88. package/dist/browser/hooks/client/useGateway.d.ts.map +0 -1
  89. package/dist/browser/hooks/viewer/UseStepRewardWeightTest.stories.d.ts +0 -12
  90. package/dist/browser/hooks/viewer/UseStepRewardWeightTest.stories.d.ts.map +0 -1
  91. package/dist/browser/hooks/viewer/useHttpRpcViewer.stories.d.ts +0 -9
  92. package/dist/browser/hooks/viewer/useHttpRpcViewer.stories.d.ts.map +0 -1
  93. package/dist/browser/hooks/viewer/useViewerFromWallet.stories.d.ts +0 -12
  94. package/dist/browser/hooks/viewer/useViewerFromWallet.stories.d.ts.map +0 -1
@@ -27,9 +27,9 @@ var ConnectedAccount = /* @__PURE__ */ __name(({ address }) => {
27
27
  // src/components/connected/ConnectAccountsStack.tsx
28
28
  import { Alert, AlertTitle, Button, Stack as Stack2, Typography as Typography2 } from "@mui/material";
29
29
  import { ButtonEx } from "@xylabs/react-button";
30
- import { isDefined as isDefined9, isUndefined as isUndefined8 } from "@xylabs/sdk-js";
30
+ import { isDefined as isDefined11, isUndefined as isUndefined8 } from "@xylabs/sdk-js";
31
31
  import { ErrorRender } from "@xyo-network/react-error";
32
- import React2, { useEffect as useEffect4 } from "react";
32
+ import React4, { useEffect as useEffect6 } from "react";
33
33
 
34
34
  // src/hooks/account/helpers/formatAccountBalanceHistory.ts
35
35
  import { hexToBigInt } from "@xylabs/sdk-js";
@@ -137,7 +137,7 @@ var useAccountBalanceHistory = /* @__PURE__ */ __name((address, viewer, maxPage
137
137
  ]);
138
138
  }, "useAccountBalanceHistory");
139
139
 
140
- // src/hooks/client/useClient.ts
140
+ // src/hooks/client/useClientFromWallet.ts
141
141
  import { isNull as isNull2 } from "@xylabs/sdk-js";
142
142
  import { useCallback, useEffect, useSyncExternalStore } from "react";
143
143
 
@@ -279,7 +279,7 @@ var TransactionConfirmationStatus = class _TransactionConfirmationStatus {
279
279
  }
280
280
  };
281
281
 
282
- // src/hooks/client/useClient.ts
282
+ // src/hooks/client/useClientFromWallet.ts
283
283
  var currentState = {
284
284
  client: void 0,
285
285
  error: null,
@@ -333,7 +333,7 @@ var subscribe = /* @__PURE__ */ __name((listener, timeout) => {
333
333
  };
334
334
  }, "subscribe");
335
335
  var getSnapshot = /* @__PURE__ */ __name(() => currentState, "getSnapshot");
336
- var useClient = /* @__PURE__ */ __name((timeout) => {
336
+ var useClientFromWallet = /* @__PURE__ */ __name((timeout) => {
337
337
  const subscribeWithTimeout = useCallback((listener) => subscribe(listener, timeout), [
338
338
  timeout
339
339
  ]);
@@ -355,11 +355,12 @@ var useClient = /* @__PURE__ */ __name((timeout) => {
355
355
  };
356
356
  });
357
357
  return clientState;
358
- }, "useClient");
358
+ }, "useClientFromWallet");
359
+ var useClient = useClientFromWallet;
359
360
 
360
361
  // src/hooks/client/permissions/usePermissions.ts
361
362
  var usePermissions = /* @__PURE__ */ __name(() => {
362
- const { client, isLoading, error, timedout } = useClient();
363
+ const { client, isLoading, error, timedout } = useClientFromWallet();
363
364
  const permissions = client?.permissions;
364
365
  return {
365
366
  permissions,
@@ -371,15 +372,33 @@ var usePermissions = /* @__PURE__ */ __name(() => {
371
372
 
372
373
  // src/hooks/client/permissions/usePermissionsAccounts.ts
373
374
  import { usePromise as usePromise2 } from "@xylabs/react-promise";
374
- import { isArray, isDefined as isDefined3, isDefinedNotNull, isString } from "@xylabs/sdk-js";
375
+ import { isArray, isDefined as isDefined4, isDefinedNotNull, isString } from "@xylabs/sdk-js";
376
+
377
+ // src/hooks/client/helpers/buildGateway.ts
378
+ import { assertEx as assertEx2, isDefined as isDefined2 } from "@xylabs/sdk-js";
379
+ import { basicRemoteRunnerLocator, basicRemoteViewerLocator } from "@xyo-network/chain-orchestration";
380
+ import { DefaultNetworks, NetworkDataLakeUrls, XyoGatewayMoniker } from "@xyo-network/xl1-sdk";
381
+ var buildGateway = /* @__PURE__ */ __name(async (gatewayName, account) => {
382
+ const network = DefaultNetworks.find((network2) => network2.id === gatewayName);
383
+ const resolvedNetwork = assertEx2(network, () => `No network found for id ${gatewayName}`);
384
+ const remoteConfig = {
385
+ rpc: {
386
+ protocol: "http",
387
+ url: `${resolvedNetwork.url}/rpc`
388
+ }
389
+ };
390
+ const dataLakeEndpoint = NetworkDataLakeUrls[gatewayName];
391
+ const locator = isDefined2(account) ? await basicRemoteRunnerLocator(gatewayName, remoteConfig, account, dataLakeEndpoint) : await basicRemoteViewerLocator(gatewayName, remoteConfig, dataLakeEndpoint);
392
+ return await locator.getInstance(XyoGatewayMoniker);
393
+ }, "buildGateway");
375
394
 
376
395
  // src/hooks/client/helpers/findCaveat.ts
377
- import { isDefined as isDefined2 } from "@xylabs/sdk-js";
396
+ import { isDefined as isDefined3 } from "@xylabs/sdk-js";
378
397
  var findCaveat = /* @__PURE__ */ __name(async (permissions, targetCapability, targetCaveatType) => {
379
398
  const existingPermissions = await permissions.getPermissions();
380
- if (isDefined2(existingPermissions) && existingPermissions.length > 0) {
399
+ if (isDefined3(existingPermissions) && existingPermissions.length > 0) {
381
400
  const foundPermissions = existingPermissions.find((p) => p.parentCapability === targetCapability);
382
- if (isDefined2(foundPermissions)) {
401
+ if (isDefined3(foundPermissions)) {
383
402
  return foundPermissions.caveats?.find((caveat) => caveat.type === targetCaveatType)?.value ?? [];
384
403
  }
385
404
  }
@@ -388,7 +407,7 @@ var findCaveat = /* @__PURE__ */ __name(async (permissions, targetCapability, ta
388
407
 
389
408
  // src/hooks/client/permissions/usePermissionsAccounts.ts
390
409
  var validateRestrictedAccounts = /* @__PURE__ */ __name((restrictedAccounts) => {
391
- if (isDefined3(restrictedAccounts)) {
410
+ if (isDefined4(restrictedAccounts)) {
392
411
  if (isArray(restrictedAccounts) && restrictedAccounts.every(isString)) {
393
412
  return restrictedAccounts;
394
413
  }
@@ -402,7 +421,7 @@ var useAccountPermissions = /* @__PURE__ */ __name(() => {
402
421
  const { permissions, error } = usePermissions();
403
422
  return usePromise2(async () => {
404
423
  if (isDefinedNotNull(error)) throw error;
405
- if (isDefined3(permissions)) {
424
+ if (isDefined4(permissions)) {
406
425
  const restrictedAccounts = await findCaveat(
407
426
  permissions,
408
427
  // TODO - extract to constant in protocol package
@@ -416,13 +435,52 @@ var useAccountPermissions = /* @__PURE__ */ __name(() => {
416
435
  ]);
417
436
  }, "useAccountPermissions");
418
437
 
419
- // src/hooks/client/useGateway.ts
420
- import { isDefined as isDefined4, isNull as isNull3 } from "@xylabs/sdk-js";
421
- var useGateway = /* @__PURE__ */ __name((gatewayName, timeout) => {
422
- const { client, isLoading, error, timedout } = useClient(timeout);
438
+ // src/hooks/client/useGatewayFromConfig.ts
439
+ import { usePromise as usePromise3 } from "@xylabs/react-promise";
440
+ import { isDefined as isDefined5 } from "@xylabs/sdk-js";
441
+ import { useState } from "react";
442
+ var useGatewayFromConfig = /* @__PURE__ */ __name((gatewayName, account) => {
443
+ const [gatewayCache, setGatewayCache] = useState({});
444
+ const clearGateways = /* @__PURE__ */ __name(() => setGatewayCache({}), "clearGateways");
445
+ const [previousAccount, setPreviousAccount] = useState(account);
446
+ if (previousAccount !== account) {
447
+ clearGateways();
448
+ setPreviousAccount(account);
449
+ }
450
+ const builtGatewayResults = usePromise3(async () => {
451
+ if (isDefined5(gatewayName)) {
452
+ if (isDefined5(gatewayCache[gatewayName])) {
453
+ return gatewayCache[gatewayName];
454
+ } else {
455
+ const gateway2 = await buildGateway(gatewayName, account);
456
+ setGatewayCache((prev) => ({
457
+ ...prev,
458
+ [gatewayName]: gateway2
459
+ }));
460
+ return gateway2;
461
+ }
462
+ }
463
+ }, [
464
+ gatewayName,
465
+ account,
466
+ gatewayCache
467
+ ]);
468
+ const [gateway, error, state] = builtGatewayResults;
469
+ return {
470
+ gateway,
471
+ error,
472
+ state,
473
+ clearGateways
474
+ };
475
+ }, "useGatewayFromConfig");
476
+
477
+ // src/hooks/client/useGatewayFromWallet.ts
478
+ import { isDefined as isDefined6, isNull as isNull3 } from "@xylabs/sdk-js";
479
+ var useGatewayFromWallet = /* @__PURE__ */ __name((gatewayName, timeout) => {
480
+ const { client, isLoading, error, timedout } = useClientFromWallet(timeout);
423
481
  const resolveGateway = /* @__PURE__ */ __name(() => {
424
482
  if (isNull3(client)) return null;
425
- if (timedout && !isLoading && isDefined4(gatewayName)) {
483
+ if (timedout && !isLoading && isDefined6(gatewayName)) {
426
484
  return null;
427
485
  }
428
486
  return client?.gateways?.[gatewayName];
@@ -433,19 +491,187 @@ var useGateway = /* @__PURE__ */ __name((gatewayName, timeout) => {
433
491
  error,
434
492
  timedout
435
493
  };
436
- }, "useGateway");
494
+ }, "useGatewayFromWallet");
495
+ var useGateway = useGatewayFromWallet;
496
+
497
+ // src/contexts/current-block/context.ts
498
+ import { createContextEx } from "@xylabs/react-shared";
499
+ var XL1CurrentBlockContext = createContextEx();
500
+
501
+ // src/contexts/current-block/Provider.tsx
502
+ import React2, { useMemo } from "react";
503
+
504
+ // src/contexts/current-block/usePollCurrentBlock.ts
505
+ import { isDefinedNotNull as isDefinedNotNull2, isUndefinedOrNull } from "@xylabs/sdk-js";
506
+ import { startTransition, useEffect as useEffect2, useState as useState2 } from "react";
507
+ var DEFAULT_POLL_INTERVAL = 1e4;
508
+ var usePollCurrentBlock = /* @__PURE__ */ __name((viewer, interval = DEFAULT_POLL_INTERVAL, pause = false) => {
509
+ const [currentBlock, setCurrentBlock] = useState2(null);
510
+ const [error, setError] = useState2();
511
+ useEffect2(() => {
512
+ let isMounted = true;
513
+ const fetchBlock = /* @__PURE__ */ __name(async () => {
514
+ if (isDefinedNotNull2(viewer)) {
515
+ try {
516
+ const block = await viewer.currentBlock();
517
+ if (isMounted) {
518
+ startTransition(() => {
519
+ setCurrentBlock((existingBlock) => {
520
+ if (isUndefinedOrNull(existingBlock)) {
521
+ return block;
522
+ }
523
+ if (isDefinedNotNull2(block) && existingBlock?.[0].block !== block[0].block) {
524
+ return block;
525
+ }
526
+ return existingBlock;
527
+ });
528
+ });
529
+ }
530
+ } catch (err) {
531
+ startTransition(() => {
532
+ setError(err);
533
+ });
534
+ }
535
+ }
536
+ }, "fetchBlock");
537
+ void fetchBlock();
538
+ const id = setInterval(() => {
539
+ if (!pause) {
540
+ void fetchBlock();
541
+ }
542
+ }, interval);
543
+ return () => {
544
+ isMounted = false;
545
+ clearInterval(id);
546
+ };
547
+ }, [
548
+ viewer,
549
+ interval,
550
+ pause
551
+ ]);
552
+ return [
553
+ currentBlock,
554
+ error
555
+ ];
556
+ }, "usePollCurrentBlock");
557
+
558
+ // src/contexts/current-block/Provider.tsx
559
+ var DEFAULT_POLLING_INTERVAL = 1e4;
560
+ var XL1CurrentBlockProvider = /* @__PURE__ */ __name(({ pollingConfig, viewer, children }) => {
561
+ const { interval } = useMemo(() => pollingConfig || {
562
+ interval: DEFAULT_POLLING_INTERVAL
563
+ }, [
564
+ pollingConfig
565
+ ]);
566
+ const [currentBlock, currentBlockError] = usePollCurrentBlock(viewer, interval);
567
+ const value = useMemo(() => ({
568
+ block: currentBlock,
569
+ blockNumber: currentBlock?.[0].block,
570
+ chain: currentBlock?.[0].chain,
571
+ error: currentBlockError,
572
+ pollingConfig,
573
+ provided: true
574
+ }), [
575
+ currentBlock,
576
+ currentBlockError,
577
+ pollingConfig
578
+ ]);
579
+ return /* @__PURE__ */ React2.createElement(XL1CurrentBlockContext, {
580
+ value
581
+ }, children);
582
+ }, "XL1CurrentBlockProvider");
583
+
584
+ // src/contexts/current-block/use.ts
585
+ import { useContextEx } from "@xylabs/react-shared";
586
+ var useXl1CurrentBlockContext = /* @__PURE__ */ __name((required = true) => useContextEx(XL1CurrentBlockContext, "XL1CurrentBlock", required), "useXl1CurrentBlockContext");
587
+
588
+ // src/contexts/gateway/context.ts
589
+ import { createContextEx as createContextEx2 } from "@xylabs/react-shared";
590
+ var GatewayContext = createContextEx2();
591
+
592
+ // src/contexts/gateway/Provider.tsx
593
+ import { isDefinedNotNull as isDefinedNotNull3, isNull as isNull4 } from "@xylabs/sdk-js";
594
+ import React3, { useEffect as useEffect3, useMemo as useMemo2, useState as useState3 } from "react";
595
+ var GatewayProvider = /* @__PURE__ */ __name(({ account, gatewayName, children }) => {
596
+ const [defaultGateway, setDefaultGateway] = useState3();
597
+ const [gateways, setGateways] = useState3({
598
+ inPageGateway: void 0,
599
+ walletGateway: void 0
600
+ });
601
+ const { gateway: gatewayFromWallet, error: gatewayFromWalletError } = useGatewayFromWallet(gatewayName);
602
+ const { gateway: gatewayFromConfig, error: gatewayFromConfigError, clearGateways: clearGatewaysFromConfig } = useGatewayFromConfig(gatewayName, account);
603
+ useEffect3(() => {
604
+ if (isNull4(gatewayFromWallet)) {
605
+ setDefaultGateway(gatewayFromConfig);
606
+ setGateways({
607
+ inPageGateway: gatewayFromConfig,
608
+ walletGateway: null
609
+ });
610
+ } else if (isDefinedNotNull3(gatewayFromWallet)) {
611
+ setDefaultGateway(gatewayFromWallet);
612
+ setGateways({
613
+ inPageGateway: gatewayFromConfig,
614
+ walletGateway: gatewayFromWallet
615
+ });
616
+ }
617
+ }, [
618
+ gatewayFromConfig,
619
+ gatewayFromWallet
620
+ ]);
621
+ const value = useMemo2(() => {
622
+ const value2 = {
623
+ defaultGateway,
624
+ error: gatewayFromWalletError || gatewayFromConfigError,
625
+ gateways,
626
+ provided: true,
627
+ resetGatewaysFromConfig: clearGatewaysFromConfig
628
+ };
629
+ return value2;
630
+ }, [
631
+ defaultGateway,
632
+ gatewayFromWalletError,
633
+ gatewayFromConfigError,
634
+ gateways,
635
+ clearGatewaysFromConfig
636
+ ]);
637
+ return /* @__PURE__ */ React3.createElement(GatewayContext, {
638
+ value
639
+ }, children);
640
+ }, "GatewayProvider");
641
+
642
+ // src/contexts/gateway/use.ts
643
+ import { useContextEx as useContextEx2 } from "@xylabs/react-shared";
644
+ var useProvidedGateway = /* @__PURE__ */ __name((required = true) => useContextEx2(GatewayContext, "Gateway", required), "useProvidedGateway");
645
+
646
+ // src/hooks/gateway/useNetwork.ts
647
+ var useNetworkFromGateway = /* @__PURE__ */ __name(() => {
648
+ const { defaultGateway } = useProvidedGateway();
649
+ return defaultGateway?.connection?.network;
650
+ }, "useNetworkFromGateway");
651
+
652
+ // src/hooks/gateway/useRunner.ts
653
+ var useRunnerFromGateway = /* @__PURE__ */ __name(() => {
654
+ const { defaultGateway } = useProvidedGateway();
655
+ return defaultGateway?.connection?.runner;
656
+ }, "useRunnerFromGateway");
657
+
658
+ // src/hooks/gateway/useViewer.ts
659
+ var useViewerFromGateway = /* @__PURE__ */ __name(() => {
660
+ const { defaultGateway } = useProvidedGateway();
661
+ return defaultGateway?.connection?.viewer;
662
+ }, "useViewerFromGateway");
437
663
 
438
664
  // src/hooks/useAddressBalance.ts
439
- import { usePromise as usePromise3 } from "@xylabs/react-promise";
440
- import { isUndefined as isUndefined3, isUndefinedOrNull } from "@xylabs/sdk-js";
665
+ import { usePromise as usePromise4 } from "@xylabs/react-promise";
666
+ import { isUndefined as isUndefined3, isUndefinedOrNull as isUndefinedOrNull2 } from "@xylabs/sdk-js";
441
667
  import { ShiftedBigInt } from "@xyo-network/xl1-sdk";
442
- import { useMemo, useRef, useState } from "react";
668
+ import { useMemo as useMemo3, useRef, useState as useState4 } from "react";
443
669
  var useAddressBalance = /* @__PURE__ */ __name((address, viewer, refresh) => {
444
- const [balancesResult, setBalancesResult] = useState();
445
- const [loading, setLoading] = useState(false);
446
- const [balancesError, setBalancesError] = useState();
670
+ const [balancesResult, setBalancesResult] = useState4();
671
+ const [loading, setLoading] = useState4(false);
672
+ const [balancesError, setBalancesError] = useState4();
447
673
  const balancePromiseRef = useRef(null);
448
- usePromise3(async () => {
674
+ usePromise4(async () => {
449
675
  if (isUndefined3(viewer) || isUndefined3(address)) return;
450
676
  setLoading(true);
451
677
  setBalancesError(void 0);
@@ -470,14 +696,14 @@ var useAddressBalance = /* @__PURE__ */ __name((address, viewer, refresh) => {
470
696
  viewer,
471
697
  refresh
472
698
  ]);
473
- useMemo(() => {
699
+ useMemo3(() => {
474
700
  if (balancesError) {
475
701
  setLoading(false);
476
702
  }
477
703
  }, [
478
704
  balancesError
479
705
  ]);
480
- const shiftedBigInt = useMemo(() => {
706
+ const shiftedBigInt = useMemo3(() => {
481
707
  if (typeof balancesResult !== "bigint") return;
482
708
  return new ShiftedBigInt(balancesResult, {
483
709
  places: 18,
@@ -489,13 +715,13 @@ var useAddressBalance = /* @__PURE__ */ __name((address, viewer, refresh) => {
489
715
  }, [
490
716
  balancesResult
491
717
  ]);
492
- const balanceIntlFriendly = useMemo(() => {
718
+ const balanceIntlFriendly = useMemo3(() => {
493
719
  return shiftedBigInt?.toFullString();
494
720
  }, [
495
721
  shiftedBigInt
496
722
  ]);
497
- const shortBalanceIntlFriendly = useMemo(() => {
498
- return isUndefinedOrNull(balancesResult) ? void 0 : balancesResult < 1000000000000n && balancesResult > 0n ? "<0.00001" : shiftedBigInt?.toShortString();
723
+ const shortBalanceIntlFriendly = useMemo3(() => {
724
+ return isUndefinedOrNull2(balancesResult) ? void 0 : balancesResult < 1000000000000n && balancesResult > 0n ? "<0.00001" : shiftedBigInt?.toShortString();
499
725
  }, [
500
726
  balancesResult,
501
727
  shiftedBigInt
@@ -511,22 +737,22 @@ var useAddressBalance = /* @__PURE__ */ __name((address, viewer, refresh) => {
511
737
  }, "useAddressBalance");
512
738
 
513
739
  // src/hooks/useConfirmTransactionBase.ts
514
- import { usePromise as usePromise4 } from "@xylabs/react-promise";
515
- import { forget as forget2, isDefined as isDefined5, isHash } from "@xylabs/sdk-js";
740
+ import { usePromise as usePromise5 } from "@xylabs/react-promise";
741
+ import { forget as forget2, isDefined as isDefined7, isHash } from "@xylabs/sdk-js";
516
742
  import { PayloadBuilder } from "@xyo-network/sdk-js";
517
- import { useEffect as useEffect2, useState as useState2 } from "react";
743
+ import { useEffect as useEffect4, useState as useState5 } from "react";
518
744
  var useConfirmTransactionBase = /* @__PURE__ */ __name((transaction, onBroadcast, onStatusUpdate, runner, viewer) => {
519
- const [status, setStatus] = useState2();
745
+ const [status, setStatus] = useState5();
520
746
  const onStatusUpdateLocal = /* @__PURE__ */ __name((newStatus) => {
521
747
  setStatus(newStatus);
522
748
  onStatusUpdate?.(newStatus);
523
749
  }, "onStatusUpdateLocal");
524
- const [transactionConfirmationStatus, transactionConfirmationError] = usePromise4(async () => {
525
- const hasRunner = isDefined5(runner);
750
+ const [transactionConfirmationStatus, transactionConfirmationError] = usePromise5(async () => {
751
+ const hasRunner = isDefined7(runner);
526
752
  if (transaction && viewer) {
527
753
  const hash = hasRunner ? await runner.broadcastTransaction(transaction) : await PayloadBuilder.hash(transaction[0]);
528
754
  if (isHash(hash)) {
529
- if (hasRunner && isDefined5(onBroadcast)) onBroadcast(hash);
755
+ if (hasRunner && isDefined7(onBroadcast)) onBroadcast(hash);
530
756
  const params = {
531
757
  onStatusUpdate: onStatusUpdateLocal,
532
758
  transaction,
@@ -545,7 +771,7 @@ var useConfirmTransactionBase = /* @__PURE__ */ __name((transaction, onBroadcast
545
771
  runner,
546
772
  viewer
547
773
  ]);
548
- useEffect2(() => {
774
+ useEffect4(() => {
549
775
  return () => {
550
776
  if (transactionConfirmationStatus) {
551
777
  forget2(transactionConfirmationStatus.stop());
@@ -562,18 +788,18 @@ var useConfirmTransactionBase = /* @__PURE__ */ __name((transaction, onBroadcast
562
788
 
563
789
  // src/hooks/useConnectAccount.ts
564
790
  import { asAddress } from "@xylabs/sdk-js";
565
- import { assertEx as assertEx2 } from "@xylabs/sdk-js";
791
+ import { assertEx as assertEx3 } from "@xylabs/sdk-js";
566
792
  import { MainNetwork } from "@xyo-network/xl1-sdk";
567
- import { useCallback as useCallback2, useState as useState3 } from "react";
793
+ import { useCallback as useCallback2, useState as useState6 } from "react";
568
794
  var useConnectAccount = /* @__PURE__ */ __name((gatewayName = MainNetwork.id, timeout) => {
569
- const [connectError, setConnectError] = useState3();
570
- const { gateway, error, timedout } = useGateway(gatewayName, timeout);
795
+ const [connectError, setConnectError] = useState6();
796
+ const { gateway, error, timedout } = useGatewayFromWallet(gatewayName, timeout);
571
797
  const [accountPermissions, accountPermissionsError] = useAccountPermissions();
572
- const [address, setAddress] = useState3();
798
+ const [address, setAddress] = useState6();
573
799
  const connectSigner = useCallback2(async () => {
574
800
  try {
575
801
  setConnectError(void 0);
576
- const assertedGateway = assertEx2(gateway, () => `Gateway ${gatewayName} is not available`);
802
+ const assertedGateway = assertEx3(gateway, () => `Gateway ${gatewayName} is not available`);
577
803
  const signer = assertedGateway.signer;
578
804
  const address2 = await signer.address();
579
805
  setAddress(address2);
@@ -595,11 +821,11 @@ var useConnectAccount = /* @__PURE__ */ __name((gatewayName = MainNetwork.id, ti
595
821
  }, "useConnectAccount");
596
822
 
597
823
  // src/hooks/useCurrentBlock.ts
598
- import { usePromise as usePromise5 } from "@xylabs/react-promise";
599
- import { isDefinedNotNull as isDefinedNotNull2 } from "@xylabs/sdk-js";
824
+ import { usePromise as usePromise6 } from "@xylabs/react-promise";
825
+ import { isDefinedNotNull as isDefinedNotNull4 } from "@xylabs/sdk-js";
600
826
  var useCurrentBlock = /* @__PURE__ */ __name((refresh = 1, viewer) => {
601
- return usePromise5(async () => {
602
- if (isDefinedNotNull2(viewer) && refresh > 0) {
827
+ return usePromise6(async () => {
828
+ if (isDefinedNotNull4(viewer) && refresh > 0) {
603
829
  const block = await viewer.currentBlock();
604
830
  return block;
605
831
  }
@@ -608,13 +834,25 @@ var useCurrentBlock = /* @__PURE__ */ __name((refresh = 1, viewer) => {
608
834
  refresh
609
835
  ]);
610
836
  }, "useCurrentBlock");
837
+ var useCurrentBlockFromGateway = /* @__PURE__ */ __name((refresh = 1) => {
838
+ const viewer = useViewerFromGateway();
839
+ return usePromise6(async () => {
840
+ if (isDefinedNotNull4(viewer) && refresh > 0) {
841
+ const block = await viewer.currentBlock();
842
+ return block;
843
+ }
844
+ }, [
845
+ viewer,
846
+ refresh
847
+ ]);
848
+ }, "useCurrentBlockFromGateway");
611
849
 
612
850
  // src/hooks/useHttpRpcRunner.ts
613
- import { usePromise as usePromise6 } from "@xylabs/react-promise";
851
+ import { usePromise as usePromise7 } from "@xylabs/react-promise";
614
852
  import { isUndefined as isUndefined4 } from "@xylabs/sdk-js";
615
853
  import { AccountBalanceViewerRpcSchemas, buildJsonRpcProviderLocator, HttpRpcTransport, JsonRpcAccountBalanceViewer, SimpleTransactionViewer, XyoRunnerMoniker } from "@xyo-network/xl1-sdk";
616
854
  var useHttpRpcRunner = /* @__PURE__ */ __name((url) => {
617
- return usePromise6(async () => {
855
+ return usePromise7(async () => {
618
856
  if (isUndefined4(url)) {
619
857
  return;
620
858
  }
@@ -635,9 +873,9 @@ var useHttpRpcRunner = /* @__PURE__ */ __name((url) => {
635
873
  // src/hooks/useNetwork.ts
636
874
  import { isUndefined as isUndefined5 } from "@xylabs/sdk-js";
637
875
  import { SimpleXyoNetwork } from "@xyo-network/xl1-sdk";
638
- import { useMemo as useMemo2 } from "react";
876
+ import { useMemo as useMemo4 } from "react";
639
877
  var useNetwork = /* @__PURE__ */ __name((id) => {
640
- const network = useMemo2(() => {
878
+ const network = useMemo4(() => {
641
879
  if (isUndefined5(id)) return;
642
880
  return new SimpleXyoNetwork(id);
643
881
  }, [
@@ -647,10 +885,10 @@ var useNetwork = /* @__PURE__ */ __name((id) => {
647
885
  }, "useNetwork");
648
886
 
649
887
  // src/hooks/useSigner.ts
650
- import { usePromise as usePromise7 } from "@xylabs/react-promise";
888
+ import { usePromise as usePromise8 } from "@xylabs/react-promise";
651
889
  import { SimpleXyoSigner } from "@xyo-network/xl1-sdk";
652
890
  var useSigner = /* @__PURE__ */ __name((_provider, account) => {
653
- return usePromise7(async () => account ? await SimpleXyoSigner.create({
891
+ return usePromise8(async () => account ? await SimpleXyoSigner.create({
654
892
  account
655
893
  }) : void 0, [
656
894
  account
@@ -658,10 +896,11 @@ var useSigner = /* @__PURE__ */ __name((_provider, account) => {
658
896
  }, "useSigner");
659
897
 
660
898
  // src/hooks/viewer/useCheckRpc.ts
661
- import { usePromise as usePromise8 } from "@xylabs/react-promise";
662
- import { delay as delay2, isDefined as isDefined6, isUndefined as isUndefined6 } from "@xylabs/sdk-js";
663
- import { AccountBalanceViewerRpcSchemas as AccountBalanceViewerRpcSchemas2, buildJsonRpcProviderLocator as buildJsonRpcProviderLocator2, HttpRpcTransport as HttpRpcTransport2, JsonRpcAccountBalanceViewer as JsonRpcAccountBalanceViewer2, LocalNetwork, SequenceNetwork, SimpleTransactionViewer as SimpleTransactionViewer2, XyoViewerMoniker } from "@xyo-network/xl1-sdk";
664
- import { useEffect as useEffect3, useState as useState4 } from "react";
899
+ import { usePromise as usePromise9 } from "@xylabs/react-promise";
900
+ import { delay as delay2, isDefined as isDefined8, isUndefined as isUndefined6 } from "@xylabs/sdk-js";
901
+ import { basicRemoteViewerLocator as basicRemoteViewerLocator2 } from "@xyo-network/chain-orchestration";
902
+ import { LocalNetwork, SequenceNetwork, XyoViewerMoniker } from "@xyo-network/xl1-sdk";
903
+ import { useEffect as useEffect5, useState as useState7 } from "react";
665
904
  var INTERVAL = 5e3;
666
905
  var localRpcEndpoint = `${LocalNetwork.url}/rpc`;
667
906
  var sequenceRpcEndpoint = `${SequenceNetwork.url}/rpc`;
@@ -670,35 +909,33 @@ var useCheckLocalRpc = /* @__PURE__ */ __name(() => {
670
909
  return isLocalProducer;
671
910
  }, "useCheckLocalRpc");
672
911
  var useCheckSequenceRpc = /* @__PURE__ */ __name(() => {
673
- const isLocalProducer = useCheckRpc(sequenceRpcEndpoint);
674
- return isLocalProducer;
912
+ const isSequenceRpc = useCheckRpc(sequenceRpcEndpoint);
913
+ return isSequenceRpc;
675
914
  }, "useCheckSequenceRpc");
676
915
  var useCheckRpc = /* @__PURE__ */ __name((endpoint) => {
677
- const [isLocalProducer, setIsLocalProducer] = useState4(false);
678
- const [error, setError] = useState4();
679
- const [viewer] = usePromise8(async () => {
916
+ const [isLocalProducer, setIsLocalProducer] = useState7(false);
917
+ const [error, setError] = useState7();
918
+ const [viewer] = usePromise9(async () => {
680
919
  if (isUndefined6(endpoint)) return;
681
- const transportFactory = /* @__PURE__ */ __name((schemas) => new HttpRpcTransport2(endpoint, schemas), "transportFactory");
682
- const locator = await buildJsonRpcProviderLocator2({
683
- transportFactory
920
+ const locator = await basicRemoteViewerLocator2(endpoint, {
921
+ rpc: {
922
+ protocol: "http",
923
+ url: endpoint
924
+ }
684
925
  });
685
- locator.register(SimpleTransactionViewer2.factory(SimpleTransactionViewer2.dependencies, {}));
686
- locator.register(JsonRpcAccountBalanceViewer2.factory(JsonRpcAccountBalanceViewer2.dependencies, {
687
- transport: await transportFactory(AccountBalanceViewerRpcSchemas2)
688
- }));
689
926
  const viewer2 = await locator.getInstance(XyoViewerMoniker);
690
927
  return viewer2;
691
928
  }, [
692
929
  endpoint
693
930
  ]);
694
- useEffect3(() => {
931
+ useEffect5(() => {
695
932
  if (isUndefined6(viewer)) return;
696
933
  void (async () => {
697
934
  setError(void 0);
698
935
  while (!isLocalProducer) {
699
936
  try {
700
937
  const block = await viewer.currentBlock();
701
- setIsLocalProducer(isDefined6(block));
938
+ setIsLocalProducer(isDefined8(block));
702
939
  } catch (err) {
703
940
  setError(err);
704
941
  setIsLocalProducer(false);
@@ -717,12 +954,12 @@ var useCheckRpc = /* @__PURE__ */ __name((endpoint) => {
717
954
  }, "useCheckRpc");
718
955
 
719
956
  // src/hooks/viewer/useHttpRpcViewer.ts
720
- import { usePromise as usePromise9 } from "@xylabs/react-promise";
721
- import { isDefined as isDefined7, isString as isString2, isUndefined as isUndefined7 } from "@xylabs/sdk-js";
722
- import { AccountBalanceViewerRpcSchemas as AccountBalanceViewerRpcSchemas3, buildJsonRpcProviderLocator as buildJsonRpcProviderLocator3, HttpRpcTransport as HttpRpcTransport3, JsonRpcAccountBalanceViewer as JsonRpcAccountBalanceViewer3, JsonRpcXyoViewer as JsonRpcXyoViewer2, NetworkDataLakeUrls, RestDataLakeViewer, SimpleTransactionViewer as SimpleTransactionViewer3, XyoViewerMoniker as XyoViewerMoniker2, XyoViewerRpcSchemas } from "@xyo-network/xl1-sdk";
957
+ import { usePromise as usePromise10 } from "@xylabs/react-promise";
958
+ import { isDefined as isDefined9, isString as isString2, isUndefined as isUndefined7 } from "@xylabs/sdk-js";
959
+ import { AccountBalanceViewerRpcSchemas as AccountBalanceViewerRpcSchemas2, buildJsonRpcProviderLocator as buildJsonRpcProviderLocator2, HttpRpcTransport as HttpRpcTransport2, JsonRpcAccountBalanceViewer as JsonRpcAccountBalanceViewer2, JsonRpcXyoViewer as JsonRpcXyoViewer2, NetworkDataLakeUrls as NetworkDataLakeUrls2, RestDataLakeViewer, SimpleTransactionViewer as SimpleTransactionViewer2, XyoViewerMoniker as XyoViewerMoniker2, XyoViewerRpcSchemas } from "@xyo-network/xl1-sdk";
723
960
 
724
961
  // src/hooks/viewer/ViewerWithDataLake.ts
725
- import { isNull as isNull4 } from "@xylabs/sdk-js";
962
+ import { isNull as isNull5 } from "@xylabs/sdk-js";
726
963
  import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/sdk-js";
727
964
  import { addDataLakePayloads, addDataLakePayloadsToPayloads, DataLakeViewerMoniker, JsonRpcXyoViewer } from "@xyo-network/xl1-sdk";
728
965
  var ViewerWithDataLake = class extends JsonRpcXyoViewer {
@@ -752,7 +989,7 @@ var ViewerWithDataLake = class extends JsonRpcXyoViewer {
752
989
  await PayloadBuilder2.addHashMeta(transaction[0]),
753
990
  await PayloadBuilder2.addHashMeta(transaction[1])
754
991
  ] : null;
755
- return isNull4(transaction) ? transaction : (await addDataLakePayloads([
992
+ return isNull5(transaction) ? transaction : (await addDataLakePayloads([
756
993
  await PayloadBuilder2.addHashMeta(transaction[0]),
757
994
  await PayloadBuilder2.addHashMeta(transaction[1])
758
995
  ], this.dataLakeViewer))[0];
@@ -765,11 +1002,11 @@ var buildLocatorParams = /* @__PURE__ */ __name((urlOrNetwork) => {
765
1002
  let dataLakeViewerParams;
766
1003
  if (isString2(urlOrNetwork)) {
767
1004
  const url = urlOrNetwork;
768
- transportFactory = /* @__PURE__ */ __name((schemas) => new HttpRpcTransport3(`${url}/rpc`, schemas), "transportFactory");
1005
+ transportFactory = /* @__PURE__ */ __name((schemas) => new HttpRpcTransport2(`${url}/rpc`, schemas), "transportFactory");
769
1006
  } else {
770
- transportFactory = /* @__PURE__ */ __name((schemas) => new HttpRpcTransport3(`${urlOrNetwork.url}/rpc`, schemas), "transportFactory");
1007
+ transportFactory = /* @__PURE__ */ __name((schemas) => new HttpRpcTransport2(`${urlOrNetwork.url}/rpc`, schemas), "transportFactory");
771
1008
  dataLakeViewerParams = {
772
- endpoint: NetworkDataLakeUrls[urlOrNetwork.id]
1009
+ endpoint: NetworkDataLakeUrls2[urlOrNetwork.id]
773
1010
  };
774
1011
  }
775
1012
  return {
@@ -778,14 +1015,14 @@ var buildLocatorParams = /* @__PURE__ */ __name((urlOrNetwork) => {
778
1015
  };
779
1016
  }, "buildLocatorParams");
780
1017
  var buildLocator = /* @__PURE__ */ __name(async (transportFactory, dataLakeViewerParams) => {
781
- const locator = await buildJsonRpcProviderLocator3({
1018
+ const locator = await buildJsonRpcProviderLocator2({
782
1019
  transportFactory
783
1020
  });
784
- locator.register(JsonRpcAccountBalanceViewer3.factory(JsonRpcAccountBalanceViewer3.dependencies, {
785
- transport: await transportFactory(AccountBalanceViewerRpcSchemas3)
1021
+ locator.register(JsonRpcAccountBalanceViewer2.factory(JsonRpcAccountBalanceViewer2.dependencies, {
1022
+ transport: await transportFactory(AccountBalanceViewerRpcSchemas2)
786
1023
  }));
787
- locator.register(SimpleTransactionViewer3.factory(SimpleTransactionViewer3.dependencies, {}));
788
- if (isDefined7(dataLakeViewerParams)) {
1024
+ locator.register(SimpleTransactionViewer2.factory(SimpleTransactionViewer2.dependencies, {}));
1025
+ if (isDefined9(dataLakeViewerParams)) {
789
1026
  locator.register(RestDataLakeViewer.factory(RestDataLakeViewer.dependencies, dataLakeViewerParams));
790
1027
  }
791
1028
  locator.register(ViewerWithDataLake.factory(JsonRpcXyoViewer2.dependencies, {
@@ -794,7 +1031,7 @@ var buildLocator = /* @__PURE__ */ __name(async (transportFactory, dataLakeViewe
794
1031
  return locator;
795
1032
  }, "buildLocator");
796
1033
  var useHttpRpcViewer = /* @__PURE__ */ __name((urlOrNetwork) => {
797
- const [resolvedViewer] = usePromise9(async () => {
1034
+ const [resolvedViewer] = usePromise10(async () => {
798
1035
  if (isUndefined7(urlOrNetwork)) {
799
1036
  return;
800
1037
  }
@@ -808,16 +1045,16 @@ var useHttpRpcViewer = /* @__PURE__ */ __name((urlOrNetwork) => {
808
1045
  }, "useHttpRpcViewer");
809
1046
 
810
1047
  // src/hooks/viewer/useViewerFromWallet.ts
811
- import { usePromise as usePromise10 } from "@xylabs/react-promise";
812
- import { isDefined as isDefined8, isDefinedNotNull as isDefinedNotNull3, isNull as isNull5 } from "@xylabs/sdk-js";
1048
+ import { usePromise as usePromise11 } from "@xylabs/react-promise";
1049
+ import { isDefined as isDefined10, isDefinedNotNull as isDefinedNotNull5, isNull as isNull6 } from "@xylabs/sdk-js";
813
1050
  var useViewerFromWallet = /* @__PURE__ */ __name((networkId, timeout) => {
814
- const { gateway, error, isLoading, timedout } = useGateway(networkId, timeout);
815
- const result = usePromise10(async () => {
1051
+ const { gateway, error, isLoading, timedout } = useGatewayFromWallet(networkId, timeout);
1052
+ const result = usePromise11(async () => {
816
1053
  await Promise.resolve();
817
- if (isDefinedNotNull3(error)) return null;
818
- if (timedout && isNull5(gateway)) return null;
1054
+ if (isDefinedNotNull5(error)) return null;
1055
+ if (timedout && isNull6(gateway)) return null;
819
1056
  if (isLoading) return;
820
- if (isDefined8(gateway) && isDefined8(networkId)) {
1057
+ if (isDefined10(gateway) && isDefined10(networkId)) {
821
1058
  const connection = gateway?.connection;
822
1059
  return connection?.viewer;
823
1060
  }
@@ -830,16 +1067,16 @@ var useViewerFromWallet = /* @__PURE__ */ __name((networkId, timeout) => {
830
1067
  }, "useViewerFromWallet");
831
1068
 
832
1069
  // src/components/connected/ConnectAccountsStack.tsx
833
- var DefaultConnectComponent = /* @__PURE__ */ __name((props) => /* @__PURE__ */ React2.createElement(ButtonEx, {
1070
+ var DefaultConnectComponent = /* @__PURE__ */ __name((props) => /* @__PURE__ */ React4.createElement(ButtonEx, {
834
1071
  variant: "contained",
835
1072
  size: "small",
836
1073
  ...props
837
1074
  }), "DefaultConnectComponent");
838
- var DefaultNoWalletInstalledComponent = /* @__PURE__ */ __name(() => /* @__PURE__ */ React2.createElement(Alert, {
1075
+ var DefaultNoWalletInstalledComponent = /* @__PURE__ */ __name(() => /* @__PURE__ */ React4.createElement(Alert, {
839
1076
  severity: "warning"
840
- }, /* @__PURE__ */ React2.createElement(AlertTitle, null, "XL1 Wallet Not Found"), /* @__PURE__ */ React2.createElement(Typography2, {
1077
+ }, /* @__PURE__ */ React4.createElement(AlertTitle, null, "XL1 Wallet Not Found"), /* @__PURE__ */ React4.createElement(Typography2, {
841
1078
  gutterBottom: true
842
- }, "Please ensure that your XL1 Wallet is installed to connect your account."), /* @__PURE__ */ React2.createElement(Button, {
1079
+ }, "Please ensure that your XL1 Wallet is installed to connect your account."), /* @__PURE__ */ React4.createElement(Button, {
843
1080
  sx: {
844
1081
  display: "flex",
845
1082
  justifySelf: "end"
@@ -852,131 +1089,42 @@ var DefaultNoWalletInstalledComponent = /* @__PURE__ */ __name(() => /* @__PURE_
852
1089
  }, "Get XL1 Wallet")), "DefaultNoWalletInstalledComponent");
853
1090
  var ConnectAccountsStack = /* @__PURE__ */ __name(({ AccountComponent = ConnectedAccount, ConnectComponent = DefaultConnectComponent, NoWalletInstalledComponent = DefaultNoWalletInstalledComponent, onAccountConnected, onCancel, timeout, ...props }) => {
854
1091
  const { address, connectSigner, error, timedout } = useConnectAccount(void 0, timeout);
855
- useEffect4(() => {
856
- if (isDefined9(error) && isDefined9(onCancel)) {
1092
+ useEffect6(() => {
1093
+ if (isDefined11(error) && isDefined11(onCancel)) {
857
1094
  onCancel();
858
1095
  }
859
1096
  }, [
860
1097
  error,
861
1098
  onCancel
862
1099
  ]);
863
- useEffect4(() => {
864
- if (isDefined9(address) && isDefined9(onAccountConnected)) {
1100
+ useEffect6(() => {
1101
+ if (isDefined11(address) && isDefined11(onAccountConnected)) {
865
1102
  onAccountConnected(address);
866
1103
  }
867
1104
  }, [
868
1105
  address,
869
1106
  onAccountConnected
870
1107
  ]);
871
- return /* @__PURE__ */ React2.createElement(Stack2, {
1108
+ return /* @__PURE__ */ React4.createElement(Stack2, {
872
1109
  direction: "row",
873
1110
  alignItems: "start",
874
1111
  spacing: 2,
875
1112
  ...props
876
- }, isDefined9(address) ? /* @__PURE__ */ React2.createElement(AccountComponent, {
1113
+ }, isDefined11(address) ? /* @__PURE__ */ React4.createElement(AccountComponent, {
877
1114
  address
878
- }) : null, isUndefined8(address) && !timedout ? /* @__PURE__ */ React2.createElement(ConnectComponent, {
1115
+ }) : null, isUndefined8(address) && !timedout ? /* @__PURE__ */ React4.createElement(ConnectComponent, {
879
1116
  onClick: /* @__PURE__ */ __name(() => void connectSigner(), "onClick")
880
- }, "Connect") : null, isUndefined8(address) && timedout ? /* @__PURE__ */ React2.createElement(NoWalletInstalledComponent, null) : null, /* @__PURE__ */ React2.createElement(ErrorRender, {
1117
+ }, "Connect") : null, isUndefined8(address) && timedout ? /* @__PURE__ */ React4.createElement(NoWalletInstalledComponent, null) : null, /* @__PURE__ */ React4.createElement(ErrorRender, {
881
1118
  error,
882
1119
  scope: "ConnectSigner:error"
883
1120
  }));
884
1121
  }, "ConnectAccountsStack");
885
-
886
- // src/contexts/current-block/context.ts
887
- import { createContextEx } from "@xylabs/react-shared";
888
- var XL1CurrentBlockContext = createContextEx();
889
-
890
- // src/contexts/current-block/Provider.tsx
891
- import React3, { useMemo as useMemo3 } from "react";
892
-
893
- // src/contexts/current-block/usePollCurrentBlock.ts
894
- import { isDefinedNotNull as isDefinedNotNull4, isUndefinedOrNull as isUndefinedOrNull2 } from "@xylabs/sdk-js";
895
- import { startTransition, useEffect as useEffect5, useState as useState5 } from "react";
896
- var DEFAULT_POLL_INTERVAL = 1e4;
897
- var usePollCurrentBlock = /* @__PURE__ */ __name((viewer, interval = DEFAULT_POLL_INTERVAL, pause = false) => {
898
- const [currentBlock, setCurrentBlock] = useState5(null);
899
- const [error, setError] = useState5();
900
- useEffect5(() => {
901
- let isMounted = true;
902
- const fetchBlock = /* @__PURE__ */ __name(async () => {
903
- if (isDefinedNotNull4(viewer)) {
904
- try {
905
- const block = await viewer.currentBlock();
906
- if (isMounted) {
907
- startTransition(() => {
908
- setCurrentBlock((existingBlock) => {
909
- if (isUndefinedOrNull2(existingBlock)) {
910
- return block;
911
- }
912
- if (isDefinedNotNull4(block) && existingBlock?.[0].block !== block[0].block) {
913
- return block;
914
- }
915
- return existingBlock;
916
- });
917
- });
918
- }
919
- } catch (err) {
920
- startTransition(() => {
921
- setError(err);
922
- });
923
- }
924
- }
925
- }, "fetchBlock");
926
- void fetchBlock();
927
- const id = setInterval(() => {
928
- if (!pause) {
929
- void fetchBlock();
930
- }
931
- }, interval);
932
- return () => {
933
- isMounted = false;
934
- clearInterval(id);
935
- };
936
- }, [
937
- viewer,
938
- interval,
939
- pause
940
- ]);
941
- return [
942
- currentBlock,
943
- error
944
- ];
945
- }, "usePollCurrentBlock");
946
-
947
- // src/contexts/current-block/Provider.tsx
948
- var DEFAULT_POLLING_INTERVAL = 1e4;
949
- var XL1CurrentBlockProvider = /* @__PURE__ */ __name(({ pollingConfig, viewer, children }) => {
950
- const { interval } = useMemo3(() => pollingConfig || {
951
- interval: DEFAULT_POLLING_INTERVAL
952
- }, [
953
- pollingConfig
954
- ]);
955
- const [currentBlock, currentBlockError] = usePollCurrentBlock(viewer, interval);
956
- const value = useMemo3(() => ({
957
- block: currentBlock,
958
- blockNumber: currentBlock?.[0].block,
959
- chain: currentBlock?.[0].chain,
960
- error: currentBlockError,
961
- pollingConfig,
962
- provided: true
963
- }), [
964
- currentBlock,
965
- currentBlockError,
966
- pollingConfig
967
- ]);
968
- return /* @__PURE__ */ React3.createElement(XL1CurrentBlockContext, {
969
- value
970
- }, children);
971
- }, "XL1CurrentBlockProvider");
972
-
973
- // src/contexts/current-block/use.ts
974
- import { useContextEx } from "@xylabs/react-shared";
975
- var useXl1CurrentBlockContext = /* @__PURE__ */ __name((required = true) => useContextEx(XL1CurrentBlockContext, "XL1CurrentBlock", required), "useXl1CurrentBlockContext");
976
1122
  export {
977
1123
  ConnectAccountsStack,
978
1124
  ConnectedAccount,
979
1125
  DEFAULT_POLLING_INTERVAL,
1126
+ GatewayContext,
1127
+ GatewayProvider,
980
1128
  TransactionConfirmationStatus,
981
1129
  ViewerWithDataLake,
982
1130
  XL1CurrentBlockContext,
@@ -993,16 +1141,24 @@ export {
993
1141
  useCheckRpc,
994
1142
  useCheckSequenceRpc,
995
1143
  useClient,
1144
+ useClientFromWallet,
996
1145
  useConfirmTransactionBase,
997
1146
  useConnectAccount,
998
1147
  useCurrentBlock,
1148
+ useCurrentBlockFromGateway,
999
1149
  useGateway,
1150
+ useGatewayFromConfig,
1151
+ useGatewayFromWallet,
1000
1152
  useHttpRpcRunner,
1001
1153
  useHttpRpcViewer,
1002
1154
  useNetwork,
1155
+ useNetworkFromGateway,
1003
1156
  usePermissions,
1004
1157
  usePollCurrentBlock,
1158
+ useProvidedGateway,
1159
+ useRunnerFromGateway,
1005
1160
  useSigner,
1161
+ useViewerFromGateway,
1006
1162
  useViewerFromWallet,
1007
1163
  useXl1CurrentBlockContext
1008
1164
  };