@xyo-network/react-chain-provider 1.16.2 → 1.16.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.
Files changed (39) hide show
  1. package/dist/browser/components/account/BalanceHistoryFlexbox.d.ts +11 -0
  2. package/dist/browser/components/account/BalanceHistoryFlexbox.d.ts.map +1 -0
  3. package/dist/browser/components/account/BalanceHistoryFlexbox.stories.d.ts +6 -0
  4. package/dist/browser/components/account/BalanceHistoryFlexbox.stories.d.ts.map +1 -0
  5. package/dist/browser/components/account/BalanceHistoryTable.d.ts +8 -0
  6. package/dist/browser/components/account/BalanceHistoryTable.d.ts.map +1 -0
  7. package/dist/browser/components/account/index.d.ts +3 -0
  8. package/dist/browser/components/account/index.d.ts.map +1 -0
  9. package/dist/browser/components/index.d.ts +1 -0
  10. package/dist/browser/components/index.d.ts.map +1 -1
  11. package/dist/browser/hooks/index.d.ts +1 -0
  12. package/dist/browser/hooks/index.d.ts.map +1 -1
  13. package/dist/browser/hooks/useAccountBalanceHistory.d.ts +11 -0
  14. package/dist/browser/hooks/useAccountBalanceHistory.d.ts.map +1 -0
  15. package/dist/browser/index.d.ts +1 -0
  16. package/dist/browser/index.d.ts.map +1 -1
  17. package/dist/browser/index.mjs +255 -55
  18. package/dist/browser/index.mjs.map +1 -1
  19. package/dist/browser/types/account/BalanceHistoryItemRow.d.ts +14 -0
  20. package/dist/browser/types/account/BalanceHistoryItemRow.d.ts.map +1 -0
  21. package/dist/browser/types/account/Table.d.ts +7 -0
  22. package/dist/browser/types/account/Table.d.ts.map +1 -0
  23. package/dist/browser/types/account/index.d.ts +3 -0
  24. package/dist/browser/types/account/index.d.ts.map +1 -0
  25. package/dist/browser/types/index.d.ts +2 -0
  26. package/dist/browser/types/index.d.ts.map +1 -0
  27. package/package.json +9 -6
  28. package/src/components/account/BalanceHistoryFlexbox.stories.tsx +25 -0
  29. package/src/components/account/BalanceHistoryFlexbox.tsx +67 -0
  30. package/src/components/account/BalanceHistoryTable.tsx +81 -0
  31. package/src/components/account/index.ts +2 -0
  32. package/src/components/index.ts +1 -0
  33. package/src/hooks/index.ts +1 -0
  34. package/src/hooks/useAccountBalanceHistory.ts +104 -0
  35. package/src/index.ts +1 -0
  36. package/src/types/account/BalanceHistoryItemRow.ts +14 -0
  37. package/src/types/account/Table.ts +14 -0
  38. package/src/types/account/index.ts +2 -0
  39. package/src/types/index.ts +1 -0
