@xyo-network/react-chain-blockchain 1.17.0 → 1.17.1

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 (60) hide show
  1. package/dist/browser/components/chain/index.d.ts +0 -1
  2. package/dist/browser/components/chain/index.d.ts.map +1 -1
  3. package/dist/browser/hooks/chain-iterator/index.d.ts +0 -2
  4. package/dist/browser/hooks/chain-iterator/index.d.ts.map +1 -1
  5. package/dist/browser/index.mjs +352 -613
  6. package/dist/browser/index.mjs.map +1 -1
  7. package/package.json +29 -29
  8. package/src/components/chain/index.ts +0 -1
  9. package/src/hooks/chain-iterator/index.ts +0 -2
  10. package/dist/browser/components/chain/render/index.d.ts +0 -2
  11. package/dist/browser/components/chain/render/index.d.ts.map +0 -1
  12. package/dist/browser/components/chain/render/static/flexbox/Flexbox.d.ts +0 -5
  13. package/dist/browser/components/chain/render/static/flexbox/Flexbox.d.ts.map +0 -1
  14. package/dist/browser/components/chain/render/static/flexbox/Flexbox.stories.d.ts +0 -8
  15. package/dist/browser/components/chain/render/static/flexbox/Flexbox.stories.d.ts.map +0 -1
  16. package/dist/browser/components/chain/render/static/flexbox/index.d.ts +0 -2
  17. package/dist/browser/components/chain/render/static/flexbox/index.d.ts.map +0 -1
  18. package/dist/browser/components/chain/render/static/flexbox/variants/Base.d.ts +0 -4
  19. package/dist/browser/components/chain/render/static/flexbox/variants/Base.d.ts.map +0 -1
  20. package/dist/browser/components/chain/render/static/flexbox/variants/WithAnalysis.d.ts +0 -4
  21. package/dist/browser/components/chain/render/static/flexbox/variants/WithAnalysis.d.ts.map +0 -1
  22. package/dist/browser/components/chain/render/static/flexbox/variants/index.d.ts +0 -3
  23. package/dist/browser/components/chain/render/static/flexbox/variants/index.d.ts.map +0 -1
  24. package/dist/browser/components/chain/render/static/hooks/index.d.ts +0 -2
  25. package/dist/browser/components/chain/render/static/hooks/index.d.ts.map +0 -1
  26. package/dist/browser/components/chain/render/static/hooks/useStaticBlockRenderComponents.d.ts +0 -11
  27. package/dist/browser/components/chain/render/static/hooks/useStaticBlockRenderComponents.d.ts.map +0 -1
  28. package/dist/browser/components/chain/render/static/index.d.ts +0 -2
  29. package/dist/browser/components/chain/render/static/index.d.ts.map +0 -1
  30. package/dist/browser/components/chain/render/static/table/Ex.d.ts +0 -5
  31. package/dist/browser/components/chain/render/static/table/Ex.d.ts.map +0 -1
  32. package/dist/browser/components/chain/render/static/table/Ex.stories.d.ts +0 -8
  33. package/dist/browser/components/chain/render/static/table/Ex.stories.d.ts.map +0 -1
  34. package/dist/browser/components/chain/render/static/table/variants/Base.d.ts +0 -4
  35. package/dist/browser/components/chain/render/static/table/variants/Base.d.ts.map +0 -1
  36. package/dist/browser/components/chain/render/static/table/variants/WithAnalysis.d.ts +0 -4
  37. package/dist/browser/components/chain/render/static/table/variants/WithAnalysis.d.ts.map +0 -1
  38. package/dist/browser/components/chain/render/static/table/variants/index.d.ts +0 -3
  39. package/dist/browser/components/chain/render/static/table/variants/index.d.ts.map +0 -1
  40. package/dist/browser/hooks/chain-iterator/ChainIteratorStore.d.ts +0 -24
  41. package/dist/browser/hooks/chain-iterator/ChainIteratorStore.d.ts.map +0 -1
  42. package/dist/browser/hooks/chain-iterator/useChainIteratorUpdatingHead.d.ts +0 -10
  43. package/dist/browser/hooks/chain-iterator/useChainIteratorUpdatingHead.d.ts.map +0 -1
  44. package/src/components/chain/render/index.ts +0 -1
  45. package/src/components/chain/render/static/flexbox/Flexbox.stories.tsx +0 -37
  46. package/src/components/chain/render/static/flexbox/Flexbox.tsx +0 -3
  47. package/src/components/chain/render/static/flexbox/index.ts +0 -1
  48. package/src/components/chain/render/static/flexbox/variants/Base.tsx +0 -31
  49. package/src/components/chain/render/static/flexbox/variants/WithAnalysis.tsx +0 -24
  50. package/src/components/chain/render/static/flexbox/variants/index.ts +0 -2
  51. package/src/components/chain/render/static/hooks/index.ts +0 -1
  52. package/src/components/chain/render/static/hooks/useStaticBlockRenderComponents.ts +0 -38
  53. package/src/components/chain/render/static/index.ts +0 -1
  54. package/src/components/chain/render/static/table/Ex.stories.tsx +0 -35
  55. package/src/components/chain/render/static/table/Ex.tsx +0 -3
  56. package/src/components/chain/render/static/table/variants/Base.tsx +0 -29
  57. package/src/components/chain/render/static/table/variants/WithAnalysis.tsx +0 -11
  58. package/src/components/chain/render/static/table/variants/index.ts +0 -2
  59. package/src/hooks/chain-iterator/ChainIteratorStore.ts +0 -87
  60. package/src/hooks/chain-iterator/useChainIteratorUpdatingHead.ts +0 -56
