@xyo-network/react-chain-blockchain 1.16.16 → 1.16.17

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "http://json.schemastore.org/package.json",
3
3
  "name": "@xyo-network/react-chain-blockchain",
4
- "version": "1.16.16",
4
+ "version": "1.16.17",
5
5
  "description": "XYO Layer One React SDK Blockchain",
6
6
  "homepage": "https://xylabs.com",
7
7
  "bugs": {
@@ -38,7 +38,10 @@
38
38
  "types": "./dist/browser/index.d.ts",
39
39
  "files": [
40
40
  "dist",
41
- "src"
41
+ "src",
42
+ "!**/*.bench.*",
43
+ "!**/*.spec.*",
44
+ "!**/*.test.*"
42
45
  ],
43
46
  "scripts": {
44
47
  "package-cycle": "echo Nothing to do"
@@ -60,18 +63,18 @@
60
63
  "@xyo-network/boundwitness-builder": "~5.1.23",
61
64
  "@xyo-network/boundwitness-model": "~5.1.23",
62
65
  "@xyo-network/bridge-http": "~5.1.23",
63
- "@xyo-network/chain-analyze": "~1.16.16",
64
- "@xyo-network/chain-protocol": "~1.16.16",
65
- "@xyo-network/chain-services": "~1.16.16",
66
- "@xyo-network/chain-utils": "~1.16.16",
67
- "@xyo-network/chain-wrappers": "~1.16.16",
66
+ "@xyo-network/chain-analyze": "~1.16.17",
67
+ "@xyo-network/chain-protocol": "~1.16.17",
68
+ "@xyo-network/chain-services": "~1.16.17",
69
+ "@xyo-network/chain-utils": "~1.16.17",
70
+ "@xyo-network/chain-wrappers": "~1.16.17",
68
71
  "@xyo-network/module-model": "~5.1.23",
69
72
  "@xyo-network/payload-builder": "~5.1.23",
70
73
  "@xyo-network/payload-model": "~5.1.23",
71
74
  "@xyo-network/react-boundwitness-plugin": "~7.3.10",
72
- "@xyo-network/react-chain-blockies": "~1.16.16",
73
- "@xyo-network/react-chain-provider": "~1.16.16",
74
- "@xyo-network/react-chain-shared": "~1.16.16",
75
+ "@xyo-network/react-chain-blockies": "~1.16.17",
76
+ "@xyo-network/react-chain-provider": "~1.16.17",
77
+ "@xyo-network/react-chain-shared": "~1.16.17",
75
78
  "@xyo-network/react-error": "~7.3.10",
76
79
  "@xyo-network/react-event": "~7.3.10",
77
80
  "@xyo-network/react-payload-raw-info": "~7.3.10",
@@ -79,7 +82,7 @@
79
82
  "@xyo-network/react-shared": "~7.3.10",
80
83
  "@xyo-network/react-table": "~7.3.10",
81
84
  "@xyo-network/xl1-protocol": "~1.13.11",
82
- "@xyo-network/xl1-protocol-sdk": "~1.16.16"
85
+ "@xyo-network/xl1-protocol-sdk": "~1.16.17"
83
86
  },
84
87
  "devDependencies": {
85
88
  "@emotion/react": "~11.14.0",
@@ -87,14 +90,15 @@
87
90
  "@mui/icons-material": "~7.3.5",
88
91
  "@mui/material": "~7.3.5",
89
92
  "@types/react": "~19.2.5",
93
+ "@xylabs/react-button": "~7.1.8",
90
94
  "@xylabs/sdk-js": "~5.0.34",
91
95
  "@xylabs/ts-scripts-yarn3": "~7.2.8",
92
96
  "@xylabs/tsconfig": "~7.2.8",
93
97
  "@xylabs/tsconfig-dom": "~7.2.8",
94
98
  "@xylabs/tsconfig-react": "~7.2.8",
95
99
  "@xyo-network/api-models": "~5.1.23",
96
- "@xyo-network/xl1-network-model": "~1.16.16",
97
- "@xyo-network/xl1-rpc": "~1.16.16",
100
+ "@xyo-network/xl1-network-model": "~1.16.17",
101
+ "@xyo-network/xl1-rpc": "~1.16.17",
98
102
  "axios": "^1.13.2",
99
103
  "eslint": "^9.39.1",
100
104
  "react": "~19.2.0",
@@ -0,0 +1 @@
1
+ export * from './usePagedAccountBalanceHistory.ts'
@@ -0,0 +1,44 @@
1
+ import type { Address } from '@xylabs/sdk-js'
2
+ import { isDefined } from '@xylabs/sdk-js'
3
+ import type { AccountBalanceHistoryItemFormatted } from '@xyo-network/react-chain-provider'
4
+ import { useAccountBalanceHistory } from '@xyo-network/react-chain-provider'
5
+ import type { XL1BlockRange } from '@xyo-network/xl1-protocol'
6
+ import type { XyoViewer } from '@xyo-network/xl1-protocol-sdk'
7
+ import {
8
+ useCallback, useMemo, useState,
9
+ } from 'react'
10
+
11
+ export const usePagedAccountBalanceHistory = (address?: Address, viewer?: XyoViewer, maxPage = 1) => {
12
+ const [updatedBlockRange, setUpdatedBlockRange] = useState<XL1BlockRange>()
13
+ const [pagedHistory, setPagedHistory] = useState<AccountBalanceHistoryItemFormatted[]>()
14
+ const [results, error, loading] = useAccountBalanceHistory(address, viewer, maxPage, updatedBlockRange)
15
+
16
+ const { history, truncated } = results || {}
17
+
18
+ useMemo(() => {
19
+ if (isDefined(history)) {
20
+ setPagedHistory((pagedHistory) => {
21
+ return [...pagedHistory ?? [], ...history]
22
+ })
23
+ }
24
+ }, [history])
25
+
26
+ const firstBlock = isDefined(history) ? history.at(0)?.blockNumber : undefined
27
+ const lastBlock = isDefined(history) ? history.at(-1)?.blockNumber : undefined
28
+ const historyComplete = isDefined(history) && history.length === 0
29
+
30
+ const updateRange = useCallback(() => {
31
+ if (isDefined(lastBlock) && lastBlock > 0 && truncated) {
32
+ const newEndBlock = lastBlock - 1
33
+ setUpdatedBlockRange([0, newEndBlock] as XL1BlockRange)
34
+ }
35
+ }, [firstBlock, lastBlock, truncated])
36
+
37
+ return {
38
+ pagedHistory,
39
+ historyComplete,
40
+ updateRange,
41
+ error,
42
+ loading,
43
+ }
44
+ }
@@ -1,3 +1,4 @@
1
1
  export * from './BalanceHistoryFlexbox.tsx'
2
2
  export * from './helpers/index.ts'
3
+ export * from './hooks/index.ts'
3
4
  export * from './table/index.ts'
@@ -1,15 +1,20 @@
1
1
  import {
2
- Alert, AlertTitle, LinearProgress, Snackbar,
2
+ Alert, AlertTitle,
3
+ LinearProgress, Snackbar,
4
+ Stack,
3
5
  } from '@mui/material'
4
6
  import type { Meta, StoryFn } from '@storybook/react-vite'
5
- import type { Address } from '@xylabs/sdk-js'
7
+ import { ButtonEx } from '@xylabs/react-button'
8
+ import { type Address } from '@xylabs/sdk-js'
6
9
  import { useAccountBalanceHistory, useHttpRpcViewer } from '@xyo-network/react-chain-provider'
7
10
  import { ErrorRender } from '@xyo-network/react-error'
8
11
  import type { Event } from '@xyo-network/react-event'
9
12
  import { useEvent } from '@xyo-network/react-event'
10
13
  import { LocalNetwork } from '@xyo-network/xl1-network-model'
11
- import React, { useState } from 'react'
14
+ import type { XL1BlockRange } from '@xyo-network/xl1-protocol'
15
+ import { useState } from 'react'
12
16
 
17
+ import { usePagedAccountBalanceHistory } from '../hooks/index.ts'
13
18
  import { AccountBalanceHistoryTableEx } from './BalanceHistoryTableEx.tsx'
14
19
 
15
20
  export default {
@@ -21,9 +26,9 @@ const TEST_ADDRESS = 'aa9401662e9cd3ce8bb8a6ab92a35ed83e85ac67' as Address
21
26
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
22
27
  const TEST_ADDRESS_1 = '2b1a21d8c90e658d8bf1e2aad31c8dc892c353c1' as Address
23
28
 
24
- const useFetchBalanceHistory = (address?: Address) => {
29
+ const useFetchBalanceHistory = (address?: Address, maxPage = 10, blockRange?: XL1BlockRange) => {
25
30
  const viewer = useHttpRpcViewer(LocalNetwork.url)
26
- return useAccountBalanceHistory(address, viewer)
31
+ return useAccountBalanceHistory(address, viewer, maxPage, blockRange)
27
32
  }
28
33
 
29
34
  const Template: StoryFn<typeof AccountBalanceHistoryTableEx> = (args) => {
@@ -66,10 +71,38 @@ const TemplateLinked: StoryFn<typeof AccountBalanceHistoryTableEx> = (args) => {
66
71
  )
67
72
  }
68
73
 
74
+ const TemplatePaged: StoryFn<typeof AccountBalanceHistoryTableEx> = (args) => {
75
+ const viewer = useHttpRpcViewer(LocalNetwork.url)
76
+ const {
77
+ pagedHistory, historyComplete, updateRange, error, loading,
78
+ } = usePagedAccountBalanceHistory(TEST_ADDRESS, viewer, 1)
79
+
80
+ return (
81
+ <Stack gap={2}>
82
+ <ErrorRender error={error} scope="AccountBalanceHistoryTableStory" />
83
+ {loading === 'pending' ? <LinearProgress /> : null}
84
+ <AccountBalanceHistoryTableEx history={pagedHistory} {...args} />
85
+ <ButtonEx
86
+ variant="contained"
87
+ onClick={updateRange}
88
+ disabled={loading === 'pending' || historyComplete}
89
+ loading={loading === 'pending'}
90
+ >
91
+ {historyComplete ? 'End of History' : 'More History'}
92
+ </ButtonEx>
93
+ </Stack>
94
+ )
95
+ }
96
+
69
97
  const Default = Template.bind({})
70
98
  Default.args = {}
71
99
 
72
100
  const WithLinked = TemplateLinked.bind({})
73
101
  WithLinked.args = { linked: true }
74
102
 
75
- export { Default, WithLinked }
103
+ const WithPaged = TemplatePaged.bind({})
104
+ WithPaged.args = {}
105
+
106
+ export {
107
+ Default, WithLinked, WithPaged,
108
+ }