@xyo-network/xl1-react-client-sdk 5.7.1 → 5.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -76,7 +76,10 @@ For read-only dApps that should work before wallet connection, mount
76
76
  `transport="rest"`, the in-page provider launches one page-owned
77
77
  `@xyo-network/xl1-browser-system` session per network and stops those sessions
78
78
  on React cleanup or `pagehide`; wallet gateways still take precedence when
79
- connected.
79
+ connected. If a network's session fails to launch (for example its endpoint
80
+ is briefly unavailable), `GatewayProvider` retries that network alone with
81
+ exponential backoff (1s doubling up to 30s) until it launches, so the page
82
+ recovers without a reload.
80
83
 
81
84
  Wallet discovery is bounded platform activity. `listenForClientInjection`
82
85
  returns an idempotent disposer and removes its listener and timeout before a
@@ -19,6 +19,12 @@ export interface InPageGatewaysStateFields {
19
19
  errors: Partial<Record<GatewayName, Error>>;
20
20
  /** Gateway providers available to the client. */
21
21
  gateways: Partial<Record<GatewayName, ContextGatewayType>>;
22
+ /**
23
+ * Relaunches one network whose launch failed, leaving the others running.
24
+ * A no-op while that network has a running system or a launch in flight.
25
+ * Optional so hand-built context values (mocks, stories) stay valid.
26
+ */
27
+ retry?: (gatewayName: GatewayName) => void;
22
28
  }
23
29
  /** State exposed by the In Page Gateways React context. */
24
30
  export type InPageGatewaysState = ContextExState<InPageGatewaysStateFields>;