@@ -0,0 +1,11 @@
1
+ import { type Address } from '@xylabs/hex';
2
+ import type { FlexBoxProps } from '@xylabs/react-flexbox';
3
+ import type { XyoViewer } from '@xyo-network/xl1-protocol-sdk';
4
+ import React from 'react';
5
+ export interface AccountBalanceHistoryFlexBoxProps extends FlexBoxProps {
6
+ address?: Address;
7
+ refresh?: number;
8
+ viewer?: XyoViewer;
9
+ }
10
+ export declare const AccountBalanceHistoryFlexBox: React.FC<AccountBalanceHistoryFlexBoxProps>;
11
+ //# sourceMappingURL=BalanceHistoryFlexbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BalanceHistoryFlexbox.d.ts","sourceRoot":"","sources":["../../../../src/components/account/BalanceHistoryFlexbox.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAKzD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;AAC9D,OAAO,KAAK,MAAM,OAAO,CAAA;AAKzB,MAAM,WAAW,iCAAkC,SAAQ,YAAY;IACrE,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,MAAM,CAAC,EAAE,SAAS,CAAA;CACnB;AAED,eAAO,MAAM,4BAA4B,EAAE,KAAK,CAAC,EAAE,CAAC,iCAAiC,CA+CpF,CAAA"}
@@ -0,0 +1,6 @@
1
+ import type { Meta } from '@storybook/react-vite';
2
+ declare const _default: Meta;
3
+ export default _default;
4
+ declare const Default: import("storybook/internal/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("./BalanceHistoryFlexbox.tsx").AccountBalanceHistoryFlexBoxProps>;
5
+ export { Default };
6
+ //# sourceMappingURL=BalanceHistoryFlexbox.stories.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BalanceHistoryFlexbox.stories.d.ts","sourceRoot":"","sources":["../../../../src/components/account/BalanceHistoryFlexbox.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAW,MAAM,uBAAuB,CAAA;wBAWrD,IAAI;AAHT,wBAGS;AAOT,QAAA,MAAM,OAAO,sKAAoB,CAAA;AAMjC,OAAO,EAAE,OAAO,EAAE,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { TableProps } from '@mui/material';
2
+ import React from 'react';
3
+ import type { AccountBalanceHistoryItemRow } from '../../types/index.ts';
4
+ export interface AccountBalanceHistoryTableProps extends TableProps {
5
+ history?: AccountBalanceHistoryItemRow[];
6
+ }
7
+ export declare const AccountBalanceHistoryTable: React.FC<AccountBalanceHistoryTableProps>;
8
+ //# sourceMappingURL=BalanceHistoryTable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BalanceHistoryTable.d.ts","sourceRoot":"","sources":["../../../../src/components/account/BalanceHistoryTable.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAa/C,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,sBAAsB,CAAA;AAGxE,MAAM,WAAW,+BAAgC,SAAQ,UAAU;IACjE,OAAO,CAAC,EAAE,4BAA4B,EAAE,CAAA;CACzC;AAED,eAAO,MAAM,0BAA0B,EAAE,KAAK,CAAC,EAAE,CAAC,+BAA+B,CA0DhF,CAAA"}
@@ -0,0 +1,3 @@
1
+ export * from './BalanceHistoryFlexbox.tsx';
2
+ export * from './BalanceHistoryTable.tsx';
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/components/account/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAA;AAC3C,cAAc,2BAA2B,CAAA"}
@@ -1,2 +1,3 @@
1
+ export * from './account/index.ts';
1
2
  export * from './connected/index.ts';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/components/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAA;AAClC,cAAc,sBAAsB,CAAA"}
@@ -1,5 +1,6 @@
1
1
  export * from './client/index.ts';
2
2
  export * from './helpers/index.ts';
3
+ export * from './useAccountBalanceHistory.ts';
3
4
  export * from './useAddressBalance.ts';
4
5
  export * from './useConfirmTransactionBase.ts';
5
6
  export * from './useConnectAccount.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,wBAAwB,CAAA;AACtC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,wBAAwB,CAAA;AACtC,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAA;AACjC,cAAc,oBAAoB,CAAA;AAClC,cAAc,+BAA+B,CAAA;AAC7C,cAAc,wBAAwB,CAAA;AACtC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,wBAAwB,CAAA;AACtC,cAAc,sBAAsB,CAAA;AACpC,cAAc,uBAAuB,CAAA;AACrC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { type Address } from '@xylabs/hex';
2
+ import type { AttoXL1 } from '@xyo-network/xl1-protocol';
3
+ import type { AccountBalanceHistoryItem, XyoViewer } from '@xyo-network/xl1-protocol-sdk';
4
+ import type { AccountBalanceHistoryItemRow } from '../types/index.ts';
5
+ export declare const formatAccountBalanceHistory: (address: Address, history: AccountBalanceHistoryItem[]) => AccountBalanceHistoryItemRow[];
6
+ export declare const useAccountBalanceHistory: (address?: Address, viewer?: XyoViewer, refresh?: number) => [{
7
+ history: AccountBalanceHistoryItemRow[];
8
+ balance: [AttoXL1, AttoXL1];
9
+ truncated: boolean;
10
+ } | undefined, Error | undefined, import("@xylabs/react-promise").UsePromiseState | undefined];
11
+ //# sourceMappingURL=useAccountBalanceHistory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useAccountBalanceHistory.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAccountBalanceHistory.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,OAAO,EAGb,MAAM,aAAa,CAAA;AAGpB,OAAO,KAAK,EAAE,OAAO,EAAiB,MAAM,2BAA2B,CAAA;AACvE,OAAO,KAAK,EAAE,yBAAyB,EAAE,SAAS,EAAE,MAAM,+BAA+B,CAAA;AAEzF,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,mBAAmB,CAAA;AAErE,eAAO,MAAM,2BAA2B,GAAI,SAAS,OAAO,EAAE,SAAS,yBAAyB,EAAE,KAAG,4BAA4B,EAiChI,CAAA;AAqBD,eAAO,MAAM,wBAAwB,GAAI,UAAU,OAAO,EAAE,SAAS,SAAS,EAAE,UAAU,MAAM;;;;8FAqC/F,CAAA"}
@@ -1,3 +1,4 @@
1
1
  export * from './components/index.ts';
2
2
  export * from './hooks/index.ts';
3
+ export * from './types/index.ts';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAA;AACrC,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA"}
@@ -1,35 +1,13 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
3
 
4
- // src/components/connected/account/Connected.tsx
5
- import { Stack, Tooltip, Typography } from "@mui/material";
6
- import { EthAddressWrapper } from "@xylabs/eth-address";
7
- import { BlockiesAvatarAddress } from "@xyo-network/react-chain-blockies";
8
- import React from "react";
9
- var ConnectedAccount = /* @__PURE__ */ __name(({ address }) => {
10
- const shortenedAddress = `${EthAddressWrapper.fromString(address)?.toShortString(4)}`;
11
- return /* @__PURE__ */ React.createElement(Stack, {
12
- direction: "row",
13
- alignItems: "center",
14
- spacing: 1
15
- }, /* @__PURE__ */ React.createElement(BlockiesAvatarAddress, {
16
- address,
17
- size: 21
18
- }), /* @__PURE__ */ React.createElement(Tooltip, {
19
- title: address
20
- }, /* @__PURE__ */ React.createElement(Typography, {
21
- color: "textSecondary",
22
- variant: "caption",
23
- fontFamily: "monospace"
24
- }, shortenedAddress)));
25
- }, "ConnectedAccount");
26
-
27
- // src/components/connected/ConnectAccountsStack.tsx
28
- import { Alert, AlertTitle, Button, Stack as Stack2, Typography as Typography2 } from "@mui/material";
29
- import { ButtonEx } from "@xylabs/react-button";
30
- import { isDefined as isDefined7, isUndefined as isUndefined6 } from "@xylabs/typeof";
4
+ // src/components/account/BalanceHistoryFlexbox.tsx
5
+ import { Typography } from "@mui/material";
6
+ import { FlexCol } from "@xylabs/react-flexbox";
7
+ import { isDefined as isDefined8 } from "@xylabs/typeof";
31
8
  import { ErrorRender } from "@xyo-network/react-error";
32
- import React2, { useEffect as useEffect3 } from "react";
9
+ import { AttoXL1, XL1Amount as XL1Amount2 } from "@xyo-network/xl1-protocol";
10
+ import React2 from "react";
33
11
 
34
12
  // src/hooks/client/useClient.ts
35
13
  import { useSyncExternalStore } from "react";
@@ -299,9 +277,100 @@ var useGateway = /* @__PURE__ */ __name((gatewayName, timeout) => {
299
277
  };
300
278
  }, "useGateway");
