@xyo-network/react-chain-blockchain 1.17.7 → 1.18.0
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/dist/browser/components/block/hooks/index.d.ts +0 -2
- package/dist/browser/components/block/hooks/index.d.ts.map +1 -1
- package/dist/browser/hooks/chain-iterator/useChainIteratorParams.d.ts +6 -3
- package/dist/browser/hooks/chain-iterator/useChainIteratorParams.d.ts.map +1 -1
- package/dist/browser/hooks/index.d.ts +0 -1
- package/dist/browser/hooks/index.d.ts.map +1 -1
- package/dist/browser/index.mjs +329 -556
- package/dist/browser/index.mjs.map +1 -1
- package/dist/browser/stories/index.d.ts +0 -1
- package/dist/browser/stories/index.d.ts.map +1 -1
- package/package.json +18 -20
- package/src/components/block/hooks/index.ts +0 -2
- package/src/hooks/index.ts +0 -1
- package/src/stories/index.ts +0 -1
- package/dist/browser/components/block/hooks/useDynamicBlockComponents.d.ts +0 -9
- package/dist/browser/components/block/hooks/useDynamicBlockComponents.d.ts.map +0 -1
- package/dist/browser/components/block/hooks/useStaticBlockComponents.d.ts +0 -9
- package/dist/browser/components/block/hooks/useStaticBlockComponents.d.ts.map +0 -1
- package/dist/browser/hooks/useIterateChain.d.ts +0 -24
- package/dist/browser/hooks/useIterateChain.d.ts.map +0 -1
- package/dist/browser/stories/ChainInfoContextDecorator.d.ts +0 -3
- package/dist/browser/stories/ChainInfoContextDecorator.d.ts.map +0 -1
- package/src/components/block/hooks/useDynamicBlockComponents.ts +0 -42
- package/src/components/block/hooks/useStaticBlockComponents.ts +0 -34
- package/src/hooks/useIterateChain.ts +0 -59
- package/src/stories/ChainInfoContextDecorator.tsx +0 -48
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/stories/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAA;AAC7C,cAAc,4CAA4C,CAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/stories/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAA;AAC7C,cAAc,4CAA4C,CAAA"}
|
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.
|
|
4
|
+
"version": "1.18.0",
|
|
5
5
|
"description": "XYO Layer One React SDK Blockchain",
|
|
6
6
|
"homepage": "https://xylabs.com",
|
|
7
7
|
"bugs": {
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"package-cycle": "echo Nothing to do"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@storybook/react-vite": "~10.1.
|
|
50
|
+
"@storybook/react-vite": "~10.1.9",
|
|
51
51
|
"@xylabs/axios": "~5.0.51",
|
|
52
52
|
"@xylabs/react-animation": "~7.1.9",
|
|
53
53
|
"@xylabs/react-error": "~7.1.9",
|
|
@@ -62,19 +62,16 @@
|
|
|
62
62
|
"@xyo-network/archivist-model": "~5.2.17",
|
|
63
63
|
"@xyo-network/boundwitness-builder": "~5.2.17",
|
|
64
64
|
"@xyo-network/boundwitness-model": "~5.2.17",
|
|
65
|
-
"@xyo-network/
|
|
66
|
-
"@xyo-network/chain-
|
|
67
|
-
"@xyo-network/chain-
|
|
68
|
-
"@xyo-network/chain-services": "~1.17.7",
|
|
69
|
-
"@xyo-network/chain-utils": "~1.17.7",
|
|
70
|
-
"@xyo-network/chain-wrappers": "~1.17.7",
|
|
65
|
+
"@xyo-network/chain-analyze": "~1.18.0",
|
|
66
|
+
"@xyo-network/chain-protocol": "~1.18.0",
|
|
67
|
+
"@xyo-network/chain-wrappers": "~1.18.0",
|
|
71
68
|
"@xyo-network/module-model": "~5.2.17",
|
|
72
69
|
"@xyo-network/payload-builder": "~5.2.17",
|
|
73
70
|
"@xyo-network/payload-model": "~5.2.17",
|
|
74
71
|
"@xyo-network/react-boundwitness-plugin": "~7.4.2",
|
|
75
|
-
"@xyo-network/react-chain-blockies": "~1.
|
|
76
|
-
"@xyo-network/react-chain-provider": "~1.
|
|
77
|
-
"@xyo-network/react-chain-shared": "~1.
|
|
72
|
+
"@xyo-network/react-chain-blockies": "~1.18.0",
|
|
73
|
+
"@xyo-network/react-chain-provider": "~1.18.0",
|
|
74
|
+
"@xyo-network/react-chain-shared": "~1.18.0",
|
|
78
75
|
"@xyo-network/react-error": "~7.4.2",
|
|
79
76
|
"@xyo-network/react-event": "~7.4.2",
|
|
80
77
|
"@xyo-network/react-payload-raw-info": "~7.4.2",
|
|
@@ -82,7 +79,7 @@
|
|
|
82
79
|
"@xyo-network/react-shared": "~7.4.2",
|
|
83
80
|
"@xyo-network/react-table": "~7.4.2",
|
|
84
81
|
"@xyo-network/xl1-protocol": "~1.14.17",
|
|
85
|
-
"@xyo-network/xl1-protocol-sdk": "~1.
|
|
82
|
+
"@xyo-network/xl1-protocol-sdk": "~1.18.0"
|
|
86
83
|
},
|
|
87
84
|
"devDependencies": {
|
|
88
85
|
"@emotion/react": "~11.14.0",
|
|
@@ -92,19 +89,20 @@
|
|
|
92
89
|
"@types/react": "~19.2.7",
|
|
93
90
|
"@xylabs/react-button": "~7.1.9",
|
|
94
91
|
"@xylabs/sdk-js": "~5.0.51",
|
|
95
|
-
"@xylabs/ts-scripts-yarn3": "~7.2.
|
|
96
|
-
"@xylabs/tsconfig": "~7.2.
|
|
97
|
-
"@xylabs/tsconfig-dom": "~7.2.
|
|
98
|
-
"@xylabs/tsconfig-react": "~7.2.
|
|
92
|
+
"@xylabs/ts-scripts-yarn3": "~7.2.32",
|
|
93
|
+
"@xylabs/tsconfig": "~7.2.32",
|
|
94
|
+
"@xylabs/tsconfig-dom": "~7.2.32",
|
|
95
|
+
"@xylabs/tsconfig-react": "~7.2.32",
|
|
99
96
|
"@xyo-network/api-models": "~5.2.17",
|
|
100
|
-
"@xyo-network/
|
|
101
|
-
"@xyo-network/xl1-
|
|
97
|
+
"@xyo-network/bridge-http": "~5.2.17",
|
|
98
|
+
"@xyo-network/xl1-network-model": "~1.18.0",
|
|
99
|
+
"@xyo-network/xl1-rpc": "~1.18.0",
|
|
102
100
|
"axios": "^1.13.2",
|
|
103
|
-
"eslint": "^9.39.
|
|
101
|
+
"eslint": "^9.39.2",
|
|
104
102
|
"react": "~19.2.3",
|
|
105
103
|
"react-dom": "~19.2.3",
|
|
106
104
|
"react-router-dom": "^7.10.1",
|
|
107
|
-
"storybook": "~10.1.
|
|
105
|
+
"storybook": "~10.1.9",
|
|
108
106
|
"typescript": "~5.9.3"
|
|
109
107
|
},
|
|
110
108
|
"peerDependencies": {
|
package/src/hooks/index.ts
CHANGED
package/src/stories/index.ts
CHANGED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { XyoChainIteratorParams } from '@xyo-network/chain-services';
|
|
2
|
-
import type { HydratedBlockWithHashMeta } from '@xyo-network/xl1-protocol';
|
|
3
|
-
import type { ComponentType } from 'react';
|
|
4
|
-
import type { BlockChainRenderComponent, BlockComponentWithTxsProps } from '../../../types/index.ts';
|
|
5
|
-
export declare const useDynamicBlockComponents: (BlockComponent: ComponentType<BlockComponentWithTxsProps>, params?: XyoChainIteratorParams, maxBlocks?: number) => {
|
|
6
|
-
blockChainRenderComponents: BlockChainRenderComponent[];
|
|
7
|
-
onAddBlock: (block: HydratedBlockWithHashMeta | undefined) => Promise<void>;
|
|
8
|
-
};
|
|
9
|
-
//# sourceMappingURL=useDynamicBlockComponents.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useDynamicBlockComponents.d.ts","sourceRoot":"","sources":["../../../../../src/components/block/hooks/useDynamicBlockComponents.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AACzE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAA;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAI1C,OAAO,KAAK,EACV,yBAAyB,EACJ,0BAA0B,EAChD,MAAM,yBAAyB,CAAA;AAGhC,eAAO,MAAM,yBAAyB,GAAI,gBAAgB,aAAa,CAAC,0BAA0B,CAAC,EAAE,SAAS,sBAAsB,EAAE,YAAY,MAAM;;wBAMrH,yBAAyB,GAAG,SAAS;CAuBvE,CAAA"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { XyoChainIteratorParams } from '@xyo-network/chain-services';
|
|
2
|
-
import type { HydratedBlockWithHashMeta } from '@xyo-network/xl1-protocol';
|
|
3
|
-
import type { ComponentType } from 'react';
|
|
4
|
-
import type { BlockComponentWithTxsProps } from '../../../types/index.ts';
|
|
5
|
-
export declare const useStaticBlockComponents: (BlockComponent: ComponentType<BlockComponentWithTxsProps>, params?: XyoChainIteratorParams, blocks?: HydratedBlockWithHashMeta[]) => {
|
|
6
|
-
blockComponents: import("../../../types/BlockComponents.ts").BlockChainRenderComponent[] | undefined;
|
|
7
|
-
errors: Error | undefined;
|
|
8
|
-
};
|
|
9
|
-
//# sourceMappingURL=useStaticBlockComponents.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useStaticBlockComponents.d.ts","sourceRoot":"","sources":["../../../../../src/components/block/hooks/useStaticBlockComponents.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AACzE,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,2BAA2B,CAAA;AAC1E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAG1C,OAAO,KAAK,EAAuB,0BAA0B,EAAE,MAAM,yBAAyB,CAAA;AAG9F,eAAO,MAAM,wBAAwB,GACnC,gBAAgB,aAAa,CAAC,0BAA0B,CAAC,EACzD,SAAS,sBAAsB,EAC/B,SAAS,yBAAyB,EAAE;;;CAoBrC,CAAA"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type { XyoChainIteratorParams } from '@xyo-network/chain-services';
|
|
2
|
-
export declare const useIterateChain: (chainIteratorParams?: XyoChainIteratorParams, maxDepth?: number) => [[{
|
|
3
|
-
schema: "network.xyo.boundwitness";
|
|
4
|
-
addresses: import("@xylabs/sdk-js").Address[];
|
|
5
|
-
payload_hashes: import("@xylabs/sdk-js").Hash[];
|
|
6
|
-
payload_schemas: string[];
|
|
7
|
-
previous_hashes: (import("@xylabs/sdk-js").Hash | null)[];
|
|
8
|
-
$signatures: (import("@xylabs/sdk-js").Hex | null)[];
|
|
9
|
-
block: import("@xyo-network/xl1-protocol").XL1BlockNumber;
|
|
10
|
-
chain: import("@xylabs/sdk-js").Hex;
|
|
11
|
-
previous: import("@xylabs/sdk-js").Hash | null;
|
|
12
|
-
$epoch: number;
|
|
13
|
-
_hash: import("@xylabs/sdk-js").Hash;
|
|
14
|
-
_dataHash: import("@xylabs/sdk-js").Hash;
|
|
15
|
-
$destination?: import("@xylabs/sdk-js").Address | undefined;
|
|
16
|
-
$sourceQuery?: import("@xylabs/sdk-js").Hash | undefined;
|
|
17
|
-
protocol?: number | undefined;
|
|
18
|
-
step_hashes?: import("@xylabs/sdk-js").Hash[] | undefined;
|
|
19
|
-
}, {
|
|
20
|
-
schema: string;
|
|
21
|
-
_hash: import("@xylabs/sdk-js").Hash;
|
|
22
|
-
_dataHash: import("@xylabs/sdk-js").Hash;
|
|
23
|
-
}[]][] | undefined, Error | undefined, import("@xylabs/react-promise").UsePromiseState | undefined];
|
|
24
|
-
//# sourceMappingURL=useIterateChain.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useIterateChain.d.ts","sourceRoot":"","sources":["../../../src/hooks/useIterateChain.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAA;AAiDzE,eAAO,MAAM,eAAe,GAC1B,sBAAsB,sBAAsB,EAC5C,WAAW,MAAM;;;;;;;;;;;;;;;;;;;;;mGAKlB,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ChainInfoContextDecorator.d.ts","sourceRoot":"","sources":["../../../src/stories/ChainInfoContextDecorator.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AAoBtD,eAAO,MAAM,yBAAyB,EAAE,SA2BvC,CAAA"}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import type { XyoChainIteratorParams } from '@xyo-network/chain-services'
|
|
2
|
-
import type { HydratedBlockWithHashMeta } from '@xyo-network/xl1-protocol'
|
|
3
|
-
import type { ComponentType } from 'react'
|
|
4
|
-
import { useState } from 'react'
|
|
5
|
-
|
|
6
|
-
import { useChainAnalyzersContext } from '../../../context/index.ts'
|
|
7
|
-
import type {
|
|
8
|
-
BlockChainRenderComponent,
|
|
9
|
-
BlockComponentProps, BlockComponentWithTxsProps,
|
|
10
|
-
} from '../../../types/index.ts'
|
|
11
|
-
import { buildBlockChainRenderComponent } from '../helpers/index.ts'
|
|
12
|
-
|
|
13
|
-
export const useDynamicBlockComponents = (BlockComponent: ComponentType<BlockComponentWithTxsProps>, params?: XyoChainIteratorParams, maxBlocks?: number) => {
|
|
14
|
-
const { chainMap } = params ?? {}
|
|
15
|
-
const [blockChainRenderComponents, setBlockChainRenderComponents] = useState<BlockChainRenderComponent[]>([])
|
|
16
|
-
|
|
17
|
-
const { onBlock } = useChainAnalyzersContext()
|
|
18
|
-
|
|
19
|
-
const onAddBlock = async (block: HydratedBlockWithHashMeta | undefined) => {
|
|
20
|
-
if (!block || !chainMap) return
|
|
21
|
-
|
|
22
|
-
const blockComponentProps: BlockComponentProps = { block }
|
|
23
|
-
const newBlockComponent = await buildBlockChainRenderComponent(BlockComponent, blockComponentProps)
|
|
24
|
-
|
|
25
|
-
if (block?.[0].block !== blockChainRenderComponents[0]?.block?.[0].block) {
|
|
26
|
-
void onBlock?.(block)
|
|
27
|
-
|
|
28
|
-
setBlockChainRenderComponents((blockComponents) => {
|
|
29
|
-
const newBlockComponents = [newBlockComponent, ...blockComponents]
|
|
30
|
-
|
|
31
|
-
if (maxBlocks !== undefined && newBlockComponents.length > maxBlocks) {
|
|
32
|
-
// trim the last block if we exceed the max
|
|
33
|
-
newBlockComponents.pop()
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return newBlockComponents
|
|
37
|
-
})
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return { blockChainRenderComponents, onAddBlock }
|
|
42
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { usePromise } from '@xylabs/react-promise'
|
|
2
|
-
import { isDefined } from '@xylabs/sdk-js'
|
|
3
|
-
import type { XyoChainIteratorParams } from '@xyo-network/chain-services'
|
|
4
|
-
import type { HydratedBlockWithHashMeta } from '@xyo-network/xl1-protocol'
|
|
5
|
-
import type { ComponentType } from 'react'
|
|
6
|
-
|
|
7
|
-
import { useChainAnalyzersContext } from '../../../context/index.ts'
|
|
8
|
-
import type { BlockComponentProps, BlockComponentWithTxsProps } from '../../../types/index.ts'
|
|
9
|
-
import { buildBlockChainRenderComponent } from '../helpers/index.ts'
|
|
10
|
-
|
|
11
|
-
export const useStaticBlockComponents = (
|
|
12
|
-
BlockComponent: ComponentType<BlockComponentWithTxsProps>,
|
|
13
|
-
params?: XyoChainIteratorParams,
|
|
14
|
-
blocks?: HydratedBlockWithHashMeta[],
|
|
15
|
-
) => {
|
|
16
|
-
const { onBlock } = useChainAnalyzersContext()
|
|
17
|
-
|
|
18
|
-
const [blockComponents, blockComponentsError] = usePromise(async () => {
|
|
19
|
-
const resolvedBlockWithStorage = blocks ?? []
|
|
20
|
-
if (!params?.chainMap) return []
|
|
21
|
-
|
|
22
|
-
return await Promise.all(resolvedBlockWithStorage?.map(async (block) => {
|
|
23
|
-
// TODO: Figure out why this onBlock is always defined (per TS), even though the context is optional?
|
|
24
|
-
if (isDefined(onBlock)) {
|
|
25
|
-
await onBlock(block)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const blockComponentProps: BlockComponentProps = { block, defaultExpanded: true }
|
|
29
|
-
return await buildBlockChainRenderComponent(BlockComponent, blockComponentProps)
|
|
30
|
-
}))
|
|
31
|
-
}, [blocks, params, BlockComponent])
|
|
32
|
-
|
|
33
|
-
return { blockComponents, errors: blockComponentsError }
|
|
34
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { usePromise } from '@xylabs/react-promise'
|
|
2
|
-
import { assertEx } from '@xylabs/sdk-js'
|
|
3
|
-
import type { XyoChainIteratorParams } from '@xyo-network/chain-services'
|
|
4
|
-
import { ChainBlockNumberIterationService } from '@xyo-network/chain-services'
|
|
5
|
-
import { PayloadBuilder } from '@xyo-network/payload-builder'
|
|
6
|
-
import type { Payload, WithStorageMeta } from '@xyo-network/payload-model'
|
|
7
|
-
import type { BlockBoundWitness, HydratedBlockWithHashMeta } from '@xyo-network/xl1-protocol'
|
|
8
|
-
import { isBlockBoundWitness } from '@xyo-network/xl1-protocol'
|
|
9
|
-
import type { PayloadMapRead } from '@xyo-network/xl1-protocol-sdk'
|
|
10
|
-
import { hydrateBlock } from '@xyo-network/xl1-protocol-sdk'
|
|
11
|
-
|
|
12
|
-
const getHydratedBlock = async (chainMap: PayloadMapRead<WithStorageMeta<Payload>>, head: BlockBoundWitness) => {
|
|
13
|
-
const headHash = await PayloadBuilder.hash(head)
|
|
14
|
-
return await hydrateBlock({ chainMap }, headHash)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
const iterateChain = async (chainIteratorParams?: XyoChainIteratorParams, maxDepth?: number) => {
|
|
18
|
-
const { chainMap, head } = chainIteratorParams ?? {} as XyoChainIteratorParams
|
|
19
|
-
const headPayload = assertEx(isBlockBoundWitness(head) ? head : null, () => 'Head is not a Block Bound Witness')
|
|
20
|
-
// confirm the head is a block
|
|
21
|
-
const headBlockBoundWitness = assertEx(isBlockBoundWitness(headPayload) ? headPayload : null, () => 'Invalid head block')
|
|
22
|
-
// create the chain iterator
|
|
23
|
-
const chainIterator = await ChainBlockNumberIterationService.create({ head: headBlockBoundWitness, chainMap })
|
|
24
|
-
|
|
25
|
-
// get head of the chain
|
|
26
|
-
const chainHead = await chainIterator.head()
|
|
27
|
-
let block = await getHydratedBlock(chainMap, chainHead)
|
|
28
|
-
|
|
29
|
-
// create the blocks array
|
|
30
|
-
const blocks: HydratedBlockWithHashMeta[] = [block]
|
|
31
|
-
|
|
32
|
-
// track the depth
|
|
33
|
-
let depth = 1
|
|
34
|
-
// iterate the chain
|
|
35
|
-
while (true) {
|
|
36
|
-
// get the next block
|
|
37
|
-
const [, next] = await chainIterator.previous(block[0].block, 2)
|
|
38
|
-
|
|
39
|
-
const nextHydratedBlock = await getHydratedBlock(chainMap, next)
|
|
40
|
-
// push the next block
|
|
41
|
-
blocks.push(nextHydratedBlock)
|
|
42
|
-
// set the next block as the current block
|
|
43
|
-
block = nextHydratedBlock
|
|
44
|
-
// increment the depth
|
|
45
|
-
depth++
|
|
46
|
-
// if max depth is set and we have reached it, break
|
|
47
|
-
if ((maxDepth !== undefined && depth >= maxDepth) || block?.[0].block === 0) break
|
|
48
|
-
}
|
|
49
|
-
return blocks
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export const useIterateChain = (
|
|
53
|
-
chainIteratorParams?: XyoChainIteratorParams,
|
|
54
|
-
maxDepth?: number,
|
|
55
|
-
) => {
|
|
56
|
-
return usePromise(async () => {
|
|
57
|
-
return await iterateChain(chainIteratorParams, maxDepth)
|
|
58
|
-
}, [chainIteratorParams, maxDepth])
|
|
59
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { Decorator } from '@storybook/react-vite'
|
|
2
|
-
import { usePromise } from '@xylabs/react-promise'
|
|
3
|
-
import { assertEx, isDefined } from '@xylabs/sdk-js'
|
|
4
|
-
import { ChainBlockNumberIterationService } from '@xyo-network/chain-services'
|
|
5
|
-
import { findFirstMatching } from '@xyo-network/chain-utils'
|
|
6
|
-
import type { Payload, WithStorageMeta } from '@xyo-network/payload-model'
|
|
7
|
-
import type { BlockBoundWitness } from '@xyo-network/xl1-protocol'
|
|
8
|
-
import { isBlockBoundWitness } from '@xyo-network/xl1-protocol'
|
|
9
|
-
import { readPayloadMapFromStore } from '@xyo-network/xl1-protocol-sdk'
|
|
10
|
-
import React from 'react'
|
|
11
|
-
|
|
12
|
-
import { ChainInfoProvider } from '../context/index.ts'
|
|
13
|
-
import type { BridgedChainArchivistParams } from '../lib/index.ts'
|
|
14
|
-
import { getChainArchivistFromBridge, getChainId } from '../lib/index.ts'
|
|
15
|
-
|
|
16
|
-
const archivistConfig: BridgedChainArchivistParams = {
|
|
17
|
-
url: 'http://localhost:8080',
|
|
18
|
-
chainArchivistModuleId: 'XYOPublic:XYOChain:Chain',
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export const ChainInfoContextDecorator: Decorator = (Story, context) => {
|
|
22
|
-
const [chainIdResponse] = usePromise(async () => {
|
|
23
|
-
return await getChainId()
|
|
24
|
-
}, [])
|
|
25
|
-
|
|
26
|
-
const chainId = chainIdResponse
|
|
27
|
-
|
|
28
|
-
const [chainArchivist] = usePromise(async () => {
|
|
29
|
-
return await getChainArchivistFromBridge(archivistConfig)
|
|
30
|
-
}, [])
|
|
31
|
-
|
|
32
|
-
const [chainIterator] = usePromise(async () => {
|
|
33
|
-
if (isDefined(chainArchivist) && isDefined(chainId)) {
|
|
34
|
-
const firstMatch = assertEx(await findFirstMatching(chainArchivist), () => `No head found in archivist: ${chainArchivist.id} `)
|
|
35
|
-
const head: BlockBoundWitness = assertEx(isBlockBoundWitness(firstMatch)
|
|
36
|
-
? firstMatch
|
|
37
|
-
: undefined, () => `Expected a block bound witness: ${JSON.stringify(firstMatch)}`)
|
|
38
|
-
const chainMap = readPayloadMapFromStore<WithStorageMeta<Payload>>(chainArchivist)
|
|
39
|
-
return await ChainBlockNumberIterationService.create({ chainMap, head })
|
|
40
|
-
}
|
|
41
|
-
}, [chainArchivist, chainId])
|
|
42
|
-
|
|
43
|
-
return (
|
|
44
|
-
<ChainInfoProvider chainArchivist={chainArchivist} chainId={chainId} chainIterator={chainIterator}>
|
|
45
|
-
<Story {...context} />
|
|
46
|
-
</ChainInfoProvider>
|
|
47
|
-
)
|
|
48
|
-
}
|