@xyo-network/xl1-react-client-sdk 5.7.0 → 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 +4 -1
- package/dist/browser/client/context/in-page/InPageGatewaysState.d.ts +6 -0
- package/dist/browser/client/context/in-page/InPageGatewaysState.d.ts.map +1 -1
- package/dist/browser/client/context/in-page/Provider.d.ts +9 -1
- package/dist/browser/client/context/in-page/Provider.d.ts.map +1 -1
- package/dist/browser/client/context/in-page/useInPageGatewayRetry.d.ts +17 -0
- package/dist/browser/client/context/in-page/useInPageGatewayRetry.d.ts.map +1 -0
- package/dist/browser/client/context/providers/GatewayProvider.d.ts +3 -1
- package/dist/browser/client/context/providers/GatewayProvider.d.ts.map +1 -1
- package/dist/browser/client/index.mjs +97 -36
- package/dist/browser/client/index.mjs.map +4 -4
- package/dist/browser/index.mjs +97 -36
- package/dist/browser/index.mjs.map +4 -4
- package/package.json +17 -17
package/dist/browser/index.mjs
CHANGED
|
@@ -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
|
|
2417
|
-
|
|
2418
|
-
|
|
2419
|
-
|
|
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 =
|
|
2457
|
+
const networkId = networkIds[index];
|
|
2451
2458
|
if (result.status === "fulfilled") {
|
|
2452
|
-
nextGateways[networkId] = result.value
|
|
2459
|
+
nextGateways[networkId] = result.value;
|
|
2453
2460
|
} else {
|
|
2454
|
-
nextErrors[networkId] =
|
|
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 {
|