@@ -1,87 +0,0 @@
1
- import { assertEx } from '@xylabs/sdk-js'
2
- import type { XyoChainIteratorParams } from '@xyo-network/chain-services'
3
- import { ChainBlockNumberIterationService } from '@xyo-network/chain-services'
4
- import { PayloadBuilder } from '@xyo-network/payload-builder'
5
- import type { HydratedBlock } from '@xyo-network/xl1-protocol'
6
- import type { EventingChainBlockNumberIteratorService, HeadEventArgs } from '@xyo-network/xl1-protocol-sdk'
7
- import { hydrateBlock } from '@xyo-network/xl1-protocol-sdk'
8
-
9
- export type Listener = (...args: Array<unknown>) => void
10
-
11
- export type ChainIteratorStoreValues = { chainIterator: ChainBlockNumberIterationService; error?: Error; head: HydratedBlock }
12
-
13
- export class ChainIteratorStore {
14
- private _chainIterator: EventingChainBlockNumberIteratorService | undefined
15
- private _externalListeners: Listener[] = []
16
- private _internalUnsubscribes: WeakRef<() => void>[] = []
17
- private _values: ChainIteratorStoreValues | undefined
18
-
19
- get chainIterator(): EventingChainBlockNumberIteratorService {
20
- return assertEx(this._chainIterator, () => 'ChainIteratorStore has not been initialized')
21
- }
22
-
23
- get values(): ChainIteratorStoreValues {
24
- return assertEx(this._values, () => 'ChainIteratorStore values have not been initialized')
25
- }
26
-
27
- static async create(params: XyoChainIteratorParams): Promise<ChainIteratorStore> {
28
- // create the classes
29
- const instance = new ChainIteratorStore()
30
- const chainIterator = await ChainBlockNumberIterationService.create(params)
31
-
32
- // set the chainIterator
33
- instance._chainIterator = chainIterator
34
-
35
- const head = await chainIterator.head()
36
- const hydratedHead = await hydrateBlock({ chainMap: params.chainMap }, await PayloadBuilder.hash(head))
37
-
38
- // set the initial values
39
- instance._values = {
40
- chainIterator,
41
- head: hydratedHead,
42
- }
43
-
44
- // set the internal listeners
45
- const headUpdatedListener = async ({ blocks }: HeadEventArgs) => {
46
- const hydratedBlock = await hydrateBlock({ chainMap: params.chainMap }, await PayloadBuilder.hash(blocks?.[0]))
47
- instance._values = {
48
- chainIterator,
49
- head: hydratedBlock,
50
- }
51
- instance.emitChange()
52
- }
53
-
54
- // Add listener to the chainIterator
55
- const unsubscribe = chainIterator.on('headUpdated', headUpdatedListener)
56
-
57
- // track the internal listener
58
- const weakRefListener = new WeakRef(unsubscribe)
59
- instance._internalUnsubscribes.push(weakRefListener)
60
-
61
- return instance
62
- }
63
-
64
- cleanup() {
65
- for (const unsubscribeRef of this._internalUnsubscribes) {
66
- const unsubscribe = unsubscribeRef.deref()
67
- unsubscribe?.()
68
- }
69
- }
70
-
71
- getSnapshot(): Partial<ChainIteratorStoreValues> {
72
- return this.values
73
- }
74
-
75
- subscribe(onStoreChange: Listener) {
76
- this._externalListeners.push(onStoreChange)
77
- return () => {
78
- this._externalListeners = this._externalListeners.filter(l => l !== onStoreChange)
79
- }
80
- }
81
-
82
- private emitChange() {
83
- for (const listener of this._externalListeners) {
84
- listener()
85
- }
86
- }
87
- }
@@ -1,56 +0,0 @@
1
- import { toHex } from '@xylabs/sdk-js'
2
- import type { ArchivistInstance } from '@xyo-network/archivist-model'
3
- import { type ChainBlockNumberIteratorService, findMostRecentBlock } from '@xyo-network/xl1-protocol-sdk'
4
- import { useEffect, useState } from 'react'
5
-
6
- export interface ChainIteratorUpdatingHeadParams {
7
- chainArchivist?: ArchivistInstance
8
- chainIterator?: ChainBlockNumberIteratorService
9
- interval?: number
10
- maxBlocks?: number
11
- }
12
-
13
- // Polls the chain archivist for new blocks and updates the chain iterator head
14
- export const useChainIteratorUpdatingHead = ({
15
- chainIterator, interval = 500, maxBlocks, chainArchivist,
16
- }: ChainIteratorUpdatingHeadParams): Error | undefined => {
17
- const [error, setError] = useState<Error>()
18
-
19
- useEffect(() => {
20
- let pollArchivistTimeout: NodeJS.Timeout | undefined
21
-
22
- const pollingFunction = async () => {
23
- if (chainIterator && chainArchivist) {
24
- try {
25
- const currentHead = await chainIterator.head()
26
- const mostRecentBlock = await findMostRecentBlock(chainArchivist)
27
- if (mostRecentBlock) {
28
- const currentBlockNumber = currentHead?.block ?? -1
29
- const nextBlockNumber = mostRecentBlock.block
30
- if (nextBlockNumber > currentBlockNumber) {
31
- console.debug('Found more recent head:', toHex(nextBlockNumber))
32
- console.debug('Updating head:', `${toHex(nextBlockNumber)}`)
33
- await chainIterator.updateHead(mostRecentBlock)
34
- console.debug('Updated head:', `${toHex(nextBlockNumber)}`)
35
- }
36
- }
37
- } catch (e) {
38
- setError(e as Error)
39
- console.error(e)
40
- }
41
- }
42
-
43
- // Schedule the next polling function
44
- // disabling because it looks like a false positive
45
- // eslint-disable-next-line react-web-api/no-leaked-timeout
46
- pollArchivistTimeout = setTimeout(() => void pollingFunction(), interval)
47
- }
48
-
49
- // Start the polling function
50
- void pollingFunction()
51
-
52
- return () => clearInterval(pollArchivistTimeout)
53
- }, [interval, chainIterator, chainArchivist, maxBlocks])
54
-
55
- return error
56
- }