@@ -1 +1 @@
1
- {"version":3,"file":"InPageGatewaysState.d.ts","sourceRoot":"","sources":["../../../../../src/client/context/in-page/InPageGatewaysState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAEvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAE9D;;;;;;;;;;GAUG;AACH,MAAM,WAAW,yBAAyB;IACxC,yDAAyD;IACzD,QAAQ,EAAE,MAAM,IAAI,CAAA;IACpB,6DAA6D;IAC7D,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,CAAA;IAC3C,iDAAiD;IACjD,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAC,CAAA;CAC3D;AAED,2DAA2D;AAC3D,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAC,yBAAyB,CAAC,CAAA"}
1
+ {"version":3,"file":"InPageGatewaysState.d.ts","sourceRoot":"","sources":["../../../../../src/client/context/in-page/InPageGatewaysState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAA;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAEvD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAA;AAE9D;;;;;;;;;;GAUG;AACH,MAAM,WAAW,yBAAyB;IACxC,yDAAyD;IACzD,QAAQ,EAAE,MAAM,IAAI,CAAA;IACpB,6DAA6D;IAC7D,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,CAAA;IAC3C,iDAAiD;IACjD,QAAQ,EAAE,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,kBAAkB,CAAC,CAAC,CAAA;IAC1D;;;;OAIG;IACH,KAAK,CAAC,EAAE,CAAC,WAAW,EAAE,WAAW,KAAK,IAAI,CAAA;CAC3C;AAED,2DAA2D;AAC3D,MAAM,MAAM,mBAAmB,GAAG,cAAc,CAAC,yBAAyB,CAAC,CAAA"}
@@ -11,7 +11,7 @@ export interface InPageGatewaysProviderProps extends PropsWithChildren {
11
11
  signerAccount?: AccountInstance;
12
12
  /** Factory that supplies the signer used by mutation providers. */
13
13
  signerFactory?: CreatableProviderFactory;
14
- /** Stable config identifier for signerFactory; defaults to its providerName. */
14
+ /** Stable config identifier for signerFactory; defaults to its provider class's `providerId`. */
15
15
  signerProviderId?: string;
16
16
  /** Optional RPC transport used to reach a remote signer. */
17
17
  signerTransport?: RpcTransport<XyoSignerRpcSchemas>;
@@ -47,6 +47,12 @@ export interface InPageGatewaysProviderProps extends PropsWithChildren {
47
47
  * `Promise.allSettled`. Networks that resolve populate `gateways[id]`;
48
48
  * networks that reject populate `errors[id]`. One failed network does
49
49
  * not block the others.
50
+ * - A failed network stays failed until `retry(id)` relaunches it alone;
51
+ * the other networks keep their running systems. `GatewayProvider` calls
52
+ * it with backoff for the network it serves, so a briefly unavailable
53
+ * endpoint (for example a REST head that is not published yet) recovers
54
+ * without a reload. A retry that succeeds publishes `gateways[id]` and
55
+ * clears `errors[id]`; one that fails replaces `errors[id]`.
50
56
  * - Every gateway is resolved once through browser-kit and shares one
51
57
  * immutable provider graph with its XL1 system actor. The page owns each
52
58
  * session until React cleanup or `pagehide`.
@@ -71,6 +77,8 @@ export interface InPageGatewaysProviderProps extends PropsWithChildren {
71
77
  * - `clearAll()` — manually empties both maps. Also invoked internally on
72
78
  * transport changes. Forwarded by `GatewayProvider` to consumers as
73
79
  * `resetGatewaysFromConfig`.
80
+ * - `retry(id)` — relaunches one failed network. A no-op while that network
81
+ * has a running system or a launch in flight.
74
82
  * - `provided: true` — lets descendants detect a real provider.
75
83
  *
76
84
  * Note: the commented-out `SimpleXyoClient` at the top is intentionally
@@ -1 +1 @@
1
- {"version":3,"file":"Provider.d.ts","sourceRoot":"","sources":["../../../../../src/client/context/in-page/Provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACvD,OAAO,KAAK,EACV,wBAAwB,EACX,YAAY,EAAE,mBAAmB,EAC/C,MAAM,sBAAsB,CAAA;AAE7B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAA;AAC9C,OAAO,KAGN,MAAM,OAAO,CAAA;AAKd,OAAO,EACL,KAAK,gBAAgB,EAGt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AAA;IAEzB,4DAA4D;IAC5D,eAAe,CAAC,EAAE,YAAY,CAAC,mBAAmB,CAAC,CAAA;IAEnD,qFAAqF;IACrF,SAAS,CAAC,EAAE,gBAAgB,CAAA;CAC7B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkEG;AACH,eAAO,MAAM,sBAAsB,EAAE,KAAK,CAAC,EAAE,CAAC,2BAA2B,CA2JxE,CAAA"}
@@ -0,0 +1,17 @@
1
+ import type { GatewayName } from '@xyo-network/xl1-sdk';
2
+ /** Delay before the first retry of a failed in-page gateway launch; doubles per failed retry. */
3
+ export declare const IN_PAGE_GATEWAY_RETRY_BASE_MS = 1000;
4
+ /** Upper bound for the delay between retries of a failed in-page gateway launch. */
5
+ export declare const IN_PAGE_GATEWAY_RETRY_MAX_MS = 30000;
6
+ /**
7
+ * Retries the in-page gateway for `gatewayName` while its launch `error` is
8
+ * set, backing off exponentially from {@link IN_PAGE_GATEWAY_RETRY_BASE_MS}
9
+ * up to {@link IN_PAGE_GATEWAY_RETRY_MAX_MS}. A failed retry publishes a new
10
+ * error, which schedules the next attempt; a successful one clears the error,
11
+ * which stops retrying and resets the backoff.
12
+ *
13
+ * A failure is counted only when its retry fires, so React strict mode's
14
+ * extra effect run does not skip a backoff step.
15
+ */
16
+ export declare function useInPageGatewayRetry(gatewayName: GatewayName | undefined, error: Error | undefined, retry: ((gatewayName: GatewayName) => void) | undefined): void;
17
+ //# sourceMappingURL=useInPageGatewayRetry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useInPageGatewayRetry.d.ts","sourceRoot":"","sources":["../../../../../src/client/context/in-page/useInPageGatewayRetry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAGvD,iGAAiG;AACjG,eAAO,MAAM,6BAA6B,OAAO,CAAA;AAEjD,oFAAoF;AACpF,eAAO,MAAM,4BAA4B,QAAS,CAAA;AAElD;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACnC,WAAW,EAAE,WAAW,GAAG,SAAS,EACpC,KAAK,EAAE,KAAK,GAAG,SAAS,EACxB,KAAK,EAAE,CAAC,CAAC,WAAW,EAAE,WAAW,KAAK,IAAI,CAAC,GAAG,SAAS,GACtD,IAAI,CAgBN"}
@@ -32,7 +32,9 @@ import type { GatewayProviderProps } from '../GatewayProviderProps.ts';
32
32
  * - `error` — first non-null of wallet error, then in-page build error
33
33
  * for this `gatewayName`. Also rendered inline via `ErrorRender` above
34
34
  * `children` so mount-time failures surface even when no consumer
35
- * reads `error`.
35
+ * reads `error`. While the in-page gateway for this `gatewayName` has a
36
+ * launch error, the provider retries that launch with exponential
37
+ * backoff (`useInPageGatewayRetry`); success clears the error.
36
38
  * - `resetGatewaysFromConfig` — forwards `clearAll` from
37
39
  * `InPageGatewaysProvider`, letting consumers force a rebuild of the
38
40
  * in-page gateways (e.g. after a network or endpoint change).
@@ -1 +1 @@
1
- {"version":3,"file":"GatewayProvider.d.ts","sourceRoot":"","sources":["../../../../../src/client/context/providers/GatewayProvider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAkB,MAAM,OAAO,CAAA;AAKtC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AAItE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAkE1D,CAAA"}
1
+ {"version":3,"file":"GatewayProvider.d.ts","sourceRoot":"","sources":["../../../../../src/client/context/providers/GatewayProvider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAkB,MAAM,OAAO,CAAA;AAKtC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,4BAA4B,CAAA;AAKtE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CAqE1D,CAAA"}
@@ -2374,6 +2374,7 @@ import {
2374
2374
  useCallback as useCallback7,
2375
2375
  useEffect as useEffect6,
2376
2376
  useMemo as useMemo6,
2377
+ useRef as useRef2,
2377
2378
  useState as useState16
2378
2379
  } from "react";
2379
2380
  import { jsx as jsx17 } from "react/jsx-runtime";
@@ -2408,50 +2409,56 @@ var InPageGatewaysProvider = ({
2408
2409
  }, { signal: controller.signal });
2409
2410
  return () => controller.abort();
2410
2411
  }, [clearAll]);
2412
+ const retryInSessionRef = useRef2(void 0);
2411
2413
  useEffect6(() => {
2412
2414
  let cancelled = false;
2413
2415
  const ownedSystems = [];
2416
+ const running = /* @__PURE__ */ new Set();
2417
+ const launching = /* @__PURE__ */ new Set();
2418
+ const launchNetwork = async (networkId) => {
2419
+ const system = await launchInPageGatewaySystem(
2420
+ networkId,
2421
+ localEndpoint,
2422
+ signerTransport,
2423
+ signerFactory,
2424
+ transport,
2425
+ signerAccount,
2426
+ signerProviderId
2427
+ );
2428
+ if (cancelled) {
2429
+ await Promise.allSettled([system.stop()]);
2430
+ return system.gateway;
2431
+ }
2432
+ const disposePageLifecycle = bindPageLifecycle(system, {
2433
+ onStopError: (error) => {
2434
+ if (cancelled) return;
2435
+ startTransition(() => {
2436
+ setErrors((previous) => ({
2437
+ ...previous,
2438
+ [networkId]: toError2(error)
2439
+ }));
2440
+ });
2441
+ }
2442
+ });
2443
+ ownedSystems.push({ disposePageLifecycle, system });
2444
+ running.add(networkId);
2445
+ return system.gateway;
2446
+ };
2414
2447
  const buildAll = async () => {
2415
2448
  if (cancelled) return;
2416
- const results = await Promise.allSettled(
2417
- DefaultNetworks3.map(async (network) => {
2418
- const system = await launchInPageGatewaySystem(
2419
- network.id,
2420
- localEndpoint,
2421
- signerTransport,
2422
- signerFactory,
2423
- transport,
2424
- signerAccount,
2425
- signerProviderId
2426
- );
2427
- if (cancelled) {
2428
- await Promise.allSettled([system.stop()]);
2429
- return { id: network.id, gateway: system.gateway };
2430
- }
2431
- const disposePageLifecycle = bindPageLifecycle(system, {
2432
- onStopError: (error) => {
2433
- if (cancelled) return;
2434
- startTransition(() => {
2435
- setErrors((previous) => ({
2436
- ...previous,
2437
- [network.id]: error instanceof Error ? error : new Error(String(error))
2438
- }));
2439
- });
2440
- }
2441
- });
2442
- ownedSystems.push({ disposePageLifecycle, system });
2443
- return { id: network.id, gateway: system.gateway };
2444
- })
2445
- );
2449
+ const networkIds = DefaultNetworks3.map((network) => network.id);
2450
+ for (const networkId of networkIds) launching.add(networkId);
2451
+ const results = await Promise.allSettled(networkIds.map(async (networkId) => await launchNetwork(networkId)));
2452
+ for (const networkId of networkIds) launching.delete(networkId);
2446
2453
  if (!cancelled) {
2447
2454
  const nextGateways = {};
2448
2455
  const nextErrors = {};
2449
2456
  for (const [index, result] of results.entries()) {
2450
- const networkId = DefaultNetworks3[index].id;
2457
+ const networkId = networkIds[index];
2451
2458
  if (result.status === "fulfilled") {
2452
- nextGateways[networkId] = result.value.gateway;
2459
+ nextGateways[networkId] = result.value;
2453
2460
  } else {
2454
- nextErrors[networkId] = result.reason instanceof Error ? result.reason : new Error(String(result.reason));
2461
+ nextErrors[networkId] = toError2(result.reason);
2455
2462
  }
2456
2463
  }
2457
2464
  startTransition(() => {
@@ -2460,24 +2467,54 @@ var InPageGatewaysProvider = ({
2460
2467
  });
2461
2468
  }
2462
2469
  };
2470
+ const retryNetwork = async (networkId) => {
2471
+ launching.add(networkId);
2472
+ try {
2473
+ const gateway = await launchNetwork(networkId);
2474
+ if (cancelled) return;
2475
+ startTransition(() => {
2476
+ setGateways((previous) => ({ ...previous, [networkId]: gateway }));
2477
+ setErrors(({ [networkId]: _cleared, ...previous }) => previous);
2478
+ });
2479
+ } catch (error) {
2480
+ if (cancelled) return;
2481
+ startTransition(() => {
2482
+ setErrors((previous) => ({ ...previous, [networkId]: toError2(error) }));
2483
+ });
2484
+ } finally {
2485
+ launching.delete(networkId);
2486
+ }
2487
+ };
2488
+ retryInSessionRef.current = (networkId) => {
2489
+ if (cancelled || running.has(networkId) || launching.has(networkId)) return;
2490
+ void retryNetwork(networkId);
2491
+ };
2463
2492
  void buildAll();
2464
2493
  return () => {
2465
2494
  cancelled = true;
2495
+ retryInSessionRef.current = void 0;
2466
2496
  for (const owned of ownedSystems) owned.disposePageLifecycle();
2467
2497
  void Promise.allSettled(ownedSystems.map(async (owned) => await owned.system.stop()));
2468
2498
  };
2469
2499
  }, [localEndpoint, pageGeneration, signerAccount, signerFactory, signerProviderId, signerTransport, transport]);
2500
+ const retry = useCallback7((gatewayName) => {
2501
+ retryInSessionRef.current?.(gatewayName);
2502
+ }, []);
2470
2503
  const value = useMemo6(() => {
2471
2504
  const value2 = {
2472
2505
  clearAll,
2473
2506
  errors,
2474
2507
  gateways,
2475
- provided: true
2508
+ provided: true,
2509
+ retry
2476
2510
  };
2477
2511
  return value2;
2478
- }, [clearAll, errors, gateways]);
2512
+ }, [clearAll, errors, gateways, retry]);
2479
2513
  return /* @__PURE__ */ jsx17(InPageGatewaysContext, { value, children });
2480
2514
  };
2515
+ function toError2(error) {
2516
+ return error instanceof Error ? error : new Error(String(error));
2517
+ }
2481
2518
 
2482
2519
  // src/client/context/in-page/useProvidedInPageGateways.ts
2483
2520
  import { useContextEx } from "@ariestools/sdk-react";
@@ -2486,6 +2523,28 @@ var useProvidedInPageGateways = (required = true) => useContextEx(InPageGateways
2486
2523
  // src/client/context/providers/GatewayProvider.tsx
2487
2524
  import { isDefinedNotNull as isDefinedNotNull12, isNull as isNull3 } from "@ariestools/sdk";
2488
2525
  import { useMemo as useMemo7 } from "react";
2526
+
2527
+ // src/client/context/in-page/useInPageGatewayRetry.ts
2528
+ import { useEffect as useEffect7, useRef as useRef3 } from "react";
2529
+ var IN_PAGE_GATEWAY_RETRY_BASE_MS = 1e3;
2530
+ var IN_PAGE_GATEWAY_RETRY_MAX_MS = 3e4;
2531
+ function useInPageGatewayRetry(gatewayName, error, retry) {
2532
+ const failuresRef = useRef3({ count: 0, gatewayName });
2533
+ useEffect7(() => {
2534
+ if (failuresRef.current.gatewayName !== gatewayName || error === void 0) {
2535
+ failuresRef.current = { count: 0, gatewayName };
2536
+ }
2537
+ if (gatewayName === void 0 || error === void 0 || retry === void 0) return;
2538
+ const delay = Math.min(IN_PAGE_GATEWAY_RETRY_MAX_MS, IN_PAGE_GATEWAY_RETRY_BASE_MS * 2 ** failuresRef.current.count);
2539
+ const timer = setTimeout(() => {
2540
+ failuresRef.current.count += 1;
2541
+ retry(gatewayName);
2542
+ }, delay);
2543
+ return () => clearTimeout(timer);
2544
+ }, [error, gatewayName, retry]);
2545
+ }
2546
+
2547
+ // src/client/context/providers/GatewayProvider.tsx
2489
2548
  import { jsx as jsx18, jsxs as jsxs17 } from "react/jsx-runtime";
2490
2549
  var GatewayProvider = ({ gatewayName, children }) => {
2491
2550
  const {
@@ -2495,10 +2554,12 @@ var GatewayProvider = ({ gatewayName, children }) => {
2495
2554
  const {
2496
2555
  gateways: allGateways,
2497
2556
  errors: allGatewayErrors,
2498
- clearAll
2557
+ clearAll,
2558
+ retry
2499
2559
  } = useProvidedInPageGateways(true);
2500
2560
  const gatewayFromConfig = gatewayName ? allGateways[gatewayName] : void 0;
2501
2561
  const gatewayFromConfigError = gatewayName ? allGatewayErrors[gatewayName] : void 0;
2562
+ useInPageGatewayRetry(gatewayName, gatewayFromConfigError, retry);
2502
2563
  const { defaultGateway, gateways } = useMemo7(() => {
2503
2564
  if (isNull3(gatewayFromWallet)) {
2504
2565
  return {