301
279
 
302
- // src/hooks/useAddressBalance.ts
280
+ // src/hooks/useAccountBalanceHistory.ts
281
+ import { hexToBigInt, toHex } from "@xylabs/hex";
303
282
  import { usePromise as usePromise2 } from "@xylabs/react-promise";
304
- import { isUndefined, isUndefinedOrNull } from "@xylabs/typeof";
283
+ import { isUndefined } from "@xylabs/typeof";
284
+ var formatAccountBalanceHistory = /* @__PURE__ */ __name((address, history) => {
285
+ let results = [];
286
+ for (const item of history) {
287
+ const [blockBw, txBw, transfer] = item;
288
+ if (address === transfer.from) {
289
+ for (const [to, amount] of Object.entries(transfer.transfers)) {
290
+ results.push({
291
+ amount: hexToBigInt(amount),
292
+ blockNumber: blockBw.block,
293
+ from: transfer.from,
294
+ timestamp: blockBw.$epoch,
295
+ key: globalThis.crypto.randomUUID(),
296
+ to,
297
+ txHash: txBw?._hash,
298
+ debug: item,
299
+ type: "send"
300
+ });
301
+ }
302
+ } else {
303
+ results.push({
304
+ amount: hexToBigInt(transfer.transfers[address]),
305
+ blockNumber: blockBw.block,
306
+ from: transfer.from,
307
+ key: globalThis.crypto.randomUUID(),
308
+ timestamp: blockBw.$epoch,
309
+ to: address,
310
+ txHash: txBw?._hash,
311
+ debug: item,
312
+ type: "receive"
313
+ });
314
+ }
315
+ }
316
+ return results;
317
+ }, "formatAccountBalanceHistory");
318
+ var findMinimumBlock = /* @__PURE__ */ __name((history) => {
319
+ if (history.length === 0) return 0;
320
+ const blockNumbers = history.map(([blockBw]) => blockBw.block);
321
+ const min = Math.min(...blockNumbers);
322
+ return Math.max(min - 1, 0);
323
+ }, "findMinimumBlock");
324
+ var balanceForRange = /* @__PURE__ */ __name((address, results) => {
325
+ const totalReceivedBalance = results?.reduce((a, [_block, _tx, transfer]) => {
326
+ return a + hexToBigInt(transfer.transfers[address] ?? toHex(0));
327
+ }, 0n);
328
+ const totalSentBalance = results?.reduce((a, [_block, _tx, transfer]) => {
329
+ return transfer.from === address ? a + Object.values(transfer.transfers).reduce((a2, v) => a2 + (v ? hexToBigInt(v) : 0n), 0n) : a;
330
+ }, 0n);
331
+ return [
332
+ totalReceivedBalance,
333
+ totalSentBalance
334
+ ];
335
+ }, "balanceForRange");
336
+ var useAccountBalanceHistory = /* @__PURE__ */ __name((address, viewer, refresh) => {
337
+ return usePromise2(async () => {
338
+ if (isUndefined(viewer) || isUndefined(address)) return;
339
+ let page = 1;
340
+ let lastBlock;
341
+ const maxPage = 10;
342
+ const pagedHistory = [];
343
+ const history = await viewer.accountBalanceHistory(address);
344
+ if (history.length > 0) {
345
+ pagedHistory.push(...history);
346
+ lastBlock = findMinimumBlock(history);
347
+ while (page < maxPage) {
348
+ const nextHistory = await viewer.accountBalanceHistory(address, [
349
+ 0,
350
+ lastBlock
351
+ ]);
352
+ if (nextHistory.length === 0) break;
353
+ lastBlock = findMinimumBlock(nextHistory);
354
+ pagedHistory.push(...nextHistory);
355
+ page++;
356
+ }
357
+ }
358
+ const formattedHistory = formatAccountBalanceHistory(address, pagedHistory);
359
+ return {
360
+ history: formattedHistory,
361
+ balance: balanceForRange(address, pagedHistory),
362
+ truncated: page >= maxPage
363
+ };
364
+ }, [
365
+ address,
366
+ viewer,
367
+ refresh
368
+ ]);
369
+ }, "useAccountBalanceHistory");
370
+
371
+ // src/hooks/useAddressBalance.ts
372
+ import { usePromise as usePromise3 } from "@xylabs/react-promise";
373
+ import { isUndefined as isUndefined2, isUndefinedOrNull } from "@xylabs/typeof";
305
374
  import { ShiftedBigInt } from "@xyo-network/xl1-protocol";
