@xyo-network/react-chain-provider 1.22.0 → 1.23.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.
- package/dist/browser/components/connected/ConnectAccountsStack.d.ts +1 -1
- package/dist/browser/components/connected/ConnectAccountsStack.d.ts.map +1 -1
- package/dist/browser/contexts/gateway/Provider.d.ts +2 -2
- package/dist/browser/contexts/gateway/Provider.d.ts.map +1 -1
- package/dist/browser/contexts/in-page-gateways/Provider.d.ts +3 -3
- package/dist/browser/contexts/in-page-gateways/Provider.d.ts.map +1 -1
- package/dist/browser/contexts/in-page-gateways/context.d.ts +2 -2
- package/dist/browser/contexts/in-page-gateways/context.d.ts.map +1 -1
- package/dist/browser/contexts/in-page-gateways/state.d.ts +2 -2
- package/dist/browser/contexts/in-page-gateways/state.d.ts.map +1 -1
- package/dist/browser/contexts/in-page-gateways/use.d.ts +2 -2
- package/dist/browser/contexts/in-page-gateways/use.d.ts.map +1 -1
- package/dist/browser/hooks/gateway/useNetwork.d.ts +2 -1
- package/dist/browser/hooks/gateway/useNetwork.d.ts.map +1 -1
- package/dist/browser/hooks/gateway/useRunner.d.ts +2 -1
- package/dist/browser/hooks/gateway/useRunner.d.ts.map +1 -1
- package/dist/browser/hooks/gateway/useViewer.d.ts +2 -1
- package/dist/browser/hooks/gateway/useViewer.d.ts.map +1 -1
- package/dist/browser/hooks/helpers/getXyoClient.d.ts +2 -2
- package/dist/browser/hooks/helpers/getXyoClient.d.ts.map +1 -1
- package/dist/browser/hooks/useConnectAccount.d.ts +12 -16
- package/dist/browser/hooks/useConnectAccount.d.ts.map +1 -1
- package/dist/browser/hooks/useCurrentBlock.d.ts +1 -33
- package/dist/browser/hooks/useCurrentBlock.d.ts.map +1 -1
- package/dist/browser/index.mjs +236 -260
- package/dist/browser/index.mjs.map +7 -1
- package/package.json +30 -48
package/dist/browser/index.mjs
CHANGED
|
@@ -1,44 +1,55 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
|
|
4
1
|
// src/components/connected/account/Connected.tsx
|
|
5
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Stack,
|
|
4
|
+
Tooltip,
|
|
5
|
+
Typography
|
|
6
|
+
} from "@mui/material";
|
|
6
7
|
import { EthAddressWrapper } from "@xylabs/sdk-js";
|
|
7
|
-
import { BlockiesAvatarAddress } from "@xyo-network/
|
|
8
|
-
import
|
|
9
|
-
var ConnectedAccount =
|
|
8
|
+
import { BlockiesAvatarAddress } from "@xyo-network/xl1-blockies";
|
|
9
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
+
var ConnectedAccount = ({ address }) => {
|
|
10
11
|
const shortenedAddress = `${EthAddressWrapper.fromString(address)?.toShortString(4)}`;
|
|
11
|
-
return /* @__PURE__ */
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
12
|
+
return /* @__PURE__ */ jsxs(
|
|
13
|
+
Stack,
|
|
14
|
+
{
|
|
15
|
+
direction: "row",
|
|
16
|
+
spacing: 1,
|
|
17
|
+
sx: { alignItems: "center" },
|
|
18
|
+
children: [
|
|
19
|
+
/* @__PURE__ */ jsx(BlockiesAvatarAddress, { address, size: 21 }),
|
|
20
|
+
/* @__PURE__ */ jsx(Tooltip, { title: address, children: /* @__PURE__ */ jsx(
|
|
21
|
+
Typography,
|
|
22
|
+
{
|
|
23
|
+
variant: "caption",
|
|
24
|
+
sx: {
|
|
25
|
+
color: "text.secondary",
|
|
26
|
+
fontFamily: "monospace"
|
|
27
|
+
},
|
|
28
|
+
children: shortenedAddress
|
|
29
|
+
}
|
|
30
|
+
) })
|
|
31
|
+
]
|
|
27
32
|
}
|
|
28
|
-
|
|
29
|
-
}
|
|
33
|
+
);
|
|
34
|
+
};
|
|
30
35
|
|
|
31
36
|
// src/components/connected/ConnectAccountsStack.tsx
|
|
32
|
-
import {
|
|
37
|
+
import {
|
|
38
|
+
Alert,
|
|
39
|
+
AlertTitle,
|
|
40
|
+
Button,
|
|
41
|
+
Stack as Stack2,
|
|
42
|
+
Typography as Typography2
|
|
43
|
+
} from "@mui/material";
|
|
33
44
|
import { ButtonEx } from "@xylabs/react-button";
|
|
34
45
|
import { isDefined as isDefined5, isUndefined as isUndefined5 } from "@xylabs/sdk-js";
|
|
35
46
|
import { ErrorRender } from "@xyo-network/react-error";
|
|
36
|
-
import
|
|
47
|
+
import { useEffect as useEffect3 } from "react";
|
|
37
48
|
|
|
38
49
|
// src/hooks/account/helpers/formatAccountBalanceHistory.ts
|
|
39
50
|
import { hexToBigInt } from "@xylabs/sdk-js";
|
|
40
51
|
import { PayloadBuilder } from "@xyo-network/sdk-js";
|
|
41
|
-
var formatAccountBalanceHistory =
|
|
52
|
+
var formatAccountBalanceHistory = async (address, history) => {
|
|
42
53
|
const results = [];
|
|
43
54
|
for (const item of history) {
|
|
44
55
|
const [blockBw, txBw, transfer] = item;
|
|
@@ -77,31 +88,40 @@ var formatAccountBalanceHistory = /* @__PURE__ */ __name(async (address, history
|
|
|
77
88
|
}
|
|
78
89
|
}
|
|
79
90
|
return results;
|
|
80
|
-
}
|
|
91
|
+
};
|
|
81
92
|
|
|
82
93
|
// src/hooks/account/useAccountBalanceHistory.ts
|
|
83
94
|
import { usePromise } from "@xylabs/react-promise";
|
|
84
|
-
import {
|
|
95
|
+
import {
|
|
96
|
+
isUndefined
|
|
97
|
+
} from "@xylabs/sdk-js";
|
|
85
98
|
|
|
86
99
|
// src/lib/balanceForRange.ts
|
|
87
|
-
import {
|
|
88
|
-
|
|
100
|
+
import {
|
|
101
|
+
hexToBigInt as hexToBigInt2,
|
|
102
|
+
isHex,
|
|
103
|
+
toHex
|
|
104
|
+
} from "@xylabs/sdk-js";
|
|
105
|
+
var balanceForRange = (address, results) => {
|
|
89
106
|
const totalReceivedBalance = results?.reduce((a, [_block, _tx, transfer]) => {
|
|
90
107
|
return a + hexToBigInt2(transfer.transfers[address] ?? toHex(0));
|
|
91
108
|
}, 0n);
|
|
92
109
|
const totalSentBalance = results?.reduce((a, [_block, _tx, transfer]) => {
|
|
93
110
|
return transfer.from === address ? a + Object.values(transfer.transfers).reduce((a2, v) => a2 + (isHex(v) ? hexToBigInt2(v) : 0n), 0n) : a;
|
|
94
111
|
}, 0n);
|
|
95
|
-
return [
|
|
96
|
-
|
|
97
|
-
totalSentBalance
|
|
98
|
-
];
|
|
99
|
-
}, "balanceForRange");
|
|
112
|
+
return [totalReceivedBalance, totalSentBalance];
|
|
113
|
+
};
|
|
100
114
|
|
|
101
115
|
// src/lib/buildGateway.ts
|
|
102
116
|
import { assertEx, isDefined } from "@xylabs/sdk-js";
|
|
103
|
-
import {
|
|
104
|
-
|
|
117
|
+
import {
|
|
118
|
+
basicRemoteRunnerLocator,
|
|
119
|
+
basicRemoteViewerLocator,
|
|
120
|
+
DefaultNetworks,
|
|
121
|
+
NetworkDataLakeUrls,
|
|
122
|
+
XyoGatewayMoniker
|
|
123
|
+
} from "@xyo-network/xl1-sdk";
|
|
124
|
+
var buildGateway = async (gatewayName, signerTransport) => {
|
|
105
125
|
const network = DefaultNetworks.find((network2) => network2.id === gatewayName);
|
|
106
126
|
const resolvedNetwork = assertEx(network, () => `No network found for id ${gatewayName}`);
|
|
107
127
|
const remoteConfig = {
|
|
@@ -113,37 +133,30 @@ var buildGateway = /* @__PURE__ */ __name(async (gatewayName, signerTransport) =
|
|
|
113
133
|
const dataLakeEndpoint = NetworkDataLakeUrls[gatewayName];
|
|
114
134
|
const locator = isDefined(signerTransport) ? await basicRemoteRunnerLocator(gatewayName, remoteConfig, signerTransport, dataLakeEndpoint) : await basicRemoteViewerLocator(gatewayName, remoteConfig, dataLakeEndpoint);
|
|
115
135
|
return await locator.getInstance(XyoGatewayMoniker);
|
|
116
|
-
}
|
|
136
|
+
};
|
|
117
137
|
|
|
118
138
|
// src/lib/findMinimumBlock.ts
|
|
119
|
-
var findMinimumBlock =
|
|
139
|
+
var findMinimumBlock = (history) => {
|
|
120
140
|
if (history.length === 0) return 0;
|
|
121
141
|
const blockNumbers = history.map(([blockBw]) => blockBw.block);
|
|
122
142
|
const min = Math.min(...blockNumbers);
|
|
123
143
|
return Math.max(min - 1, 0);
|
|
124
|
-
}
|
|
144
|
+
};
|
|
125
145
|
|
|
126
146
|
// src/hooks/account/useAccountBalanceHistory.ts
|
|
127
|
-
var useAccountBalanceHistory =
|
|
147
|
+
var useAccountBalanceHistory = (address, viewer, maxPage = 10, blockRange, refresh) => {
|
|
128
148
|
return usePromise(async () => {
|
|
129
149
|
if (isUndefined(viewer) || isUndefined(address)) return;
|
|
130
150
|
let page = 1;
|
|
131
151
|
let lastBlock;
|
|
132
152
|
const pagedHistory = [];
|
|
133
153
|
const resolvedStartBlock = blockRange ? blockRange[0] : 0;
|
|
134
|
-
const history = await viewer.account.balance.accountBalanceHistory(address, blockRange ? {
|
|
135
|
-
range: blockRange
|
|
136
|
-
} : {});
|
|
154
|
+
const history = await viewer.account.balance.accountBalanceHistory(address, blockRange ? { range: blockRange } : {});
|
|
137
155
|
if (history.length > 0) {
|
|
138
156
|
pagedHistory.push(...history);
|
|
139
157
|
lastBlock = findMinimumBlock(history);
|
|
140
158
|
while (page < maxPage) {
|
|
141
|
-
const nextHistory = await viewer.account.balance.accountBalanceHistory(address, {
|
|
142
|
-
range: [
|
|
143
|
-
resolvedStartBlock,
|
|
144
|
-
lastBlock
|
|
145
|
-
]
|
|
146
|
-
});
|
|
159
|
+
const nextHistory = await viewer.account.balance.accountBalanceHistory(address, { range: [resolvedStartBlock, lastBlock] });
|
|
147
160
|
if (nextHistory.length === 0) break;
|
|
148
161
|
lastBlock = findMinimumBlock(nextHistory);
|
|
149
162
|
pagedHistory.push(...nextHistory);
|
|
@@ -156,45 +169,42 @@ var useAccountBalanceHistory = /* @__PURE__ */ __name((address, viewer, maxPage
|
|
|
156
169
|
balance: balanceForRange(address, pagedHistory),
|
|
157
170
|
truncated: page >= maxPage
|
|
158
171
|
};
|
|
159
|
-
}, [
|
|
160
|
-
|
|
161
|
-
viewer,
|
|
162
|
-
refresh,
|
|
163
|
-
blockRange,
|
|
164
|
-
maxPage
|
|
165
|
-
]);
|
|
166
|
-
}, "useAccountBalanceHistory");
|
|
172
|
+
}, [address, viewer, refresh, blockRange, maxPage]);
|
|
173
|
+
};
|
|
167
174
|
|
|
168
175
|
// src/hooks/gateway/useNetwork.ts
|
|
169
|
-
import { useProvidedGateway } from "@xyo-network/react-
|
|
170
|
-
var useNetworkFromGateway =
|
|
176
|
+
import { useProvidedGateway } from "@xyo-network/xl1-react-client-sdk";
|
|
177
|
+
var useNetworkFromGateway = () => {
|
|
171
178
|
const { defaultGateway } = useProvidedGateway();
|
|
172
179
|
return defaultGateway?.connection?.network;
|
|
173
|
-
}
|
|
180
|
+
};
|
|
174
181
|
|
|
175
182
|
// src/hooks/gateway/useRunner.ts
|
|
176
|
-
import { useProvidedGateway as useProvidedGateway2 } from "@xyo-network/react-
|
|
177
|
-
var useRunnerFromGateway =
|
|
183
|
+
import { useProvidedGateway as useProvidedGateway2 } from "@xyo-network/xl1-react-client-sdk";
|
|
184
|
+
var useRunnerFromGateway = () => {
|
|
178
185
|
const { defaultGateway } = useProvidedGateway2();
|
|
179
186
|
return defaultGateway?.connection?.runner;
|
|
180
|
-
}
|
|
187
|
+
};
|
|
181
188
|
|
|
182
189
|
// src/hooks/gateway/useViewer.ts
|
|
183
|
-
import { useProvidedGateway as useProvidedGateway3 } from "@xyo-network/react-
|
|
184
|
-
var useViewerFromGateway =
|
|
190
|
+
import { useProvidedGateway as useProvidedGateway3 } from "@xyo-network/xl1-react-client-sdk";
|
|
191
|
+
var useViewerFromGateway = () => {
|
|
185
192
|
const { defaultGateway } = useProvidedGateway3();
|
|
186
193
|
return defaultGateway?.connection?.viewer;
|
|
187
|
-
}
|
|
194
|
+
};
|
|
188
195
|
|
|
189
196
|
// src/hooks/helpers/getXyoClient.ts
|
|
190
|
-
import { getXyoClient, listenForClientInjection } from "@xyo-network/react-
|
|
197
|
+
import { getXyoClient, listenForClientInjection } from "@xyo-network/xl1-react-client-sdk";
|
|
191
198
|
|
|
192
199
|
// src/hooks/helpers/transaction/Confirmation.ts
|
|
193
|
-
import {
|
|
200
|
+
import {
|
|
201
|
+
assertEx as assertEx2,
|
|
202
|
+
delay,
|
|
203
|
+
forget,
|
|
204
|
+
isDefined as isDefined2,
|
|
205
|
+
isNull
|
|
206
|
+
} from "@xylabs/sdk-js";
|
|
194
207
|
var TransactionConfirmationStatus = class _TransactionConfirmationStatus {
|
|
195
|
-
static {
|
|
196
|
-
__name(this, "TransactionConfirmationStatus");
|
|
197
|
-
}
|
|
198
208
|
_params;
|
|
199
209
|
active = false;
|
|
200
210
|
constructor(params) {
|
|
@@ -297,8 +307,12 @@ var TransactionConfirmationStatus = class _TransactionConfirmationStatus {
|
|
|
297
307
|
import { usePromise as usePromise2 } from "@xylabs/react-promise";
|
|
298
308
|
import { isUndefined as isUndefined2, isUndefinedOrNull } from "@xylabs/sdk-js";
|
|
299
309
|
import { ShiftedBigInt } from "@xyo-network/xl1-sdk";
|
|
300
|
-
import {
|
|
301
|
-
|
|
310
|
+
import {
|
|
311
|
+
useMemo,
|
|
312
|
+
useRef,
|
|
313
|
+
useState
|
|
314
|
+
} from "react";
|
|
315
|
+
var useAddressBalance = (address, viewer, refresh, reset) => {
|
|
302
316
|
const [balancesResult, setBalancesResult] = useState();
|
|
303
317
|
const [loading, setLoading] = useState(false);
|
|
304
318
|
const [balancesError, setBalancesError] = useState();
|
|
@@ -330,11 +344,7 @@ var useAddressBalance = /* @__PURE__ */ __name((address, viewer, refresh, reset)
|
|
|
330
344
|
setLoading(false);
|
|
331
345
|
}
|
|
332
346
|
}
|
|
333
|
-
}, [
|
|
334
|
-
address,
|
|
335
|
-
viewer,
|
|
336
|
-
refresh
|
|
337
|
-
]);
|
|
347
|
+
}, [address, viewer, refresh]);
|
|
338
348
|
const shiftedBigInt = useMemo(() => {
|
|
339
349
|
if (typeof balancesResult !== "bigint") return;
|
|
340
350
|
return new ShiftedBigInt(balancesResult, {
|
|
@@ -344,20 +354,13 @@ var useAddressBalance = /* @__PURE__ */ __name((address, viewer, refresh, reset)
|
|
|
344
354
|
minDecimals: 1,
|
|
345
355
|
locale: navigator.language
|
|
346
356
|
});
|
|
347
|
-
}, [
|
|
348
|
-
balancesResult
|
|
349
|
-
]);
|
|
357
|
+
}, [balancesResult]);
|
|
350
358
|
const balanceIntlFriendly = useMemo(() => {
|
|
351
359
|
return shiftedBigInt?.toFullString();
|
|
352
|
-
}, [
|
|
353
|
-
shiftedBigInt
|
|
354
|
-
]);
|
|
360
|
+
}, [shiftedBigInt]);
|
|
355
361
|
const shortBalanceIntlFriendly = useMemo(() => {
|
|
356
362
|
return isUndefinedOrNull(balancesResult) ? void 0 : balancesResult < 1000000000000n && balancesResult > 0n ? "<0.00001" : shiftedBigInt?.toShortString();
|
|
357
|
-
}, [
|
|
358
|
-
balancesResult,
|
|
359
|
-
shiftedBigInt
|
|
360
|
-
]);
|
|
363
|
+
}, [balancesResult, shiftedBigInt]);
|
|
361
364
|
return {
|
|
362
365
|
address,
|
|
363
366
|
balanceForAddress: balancesResult,
|
|
@@ -366,19 +369,23 @@ var useAddressBalance = /* @__PURE__ */ __name((address, viewer, refresh, reset)
|
|
|
366
369
|
error: balancesError,
|
|
367
370
|
loading
|
|
368
371
|
};
|
|
369
|
-
}
|
|
372
|
+
};
|
|
370
373
|
|
|
371
374
|
// src/hooks/useConfirmTransactionBase.ts
|
|
372
375
|
import { usePromise as usePromise3 } from "@xylabs/react-promise";
|
|
373
|
-
import {
|
|
376
|
+
import {
|
|
377
|
+
forget as forget2,
|
|
378
|
+
isDefined as isDefined3,
|
|
379
|
+
isHash
|
|
380
|
+
} from "@xylabs/sdk-js";
|
|
374
381
|
import { PayloadBuilder as PayloadBuilder2 } from "@xyo-network/sdk-js";
|
|
375
382
|
import { useEffect, useState as useState2 } from "react";
|
|
376
|
-
var useConfirmTransactionBase =
|
|
383
|
+
var useConfirmTransactionBase = (transaction, onBroadcast, onStatusUpdate, runner, viewer) => {
|
|
377
384
|
const [status, setStatus] = useState2();
|
|
378
|
-
const onStatusUpdateLocal =
|
|
385
|
+
const onStatusUpdateLocal = (newStatus) => {
|
|
379
386
|
setStatus(newStatus);
|
|
380
387
|
onStatusUpdate?.(newStatus);
|
|
381
|
-
}
|
|
388
|
+
};
|
|
382
389
|
const [transactionConfirmationStatus, transactionConfirmationError] = usePromise3(async () => {
|
|
383
390
|
const hasRunner = isDefined3(runner);
|
|
384
391
|
if (transaction && viewer) {
|
|
@@ -398,35 +405,30 @@ var useConfirmTransactionBase = /* @__PURE__ */ __name((transaction, onBroadcast
|
|
|
398
405
|
throw new Error("unexpected return type from broadcast transaction");
|
|
399
406
|
}
|
|
400
407
|
}
|
|
401
|
-
}, [
|
|
402
|
-
transaction,
|
|
403
|
-
runner,
|
|
404
|
-
viewer
|
|
405
|
-
]);
|
|
408
|
+
}, [transaction, runner, viewer]);
|
|
406
409
|
useEffect(() => {
|
|
407
410
|
return () => {
|
|
408
411
|
if (transactionConfirmationStatus) {
|
|
409
412
|
forget2(transactionConfirmationStatus.stop());
|
|
410
413
|
}
|
|
411
414
|
};
|
|
412
|
-
}, [
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
return {
|
|
416
|
-
status,
|
|
417
|
-
transactionConfirmationError
|
|
418
|
-
};
|
|
419
|
-
}, "useConfirmTransactionBase");
|
|
415
|
+
}, [transactionConfirmationStatus]);
|
|
416
|
+
return { status, transactionConfirmationError };
|
|
417
|
+
};
|
|
420
418
|
|
|
421
419
|
// src/hooks/useConnectAccount.ts
|
|
422
420
|
import { asAddress } from "@xylabs/sdk-js";
|
|
423
421
|
import { assertEx as assertEx3 } from "@xylabs/sdk-js";
|
|
424
|
-
import { useAccountPermissions, useGatewayFromWallet } from "@xyo-network/react-
|
|
422
|
+
import { useAccountPermissions, useGatewayFromWallet } from "@xyo-network/xl1-react-client-sdk";
|
|
425
423
|
import { MainNetwork } from "@xyo-network/xl1-sdk";
|
|
426
424
|
import { useCallback, useState as useState3 } from "react";
|
|
427
|
-
var useConnectAccount =
|
|
425
|
+
var useConnectAccount = (gatewayName = MainNetwork.id, timeout) => {
|
|
428
426
|
const [connectError, setConnectError] = useState3();
|
|
429
|
-
const {
|
|
427
|
+
const {
|
|
428
|
+
gateway,
|
|
429
|
+
error,
|
|
430
|
+
timedout
|
|
431
|
+
} = useGatewayFromWallet(gatewayName, timeout);
|
|
430
432
|
const [accountPermissions, accountPermissionsError] = useAccountPermissions();
|
|
431
433
|
const [address, setAddress] = useState3();
|
|
432
434
|
const connectSigner = useCallback(async () => {
|
|
@@ -440,10 +442,7 @@ var useConnectAccount = /* @__PURE__ */ __name((gatewayName = MainNetwork.id, ti
|
|
|
440
442
|
} catch (e) {
|
|
441
443
|
setConnectError(e);
|
|
442
444
|
}
|
|
443
|
-
}, [
|
|
444
|
-
gateway,
|
|
445
|
-
gatewayName
|
|
446
|
-
]);
|
|
445
|
+
}, [gateway, gatewayName]);
|
|
447
446
|
return {
|
|
448
447
|
address: asAddress(accountPermissions?.[0] ?? address),
|
|
449
448
|
connectSigner,
|
|
@@ -451,92 +450,84 @@ var useConnectAccount = /* @__PURE__ */ __name((gatewayName = MainNetwork.id, ti
|
|
|
451
450
|
gateway,
|
|
452
451
|
timedout
|
|
453
452
|
};
|
|
454
|
-
}
|
|
453
|
+
};
|
|
455
454
|
|
|
456
455
|
// src/hooks/useCurrentBlock.ts
|
|
457
456
|
import { usePromise as usePromise4 } from "@xylabs/react-promise";
|
|
458
457
|
import { isDefinedNotNull } from "@xylabs/sdk-js";
|
|
459
|
-
var useCurrentBlock =
|
|
458
|
+
var useCurrentBlock = (refresh = 1, viewer) => {
|
|
460
459
|
return usePromise4(async () => {
|
|
461
460
|
if (isDefinedNotNull(viewer) && refresh > 0) {
|
|
462
461
|
const block = await viewer.currentBlock();
|
|
463
462
|
return block;
|
|
464
463
|
}
|
|
465
|
-
}, [
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
]);
|
|
469
|
-
}, "useCurrentBlock");
|
|
470
|
-
var useCurrentBlockFromGateway = /* @__PURE__ */ __name((refresh = 1) => {
|
|
464
|
+
}, [viewer, refresh]);
|
|
465
|
+
};
|
|
466
|
+
var useCurrentBlockFromGateway = (refresh = 1) => {
|
|
471
467
|
const viewer = useViewerFromGateway();
|
|
472
468
|
return usePromise4(async () => {
|
|
473
469
|
if (isDefinedNotNull(viewer) && refresh > 0) {
|
|
474
470
|
const block = await viewer.currentBlock();
|
|
475
471
|
return block;
|
|
476
472
|
}
|
|
477
|
-
}, [
|
|
478
|
-
|
|
479
|
-
refresh
|
|
480
|
-
]);
|
|
481
|
-
}, "useCurrentBlockFromGateway");
|
|
473
|
+
}, [viewer, refresh]);
|
|
474
|
+
};
|
|
482
475
|
|
|
483
476
|
// src/hooks/useNetwork.ts
|
|
484
477
|
import { isUndefined as isUndefined3 } from "@xylabs/sdk-js";
|
|
485
478
|
import { SimpleXyoNetwork } from "@xyo-network/xl1-sdk";
|
|
486
479
|
import { useMemo as useMemo2 } from "react";
|
|
487
|
-
var useNetwork =
|
|
480
|
+
var useNetwork = (id) => {
|
|
488
481
|
const network = useMemo2(() => {
|
|
489
482
|
if (isUndefined3(id)) return;
|
|
490
483
|
return new SimpleXyoNetwork(id);
|
|
491
|
-
}, [
|
|
492
|
-
id
|
|
493
|
-
]);
|
|
484
|
+
}, [id]);
|
|
494
485
|
return network;
|
|
495
|
-
}
|
|
486
|
+
};
|
|
496
487
|
|
|
497
488
|
// src/hooks/useSigner.ts
|
|
498
489
|
import { usePromise as usePromise5 } from "@xylabs/react-promise";
|
|
499
|
-
import {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
}) : void 0, [
|
|
504
|
-
|
|
505
|
-
]);
|
|
506
|
-
}, "useSigner");
|
|
490
|
+
import {
|
|
491
|
+
SimpleXyoSigner
|
|
492
|
+
} from "@xyo-network/xl1-sdk";
|
|
493
|
+
var useSigner = (_provider, account) => {
|
|
494
|
+
return usePromise5(async () => account ? await SimpleXyoSigner.create({ account }) : void 0, [account]);
|
|
495
|
+
};
|
|
507
496
|
|
|
508
497
|
// src/hooks/viewer/useCheckRpc.ts
|
|
509
498
|
import { usePromise as usePromise6 } from "@xylabs/react-promise";
|
|
510
|
-
import {
|
|
511
|
-
|
|
499
|
+
import {
|
|
500
|
+
delay as delay2,
|
|
501
|
+
isDefined as isDefined4,
|
|
502
|
+
isUndefined as isUndefined4
|
|
503
|
+
} from "@xylabs/sdk-js";
|
|
504
|
+
import {
|
|
505
|
+
basicRemoteViewerLocator as basicRemoteViewerLocator2,
|
|
506
|
+
LocalNetwork,
|
|
507
|
+
SequenceNetwork,
|
|
508
|
+
XyoViewerMoniker
|
|
509
|
+
} from "@xyo-network/xl1-sdk";
|
|
512
510
|
import { useEffect as useEffect2, useState as useState4 } from "react";
|
|
513
511
|
var INTERVAL = 5e3;
|
|
514
512
|
var localRpcEndpoint = `${LocalNetwork.url}/rpc`;
|
|
515
513
|
var sequenceRpcEndpoint = `${SequenceNetwork.url}/rpc`;
|
|
516
|
-
var useCheckLocalRpc =
|
|
514
|
+
var useCheckLocalRpc = () => {
|
|
517
515
|
const isLocalProducer = useCheckRpc(localRpcEndpoint);
|
|
518
516
|
return isLocalProducer;
|
|
519
|
-
}
|
|
520
|
-
var useCheckSequenceRpc =
|
|
517
|
+
};
|
|
518
|
+
var useCheckSequenceRpc = () => {
|
|
521
519
|
const isSequenceRpc = useCheckRpc(sequenceRpcEndpoint);
|
|
522
520
|
return isSequenceRpc;
|
|
523
|
-
}
|
|
524
|
-
var useCheckRpc =
|
|
521
|
+
};
|
|
522
|
+
var useCheckRpc = (endpoint) => {
|
|
525
523
|
const [isLocalProducer, setIsLocalProducer] = useState4(false);
|
|
526
524
|
const [error, setError] = useState4();
|
|
527
525
|
const [viewer] = usePromise6(async () => {
|
|
528
526
|
if (isUndefined4(endpoint)) return;
|
|
529
|
-
const locator = await basicRemoteViewerLocator2(endpoint, {
|
|
530
|
-
rpc: {
|
|
531
|
-
protocol: "http",
|
|
532
|
-
url: endpoint
|
|
533
|
-
}
|
|
534
|
-
});
|
|
527
|
+
const locator = await basicRemoteViewerLocator2(endpoint, { rpc: { protocol: "http", url: endpoint } });
|
|
535
528
|
const viewer2 = await locator.getInstance(XyoViewerMoniker);
|
|
536
529
|
return viewer2;
|
|
537
|
-
}, [
|
|
538
|
-
endpoint
|
|
539
|
-
]);
|
|
530
|
+
}, [endpoint]);
|
|
540
531
|
useEffect2(() => {
|
|
541
532
|
if (isUndefined4(viewer)) return;
|
|
542
533
|
void (async () => {
|
|
@@ -552,24 +543,20 @@ var useCheckRpc = /* @__PURE__ */ __name((endpoint) => {
|
|
|
552
543
|
await delay2(INTERVAL);
|
|
553
544
|
}
|
|
554
545
|
})();
|
|
555
|
-
}, [
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
]);
|
|
559
|
-
return {
|
|
560
|
-
isLocalProducer,
|
|
561
|
-
error
|
|
562
|
-
};
|
|
563
|
-
}, "useCheckRpc");
|
|
546
|
+
}, [isLocalProducer, viewer]);
|
|
547
|
+
return { isLocalProducer, error };
|
|
548
|
+
};
|
|
564
549
|
|
|
565
550
|
// src/hooks/viewer/ViewerWithDataLake.ts
|
|
566
551
|
import { isNull as isNull2 } from "@xylabs/sdk-js";
|
|
567
552
|
import { PayloadBuilder as PayloadBuilder3 } from "@xyo-network/sdk-js";
|
|
568
|
-
import {
|
|
553
|
+
import {
|
|
554
|
+
addDataLakePayloads,
|
|
555
|
+
addDataLakePayloadsToPayloads,
|
|
556
|
+
DataLakeViewerMoniker,
|
|
557
|
+
JsonRpcXyoViewer
|
|
558
|
+
} from "@xyo-network/xl1-sdk";
|
|
569
559
|
var ViewerWithDataLake = class extends JsonRpcXyoViewer {
|
|
570
|
-
static {
|
|
571
|
-
__name(this, "ViewerWithDataLake");
|
|
572
|
-
}
|
|
573
560
|
dataLakeViewer;
|
|
574
561
|
async blocksByHash(hash, limit) {
|
|
575
562
|
const blocks = await super.blocksByHash(hash, limit);
|
|
@@ -589,10 +576,7 @@ var ViewerWithDataLake = class extends JsonRpcXyoViewer {
|
|
|
589
576
|
}
|
|
590
577
|
async transactionByHash(hash) {
|
|
591
578
|
const transaction = await super.transaction.byHash(hash);
|
|
592
|
-
if (!this.dataLakeViewer) return transaction ? [
|
|
593
|
-
await PayloadBuilder3.addHashMeta(transaction[0]),
|
|
594
|
-
await PayloadBuilder3.addHashMeta(transaction[1])
|
|
595
|
-
] : null;
|
|
579
|
+
if (!this.dataLakeViewer) return transaction ? [await PayloadBuilder3.addHashMeta(transaction[0]), await PayloadBuilder3.addHashMeta(transaction[1])] : null;
|
|
596
580
|
return isNull2(transaction) ? transaction : (await addDataLakePayloads([
|
|
597
581
|
await PayloadBuilder3.addHashMeta(transaction[0]),
|
|
598
582
|
await PayloadBuilder3.addHashMeta(transaction[1])
|
|
@@ -601,83 +585,87 @@ var ViewerWithDataLake = class extends JsonRpcXyoViewer {
|
|
|
601
585
|
};
|
|
602
586
|
|
|
603
587
|
// src/components/connected/ConnectAccountsStack.tsx
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
588
|
+
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
589
|
+
var DefaultConnectComponent = (props) => /* @__PURE__ */ jsx2(ButtonEx, { variant: "contained", size: "small", ...props });
|
|
590
|
+
var DefaultNoWalletInstalledComponent = () => /* @__PURE__ */ jsxs2(Alert, { severity: "warning", children: [
|
|
591
|
+
/* @__PURE__ */ jsx2(AlertTitle, { children: "XL1 Wallet Not Found" }),
|
|
592
|
+
/* @__PURE__ */ jsx2(Typography2, { gutterBottom: true, children: "Please ensure that your XL1 Wallet is installed to connect your account." }),
|
|
593
|
+
/* @__PURE__ */ jsx2(
|
|
594
|
+
Button,
|
|
595
|
+
{
|
|
596
|
+
sx: { display: "flex", justifySelf: "end" },
|
|
597
|
+
size: "small",
|
|
598
|
+
variant: "outlined",
|
|
599
|
+
href: "https://chromewebstore.google.com/detail/xl1-wallet/fblbagcjeigmhakkfgjpdlcapcgmcfbm",
|
|
600
|
+
target: "_blank",
|
|
601
|
+
rel: "noopener",
|
|
602
|
+
children: "Get XL1 Wallet"
|
|
603
|
+
}
|
|
604
|
+
)
|
|
605
|
+
] });
|
|
606
|
+
var ConnectAccountsStack = ({
|
|
607
|
+
AccountComponent = ConnectedAccount,
|
|
608
|
+
ConnectComponent = DefaultConnectComponent,
|
|
609
|
+
NoWalletInstalledComponent = DefaultNoWalletInstalledComponent,
|
|
610
|
+
onAccountConnected,
|
|
611
|
+
onCancel,
|
|
612
|
+
timeout,
|
|
607
613
|
...props
|
|
608
|
-
})
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
display: "flex",
|
|
616
|
-
justifySelf: "end"
|
|
617
|
-
},
|
|
618
|
-
size: "small",
|
|
619
|
-
variant: "outlined",
|
|
620
|
-
href: "https://chromewebstore.google.com/detail/xl1-wallet/fblbagcjeigmhakkfgjpdlcapcgmcfbm",
|
|
621
|
-
target: "_blank",
|
|
622
|
-
rel: "noopener"
|
|
623
|
-
}, "Get XL1 Wallet")), "DefaultNoWalletInstalledComponent");
|
|
624
|
-
var ConnectAccountsStack = /* @__PURE__ */ __name(({ AccountComponent = ConnectedAccount, ConnectComponent = DefaultConnectComponent, NoWalletInstalledComponent = DefaultNoWalletInstalledComponent, onAccountConnected, onCancel, timeout, ...props }) => {
|
|
625
|
-
const { address, connectSigner, error, timedout } = useConnectAccount(void 0, timeout);
|
|
614
|
+
}) => {
|
|
615
|
+
const {
|
|
616
|
+
address,
|
|
617
|
+
connectSigner,
|
|
618
|
+
error,
|
|
619
|
+
timedout
|
|
620
|
+
} = useConnectAccount(void 0, timeout);
|
|
626
621
|
useEffect3(() => {
|
|
627
622
|
if (isDefined5(error) && isDefined5(onCancel)) {
|
|
628
623
|
onCancel();
|
|
629
624
|
}
|
|
630
|
-
}, [
|
|
631
|
-
error,
|
|
632
|
-
onCancel
|
|
633
|
-
]);
|
|
625
|
+
}, [error, onCancel]);
|
|
634
626
|
useEffect3(() => {
|
|
635
627
|
if (isDefined5(address) && isDefined5(onAccountConnected)) {
|
|
636
628
|
onAccountConnected(address);
|
|
637
629
|
}
|
|
638
|
-
}, [
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
props.sx
|
|
630
|
+
}, [address, onAccountConnected]);
|
|
631
|
+
return /* @__PURE__ */ jsxs2(
|
|
632
|
+
Stack2,
|
|
633
|
+
{
|
|
634
|
+
direction: "row",
|
|
635
|
+
spacing: 2,
|
|
636
|
+
...props,
|
|
637
|
+
sx: [{ alignItems: "start" }, ...Array.isArray(props.sx) ? props.sx : [props.sx]],
|
|
638
|
+
children: [
|
|
639
|
+
isDefined5(address) ? /* @__PURE__ */ jsx2(AccountComponent, { address }) : null,
|
|
640
|
+
isUndefined5(address) && !timedout ? /* @__PURE__ */ jsx2(ConnectComponent, { onClick: () => void connectSigner(), children: "Connect" }) : null,
|
|
641
|
+
isUndefined5(address) && timedout ? /* @__PURE__ */ jsx2(NoWalletInstalledComponent, {}) : null,
|
|
642
|
+
/* @__PURE__ */ jsx2(ErrorRender, { error, scope: "ConnectSigner:error" })
|
|
652
643
|
]
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
}) : null, isUndefined5(address) && !timedout ? /* @__PURE__ */ React2.createElement(ConnectComponent, {
|
|
657
|
-
onClick: /* @__PURE__ */ __name(() => void connectSigner(), "onClick")
|
|
658
|
-
}, "Connect") : null, isUndefined5(address) && timedout ? /* @__PURE__ */ React2.createElement(NoWalletInstalledComponent, null) : null, /* @__PURE__ */ React2.createElement(ErrorRender, {
|
|
659
|
-
error,
|
|
660
|
-
scope: "ConnectSigner:error"
|
|
661
|
-
}));
|
|
662
|
-
}, "ConnectAccountsStack");
|
|
644
|
+
}
|
|
645
|
+
);
|
|
646
|
+
};
|
|
663
647
|
|
|
664
648
|
// src/contexts/current-block/context.ts
|
|
665
649
|
import { createContextEx } from "@xylabs/react-shared";
|
|
666
650
|
var XL1CurrentBlockContext = createContextEx();
|
|
667
651
|
|
|
668
652
|
// src/contexts/current-block/Provider.tsx
|
|
669
|
-
import
|
|
653
|
+
import { useMemo as useMemo3 } from "react";
|
|
670
654
|
|
|
671
655
|
// src/contexts/current-block/usePollCurrentBlock.ts
|
|
672
656
|
import { isDefinedNotNull as isDefinedNotNull2, isUndefinedOrNull as isUndefinedOrNull2 } from "@xylabs/sdk-js";
|
|
673
|
-
import {
|
|
657
|
+
import {
|
|
658
|
+
startTransition,
|
|
659
|
+
useEffect as useEffect4,
|
|
660
|
+
useState as useState5
|
|
661
|
+
} from "react";
|
|
674
662
|
var DEFAULT_POLL_INTERVAL = 1e4;
|
|
675
|
-
var usePollCurrentBlock =
|
|
663
|
+
var usePollCurrentBlock = (viewer, interval = DEFAULT_POLL_INTERVAL, pause = false) => {
|
|
676
664
|
const [currentBlock, setCurrentBlock] = useState5(null);
|
|
677
665
|
const [error, setError] = useState5();
|
|
678
666
|
useEffect4(() => {
|
|
679
667
|
let isMounted = true;
|
|
680
|
-
const fetchBlock =
|
|
668
|
+
const fetchBlock = async () => {
|
|
681
669
|
if (isDefinedNotNull2(viewer)) {
|
|
682
670
|
try {
|
|
683
671
|
const block = await viewer.currentBlock();
|
|
@@ -700,7 +688,7 @@ var usePollCurrentBlock = /* @__PURE__ */ __name((viewer, interval = DEFAULT_POL
|
|
|
700
688
|
});
|
|
701
689
|
}
|
|
702
690
|
}
|
|
703
|
-
}
|
|
691
|
+
};
|
|
704
692
|
void fetchBlock();
|
|
705
693
|
const id = setInterval(() => {
|
|
706
694
|
if (!pause) {
|
|
@@ -711,25 +699,19 @@ var usePollCurrentBlock = /* @__PURE__ */ __name((viewer, interval = DEFAULT_POL
|
|
|
711
699
|
isMounted = false;
|
|
712
700
|
clearInterval(id);
|
|
713
701
|
};
|
|
714
|
-
}, [
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
pause
|
|
718
|
-
]);
|
|
719
|
-
return [
|
|
720
|
-
currentBlock,
|
|
721
|
-
error
|
|
722
|
-
];
|
|
723
|
-
}, "usePollCurrentBlock");
|
|
702
|
+
}, [viewer, interval, pause]);
|
|
703
|
+
return [currentBlock, error];
|
|
704
|
+
};
|
|
724
705
|
|
|
725
706
|
// src/contexts/current-block/Provider.tsx
|
|
707
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
726
708
|
var DEFAULT_POLLING_INTERVAL = 1e4;
|
|
727
|
-
var XL1CurrentBlockProvider =
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
]);
|
|
709
|
+
var XL1CurrentBlockProvider = ({
|
|
710
|
+
pollingConfig,
|
|
711
|
+
viewer,
|
|
712
|
+
children
|
|
713
|
+
}) => {
|
|
714
|
+
const { interval } = useMemo3(() => pollingConfig || { interval: DEFAULT_POLLING_INTERVAL }, [pollingConfig]);
|
|
733
715
|
const [currentBlock, currentBlockError] = usePollCurrentBlock(viewer, interval);
|
|
734
716
|
const value = useMemo3(() => ({
|
|
735
717
|
block: currentBlock,
|
|
@@ -738,31 +720,25 @@ var XL1CurrentBlockProvider = /* @__PURE__ */ __name(({ pollingConfig, viewer, c
|
|
|
738
720
|
error: currentBlockError,
|
|
739
721
|
pollingConfig,
|
|
740
722
|
provided: true
|
|
741
|
-
}), [
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
pollingConfig
|
|
745
|
-
]);
|
|
746
|
-
return /* @__PURE__ */ React3.createElement(XL1CurrentBlockContext, {
|
|
747
|
-
value
|
|
748
|
-
}, children);
|
|
749
|
-
}, "XL1CurrentBlockProvider");
|
|
723
|
+
}), [currentBlock, currentBlockError, pollingConfig]);
|
|
724
|
+
return /* @__PURE__ */ jsx3(XL1CurrentBlockContext, { value, children });
|
|
725
|
+
};
|
|
750
726
|
|
|
751
727
|
// src/contexts/current-block/use.ts
|
|
752
728
|
import { useContextEx } from "@xylabs/react-shared";
|
|
753
|
-
var useXl1CurrentBlockContext =
|
|
729
|
+
var useXl1CurrentBlockContext = (required = true) => useContextEx(XL1CurrentBlockContext, "XL1CurrentBlock", required);
|
|
754
730
|
|
|
755
731
|
// src/contexts/gateway/Provider.tsx
|
|
756
|
-
import { GatewayProvider } from "@xyo-network/react-
|
|
732
|
+
import { GatewayProvider } from "@xyo-network/xl1-react-client-sdk";
|
|
757
733
|
|
|
758
734
|
// src/contexts/in-page-gateways/context.ts
|
|
759
|
-
import { InPageGatewaysContext } from "@xyo-network/react-
|
|
735
|
+
import { InPageGatewaysContext } from "@xyo-network/xl1-react-client-sdk";
|
|
760
736
|
|
|
761
737
|
// src/contexts/in-page-gateways/Provider.tsx
|
|
762
|
-
import { InPageGatewaysProvider } from "@xyo-network/react-
|
|
738
|
+
import { InPageGatewaysProvider } from "@xyo-network/xl1-react-client-sdk";
|
|
763
739
|
|
|
764
740
|
// src/contexts/in-page-gateways/use.ts
|
|
765
|
-
import { useProvidedInPageGateways } from "@xyo-network/react-
|
|
741
|
+
import { useProvidedInPageGateways } from "@xyo-network/xl1-react-client-sdk";
|
|
766
742
|
export {
|
|
767
743
|
ConnectAccountsStack,
|
|
768
744
|
ConnectedAccount,
|
|
@@ -798,4 +774,4 @@ export {
|
|
|
798
774
|
useViewerFromGateway,
|
|
799
775
|
useXl1CurrentBlockContext
|
|
800
776
|
};
|
|
801
|
-
//# sourceMappingURL=index.mjs.map
|
|
777
|
+
//# sourceMappingURL=index.mjs.map
|