@xyo-network/react-chain-blockchain 1.15.2 → 1.15.4
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/README.md +88 -59
- package/dist/browser/components/chain/render/index.d.ts +0 -1
- package/dist/browser/components/chain/render/index.d.ts.map +1 -1
- package/dist/browser/components/transactions/submit/Builder.d.ts.map +1 -1
- package/dist/browser/context/chain/Context.d.ts +3 -3
- package/dist/browser/context/chain/State.d.ts +2 -2
- package/dist/browser/context/chain/State.d.ts.map +1 -1
- package/dist/browser/context/chain/use.d.ts +1 -1
- package/dist/browser/hooks/chain-iterator/index.d.ts +0 -1
- package/dist/browser/hooks/chain-iterator/index.d.ts.map +1 -1
- package/dist/browser/hooks/chain-iterator/useChainIteratorParams.d.ts +8 -3
- package/dist/browser/hooks/chain-iterator/useChainIteratorParams.d.ts.map +1 -1
- package/dist/browser/hooks/useIterateChain.d.ts.map +1 -1
- package/dist/browser/index.mjs +371 -569
- package/dist/browser/index.mjs.map +1 -1
- package/dist/browser/stories/ChainInfoContextDecorator.d.ts.map +1 -1
- package/dist/browser/types/render/BlockChainRenderProps.d.ts +5 -4
- package/dist/browser/types/render/BlockChainRenderProps.d.ts.map +1 -1
- package/package.json +57 -57
- package/src/components/block/hooks/useDynamicBlockComponents.ts +2 -2
- package/src/components/block/hooks/useStaticBlockComponents.ts +1 -1
- package/src/components/chain/render/index.ts +0 -1
- package/src/components/transactions/submit/Builder.tsx +2 -2
- package/src/context/chain/State.ts +2 -2
- package/src/hooks/chain-iterator/ChainIteratorStore.ts +2 -2
- package/src/hooks/chain-iterator/index.ts +0 -1
- package/src/hooks/chain-iterator/useChainIteratorParams.ts +5 -5
- package/src/hooks/useIterateChain.ts +8 -7
- package/src/stories/ChainInfoContextDecorator.tsx +4 -1
- package/src/types/render/BlockChainRenderProps.ts +5 -4
- package/dist/browser/components/chain/render/dynamic/flexbox/Flexbox.d.ts +0 -6
- package/dist/browser/components/chain/render/dynamic/flexbox/Flexbox.d.ts.map +0 -1
- package/dist/browser/components/chain/render/dynamic/flexbox/Flexbox.stories.d.ts +0 -8
- package/dist/browser/components/chain/render/dynamic/flexbox/Flexbox.stories.d.ts.map +0 -1
- package/dist/browser/components/chain/render/dynamic/flexbox/Remote.stories.d.ts +0 -8
- package/dist/browser/components/chain/render/dynamic/flexbox/Remote.stories.d.ts.map +0 -1
- package/dist/browser/components/chain/render/dynamic/flexbox/index.d.ts +0 -2
- package/dist/browser/components/chain/render/dynamic/flexbox/index.d.ts.map +0 -1
- package/dist/browser/components/chain/render/dynamic/flexbox/variants/Base.d.ts +0 -4
- package/dist/browser/components/chain/render/dynamic/flexbox/variants/Base.d.ts.map +0 -1
- package/dist/browser/components/chain/render/dynamic/flexbox/variants/WithAnalysis.d.ts +0 -4
- package/dist/browser/components/chain/render/dynamic/flexbox/variants/WithAnalysis.d.ts.map +0 -1
- package/dist/browser/components/chain/render/dynamic/flexbox/variants/WithRemote.d.ts +0 -4
- package/dist/browser/components/chain/render/dynamic/flexbox/variants/WithRemote.d.ts.map +0 -1
- package/dist/browser/components/chain/render/dynamic/flexbox/variants/index.d.ts +0 -4
- package/dist/browser/components/chain/render/dynamic/flexbox/variants/index.d.ts.map +0 -1
- package/dist/browser/components/chain/render/dynamic/hooks/index.d.ts +0 -3
- package/dist/browser/components/chain/render/dynamic/hooks/index.d.ts.map +0 -1
- package/dist/browser/components/chain/render/dynamic/hooks/useDynamicBlockRenderComponents.d.ts +0 -10
- package/dist/browser/components/chain/render/dynamic/hooks/useDynamicBlockRenderComponents.d.ts.map +0 -1
- package/dist/browser/components/chain/render/dynamic/hooks/useRemoteBlockChainRenderProps.d.ts +0 -5
- package/dist/browser/components/chain/render/dynamic/hooks/useRemoteBlockChainRenderProps.d.ts.map +0 -1
- package/dist/browser/components/chain/render/dynamic/index.d.ts +0 -2
- package/dist/browser/components/chain/render/dynamic/index.d.ts.map +0 -1
- package/dist/browser/hooks/chain-iterator/useChainIteratorStore.d.ts +0 -4
- package/dist/browser/hooks/chain-iterator/useChainIteratorStore.d.ts.map +0 -1
- package/src/components/chain/render/dynamic/flexbox/Flexbox.stories.tsx +0 -34
- package/src/components/chain/render/dynamic/flexbox/Flexbox.tsx +0 -7
- package/src/components/chain/render/dynamic/flexbox/Remote.stories.tsx +0 -49
- package/src/components/chain/render/dynamic/flexbox/index.ts +0 -1
- package/src/components/chain/render/dynamic/flexbox/variants/Base.tsx +0 -27
- package/src/components/chain/render/dynamic/flexbox/variants/WithAnalysis.tsx +0 -26
- package/src/components/chain/render/dynamic/flexbox/variants/WithRemote.tsx +0 -19
- package/src/components/chain/render/dynamic/flexbox/variants/index.ts +0 -3
- package/src/components/chain/render/dynamic/hooks/index.ts +0 -2
- package/src/components/chain/render/dynamic/hooks/useDynamicBlockRenderComponents.ts +0 -37
- package/src/components/chain/render/dynamic/hooks/useRemoteBlockChainRenderProps.ts +0 -31
- package/src/components/chain/render/dynamic/index.ts +0 -1
- package/src/hooks/chain-iterator/useChainIteratorStore.ts +0 -66
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Flexbox.tsx'
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { ErrorRender } from '@xylabs/react-error'
|
|
2
|
-
import { FlexCol } from '@xylabs/react-flexbox'
|
|
3
|
-
import React from 'react'
|
|
4
|
-
|
|
5
|
-
import type { BlockChainRenderFlexboxProps } from '../../../../../../types/index.ts'
|
|
6
|
-
import { BlockHeadingFlexbox } from '../../../../../block/index.ts'
|
|
7
|
-
import { MemoizedPollingControlsFlexbox } from '../../../../controls/index.ts'
|
|
8
|
-
import { BlockListAnimated } from '../../../../list/index.ts'
|
|
9
|
-
import { useDynamicBlockRenderComponents } from '../../hooks/index.ts'
|
|
10
|
-
|
|
11
|
-
export const DynamicListBase: React.FC<BlockChainRenderFlexboxProps> = ({ blockChainRenderProps, ...props }) => {
|
|
12
|
-
const {
|
|
13
|
-
errors, blockChainRenderComponents, blocksWhilePaused, pollingState, updatePollingState,
|
|
14
|
-
} = useDynamicBlockRenderComponents(BlockHeadingFlexbox, blockChainRenderProps)
|
|
15
|
-
|
|
16
|
-
return (
|
|
17
|
-
<FlexCol alignItems="start" {...props}>
|
|
18
|
-
{errors?.map(error => <ErrorRender error={error} key={error?.name} scope="DynamicBlockchainRenderFlexboxInner" />)}
|
|
19
|
-
<MemoizedPollingControlsFlexbox
|
|
20
|
-
blocksBehind={blocksWhilePaused?.length}
|
|
21
|
-
pollingState={pollingState}
|
|
22
|
-
setPollingState={updatePollingState}
|
|
23
|
-
/>
|
|
24
|
-
<BlockListAnimated blockChainRenderComponents={blockChainRenderComponents} />
|
|
25
|
-
</FlexCol>
|
|
26
|
-
)
|
|
27
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { isAddress } from '@xylabs/hex'
|
|
2
|
-
import { ChainProducersAnalyzer } from '@xyo-network/chain-analyze'
|
|
3
|
-
import React, { useMemo } from 'react'
|
|
4
|
-
|
|
5
|
-
import type { ChainAnalyzers } from '../../../../../../context/index.ts'
|
|
6
|
-
import { ChainAnalyzersProvider, ChainPollingProvider } from '../../../../../../context/index.ts'
|
|
7
|
-
import type { BlockChainRenderFlexboxProps } from '../../../../../../types/index.ts'
|
|
8
|
-
import { DynamicListBase } from './Base.tsx'
|
|
9
|
-
|
|
10
|
-
export const WithAnalysis: React.FC<BlockChainRenderFlexboxProps> = ({ blockChainRenderProps, ...props }) => {
|
|
11
|
-
const { chainId } = blockChainRenderProps ?? {}
|
|
12
|
-
|
|
13
|
-
const analyzers = useMemo(() => {
|
|
14
|
-
if (isAddress(chainId)) {
|
|
15
|
-
return { producers: new ChainProducersAnalyzer() } as ChainAnalyzers
|
|
16
|
-
}
|
|
17
|
-
}, [chainId])
|
|
18
|
-
|
|
19
|
-
return (
|
|
20
|
-
<ChainAnalyzersProvider analyzers={analyzers}>
|
|
21
|
-
<ChainPollingProvider>
|
|
22
|
-
<DynamicListBase blockChainRenderProps={blockChainRenderProps} {...props} />
|
|
23
|
-
</ChainPollingProvider>
|
|
24
|
-
</ChainAnalyzersProvider>
|
|
25
|
-
)
|
|
26
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { ErrorRender } from '@xylabs/react-error'
|
|
2
|
-
import React from 'react'
|
|
3
|
-
|
|
4
|
-
import type { RemoteBlockChainRenderFlexboxProps } from '../../../../../../types/index.ts'
|
|
5
|
-
import { useRemoteBlockChainRenderProps } from '../../hooks/index.ts'
|
|
6
|
-
import { WithAnalysis } from './WithAnalysis.tsx'
|
|
7
|
-
|
|
8
|
-
export const WithRemote: React.FC<RemoteBlockChainRenderFlexboxProps> = ({
|
|
9
|
-
url, chainArchivistModuleId, blockChainRenderProps: blockChainRenderPropsArg, ...props
|
|
10
|
-
}) => {
|
|
11
|
-
const { error, blockChainRenderProps } = useRemoteBlockChainRenderProps(chainArchivistModuleId, url, blockChainRenderPropsArg)
|
|
12
|
-
|
|
13
|
-
return (
|
|
14
|
-
<>
|
|
15
|
-
<ErrorRender error={error} scope="RemoteChainProviderFlexbox" />
|
|
16
|
-
<WithAnalysis blockChainRenderProps={blockChainRenderProps} {...props} />
|
|
17
|
-
</>
|
|
18
|
-
)
|
|
19
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { CreatableName } from '@xylabs/creatable'
|
|
2
|
-
import type { ComponentType } from 'react'
|
|
3
|
-
import { useMemo } from 'react'
|
|
4
|
-
|
|
5
|
-
import { useChainPollingContext } from '../../../../../context/index.ts'
|
|
6
|
-
import { useChainIteratorParams, useChainIteratorStore } from '../../../../../hooks/index.ts'
|
|
7
|
-
import type { BlockChainRenderProps, BlockComponentWithTxsProps } from '../../../../../types/index.ts'
|
|
8
|
-
import { useDynamicBlockComponents } from '../../../../block/index.ts'
|
|
9
|
-
import { useOnBlock } from '../../../hooks/index.ts'
|
|
10
|
-
|
|
11
|
-
// Note: This is a hook but could easily be bundled up in a class with callbacks
|
|
12
|
-
export const useDynamicBlockRenderComponents = (
|
|
13
|
-
BlockComponent: ComponentType<BlockComponentWithTxsProps>,
|
|
14
|
-
blockChainRenderProps?: BlockChainRenderProps,
|
|
15
|
-
) => {
|
|
16
|
-
const { maxBlocks } = blockChainRenderProps ?? {}
|
|
17
|
-
|
|
18
|
-
const chainIteratorParams = useMemo(() => blockChainRenderProps ?? { name: 'unknown' as CreatableName }, [blockChainRenderProps])
|
|
19
|
-
|
|
20
|
-
const [params, paramsError] = useChainIteratorParams(chainIteratorParams)
|
|
21
|
-
|
|
22
|
-
const { blockChainRenderComponents, onAddBlock } = useDynamicBlockComponents(BlockComponent, params, maxBlocks)
|
|
23
|
-
|
|
24
|
-
const { head: liveHead } = useChainIteratorStore(params)
|
|
25
|
-
|
|
26
|
-
const { pollingState, updatePollingState } = useChainPollingContext()
|
|
27
|
-
|
|
28
|
-
const blocksWhilePaused = useOnBlock(blockChainRenderComponents[0]?.block?.[0].block, onAddBlock, liveHead, pollingState)
|
|
29
|
-
|
|
30
|
-
return {
|
|
31
|
-
errors: [paramsError],
|
|
32
|
-
blockChainRenderComponents,
|
|
33
|
-
blocksWhilePaused,
|
|
34
|
-
updatePollingState,
|
|
35
|
-
pollingState,
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { CreatableName } from '@xylabs/creatable'
|
|
2
|
-
import { usePromise } from '@xylabs/react-promise'
|
|
3
|
-
import type { ModuleIdentifier } from '@xyo-network/module-model'
|
|
4
|
-
import { useMemo } from 'react'
|
|
5
|
-
|
|
6
|
-
import { getChainArchivistFromBridge } from '../../../../../lib/index.ts'
|
|
7
|
-
import type { BlockChainRenderBaseProps, BlockChainRenderProps } from '../../../../../types/index.ts'
|
|
8
|
-
|
|
9
|
-
/** take blockChainRenderProps and remote archivist props and return with resolved chainArchivist */
|
|
10
|
-
export const useRemoteBlockChainRenderProps = (
|
|
11
|
-
chainArchivistModuleId?: ModuleIdentifier,
|
|
12
|
-
url?: string,
|
|
13
|
-
blockChainRenderPropsArg?: BlockChainRenderProps,
|
|
14
|
-
): BlockChainRenderBaseProps => {
|
|
15
|
-
const [chainArchivist, chainArchivistError] = usePromise(async () => {
|
|
16
|
-
if (url !== undefined && chainArchivistModuleId !== undefined) {
|
|
17
|
-
return await getChainArchivistFromBridge({ url, chainArchivistModuleId })
|
|
18
|
-
}
|
|
19
|
-
}, [url, chainArchivistModuleId])
|
|
20
|
-
|
|
21
|
-
const blockChainRenderProps: BlockChainRenderProps = useMemo(() => ({
|
|
22
|
-
...blockChainRenderPropsArg,
|
|
23
|
-
chainArchivist,
|
|
24
|
-
name: 'blockChainRenderProps' as CreatableName,
|
|
25
|
-
}), [blockChainRenderPropsArg, chainArchivist])
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
blockChainRenderProps,
|
|
29
|
-
error: chainArchivistError,
|
|
30
|
-
}
|
|
31
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './flexbox/index.ts'
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import { usePromise } from '@xylabs/react-promise'
|
|
2
|
-
import type { XyoChainIteratorParams } from '@xyo-network/chain-services'
|
|
3
|
-
import {
|
|
4
|
-
useEffect,
|
|
5
|
-
useMemo, useRef, useSyncExternalStore,
|
|
6
|
-
} from 'react'
|
|
7
|
-
|
|
8
|
-
import type { ChainIteratorStoreValues } from './ChainIteratorStore.ts'
|
|
9
|
-
import { ChainIteratorStore } from './ChainIteratorStore.ts'
|
|
10
|
-
import { useChainIteratorUpdatingHead } from './useChainIteratorUpdatingHead.ts'
|
|
11
|
-
|
|
12
|
-
const stub = {} as Partial<ChainIteratorStoreValues>
|
|
13
|
-
|
|
14
|
-
// Returns the latest head every time it changes
|
|
15
|
-
export const useChainIteratorStore = (chainIteratorParams?: XyoChainIteratorParams) => {
|
|
16
|
-
const [chainIteratorStore] = usePromise(async () => {
|
|
17
|
-
return chainIteratorParams ? await ChainIteratorStore.create(chainIteratorParams) : undefined
|
|
18
|
-
}, [chainIteratorParams])
|
|
19
|
-
|
|
20
|
-
const { chainIterator } = chainIteratorStore || {}
|
|
21
|
-
const chainArchivist = chainIteratorParams?.chainArchivist
|
|
22
|
-
|
|
23
|
-
// Update the head of the chain iterator
|
|
24
|
-
const error = useChainIteratorUpdatingHead({ chainIterator, chainArchivist })
|
|
25
|
-
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
return () => {
|
|
28
|
-
if (chainIteratorStore) {
|
|
29
|
-
chainIteratorStore.cleanup()
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}, [chainIteratorStore])
|
|
33
|
-
|
|
34
|
-
const cachedSnapshot = useRef<Partial<ChainIteratorStoreValues>>({})
|
|
35
|
-
|
|
36
|
-
const { getSnapShot, subscribe } = useMemo(() => {
|
|
37
|
-
if (chainIteratorStore) {
|
|
38
|
-
return {
|
|
39
|
-
getSnapShot: () => {
|
|
40
|
-
const snapshot = chainIteratorStore.getSnapshot()
|
|
41
|
-
const newValues = {
|
|
42
|
-
...snapshot,
|
|
43
|
-
error,
|
|
44
|
-
}
|
|
45
|
-
// Only update the cached snapshot if there is no cached iterator or the head has changed
|
|
46
|
-
const noCachedValue = cachedSnapshot.current.chainIterator === undefined
|
|
47
|
-
const cachedBlock = cachedSnapshot.current?.head?.[0]?.block
|
|
48
|
-
const newBlock = cachedBlock !== newValues.head?.[0]?.block
|
|
49
|
-
if (noCachedValue || newBlock) {
|
|
50
|
-
cachedSnapshot.current = newValues
|
|
51
|
-
return newValues
|
|
52
|
-
}
|
|
53
|
-
return cachedSnapshot.current
|
|
54
|
-
},
|
|
55
|
-
subscribe: chainIteratorStore.subscribe.bind(chainIteratorStore),
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
// Return a default implementation to satisfy the hook interface
|
|
59
|
-
return {
|
|
60
|
-
getSnapShot: () => stub,
|
|
61
|
-
subscribe: () => () => {},
|
|
62
|
-
}
|
|
63
|
-
}, [chainIteratorStore])
|
|
64
|
-
|
|
65
|
-
return useSyncExternalStore(subscribe, getSnapShot)
|
|
66
|
-
}
|