306
375
  import { useMemo, useRef, useState } from "react";
307
376
  var useAddressBalance = /* @__PURE__ */ __name((address, viewer, refresh) => {
@@ -309,8 +378,8 @@ var useAddressBalance = /* @__PURE__ */ __name((address, viewer, refresh) => {
309
378
  const [loading, setLoading] = useState(false);
310
379
  const [balancesError, setBalancesError] = useState();
311
380
  const balancePromiseRef = useRef(null);
312
- usePromise2(async () => {
313
- if (isUndefined(viewer) || isUndefined(address)) return;
381
+ usePromise3(async () => {
382
+ if (isUndefined2(viewer) || isUndefined2(address)) return;
314
383
  setLoading(true);
315
384
  setBalancesError(void 0);
316
385
  const currentPromise = viewer.accountBalance(address);
@@ -376,7 +445,7 @@ var useAddressBalance = /* @__PURE__ */ __name((address, viewer, refresh) => {
376
445
  // src/hooks/useConfirmTransactionBase.ts
377
446
  import { forget as forget2 } from "@xylabs/forget";
378
447
  import { isHash } from "@xylabs/hex";
379
- import { usePromise as usePromise3 } from "@xylabs/react-promise";
448
+ import { usePromise as usePromise4 } from "@xylabs/react-promise";
380
449
  import { isDefined as isDefined4 } from "@xylabs/typeof";
381
450
  import { PayloadBuilder } from "@xyo-network/payload-builder";
382
451
  import { useEffect, useState as useState2 } from "react";
@@ -386,7 +455,7 @@ var useConfirmTransactionBase = /* @__PURE__ */ __name((transaction, onBroadcast
386
455
  setStatus(newStatus);
387
456
  onStatusUpdate?.(newStatus);
388
457
  }, "onStatusUpdateLocal");
389
- const [transactionConfirmationStatus, transactionConfirmationError] = usePromise3(async () => {
458
+ const [transactionConfirmationStatus, transactionConfirmationError] = usePromise4(async () => {
390
459
  const hasRunner = isDefined4(runner);
391
460
  if (transaction && viewer) {
392
461
  const hash = hasRunner ? await runner.broadcastTransaction(transaction) : await PayloadBuilder.hash(transaction[0]);
@@ -459,10 +528,10 @@ var useConnectAccount = /* @__PURE__ */ __name((gatewayName = MainNetwork.id, ti
459
528
  }, "useConnectAccount");
460
529
 
461
530
  // src/hooks/useCurrentBlock.ts
462
- import { usePromise as usePromise4 } from "@xylabs/react-promise";
531
+ import { usePromise as usePromise5 } from "@xylabs/react-promise";
463
532
  import { isDefinedNotNull as isDefinedNotNull2 } from "@xylabs/typeof";
464
533
  var useCurrentBlock = /* @__PURE__ */ __name((refresh = 1, viewer) => {
465
- return usePromise4(async () => {
534
+ return usePromise5(async () => {
466
535
  if (isDefinedNotNull2(viewer) && refresh > 0) {
467
536
  const block = await viewer.currentBlock();
468
537
  return block;
@@ -474,12 +543,12 @@ var useCurrentBlock = /* @__PURE__ */ __name((refresh = 1, viewer) => {
474
543
  }, "useCurrentBlock");
475
544
 
476
545
  // src/hooks/useHttpRpcRunner.ts
477
- import { isUndefined as isUndefined2 } from "@xylabs/typeof";
546
+ import { isUndefined as isUndefined3 } from "@xylabs/typeof";
478
547
  import { AllRpcSchemas, HttpRpcTransport, JsonRpcXyoRunner } from "@xyo-network/xl1-rpc";
479
548
  import { useMemo as useMemo2 } from "react";
480
549
  var useHttpRpcRunner = /* @__PURE__ */ __name((url) => {
481
550
  return useMemo2(() => {
482
- if (isUndefined2(url)) {
551
+ if (isUndefined3(url)) {
483
552
  return;
484
553
  }
485
554
  const transport = new HttpRpcTransport(`${url}/rpc`, AllRpcSchemas);
@@ -490,12 +559,12 @@ var useHttpRpcRunner = /* @__PURE__ */ __name((url) => {
490
559
  }, "useHttpRpcRunner");
491
560
 
492
561
  // src/hooks/useNetwork.ts
493
- import { isUndefined as isUndefined3 } from "@xylabs/typeof";
562
+ import { isUndefined as isUndefined4 } from "@xylabs/typeof";
494
563
  import { SimpleXyoNetwork } from "@xyo-network/xl1-protocol-sdk";
495
564
  import { useMemo as useMemo3 } from "react";
496
565
  var useNetwork = /* @__PURE__ */ __name((id) => {
497
566
  const network = useMemo3(() => {
498
- if (isUndefined3(id)) return;
567
+ if (isUndefined4(id)) return;
499
568
  return new SimpleXyoNetwork(id);
500
569
  }, [
501
570
  id
@@ -514,7 +583,7 @@ var useSigner = /* @__PURE__ */ __name((_provider, account) => {
514
583
 
515
584
  // src/hooks/viewer/useCheckRpc.ts
516
585
  import { delay as delay2 } from "@xylabs/delay";
517
- import { isDefined as isDefined5, isUndefined as isUndefined4 } from "@xylabs/typeof";
586
+ import { isDefined as isDefined5, isUndefined as isUndefined5 } from "@xylabs/typeof";
518
587
  import { LocalNetwork, SequenceNetwork } from "@xyo-network/chain-network-model";
519
588
  import { HttpRpcTransport as HttpRpcTransport2, JsonRpcNetworkStakeViewer, JsonRpcXyoViewer, NetworkStakeViewerRpcSchemas, XyoViewerRpcSchemas } from "@xyo-network/xl1-rpc";
520
589
  import { useEffect as useEffect2, useMemo as useMemo5, useState as useState4 } from "react";
@@ -533,7 +602,7 @@ var useCheckRpc = /* @__PURE__ */ __name((endpoint) => {
533
602
  const [isLocalProducer, setIsLocalProducer] = useState4(false);
534
603
  const [error, setError] = useState4();
535
604
  const viewer = useMemo5(() => {
536
- if (isUndefined4(endpoint)) return;
605
+ if (isUndefined5(endpoint)) return;
537
606
  const transport = new HttpRpcTransport2(endpoint, {
538
607
  ...XyoViewerRpcSchemas,
539
608
  ...NetworkStakeViewerRpcSchemas
@@ -547,7 +616,7 @@ var useCheckRpc = /* @__PURE__ */ __name((endpoint) => {
547
616
  endpoint
548
617
  ]);
549
618
  useEffect2(() => {
550
- if (isUndefined4(viewer)) return;
619
+ if (isUndefined5(viewer)) return;
551
620
  void (async () => {
552
621
  setError(void 0);
553
622
  while (!isLocalProducer) {
@@ -571,12 +640,12 @@ var useCheckRpc = /* @__PURE__ */ __name((endpoint) => {
571
640
  }, "useCheckRpc");
572
641
 
573
642
  // src/hooks/viewer/useHttpRpcViewer.ts
574
- import { isUndefined as isUndefined5 } from "@xylabs/typeof";
643
+ import { isUndefined as isUndefined6 } from "@xylabs/typeof";
575
644
  import { HttpRpcTransport as HttpRpcTransport3, JsonRpcNetworkStakeViewer as JsonRpcNetworkStakeViewer2, JsonRpcXyoViewer as JsonRpcXyoViewer2, NetworkStakeViewerRpcSchemas as NetworkStakeViewerRpcSchemas2, XyoViewerRpcSchemas as XyoViewerRpcSchemas2 } from "@xyo-network/xl1-rpc";
576
645
  import { useMemo as useMemo6 } from "react";
577
646
  var useHttpRpcViewer = /* @__PURE__ */ __name((url) => {
578
647
  const resolvedViewer = useMemo6(() => {
579
- if (isUndefined5(url)) {
648
+ if (isUndefined6(url)) {
580
649
  return;
581
650
  }
582
651
  const transport = new HttpRpcTransport3(`${url}/rpc`, {
@@ -604,17 +673,143 @@ var useViewerFromWallet = /* @__PURE__ */ __name((networkId) => {
604
673
  }
605
674
  }, "useViewerFromWallet");
606
675
 
676
+ // src/components/account/BalanceHistoryTable.tsx
677
+ import { Table, TableBody, TableCell, TableHead, TableRow, Tooltip } from "@mui/material";
678
+ import { isDefined as isDefined7 } from "@xylabs/typeof";
679
+ import { BlockAddressChip, BlockEpochTableCellInner, BlockNumberTableCellInner } from "@xyo-network/react-chain-blockchain";
680
+ import { RawInfoIconButton } from "@xyo-network/react-payload-raw-info";
681
+ import { XL1Amount } from "@xyo-network/xl1-protocol";
682
+ import React from "react";
683
+
684
+ // src/types/account/Table.ts
685
+ var TableHeadingLabels = [
686
+ "Tx Hash",
687
+ "BlockNumber",
688
+ "Timestamp",
689
+ "From",
690
+ "To",
691
+ "Amount",
692
+ "Debug"
693
+ ];
694
+
695
+ // src/components/account/BalanceHistoryTable.tsx
696
+ var AccountBalanceHistoryTable = /* @__PURE__ */ __name(({ history, ...props }) => {
697
+ const formatAmount = /* @__PURE__ */ __name((amount) => {
698
+ if (!isDefined7(amount)) {
699
+ return "N/A";
700
+ }
701
+ const xl1Amount = new XL1Amount(amount);
702
+ return xl1Amount.toString(void 0, {
703
+ places: 18,
704
+ maxDecimal: 12,
705
+ maxCharacters: 12,
706
+ minDecimals: 1,
707
+ locale: navigator.language
708
+ });
709
+ }, "formatAmount");
710
+ return isDefined7(history) ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Table, props, /* @__PURE__ */ React.createElement(TableHead, null, /* @__PURE__ */ React.createElement(TableRow, null, TableHeadingLabels.map((heading) => /* @__PURE__ */ React.createElement(TableCell, {
711
+ key: heading
712
+ }, heading)))), /* @__PURE__ */ React.createElement(TableBody, null, history?.map(({ amount, blockNumber, debug, from, key, timestamp, to, type, txHash }) => /* @__PURE__ */ React.createElement(TableRow, {
713
+ key
714
+ }, /* @__PURE__ */ React.createElement(TableCell, null, txHash || "N/A"), /* @__PURE__ */ React.createElement(BlockNumberTableCellInner, {
715
+ blockNumber
716
+ }), /* @__PURE__ */ React.createElement(BlockEpochTableCellInner, {
717
+ epoch: timestamp
718
+ }), /* @__PURE__ */ React.createElement(TableCell, null, /* @__PURE__ */ React.createElement(Tooltip, {
719
+ title: `From Address: ${from}`
720
+ }, /* @__PURE__ */ React.createElement(BlockAddressChip, {
721
+ address: from,
722
+ toolTipTitle: `From: ${from}`
723
+ }))), /* @__PURE__ */ React.createElement(TableCell, null, /* @__PURE__ */ React.createElement(Tooltip, {
724
+ title: `To Address: ${to}`
725
+ }, /* @__PURE__ */ React.createElement(BlockAddressChip, {
726
+ address: to,
727
+ toolTipTitle: `To: ${to}`
728
+ }))), /* @__PURE__ */ React.createElement(TableCell, null, /* @__PURE__ */ React.createElement(Tooltip, {
729
+ title: `Raw Amount: ${amount}`
730
+ }, /* @__PURE__ */ React.createElement("span", null, type === "send" ? "-" : "", formatAmount(amount)))), /* @__PURE__ */ React.createElement(TableCell, null, /* @__PURE__ */ React.createElement(RawInfoIconButton, {
731
+ rawValue: debug
732
+ }))))))) : null;
733
+ }, "AccountBalanceHistoryTable");
734
+
735
+ // src/components/account/BalanceHistoryFlexbox.tsx
736
+ var AccountBalanceHistoryFlexBox = /* @__PURE__ */ __name(({ address, refresh, viewer, ...props }) => {
737
+ const [results, error] = useAccountBalanceHistory(address, viewer, refresh);
738
+ const { history, balance, truncated } = results || {
739
+ balance: [
740
+ AttoXL1(0n),
741
+ AttoXL1(0n)
742
+ ],
743
+ history: void 0
744
+ };
745
+ const formatBalance = /* @__PURE__ */ __name((balance2) => {
746
+ const xl1Amount = new XL1Amount2(balance2);
747
+ return xl1Amount.toString(void 0, {
748
+ places: 18,
749
+ maxDecimal: 12,
750
+ maxCharacters: 12,
751
+ minDecimals: 1,
752
+ locale: navigator.language
753
+ });
754
+ }, "formatBalance");
755
+ const formatBalanceMagnitude = /* @__PURE__ */ __name((set) => {
756
+ const [received, sent] = set;
757
+ const netBalance = received - sent;
758
+ return netBalance < 0n ? `-${formatBalance(sent - received)}` : formatBalance(netBalance);
759
+ }, "formatBalanceMagnitude");
760
+ return isDefined8(history) && isDefined8(address) ? /* @__PURE__ */ React2.createElement(FlexCol, props, /* @__PURE__ */ React2.createElement(ErrorRender, {
761
+ error,
762
+ scope: "AccountBalanceHistoryTable"
763
+ }), /* @__PURE__ */ React2.createElement(Typography, {
764
+ variant: "h6",
765
+ gutterBottom: true
766
+ }, formatBalanceMagnitude(balance)), truncated ? /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(Typography, {
767
+ variant: "caption",
768
+ gutterBottom: true
769
+ }, "Ranged Balance from", " ", history.at(-1).blockNumber, " ", "-", " ", history[0].blockNumber)) : null, /* @__PURE__ */ React2.createElement(AccountBalanceHistoryTable, {
770
+ history
771
+ })) : null;
772
+ }, "AccountBalanceHistoryFlexBox");
773
+
774
+ // src/components/connected/account/Connected.tsx
775
+ import { Stack, Tooltip as Tooltip2, Typography as Typography2 } from "@mui/material";
776
+ import { EthAddressWrapper } from "@xylabs/eth-address";
777
+ import { BlockiesAvatarAddress } from "@xyo-network/react-chain-blockies";
778
+ import React3 from "react";
779
+ var ConnectedAccount = /* @__PURE__ */ __name(({ address }) => {
780
+ const shortenedAddress = `${EthAddressWrapper.fromString(address)?.toShortString(4)}`;
781
+ return /* @__PURE__ */ React3.createElement(Stack, {
782
+ direction: "row",
783
+ alignItems: "center",
784
+ spacing: 1
785
+ }, /* @__PURE__ */ React3.createElement(BlockiesAvatarAddress, {
786
+ address,
787
+ size: 21
788
+ }), /* @__PURE__ */ React3.createElement(Tooltip2, {
789
+ title: address
790
+ }, /* @__PURE__ */ React3.createElement(Typography2, {
791
+ color: "textSecondary",
792
+ variant: "caption",
793
+ fontFamily: "monospace"
794
+ }, shortenedAddress)));
795
+ }, "ConnectedAccount");
796
+
607
797
  // src/components/connected/ConnectAccountsStack.tsx
608
- var DefaultConnectComponent = /* @__PURE__ */ __name((props) => /* @__PURE__ */ React2.createElement(ButtonEx, {
798
+ import { Alert, AlertTitle, Button, Stack as Stack2, Typography as Typography3 } from "@mui/material";
799
+ import { ButtonEx } from "@xylabs/react-button";
800
+ import { isDefined as isDefined9, isUndefined as isUndefined7 } from "@xylabs/typeof";
801
+ import { ErrorRender as ErrorRender2 } from "@xyo-network/react-error";
802
+ import React4, { useEffect as useEffect3 } from "react";
803
+ var DefaultConnectComponent = /* @__PURE__ */ __name((props) => /* @__PURE__ */ React4.createElement(ButtonEx, {
609
804
  variant: "contained",
610
805
  size: "small",
611
806
  ...props
612
807
  }), "DefaultConnectComponent");
613
- var DefaultNoWalletInstalledComponent = /* @__PURE__ */ __name(() => /* @__PURE__ */ React2.createElement(Alert, {
808
+ var DefaultNoWalletInstalledComponent = /* @__PURE__ */ __name(() => /* @__PURE__ */ React4.createElement(Alert, {
614
809
  severity: "warning"
615
- }, /* @__PURE__ */ React2.createElement(AlertTitle, null, "XL1 Wallet Not Found"), /* @__PURE__ */ React2.createElement(Typography2, {
810
+ }, /* @__PURE__ */ React4.createElement(AlertTitle, null, "XL1 Wallet Not Found"), /* @__PURE__ */ React4.createElement(Typography3, {
616
811
  gutterBottom: true
617
- }, "Please ensure that your XL1 Wallet is installed to connect your account."), /* @__PURE__ */ React2.createElement(Button, {
812
+ }, "Please ensure that your XL1 Wallet is installed to connect your account."), /* @__PURE__ */ React4.createElement(Button, {
618
813
  sx: {
619
814
  display: "flex",
620
815
  justifySelf: "end"
@@ -628,7 +823,7 @@ var DefaultNoWalletInstalledComponent = /* @__PURE__ */ __name(() => /* @__PURE_
628
823
  var ConnectAccountsStack = /* @__PURE__ */ __name(({ AccountComponent = ConnectedAccount, ConnectComponent = DefaultConnectComponent, NoWalletInstalledComponent = DefaultNoWalletInstalledComponent, onAccountConnected, onCancel, timeout, ...props }) => {
629
824
  const { address, connectSigner, error, timedout } = useConnectAccount(void 0, timeout);
630
825
  useEffect3(() => {
631
- if (isDefined7(error) && isDefined7(onCancel)) {
826
+ if (isDefined9(error) && isDefined9(onCancel)) {
632
827
  onCancel();
633
828
  }
634
829
  }, [
@@ -636,33 +831,38 @@ var ConnectAccountsStack = /* @__PURE__ */ __name(({ AccountComponent = Connecte
636
831
  onCancel
637
832
  ]);
638
833
  useEffect3(() => {
639
- if (isDefined7(address) && isDefined7(onAccountConnected)) {
834
+ if (isDefined9(address) && isDefined9(onAccountConnected)) {
640
835
  onAccountConnected(address);
641
836
  }
642
837
  }, [
643
838
  address,
644
839
  onAccountConnected
645
840
  ]);
646
- return /* @__PURE__ */ React2.createElement(Stack2, {
841
+ return /* @__PURE__ */ React4.createElement(Stack2, {
647
842
  direction: "row",
648
843
  alignItems: "start",
649
844
  spacing: 2,
650
845
  ...props
651
- }, isDefined7(address) ? /* @__PURE__ */ React2.createElement(AccountComponent, {
846
+ }, isDefined9(address) ? /* @__PURE__ */ React4.createElement(AccountComponent, {
652
847
  address
653
- }) : null, isUndefined6(address) && !timedout ? /* @__PURE__ */ React2.createElement(ConnectComponent, {
848
+ }) : null, isUndefined7(address) && !timedout ? /* @__PURE__ */ React4.createElement(ConnectComponent, {
654
849
  onClick: /* @__PURE__ */ __name(() => void connectSigner(), "onClick")
655
- }, "Connect") : null, isUndefined6(address) && timedout ? /* @__PURE__ */ React2.createElement(NoWalletInstalledComponent, null) : null, /* @__PURE__ */ React2.createElement(ErrorRender, {
850
+ }, "Connect") : null, isUndefined7(address) && timedout ? /* @__PURE__ */ React4.createElement(NoWalletInstalledComponent, null) : null, /* @__PURE__ */ React4.createElement(ErrorRender2, {
656
851
  error,
657
852
  scope: "ConnectSigner:error"
658
853
  }));
659
854
  }, "ConnectAccountsStack");
660
855
  export {
856
+ AccountBalanceHistoryFlexBox,
857
+ AccountBalanceHistoryTable,
661
858
  ConnectAccountsStack,
662
859
  ConnectedAccount,
860
+ TableHeadingLabels,
663
861
  TransactionConfirmationStatus,
862
+ formatAccountBalanceHistory,
664
863
  getXyoClient,
665
864
  listenForClientInjection,
865
+ useAccountBalanceHistory,
666
866
  useAccountPermissions,
667
867
  useAddressBalance,
668
868
  useCheckLocalRpc,