@xyo-network/react-chain-blockchain 1.16.26 → 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 -57
@@ -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,57 +0,0 @@
1
- import { toHex } from '@xylabs/sdk-js'
2
- import type { ArchivistInstance } from '@xyo-network/archivist-model'
3
- import { findMostRecentBlock } from '@xyo-network/chain-protocol'
4
- import type { ChainBlockNumberIteratorService } from '@xyo-network/xl1-protocol-sdk'
5
- import { useEffect, useState } from 'react'
6
-
7
- export interface ChainIteratorUpdatingHeadParams {
8
- chainArchivist?: ArchivistInstance
9
- chainIterator?: ChainBlockNumberIteratorService
10
- interval?: number
11
- maxBlocks?: number
12
- }
13
-
14
- // Polls the chain archivist for new blocks and updates the chain iterator head
15
- export const useChainIteratorUpdatingHead = ({
16
- chainIterator, interval = 500, maxBlocks, chainArchivist,
17
- }: ChainIteratorUpdatingHeadParams): Error | undefined => {
18
- const [error, setError] = useState<Error>()
19
-
20
- useEffect(() => {
21
- let pollArchivistTimeout: NodeJS.Timeout | undefined
22
-
23
- const pollingFunction = async () => {
24
- if (chainIterator && chainArchivist) {
25
- try {
26
- const currentHead = await chainIterator.head()
27
- const mostRecentBlock = await findMostRecentBlock(chainArchivist)
28
- if (mostRecentBlock) {
29
- const currentBlockNumber = currentHead?.block ?? -1
30
- const nextBlockNumber = mostRecentBlock.block
31
- if (nextBlockNumber > currentBlockNumber) {
32
- console.debug('Found more recent head:', toHex(nextBlockNumber))
33
- console.debug('Updating head:', `${toHex(nextBlockNumber)}`)
34
- await chainIterator.updateHead(mostRecentBlock)
35
- console.debug('Updated head:', `${toHex(nextBlockNumber)}`)
36
- }
37
- }
38
- } catch (e) {
39
- setError(e as Error)
40
- console.error(e)
41
- }
42
- }
43
-
44
- // Schedule the next polling function
45
- // disabling because it looks like a false positive
46
- // eslint-disable-next-line react-web-api/no-leaked-timeout
47
- pollArchivistTimeout = setTimeout(() => void pollingFunction(), interval)
48
- }
49
-
50
- // Start the polling function
51
- void pollingFunction()
52
-
53
- return () => clearInterval(pollArchivistTimeout)
54
- }, [interval, chainIterator, chainArchivist, maxBlocks])
55
-
56
- return error
57
- }