@xyo-network/react-chain-provider 1.20.1 → 1.20.3
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/browser/contexts/gateway/Provider.d.ts +8 -0
- package/dist/browser/contexts/gateway/Provider.d.ts.map +1 -0
- package/dist/browser/contexts/gateway/context.d.ts +8 -0
- package/dist/browser/contexts/gateway/context.d.ts.map +1 -0
- package/dist/browser/contexts/gateway/index.d.ts +5 -0
- package/dist/browser/contexts/gateway/index.d.ts.map +1 -0
- package/dist/browser/contexts/gateway/state.d.ts +13 -0
- package/dist/browser/contexts/gateway/state.d.ts.map +1 -0
- package/dist/browser/contexts/gateway/story/GatewayStats.d.ts +9 -0
- package/dist/browser/contexts/gateway/story/GatewayStats.d.ts.map +1 -0
- package/dist/browser/contexts/gateway/story/GatewayStatus.d.ts +3 -0
- package/dist/browser/contexts/gateway/story/GatewayStatus.d.ts.map +1 -0
- package/dist/browser/contexts/gateway/use.d.ts +4 -0
- package/dist/browser/contexts/gateway/use.d.ts.map +1 -0
- package/dist/browser/contexts/in-page-gateways/Provider.d.ts +8 -0
- package/dist/browser/contexts/in-page-gateways/Provider.d.ts.map +1 -0
- package/dist/browser/contexts/in-page-gateways/context.d.ts +8 -0
- package/dist/browser/contexts/in-page-gateways/context.d.ts.map +1 -0
- package/dist/browser/contexts/in-page-gateways/index.d.ts +5 -0
- package/dist/browser/contexts/in-page-gateways/index.d.ts.map +1 -0
- package/dist/browser/contexts/in-page-gateways/state.d.ts +10 -0
- package/dist/browser/contexts/in-page-gateways/state.d.ts.map +1 -0
- package/dist/browser/contexts/in-page-gateways/use.d.ts +4 -0
- package/dist/browser/contexts/in-page-gateways/use.d.ts.map +1 -0
- package/dist/browser/contexts/index.d.ts +2 -0
- package/dist/browser/contexts/index.d.ts.map +1 -1
- package/dist/browser/hooks/client/index.d.ts +2 -2
- package/dist/browser/hooks/client/index.d.ts.map +1 -1
- package/dist/browser/hooks/client/{useClient.d.ts → useClientFromWallet.d.ts} +3 -1
- package/dist/browser/hooks/client/useClientFromWallet.d.ts.map +1 -0
- package/dist/browser/hooks/client/useGatewayFromWallet.d.ts +6 -0
- package/dist/browser/hooks/client/useGatewayFromWallet.d.ts.map +1 -0
- package/dist/browser/hooks/gateway/index.d.ts +4 -0
- package/dist/browser/hooks/gateway/index.d.ts.map +1 -0
- package/dist/browser/hooks/gateway/useNetwork.d.ts +2 -0
- package/dist/browser/hooks/gateway/useNetwork.d.ts.map +1 -0
- package/dist/browser/hooks/gateway/useRunner.d.ts +2 -0
- package/dist/browser/hooks/gateway/useRunner.d.ts.map +1 -0
- package/dist/browser/hooks/gateway/useViewer.d.ts +2 -0
- package/dist/browser/hooks/gateway/useViewer.d.ts.map +1 -0
- package/dist/browser/hooks/index.d.ts +1 -0
- package/dist/browser/hooks/index.d.ts.map +1 -1
- package/dist/browser/hooks/useCurrentBlock.d.ts +33 -0
- package/dist/browser/hooks/useCurrentBlock.d.ts.map +1 -1
- package/dist/browser/hooks/useHttpRpcRunner.d.ts.map +1 -1
- package/dist/browser/hooks/viewer/useCheckRpc.d.ts.map +1 -1
- package/dist/browser/hooks/viewer/useHttpRpcViewer.d.ts +1 -0
- package/dist/browser/hooks/viewer/useHttpRpcViewer.d.ts.map +1 -1
- package/dist/browser/index.d.ts +1 -0
- package/dist/browser/index.d.ts.map +1 -1
- package/dist/browser/index.mjs +388 -187
- package/dist/browser/index.mjs.map +1 -1
- package/dist/browser/lib/buildGateway.d.ts +4 -0
- package/dist/browser/lib/buildGateway.d.ts.map +1 -0
- package/dist/browser/lib/index.d.ts +1 -0
- package/dist/browser/lib/index.d.ts.map +1 -1
- package/dist/browser/types/ContextGatewayType.d.ts +3 -0
- package/dist/browser/types/ContextGatewayType.d.ts.map +1 -0
- package/dist/browser/types/GatewayFromWallet.d.ts +8 -0
- package/dist/browser/types/GatewayFromWallet.d.ts.map +1 -0
- package/dist/browser/types/index.d.ts +3 -0
- package/dist/browser/types/index.d.ts.map +1 -0
- package/package.json +21 -19
- package/src/contexts/gateway/Provider.tsx +82 -0
- package/src/contexts/gateway/context.ts +5 -0
- package/src/contexts/gateway/index.ts +4 -0
- package/src/contexts/gateway/state.ts +15 -0
- package/src/contexts/gateway/story/GatewayStats.tsx +33 -0
- package/src/contexts/gateway/story/GatewayStatus.tsx +53 -0
- package/src/contexts/gateway/story/Provider.stories.tsx +38 -0
- package/src/contexts/gateway/story/ProviderWithWallet.stories.tsx +46 -0
- package/src/contexts/gateway/use.ts +5 -0
- package/src/contexts/in-page-gateways/Provider.tsx +82 -0
- package/src/contexts/in-page-gateways/context.ts +5 -0
- package/src/contexts/in-page-gateways/index.ts +4 -0
- package/src/contexts/in-page-gateways/state.ts +12 -0
- package/src/contexts/in-page-gateways/use.ts +5 -0
- package/src/contexts/index.ts +2 -0
- package/src/hooks/client/index.ts +2 -2
- package/src/hooks/client/permissions/usePermissions.ts +2 -2
- package/src/hooks/client/{useClient.ts → useClientFromWallet.ts} +4 -1
- package/src/hooks/client/{useGateway.ts → useGatewayFromWallet.ts} +7 -3
- package/src/hooks/gateway/index.ts +3 -0
- package/src/hooks/gateway/useNetwork.ts +6 -0
- package/src/hooks/gateway/useRunner.ts +6 -0
- package/src/hooks/gateway/useViewer.ts +6 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useConnectAccount.ts +2 -2
- package/src/hooks/useCurrentBlock.ts +13 -0
- package/src/hooks/useHttpRpcRunner.ts +1 -0
- package/src/hooks/viewer/useCheckRpc.ts +8 -17
- package/src/hooks/viewer/useHttpRpcViewer.ts +1 -0
- package/src/hooks/viewer/useViewerFromWallet.ts +2 -2
- package/src/index.ts +1 -0
- package/src/lib/buildGateway.ts +29 -0
- package/src/lib/index.ts +1 -0
- package/src/types/ContextGatewayType.ts +4 -0
- package/src/types/GatewayFromWallet.ts +8 -0
- package/src/types/index.ts +2 -0
- package/dist/browser/components/connected/ConnectAccountsStack.stories.d.ts +0 -6
- package/dist/browser/components/connected/ConnectAccountsStack.stories.d.ts.map +0 -1
- package/dist/browser/contexts/current-block/Provider.stories.d.ts +0 -7
- package/dist/browser/contexts/current-block/Provider.stories.d.ts.map +0 -1
- package/dist/browser/hooks/client/useClient.d.ts.map +0 -1
- package/dist/browser/hooks/client/useGateway.d.ts +0 -8
- package/dist/browser/hooks/client/useGateway.d.ts.map +0 -1
- package/dist/browser/hooks/viewer/UseStepRewardWeightTest.stories.d.ts +0 -12
- package/dist/browser/hooks/viewer/UseStepRewardWeightTest.stories.d.ts.map +0 -1
- package/dist/browser/hooks/viewer/useHttpRpcViewer.stories.d.ts +0 -9
- package/dist/browser/hooks/viewer/useHttpRpcViewer.stories.d.ts.map +0 -1
- package/dist/browser/hooks/viewer/useViewerFromWallet.stories.d.ts +0 -12
- package/dist/browser/hooks/viewer/useViewerFromWallet.stories.d.ts.map +0 -1
package/dist/browser/index.mjs
CHANGED
|
@@ -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
|
|
31
|
-
import { ErrorRender } from "@xyo-network/react-error";
|
|
32
|
-
import
|
|
30
|
+
import { isDefined as isDefined10, isUndefined as isUndefined8 } from "@xylabs/sdk-js";
|
|
31
|
+
import { ErrorRender as ErrorRender2 } from "@xyo-network/react-error";
|
|
32
|
+
import React5, { useEffect as useEffect7 } from "react";
|
|
33
33
|
|
|
34
34
|
// src/hooks/account/helpers/formatAccountBalanceHistory.ts
|
|
35
35
|
import { hexToBigInt } from "@xylabs/sdk-js";
|
|
@@ -87,6 +87,24 @@ var balanceForRange = /* @__PURE__ */ __name((address, results) => {
|
|
|
87
87
|
];
|
|
88
88
|
}, "balanceForRange");
|
|
89
89
|
|
|
90
|
+
// src/lib/buildGateway.ts
|
|
91
|
+
import { assertEx, isDefined } from "@xylabs/sdk-js";
|
|
92
|
+
import { basicRemoteRunnerLocator, basicRemoteViewerLocator } from "@xyo-network/chain-orchestration";
|
|
93
|
+
import { DefaultNetworks, NetworkDataLakeUrls, XyoGatewayMoniker } from "@xyo-network/xl1-sdk";
|
|
94
|
+
var buildGateway = /* @__PURE__ */ __name(async (gatewayName, account) => {
|
|
95
|
+
const network = DefaultNetworks.find((network2) => network2.id === gatewayName);
|
|
96
|
+
const resolvedNetwork = assertEx(network, () => `No network found for id ${gatewayName}`);
|
|
97
|
+
const remoteConfig = {
|
|
98
|
+
rpc: {
|
|
99
|
+
protocol: "http",
|
|
100
|
+
url: `${resolvedNetwork.url}/rpc`
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
const dataLakeEndpoint = NetworkDataLakeUrls[gatewayName];
|
|
104
|
+
const locator = isDefined(account) ? await basicRemoteRunnerLocator(gatewayName, remoteConfig, account, dataLakeEndpoint) : await basicRemoteViewerLocator(gatewayName, remoteConfig, dataLakeEndpoint);
|
|
105
|
+
return await locator.getInstance(XyoGatewayMoniker);
|
|
106
|
+
}, "buildGateway");
|
|
107
|
+
|
|
90
108
|
// src/lib/findMinimumBlock.ts
|
|
91
109
|
var findMinimumBlock = /* @__PURE__ */ __name((history) => {
|
|
92
110
|
if (history.length === 0) return 0;
|
|
@@ -137,7 +155,7 @@ var useAccountBalanceHistory = /* @__PURE__ */ __name((address, viewer, maxPage
|
|
|
137
155
|
]);
|
|
138
156
|
}, "useAccountBalanceHistory");
|
|
139
157
|
|
|
140
|
-
// src/hooks/client/
|
|
158
|
+
// src/hooks/client/useClientFromWallet.ts
|
|
141
159
|
import { isNull as isNull2 } from "@xylabs/sdk-js";
|
|
142
160
|
import { useCallback, useEffect, useSyncExternalStore } from "react";
|
|
143
161
|
|
|
@@ -176,7 +194,7 @@ async function getXyoClient(timeout = CLIENT_LISTENER_TIMEOUT) {
|
|
|
176
194
|
__name(getXyoClient, "getXyoClient");
|
|
177
195
|
|
|
178
196
|
// src/hooks/helpers/transaction/Confirmation.ts
|
|
179
|
-
import { assertEx, delay, forget, isDefined, isNull } from "@xylabs/sdk-js";
|
|
197
|
+
import { assertEx as assertEx2, delay, forget, isDefined as isDefined2, isNull } from "@xylabs/sdk-js";
|
|
180
198
|
var TransactionConfirmationStatus = class _TransactionConfirmationStatus {
|
|
181
199
|
static {
|
|
182
200
|
__name(this, "TransactionConfirmationStatus");
|
|
@@ -187,10 +205,10 @@ var TransactionConfirmationStatus = class _TransactionConfirmationStatus {
|
|
|
187
205
|
this._params = params;
|
|
188
206
|
}
|
|
189
207
|
get exp() {
|
|
190
|
-
return
|
|
208
|
+
return assertEx2(this.transaction[0].exp, () => "exp is not found, transaction is not set");
|
|
191
209
|
}
|
|
192
210
|
get nbf() {
|
|
193
|
-
return
|
|
211
|
+
return assertEx2(this.transaction[0].nbf, () => "nbf is not found, transaction is not set");
|
|
194
212
|
}
|
|
195
213
|
get onStatusUpdate() {
|
|
196
214
|
return this._params.onStatusUpdate;
|
|
@@ -214,7 +232,7 @@ var TransactionConfirmationStatus = class _TransactionConfirmationStatus {
|
|
|
214
232
|
this.active = true;
|
|
215
233
|
try {
|
|
216
234
|
const currentBlockNumber = await this.viewer.currentBlockNumber();
|
|
217
|
-
while (
|
|
235
|
+
while (isDefined2(currentBlockNumber) && this.active) {
|
|
218
236
|
await this.checkBlock(currentBlockNumber);
|
|
219
237
|
await delay(1e3);
|
|
220
238
|
}
|
|
@@ -279,7 +297,7 @@ var TransactionConfirmationStatus = class _TransactionConfirmationStatus {
|
|
|
279
297
|
}
|
|
280
298
|
};
|
|
281
299
|
|
|
282
|
-
// src/hooks/client/
|
|
300
|
+
// src/hooks/client/useClientFromWallet.ts
|
|
283
301
|
var currentState = {
|
|
284
302
|
client: void 0,
|
|
285
303
|
error: null,
|
|
@@ -333,7 +351,7 @@ var subscribe = /* @__PURE__ */ __name((listener, timeout) => {
|
|
|
333
351
|
};
|
|
334
352
|
}, "subscribe");
|
|
335
353
|
var getSnapshot = /* @__PURE__ */ __name(() => currentState, "getSnapshot");
|
|
336
|
-
var
|
|
354
|
+
var useClientFromWallet = /* @__PURE__ */ __name((timeout) => {
|
|
337
355
|
const subscribeWithTimeout = useCallback((listener) => subscribe(listener, timeout), [
|
|
338
356
|
timeout
|
|
339
357
|
]);
|
|
@@ -355,11 +373,12 @@ var useClient = /* @__PURE__ */ __name((timeout) => {
|
|
|
355
373
|
};
|
|
356
374
|
});
|
|
357
375
|
return clientState;
|
|
358
|
-
}, "
|
|
376
|
+
}, "useClientFromWallet");
|
|
377
|
+
var useClient = useClientFromWallet;
|
|
359
378
|
|
|
360
379
|
// src/hooks/client/permissions/usePermissions.ts
|
|
361
380
|
var usePermissions = /* @__PURE__ */ __name(() => {
|
|
362
|
-
const { client, isLoading, error, timedout } =
|
|
381
|
+
const { client, isLoading, error, timedout } = useClientFromWallet();
|
|
363
382
|
const permissions = client?.permissions;
|
|
364
383
|
return {
|
|
365
384
|
permissions,
|
|
@@ -371,15 +390,15 @@ var usePermissions = /* @__PURE__ */ __name(() => {
|
|
|
371
390
|
|
|
372
391
|
// src/hooks/client/permissions/usePermissionsAccounts.ts
|
|
373
392
|
import { usePromise as usePromise2 } from "@xylabs/react-promise";
|
|
374
|
-
import { isArray, isDefined as
|
|
393
|
+
import { isArray, isDefined as isDefined4, isDefinedNotNull, isString } from "@xylabs/sdk-js";
|
|
375
394
|
|
|
376
395
|
// src/hooks/client/helpers/findCaveat.ts
|
|
377
|
-
import { isDefined as
|
|
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 (
|
|
399
|
+
if (isDefined3(existingPermissions) && existingPermissions.length > 0) {
|
|
381
400
|
const foundPermissions = existingPermissions.find((p) => p.parentCapability === targetCapability);
|
|
382
|
-
if (
|
|
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 (
|
|
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 (
|
|
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,13 @@ var useAccountPermissions = /* @__PURE__ */ __name(() => {
|
|
|
416
435
|
]);
|
|
417
436
|
}, "useAccountPermissions");
|
|
418
437
|
|
|
419
|
-
// src/hooks/client/
|
|
420
|
-
import { isDefined as
|
|
421
|
-
var
|
|
422
|
-
const { client, isLoading, error, timedout } =
|
|
438
|
+
// src/hooks/client/useGatewayFromWallet.ts
|
|
439
|
+
import { isDefined as isDefined5, isNull as isNull3 } from "@xylabs/sdk-js";
|
|
440
|
+
var useGatewayFromWallet = /* @__PURE__ */ __name((gatewayName, timeout) => {
|
|
441
|
+
const { client, isLoading, error, timedout } = useClientFromWallet(timeout);
|
|
423
442
|
const resolveGateway = /* @__PURE__ */ __name(() => {
|
|
424
443
|
if (isNull3(client)) return null;
|
|
425
|
-
if (timedout && !isLoading &&
|
|
444
|
+
if (timedout && !isLoading && isDefined5(gatewayName)) {
|
|
426
445
|
return null;
|
|
427
446
|
}
|
|
428
447
|
return client?.gateways?.[gatewayName];
|
|
@@ -433,17 +452,266 @@ var useGateway = /* @__PURE__ */ __name((gatewayName, timeout) => {
|
|
|
433
452
|
error,
|
|
434
453
|
timedout
|
|
435
454
|
};
|
|
436
|
-
}, "
|
|
455
|
+
}, "useGatewayFromWallet");
|
|
456
|
+
var useGateway = useGatewayFromWallet;
|
|
457
|
+
|
|
458
|
+
// src/contexts/current-block/context.ts
|
|
459
|
+
import { createContextEx } from "@xylabs/react-shared";
|
|
460
|
+
var XL1CurrentBlockContext = createContextEx();
|
|
461
|
+
|
|
462
|
+
// src/contexts/current-block/Provider.tsx
|
|
463
|
+
import React2, { useMemo } from "react";
|
|
464
|
+
|
|
465
|
+
// src/contexts/current-block/usePollCurrentBlock.ts
|
|
466
|
+
import { isDefinedNotNull as isDefinedNotNull2, isUndefinedOrNull } from "@xylabs/sdk-js";
|
|
467
|
+
import { startTransition, useEffect as useEffect2, useState } from "react";
|
|
468
|
+
var DEFAULT_POLL_INTERVAL = 1e4;
|
|
469
|
+
var usePollCurrentBlock = /* @__PURE__ */ __name((viewer, interval = DEFAULT_POLL_INTERVAL, pause = false) => {
|
|
470
|
+
const [currentBlock, setCurrentBlock] = useState(null);
|
|
471
|
+
const [error, setError] = useState();
|
|
472
|
+
useEffect2(() => {
|
|
473
|
+
let isMounted = true;
|
|
474
|
+
const fetchBlock = /* @__PURE__ */ __name(async () => {
|
|
475
|
+
if (isDefinedNotNull2(viewer)) {
|
|
476
|
+
try {
|
|
477
|
+
const block = await viewer.currentBlock();
|
|
478
|
+
if (isMounted) {
|
|
479
|
+
startTransition(() => {
|
|
480
|
+
setCurrentBlock((existingBlock) => {
|
|
481
|
+
if (isUndefinedOrNull(existingBlock)) {
|
|
482
|
+
return block;
|
|
483
|
+
}
|
|
484
|
+
if (isDefinedNotNull2(block) && existingBlock?.[0].block !== block[0].block) {
|
|
485
|
+
return block;
|
|
486
|
+
}
|
|
487
|
+
return existingBlock;
|
|
488
|
+
});
|
|
489
|
+
});
|
|
490
|
+
}
|
|
491
|
+
} catch (err) {
|
|
492
|
+
startTransition(() => {
|
|
493
|
+
setError(err);
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
}, "fetchBlock");
|
|
498
|
+
void fetchBlock();
|
|
499
|
+
const id = setInterval(() => {
|
|
500
|
+
if (!pause) {
|
|
501
|
+
void fetchBlock();
|
|
502
|
+
}
|
|
503
|
+
}, interval);
|
|
504
|
+
return () => {
|
|
505
|
+
isMounted = false;
|
|
506
|
+
clearInterval(id);
|
|
507
|
+
};
|
|
508
|
+
}, [
|
|
509
|
+
viewer,
|
|
510
|
+
interval,
|
|
511
|
+
pause
|
|
512
|
+
]);
|
|
513
|
+
return [
|
|
514
|
+
currentBlock,
|
|
515
|
+
error
|
|
516
|
+
];
|
|
517
|
+
}, "usePollCurrentBlock");
|
|
518
|
+
|
|
519
|
+
// src/contexts/current-block/Provider.tsx
|
|
520
|
+
var DEFAULT_POLLING_INTERVAL = 1e4;
|
|
521
|
+
var XL1CurrentBlockProvider = /* @__PURE__ */ __name(({ pollingConfig, viewer, children }) => {
|
|
522
|
+
const { interval } = useMemo(() => pollingConfig || {
|
|
523
|
+
interval: DEFAULT_POLLING_INTERVAL
|
|
524
|
+
}, [
|
|
525
|
+
pollingConfig
|
|
526
|
+
]);
|
|
527
|
+
const [currentBlock, currentBlockError] = usePollCurrentBlock(viewer, interval);
|
|
528
|
+
const value = useMemo(() => ({
|
|
529
|
+
block: currentBlock,
|
|
530
|
+
blockNumber: currentBlock?.[0].block,
|
|
531
|
+
chain: currentBlock?.[0].chain,
|
|
532
|
+
error: currentBlockError,
|
|
533
|
+
pollingConfig,
|
|
534
|
+
provided: true
|
|
535
|
+
}), [
|
|
536
|
+
currentBlock,
|
|
537
|
+
currentBlockError,
|
|
538
|
+
pollingConfig
|
|
539
|
+
]);
|
|
540
|
+
return /* @__PURE__ */ React2.createElement(XL1CurrentBlockContext, {
|
|
541
|
+
value
|
|
542
|
+
}, children);
|
|
543
|
+
}, "XL1CurrentBlockProvider");
|
|
544
|
+
|
|
545
|
+
// src/contexts/current-block/use.ts
|
|
546
|
+
import { useContextEx } from "@xylabs/react-shared";
|
|
547
|
+
var useXl1CurrentBlockContext = /* @__PURE__ */ __name((required = true) => useContextEx(XL1CurrentBlockContext, "XL1CurrentBlock", required), "useXl1CurrentBlockContext");
|
|
548
|
+
|
|
549
|
+
// src/contexts/gateway/context.ts
|
|
550
|
+
import { createContextEx as createContextEx2 } from "@xylabs/react-shared";
|
|
551
|
+
var GatewayContext = createContextEx2();
|
|
552
|
+
|
|
553
|
+
// src/contexts/gateway/Provider.tsx
|
|
554
|
+
import { isDefinedNotNull as isDefinedNotNull3, isNull as isNull4 } from "@xylabs/sdk-js";
|
|
555
|
+
import { ErrorRender } from "@xyo-network/react-error";
|
|
556
|
+
import React4, { useEffect as useEffect4, useMemo as useMemo3, useState as useState3 } from "react";
|
|
557
|
+
|
|
558
|
+
// src/contexts/in-page-gateways/context.ts
|
|
559
|
+
import { createContextEx as createContextEx3 } from "@xylabs/react-shared";
|
|
560
|
+
var InPageGatewaysContext = createContextEx3();
|
|
561
|
+
|
|
562
|
+
// src/contexts/in-page-gateways/Provider.tsx
|
|
563
|
+
import { DefaultNetworks as DefaultNetworks2 } from "@xyo-network/xl1-sdk";
|
|
564
|
+
import React3, { startTransition as startTransition2, useCallback as useCallback2, useEffect as useEffect3, useMemo as useMemo2, useState as useState2 } from "react";
|
|
565
|
+
var InPageGatewaysProvider = /* @__PURE__ */ __name(({ account, children }) => {
|
|
566
|
+
const [gateways, setGateways] = useState2({});
|
|
567
|
+
const [errors, setErrors] = useState2({});
|
|
568
|
+
const [previousAccount, setPreviousAccount] = useState2(account);
|
|
569
|
+
const clearAll = useCallback2(() => {
|
|
570
|
+
setGateways({});
|
|
571
|
+
setErrors({});
|
|
572
|
+
}, []);
|
|
573
|
+
if (previousAccount !== account) {
|
|
574
|
+
clearAll();
|
|
575
|
+
setPreviousAccount(account);
|
|
576
|
+
}
|
|
577
|
+
useEffect3(() => {
|
|
578
|
+
let cancelled = false;
|
|
579
|
+
const buildAll = /* @__PURE__ */ __name(async () => {
|
|
580
|
+
const results = await Promise.allSettled(DefaultNetworks2.map(async (network) => {
|
|
581
|
+
const gateway = await buildGateway(network.id, account);
|
|
582
|
+
return {
|
|
583
|
+
id: network.id,
|
|
584
|
+
gateway
|
|
585
|
+
};
|
|
586
|
+
}));
|
|
587
|
+
if (cancelled) return;
|
|
588
|
+
const nextGateways = {};
|
|
589
|
+
const nextErrors = {};
|
|
590
|
+
for (const [index, result] of results.entries()) {
|
|
591
|
+
const networkId = DefaultNetworks2[index].id;
|
|
592
|
+
if (result.status === "fulfilled") {
|
|
593
|
+
nextGateways[networkId] = result.value.gateway;
|
|
594
|
+
} else {
|
|
595
|
+
nextErrors[networkId] = result.reason instanceof Error ? result.reason : new Error(String(result.reason));
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
startTransition2(() => {
|
|
599
|
+
setGateways(nextGateways);
|
|
600
|
+
setErrors(nextErrors);
|
|
601
|
+
});
|
|
602
|
+
}, "buildAll");
|
|
603
|
+
void buildAll();
|
|
604
|
+
return () => {
|
|
605
|
+
cancelled = true;
|
|
606
|
+
};
|
|
607
|
+
}, [
|
|
608
|
+
account
|
|
609
|
+
]);
|
|
610
|
+
const value = useMemo2(() => {
|
|
611
|
+
const value2 = {
|
|
612
|
+
clearAll,
|
|
613
|
+
errors,
|
|
614
|
+
gateways,
|
|
615
|
+
provided: true
|
|
616
|
+
};
|
|
617
|
+
return value2;
|
|
618
|
+
}, [
|
|
619
|
+
clearAll,
|
|
620
|
+
errors,
|
|
621
|
+
gateways
|
|
622
|
+
]);
|
|
623
|
+
return /* @__PURE__ */ React3.createElement(InPageGatewaysContext, {
|
|
624
|
+
value
|
|
625
|
+
}, children);
|
|
626
|
+
}, "InPageGatewaysProvider");
|
|
627
|
+
|
|
628
|
+
// src/contexts/in-page-gateways/use.ts
|
|
629
|
+
import { useContextEx as useContextEx2 } from "@xylabs/react-shared";
|
|
630
|
+
var useProvidedInPageGateways = /* @__PURE__ */ __name((required = true) => useContextEx2(InPageGatewaysContext, "InPageGateways", required), "useProvidedInPageGateways");
|
|
631
|
+
|
|
632
|
+
// src/contexts/gateway/Provider.tsx
|
|
633
|
+
var GatewayProvider = /* @__PURE__ */ __name(({ gatewayName, children }) => {
|
|
634
|
+
const [defaultGateway, setDefaultGateway] = useState3();
|
|
635
|
+
const [gateways, setGateways] = useState3({
|
|
636
|
+
inPageGateway: void 0,
|
|
637
|
+
walletGateway: void 0
|
|
638
|
+
});
|
|
639
|
+
const { gateway: gatewayFromWallet, error: gatewayFromWalletError } = useGatewayFromWallet(gatewayName);
|
|
640
|
+
const { gateways: allGateways, errors: allGatewayErrors, clearAll } = useProvidedInPageGateways(true);
|
|
641
|
+
const gatewayFromConfig = gatewayName ? allGateways[gatewayName] : void 0;
|
|
642
|
+
const gatewayFromConfigError = gatewayName ? allGatewayErrors[gatewayName] : void 0;
|
|
643
|
+
useEffect4(() => {
|
|
644
|
+
if (isNull4(gatewayFromWallet)) {
|
|
645
|
+
setDefaultGateway(gatewayFromConfig);
|
|
646
|
+
setGateways({
|
|
647
|
+
inPageGateway: gatewayFromConfig,
|
|
648
|
+
walletGateway: null
|
|
649
|
+
});
|
|
650
|
+
} else if (isDefinedNotNull3(gatewayFromWallet)) {
|
|
651
|
+
setDefaultGateway(gatewayFromWallet);
|
|
652
|
+
setGateways({
|
|
653
|
+
inPageGateway: gatewayFromConfig,
|
|
654
|
+
walletGateway: gatewayFromWallet
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
}, [
|
|
658
|
+
gatewayFromConfig,
|
|
659
|
+
gatewayFromWallet
|
|
660
|
+
]);
|
|
661
|
+
const value = useMemo3(() => {
|
|
662
|
+
const value2 = {
|
|
663
|
+
defaultGateway,
|
|
664
|
+
error: gatewayFromWalletError || gatewayFromConfigError,
|
|
665
|
+
gateways,
|
|
666
|
+
provided: true,
|
|
667
|
+
resetGatewaysFromConfig: clearAll
|
|
668
|
+
};
|
|
669
|
+
return value2;
|
|
670
|
+
}, [
|
|
671
|
+
defaultGateway,
|
|
672
|
+
gatewayFromWalletError,
|
|
673
|
+
gatewayFromConfigError,
|
|
674
|
+
gateways,
|
|
675
|
+
clearAll
|
|
676
|
+
]);
|
|
677
|
+
return /* @__PURE__ */ React4.createElement(GatewayContext, {
|
|
678
|
+
value
|
|
679
|
+
}, /* @__PURE__ */ React4.createElement(ErrorRender, {
|
|
680
|
+
error: gatewayFromConfigError
|
|
681
|
+
}), children);
|
|
682
|
+
}, "GatewayProvider");
|
|
683
|
+
|
|
684
|
+
// src/contexts/gateway/use.ts
|
|
685
|
+
import { useContextEx as useContextEx3 } from "@xylabs/react-shared";
|
|
686
|
+
var useProvidedGateway = /* @__PURE__ */ __name((required = true) => useContextEx3(GatewayContext, "Gateway", required), "useProvidedGateway");
|
|
687
|
+
|
|
688
|
+
// src/hooks/gateway/useNetwork.ts
|
|
689
|
+
var useNetworkFromGateway = /* @__PURE__ */ __name(() => {
|
|
690
|
+
const { defaultGateway } = useProvidedGateway();
|
|
691
|
+
return defaultGateway?.connection?.network;
|
|
692
|
+
}, "useNetworkFromGateway");
|
|
693
|
+
|
|
694
|
+
// src/hooks/gateway/useRunner.ts
|
|
695
|
+
var useRunnerFromGateway = /* @__PURE__ */ __name(() => {
|
|
696
|
+
const { defaultGateway } = useProvidedGateway();
|
|
697
|
+
return defaultGateway?.connection?.runner;
|
|
698
|
+
}, "useRunnerFromGateway");
|
|
699
|
+
|
|
700
|
+
// src/hooks/gateway/useViewer.ts
|
|
701
|
+
var useViewerFromGateway = /* @__PURE__ */ __name(() => {
|
|
702
|
+
const { defaultGateway } = useProvidedGateway();
|
|
703
|
+
return defaultGateway?.connection?.viewer;
|
|
704
|
+
}, "useViewerFromGateway");
|
|
437
705
|
|
|
438
706
|
// src/hooks/useAddressBalance.ts
|
|
439
707
|
import { usePromise as usePromise3 } from "@xylabs/react-promise";
|
|
440
|
-
import { isUndefined as isUndefined3, isUndefinedOrNull } from "@xylabs/sdk-js";
|
|
708
|
+
import { isUndefined as isUndefined3, isUndefinedOrNull as isUndefinedOrNull2 } from "@xylabs/sdk-js";
|
|
441
709
|
import { ShiftedBigInt } from "@xyo-network/xl1-sdk";
|
|
442
|
-
import { useMemo, useRef, useState } from "react";
|
|
710
|
+
import { useMemo as useMemo4, useRef, useState as useState4 } from "react";
|
|
443
711
|
var useAddressBalance = /* @__PURE__ */ __name((address, viewer, refresh) => {
|
|
444
|
-
const [balancesResult, setBalancesResult] =
|
|
445
|
-
const [loading, setLoading] =
|
|
446
|
-
const [balancesError, setBalancesError] =
|
|
712
|
+
const [balancesResult, setBalancesResult] = useState4();
|
|
713
|
+
const [loading, setLoading] = useState4(false);
|
|
714
|
+
const [balancesError, setBalancesError] = useState4();
|
|
447
715
|
const balancePromiseRef = useRef(null);
|
|
448
716
|
usePromise3(async () => {
|
|
449
717
|
if (isUndefined3(viewer) || isUndefined3(address)) return;
|
|
@@ -470,14 +738,14 @@ var useAddressBalance = /* @__PURE__ */ __name((address, viewer, refresh) => {
|
|
|
470
738
|
viewer,
|
|
471
739
|
refresh
|
|
472
740
|
]);
|
|
473
|
-
|
|
741
|
+
useMemo4(() => {
|
|
474
742
|
if (balancesError) {
|
|
475
743
|
setLoading(false);
|
|
476
744
|
}
|
|
477
745
|
}, [
|
|
478
746
|
balancesError
|
|
479
747
|
]);
|
|
480
|
-
const shiftedBigInt =
|
|
748
|
+
const shiftedBigInt = useMemo4(() => {
|
|
481
749
|
if (typeof balancesResult !== "bigint") return;
|
|
482
750
|
return new ShiftedBigInt(balancesResult, {
|
|
483
751
|
places: 18,
|
|
@@ -489,13 +757,13 @@ var useAddressBalance = /* @__PURE__ */ __name((address, viewer, refresh) => {
|
|
|
489
757
|
}, [
|
|
490
758
|
balancesResult
|
|
491
759
|
]);
|
|
492
|
-
const balanceIntlFriendly =
|
|
760
|
+
const balanceIntlFriendly = useMemo4(() => {
|
|
493
761
|
return shiftedBigInt?.toFullString();
|
|
494
762
|
}, [
|
|
495
763
|
shiftedBigInt
|
|
496
764
|
]);
|
|
497
|
-
const shortBalanceIntlFriendly =
|
|
498
|
-
return
|
|
765
|
+
const shortBalanceIntlFriendly = useMemo4(() => {
|
|
766
|
+
return isUndefinedOrNull2(balancesResult) ? void 0 : balancesResult < 1000000000000n && balancesResult > 0n ? "<0.00001" : shiftedBigInt?.toShortString();
|
|
499
767
|
}, [
|
|
500
768
|
balancesResult,
|
|
501
769
|
shiftedBigInt
|
|
@@ -512,21 +780,21 @@ var useAddressBalance = /* @__PURE__ */ __name((address, viewer, refresh) => {
|
|
|
512
780
|
|
|
513
781
|
// src/hooks/useConfirmTransactionBase.ts
|
|
514
782
|
import { usePromise as usePromise4 } from "@xylabs/react-promise";
|
|
515
|
-
import { forget as forget2, isDefined as
|
|
783
|
+
import { forget as forget2, isDefined as isDefined6, isHash } from "@xylabs/sdk-js";
|
|
516
784
|
import { PayloadBuilder } from "@xyo-network/sdk-js";
|
|
517
|
-
import { useEffect as
|
|
785
|
+
import { useEffect as useEffect5, useState as useState5 } from "react";
|
|
518
786
|
var useConfirmTransactionBase = /* @__PURE__ */ __name((transaction, onBroadcast, onStatusUpdate, runner, viewer) => {
|
|
519
|
-
const [status, setStatus] =
|
|
787
|
+
const [status, setStatus] = useState5();
|
|
520
788
|
const onStatusUpdateLocal = /* @__PURE__ */ __name((newStatus) => {
|
|
521
789
|
setStatus(newStatus);
|
|
522
790
|
onStatusUpdate?.(newStatus);
|
|
523
791
|
}, "onStatusUpdateLocal");
|
|
524
792
|
const [transactionConfirmationStatus, transactionConfirmationError] = usePromise4(async () => {
|
|
525
|
-
const hasRunner =
|
|
793
|
+
const hasRunner = isDefined6(runner);
|
|
526
794
|
if (transaction && viewer) {
|
|
527
795
|
const hash = hasRunner ? await runner.broadcastTransaction(transaction) : await PayloadBuilder.hash(transaction[0]);
|
|
528
796
|
if (isHash(hash)) {
|
|
529
|
-
if (hasRunner &&
|
|
797
|
+
if (hasRunner && isDefined6(onBroadcast)) onBroadcast(hash);
|
|
530
798
|
const params = {
|
|
531
799
|
onStatusUpdate: onStatusUpdateLocal,
|
|
532
800
|
transaction,
|
|
@@ -545,7 +813,7 @@ var useConfirmTransactionBase = /* @__PURE__ */ __name((transaction, onBroadcast
|
|
|
545
813
|
runner,
|
|
546
814
|
viewer
|
|
547
815
|
]);
|
|
548
|
-
|
|
816
|
+
useEffect5(() => {
|
|
549
817
|
return () => {
|
|
550
818
|
if (transactionConfirmationStatus) {
|
|
551
819
|
forget2(transactionConfirmationStatus.stop());
|
|
@@ -562,18 +830,18 @@ var useConfirmTransactionBase = /* @__PURE__ */ __name((transaction, onBroadcast
|
|
|
562
830
|
|
|
563
831
|
// src/hooks/useConnectAccount.ts
|
|
564
832
|
import { asAddress } from "@xylabs/sdk-js";
|
|
565
|
-
import { assertEx as
|
|
833
|
+
import { assertEx as assertEx3 } from "@xylabs/sdk-js";
|
|
566
834
|
import { MainNetwork } from "@xyo-network/xl1-sdk";
|
|
567
|
-
import { useCallback as
|
|
835
|
+
import { useCallback as useCallback3, useState as useState6 } from "react";
|
|
568
836
|
var useConnectAccount = /* @__PURE__ */ __name((gatewayName = MainNetwork.id, timeout) => {
|
|
569
|
-
const [connectError, setConnectError] =
|
|
570
|
-
const { gateway, error, timedout } =
|
|
837
|
+
const [connectError, setConnectError] = useState6();
|
|
838
|
+
const { gateway, error, timedout } = useGatewayFromWallet(gatewayName, timeout);
|
|
571
839
|
const [accountPermissions, accountPermissionsError] = useAccountPermissions();
|
|
572
|
-
const [address, setAddress] =
|
|
573
|
-
const connectSigner =
|
|
840
|
+
const [address, setAddress] = useState6();
|
|
841
|
+
const connectSigner = useCallback3(async () => {
|
|
574
842
|
try {
|
|
575
843
|
setConnectError(void 0);
|
|
576
|
-
const assertedGateway =
|
|
844
|
+
const assertedGateway = assertEx3(gateway, () => `Gateway ${gatewayName} is not available`);
|
|
577
845
|
const signer = assertedGateway.signer;
|
|
578
846
|
const address2 = await signer.address();
|
|
579
847
|
setAddress(address2);
|
|
@@ -596,10 +864,10 @@ var useConnectAccount = /* @__PURE__ */ __name((gatewayName = MainNetwork.id, ti
|
|
|
596
864
|
|
|
597
865
|
// src/hooks/useCurrentBlock.ts
|
|
598
866
|
import { usePromise as usePromise5 } from "@xylabs/react-promise";
|
|
599
|
-
import { isDefinedNotNull as
|
|
867
|
+
import { isDefinedNotNull as isDefinedNotNull4 } from "@xylabs/sdk-js";
|
|
600
868
|
var useCurrentBlock = /* @__PURE__ */ __name((refresh = 1, viewer) => {
|
|
601
869
|
return usePromise5(async () => {
|
|
602
|
-
if (
|
|
870
|
+
if (isDefinedNotNull4(viewer) && refresh > 0) {
|
|
603
871
|
const block = await viewer.currentBlock();
|
|
604
872
|
return block;
|
|
605
873
|
}
|
|
@@ -608,6 +876,18 @@ var useCurrentBlock = /* @__PURE__ */ __name((refresh = 1, viewer) => {
|
|
|
608
876
|
refresh
|
|
609
877
|
]);
|
|
610
878
|
}, "useCurrentBlock");
|
|
879
|
+
var useCurrentBlockFromGateway = /* @__PURE__ */ __name((refresh = 1) => {
|
|
880
|
+
const viewer = useViewerFromGateway();
|
|
881
|
+
return usePromise5(async () => {
|
|
882
|
+
if (isDefinedNotNull4(viewer) && refresh > 0) {
|
|
883
|
+
const block = await viewer.currentBlock();
|
|
884
|
+
return block;
|
|
885
|
+
}
|
|
886
|
+
}, [
|
|
887
|
+
viewer,
|
|
888
|
+
refresh
|
|
889
|
+
]);
|
|
890
|
+
}, "useCurrentBlockFromGateway");
|
|
611
891
|
|
|
612
892
|
// src/hooks/useHttpRpcRunner.ts
|
|
613
893
|
import { usePromise as usePromise6 } from "@xylabs/react-promise";
|
|
@@ -635,9 +915,9 @@ var useHttpRpcRunner = /* @__PURE__ */ __name((url) => {
|
|
|
635
915
|
// src/hooks/useNetwork.ts
|
|
636
916
|
import { isUndefined as isUndefined5 } from "@xylabs/sdk-js";
|
|
637
917
|
import { SimpleXyoNetwork } from "@xyo-network/xl1-sdk";
|
|
638
|
-
import { useMemo as
|
|
918
|
+
import { useMemo as useMemo5 } from "react";
|
|
639
919
|
var useNetwork = /* @__PURE__ */ __name((id) => {
|
|
640
|
-
const network =
|
|
920
|
+
const network = useMemo5(() => {
|
|
641
921
|
if (isUndefined5(id)) return;
|
|
642
922
|
return new SimpleXyoNetwork(id);
|
|
643
923
|
}, [
|
|
@@ -659,9 +939,10 @@ var useSigner = /* @__PURE__ */ __name((_provider, account) => {
|
|
|
659
939
|
|
|
660
940
|
// src/hooks/viewer/useCheckRpc.ts
|
|
661
941
|
import { usePromise as usePromise8 } from "@xylabs/react-promise";
|
|
662
|
-
import { delay as delay2, isDefined as
|
|
663
|
-
import {
|
|
664
|
-
import {
|
|
942
|
+
import { delay as delay2, isDefined as isDefined7, isUndefined as isUndefined6 } from "@xylabs/sdk-js";
|
|
943
|
+
import { basicRemoteViewerLocator as basicRemoteViewerLocator2 } from "@xyo-network/chain-orchestration";
|
|
944
|
+
import { LocalNetwork, SequenceNetwork, XyoViewerMoniker } from "@xyo-network/xl1-sdk";
|
|
945
|
+
import { useEffect as useEffect6, useState as useState7 } from "react";
|
|
665
946
|
var INTERVAL = 5e3;
|
|
666
947
|
var localRpcEndpoint = `${LocalNetwork.url}/rpc`;
|
|
667
948
|
var sequenceRpcEndpoint = `${SequenceNetwork.url}/rpc`;
|
|
@@ -670,35 +951,33 @@ var useCheckLocalRpc = /* @__PURE__ */ __name(() => {
|
|
|
670
951
|
return isLocalProducer;
|
|
671
952
|
}, "useCheckLocalRpc");
|
|
672
953
|
var useCheckSequenceRpc = /* @__PURE__ */ __name(() => {
|
|
673
|
-
const
|
|
674
|
-
return
|
|
954
|
+
const isSequenceRpc = useCheckRpc(sequenceRpcEndpoint);
|
|
955
|
+
return isSequenceRpc;
|
|
675
956
|
}, "useCheckSequenceRpc");
|
|
676
957
|
var useCheckRpc = /* @__PURE__ */ __name((endpoint) => {
|
|
677
|
-
const [isLocalProducer, setIsLocalProducer] =
|
|
678
|
-
const [error, setError] =
|
|
958
|
+
const [isLocalProducer, setIsLocalProducer] = useState7(false);
|
|
959
|
+
const [error, setError] = useState7();
|
|
679
960
|
const [viewer] = usePromise8(async () => {
|
|
680
961
|
if (isUndefined6(endpoint)) return;
|
|
681
|
-
const
|
|
682
|
-
|
|
683
|
-
|
|
962
|
+
const locator = await basicRemoteViewerLocator2(endpoint, {
|
|
963
|
+
rpc: {
|
|
964
|
+
protocol: "http",
|
|
965
|
+
url: endpoint
|
|
966
|
+
}
|
|
684
967
|
});
|
|
685
|
-
locator.register(SimpleTransactionViewer2.factory(SimpleTransactionViewer2.dependencies, {}));
|
|
686
|
-
locator.register(JsonRpcAccountBalanceViewer2.factory(JsonRpcAccountBalanceViewer2.dependencies, {
|
|
687
|
-
transport: await transportFactory(AccountBalanceViewerRpcSchemas2)
|
|
688
|
-
}));
|
|
689
968
|
const viewer2 = await locator.getInstance(XyoViewerMoniker);
|
|
690
969
|
return viewer2;
|
|
691
970
|
}, [
|
|
692
971
|
endpoint
|
|
693
972
|
]);
|
|
694
|
-
|
|
973
|
+
useEffect6(() => {
|
|
695
974
|
if (isUndefined6(viewer)) return;
|
|
696
975
|
void (async () => {
|
|
697
976
|
setError(void 0);
|
|
698
977
|
while (!isLocalProducer) {
|
|
699
978
|
try {
|
|
700
979
|
const block = await viewer.currentBlock();
|
|
701
|
-
setIsLocalProducer(
|
|
980
|
+
setIsLocalProducer(isDefined7(block));
|
|
702
981
|
} catch (err) {
|
|
703
982
|
setError(err);
|
|
704
983
|
setIsLocalProducer(false);
|
|
@@ -718,11 +997,11 @@ var useCheckRpc = /* @__PURE__ */ __name((endpoint) => {
|
|
|
718
997
|
|
|
719
998
|
// src/hooks/viewer/useHttpRpcViewer.ts
|
|
720
999
|
import { usePromise as usePromise9 } from "@xylabs/react-promise";
|
|
721
|
-
import { isDefined as
|
|
722
|
-
import { AccountBalanceViewerRpcSchemas as
|
|
1000
|
+
import { isDefined as isDefined8, isString as isString2, isUndefined as isUndefined7 } from "@xylabs/sdk-js";
|
|
1001
|
+
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
1002
|
|
|
724
1003
|
// src/hooks/viewer/ViewerWithDataLake.ts
|
|
725
|
-
import { isNull as
|
|
1004
|
+
import { isNull as isNull5 } from "@xylabs/sdk-js";
|
|
726
1005
|
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/sdk-js";
|
|
727
1006
|
import { addDataLakePayloads, addDataLakePayloadsToPayloads, DataLakeViewerMoniker, JsonRpcXyoViewer } from "@xyo-network/xl1-sdk";
|
|
728
1007
|
var ViewerWithDataLake = class extends JsonRpcXyoViewer {
|
|
@@ -752,7 +1031,7 @@ var ViewerWithDataLake = class extends JsonRpcXyoViewer {
|
|
|
752
1031
|
await PayloadBuilder2.addHashMeta(transaction[0]),
|
|
753
1032
|
await PayloadBuilder2.addHashMeta(transaction[1])
|
|
754
1033
|
] : null;
|
|
755
|
-
return
|
|
1034
|
+
return isNull5(transaction) ? transaction : (await addDataLakePayloads([
|
|
756
1035
|
await PayloadBuilder2.addHashMeta(transaction[0]),
|
|
757
1036
|
await PayloadBuilder2.addHashMeta(transaction[1])
|
|
758
1037
|
], this.dataLakeViewer))[0];
|
|
@@ -765,11 +1044,11 @@ var buildLocatorParams = /* @__PURE__ */ __name((urlOrNetwork) => {
|
|
|
765
1044
|
let dataLakeViewerParams;
|
|
766
1045
|
if (isString2(urlOrNetwork)) {
|
|
767
1046
|
const url = urlOrNetwork;
|
|
768
|
-
transportFactory = /* @__PURE__ */ __name((schemas) => new
|
|
1047
|
+
transportFactory = /* @__PURE__ */ __name((schemas) => new HttpRpcTransport2(`${url}/rpc`, schemas), "transportFactory");
|
|
769
1048
|
} else {
|
|
770
|
-
transportFactory = /* @__PURE__ */ __name((schemas) => new
|
|
1049
|
+
transportFactory = /* @__PURE__ */ __name((schemas) => new HttpRpcTransport2(`${urlOrNetwork.url}/rpc`, schemas), "transportFactory");
|
|
771
1050
|
dataLakeViewerParams = {
|
|
772
|
-
endpoint:
|
|
1051
|
+
endpoint: NetworkDataLakeUrls2[urlOrNetwork.id]
|
|
773
1052
|
};
|
|
774
1053
|
}
|
|
775
1054
|
return {
|
|
@@ -778,14 +1057,14 @@ var buildLocatorParams = /* @__PURE__ */ __name((urlOrNetwork) => {
|
|
|
778
1057
|
};
|
|
779
1058
|
}, "buildLocatorParams");
|
|
780
1059
|
var buildLocator = /* @__PURE__ */ __name(async (transportFactory, dataLakeViewerParams) => {
|
|
781
|
-
const locator = await
|
|
1060
|
+
const locator = await buildJsonRpcProviderLocator2({
|
|
782
1061
|
transportFactory
|
|
783
1062
|
});
|
|
784
|
-
locator.register(
|
|
785
|
-
transport: await transportFactory(
|
|
1063
|
+
locator.register(JsonRpcAccountBalanceViewer2.factory(JsonRpcAccountBalanceViewer2.dependencies, {
|
|
1064
|
+
transport: await transportFactory(AccountBalanceViewerRpcSchemas2)
|
|
786
1065
|
}));
|
|
787
|
-
locator.register(
|
|
788
|
-
if (
|
|
1066
|
+
locator.register(SimpleTransactionViewer2.factory(SimpleTransactionViewer2.dependencies, {}));
|
|
1067
|
+
if (isDefined8(dataLakeViewerParams)) {
|
|
789
1068
|
locator.register(RestDataLakeViewer.factory(RestDataLakeViewer.dependencies, dataLakeViewerParams));
|
|
790
1069
|
}
|
|
791
1070
|
locator.register(ViewerWithDataLake.factory(JsonRpcXyoViewer2.dependencies, {
|
|
@@ -809,15 +1088,15 @@ var useHttpRpcViewer = /* @__PURE__ */ __name((urlOrNetwork) => {
|
|
|
809
1088
|
|
|
810
1089
|
// src/hooks/viewer/useViewerFromWallet.ts
|
|
811
1090
|
import { usePromise as usePromise10 } from "@xylabs/react-promise";
|
|
812
|
-
import { isDefined as
|
|
1091
|
+
import { isDefined as isDefined9, isDefinedNotNull as isDefinedNotNull5, isNull as isNull6 } from "@xylabs/sdk-js";
|
|
813
1092
|
var useViewerFromWallet = /* @__PURE__ */ __name((networkId, timeout) => {
|
|
814
|
-
const { gateway, error, isLoading, timedout } =
|
|
1093
|
+
const { gateway, error, isLoading, timedout } = useGatewayFromWallet(networkId, timeout);
|
|
815
1094
|
const result = usePromise10(async () => {
|
|
816
1095
|
await Promise.resolve();
|
|
817
|
-
if (
|
|
818
|
-
if (timedout &&
|
|
1096
|
+
if (isDefinedNotNull5(error)) return null;
|
|
1097
|
+
if (timedout && isNull6(gateway)) return null;
|
|
819
1098
|
if (isLoading) return;
|
|
820
|
-
if (
|
|
1099
|
+
if (isDefined9(gateway) && isDefined9(networkId)) {
|
|
821
1100
|
const connection = gateway?.connection;
|
|
822
1101
|
return connection?.viewer;
|
|
823
1102
|
}
|
|
@@ -830,16 +1109,16 @@ var useViewerFromWallet = /* @__PURE__ */ __name((networkId, timeout) => {
|
|
|
830
1109
|
}, "useViewerFromWallet");
|
|
831
1110
|
|
|
832
1111
|
// src/components/connected/ConnectAccountsStack.tsx
|
|
833
|
-
var DefaultConnectComponent = /* @__PURE__ */ __name((props) => /* @__PURE__ */
|
|
1112
|
+
var DefaultConnectComponent = /* @__PURE__ */ __name((props) => /* @__PURE__ */ React5.createElement(ButtonEx, {
|
|
834
1113
|
variant: "contained",
|
|
835
1114
|
size: "small",
|
|
836
1115
|
...props
|
|
837
1116
|
}), "DefaultConnectComponent");
|
|
838
|
-
var DefaultNoWalletInstalledComponent = /* @__PURE__ */ __name(() => /* @__PURE__ */
|
|
1117
|
+
var DefaultNoWalletInstalledComponent = /* @__PURE__ */ __name(() => /* @__PURE__ */ React5.createElement(Alert, {
|
|
839
1118
|
severity: "warning"
|
|
840
|
-
}, /* @__PURE__ */
|
|
1119
|
+
}, /* @__PURE__ */ React5.createElement(AlertTitle, null, "XL1 Wallet Not Found"), /* @__PURE__ */ React5.createElement(Typography2, {
|
|
841
1120
|
gutterBottom: true
|
|
842
|
-
}, "Please ensure that your XL1 Wallet is installed to connect your account."), /* @__PURE__ */
|
|
1121
|
+
}, "Please ensure that your XL1 Wallet is installed to connect your account."), /* @__PURE__ */ React5.createElement(Button, {
|
|
843
1122
|
sx: {
|
|
844
1123
|
display: "flex",
|
|
845
1124
|
justifySelf: "end"
|
|
@@ -852,136 +1131,50 @@ var DefaultNoWalletInstalledComponent = /* @__PURE__ */ __name(() => /* @__PURE_
|
|
|
852
1131
|
}, "Get XL1 Wallet")), "DefaultNoWalletInstalledComponent");
|
|
853
1132
|
var ConnectAccountsStack = /* @__PURE__ */ __name(({ AccountComponent = ConnectedAccount, ConnectComponent = DefaultConnectComponent, NoWalletInstalledComponent = DefaultNoWalletInstalledComponent, onAccountConnected, onCancel, timeout, ...props }) => {
|
|
854
1133
|
const { address, connectSigner, error, timedout } = useConnectAccount(void 0, timeout);
|
|
855
|
-
|
|
856
|
-
if (
|
|
1134
|
+
useEffect7(() => {
|
|
1135
|
+
if (isDefined10(error) && isDefined10(onCancel)) {
|
|
857
1136
|
onCancel();
|
|
858
1137
|
}
|
|
859
1138
|
}, [
|
|
860
1139
|
error,
|
|
861
1140
|
onCancel
|
|
862
1141
|
]);
|
|
863
|
-
|
|
864
|
-
if (
|
|
1142
|
+
useEffect7(() => {
|
|
1143
|
+
if (isDefined10(address) && isDefined10(onAccountConnected)) {
|
|
865
1144
|
onAccountConnected(address);
|
|
866
1145
|
}
|
|
867
1146
|
}, [
|
|
868
1147
|
address,
|
|
869
1148
|
onAccountConnected
|
|
870
1149
|
]);
|
|
871
|
-
return /* @__PURE__ */
|
|
1150
|
+
return /* @__PURE__ */ React5.createElement(Stack2, {
|
|
872
1151
|
direction: "row",
|
|
873
1152
|
alignItems: "start",
|
|
874
1153
|
spacing: 2,
|
|
875
1154
|
...props
|
|
876
|
-
},
|
|
1155
|
+
}, isDefined10(address) ? /* @__PURE__ */ React5.createElement(AccountComponent, {
|
|
877
1156
|
address
|
|
878
|
-
}) : null, isUndefined8(address) && !timedout ? /* @__PURE__ */
|
|
1157
|
+
}) : null, isUndefined8(address) && !timedout ? /* @__PURE__ */ React5.createElement(ConnectComponent, {
|
|
879
1158
|
onClick: /* @__PURE__ */ __name(() => void connectSigner(), "onClick")
|
|
880
|
-
}, "Connect") : null, isUndefined8(address) && timedout ? /* @__PURE__ */
|
|
1159
|
+
}, "Connect") : null, isUndefined8(address) && timedout ? /* @__PURE__ */ React5.createElement(NoWalletInstalledComponent, null) : null, /* @__PURE__ */ React5.createElement(ErrorRender2, {
|
|
881
1160
|
error,
|
|
882
1161
|
scope: "ConnectSigner:error"
|
|
883
1162
|
}));
|
|
884
1163
|
}, "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
1164
|
export {
|
|
977
1165
|
ConnectAccountsStack,
|
|
978
1166
|
ConnectedAccount,
|
|
979
1167
|
DEFAULT_POLLING_INTERVAL,
|
|
1168
|
+
GatewayContext,
|
|
1169
|
+
GatewayProvider,
|
|
1170
|
+
InPageGatewaysContext,
|
|
1171
|
+
InPageGatewaysProvider,
|
|
980
1172
|
TransactionConfirmationStatus,
|
|
981
1173
|
ViewerWithDataLake,
|
|
982
1174
|
XL1CurrentBlockContext,
|
|
983
1175
|
XL1CurrentBlockProvider,
|
|
984
1176
|
balanceForRange,
|
|
1177
|
+
buildGateway,
|
|
985
1178
|
findMinimumBlock,
|
|
986
1179
|
formatAccountBalanceHistory,
|
|
987
1180
|
getXyoClient,
|
|
@@ -993,16 +1186,24 @@ export {
|
|
|
993
1186
|
useCheckRpc,
|
|
994
1187
|
useCheckSequenceRpc,
|
|
995
1188
|
useClient,
|
|
1189
|
+
useClientFromWallet,
|
|
996
1190
|
useConfirmTransactionBase,
|
|
997
1191
|
useConnectAccount,
|
|
998
1192
|
useCurrentBlock,
|
|
1193
|
+
useCurrentBlockFromGateway,
|
|
999
1194
|
useGateway,
|
|
1195
|
+
useGatewayFromWallet,
|
|
1000
1196
|
useHttpRpcRunner,
|
|
1001
1197
|
useHttpRpcViewer,
|
|
1002
1198
|
useNetwork,
|
|
1199
|
+
useNetworkFromGateway,
|
|
1003
1200
|
usePermissions,
|
|
1004
1201
|
usePollCurrentBlock,
|
|
1202
|
+
useProvidedGateway,
|
|
1203
|
+
useProvidedInPageGateways,
|
|
1204
|
+
useRunnerFromGateway,
|
|
1005
1205
|
useSigner,
|
|
1206
|
+
useViewerFromGateway,
|
|
1006
1207
|
useViewerFromWallet,
|
|
1007
1208
|
useXl1CurrentBlockContext
|
|
1008
1209
|
};
|