@xyo-network/react-chain-boundwitness 1.3.13 → 1.3.14

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 CHANGED
@@ -1,6 +1,16 @@
1
+ # @xyo-network/react-chain-boundwitness
2
+
1
3
  [![logo][]](https://xyo.network)
2
4
 
3
- Part of [@xyo-network/sdk-xyo-react](https://www.npmjs.com/package/@xyo-network/sdk-xyo-react)
5
+ Version: 1.3.13
6
+
7
+ XYO Layer One React SDK BoundWitness
8
+
9
+ ## Documentation
10
+
11
+ [TypeDoc Generated Documentation](https://gitbook.xyo.network/xyo-data-lab/xyo-reference/package-documentation/xyo-network__react-chain-boundwitness)
12
+
13
+ Part of [sdk-xyo-client-js](https://www.npmjs.com/package/@xyo-network/sdk-xyo-client-js)
4
14
 
5
15
  ## License
6
16
 
@@ -0,0 +1,10 @@
1
+ import type { FlexBoxProps } from '@xylabs/react-flexbox';
2
+ import { type SignedHydratedBlock } from '@xyo-network/xl1-protocol';
3
+ import React from 'react';
4
+ export interface BoundWitnessDetailsProps extends FlexBoxProps {
5
+ block?: SignedHydratedBlock;
6
+ }
7
+ export declare const BlockBoundWitnessDetails: ({ ref, block, paper, children, ...props }: BoundWitnessDetailsProps & {
8
+ ref?: React.Ref<unknown | null>;
9
+ }) => import("react/jsx-runtime").JSX.Element;
10
+ //# sourceMappingURL=BlockBoundWitnessDetails.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BlockBoundWitnessDetails.d.ts","sourceRoot":"","sources":["../../../src/components/BlockBoundWitnessDetails.tsx"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAezD,OAAO,EAA6B,KAAK,mBAAmB,EAAE,MAAM,2BAA2B,CAAA;AAC/F,OAAO,KAAK,MAAM,OAAO,CAAA;AAKzB,MAAM,WAAW,wBAAyB,SAAQ,YAAY;IAC5D,KAAK,CAAC,EAAE,mBAAmB,CAAA;CAC5B;AAED,eAAO,MAAM,wBAAwB,GAAI,2CAEtC,wBAAwB,GAAG;IAAE,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC,CAAA;CAAE,4CAsFhE,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-boundwitness",
4
- "version": "1.3.13",
4
+ "version": "1.3.14",
5
5
  "description": "XYO Layer One React SDK BoundWitness",
6
6
  "homepage": "https://xylabs.com",
7
7
  "bugs": {
@@ -33,10 +33,30 @@
33
33
  },
34
34
  "module": "dist/browser/index.mjs",
35
35
  "types": "dist/types/index.d.ts",
36
+ "dependencies": {
37
+ "@xylabs/array": "^4.8.9",
38
+ "@xylabs/react-error": "^6.2.19",
39
+ "@xylabs/react-promise": "^6.2.19",
40
+ "@xyo-network/payload-builder": "^3.14.16",
41
+ "@xyo-network/react-boundwitness-plugin": "^5.2.7",
42
+ "@xyo-network/react-chain-blockchain": "^1.3.14",
43
+ "@xyo-network/react-payload-details": "^5.2.7",
44
+ "@xyo-network/react-shared": "^5.2.7",
45
+ "@xyo-network/react-table": "^5.2.7",
46
+ "@xyo-network/xl1-protocol": "^1.3.11",
47
+ "react-icons": "^5.5.0"
48
+ },
36
49
  "devDependencies": {
50
+ "@emotion/react": "^11",
51
+ "@emotion/styled": "^11",
52
+ "@mui/icons-material": ">=6 <8",
53
+ "@mui/material": ">=6 <8",
37
54
  "@xylabs/ts-scripts-yarn3": "^6.5.5",
38
55
  "@xylabs/tsconfig-react": "^6.5.5",
39
56
  "knip": "^5.52.0",
57
+ "react": "^19",
58
+ "react-dom": "^19",
59
+ "react-router-dom": "^7",
40
60
  "typescript": "^5.8.3"
41
61
  },
42
62
  "peerDependencies": {
@@ -0,0 +1,72 @@
1
+ import {
2
+ Alert, AlertTitle, List, ListItem, Stack,
3
+ } from '@mui/material'
4
+ import type { Meta, StoryFn } from '@storybook/react'
5
+ import { type BlockHeaderEventNouns, useBlockHeadingEvents } from '@xyo-network/react-chain-blockchain'
6
+ import { buildRandomBlockChain } from '@xyo-network/react-chain-shared'
7
+ import React, { useState } from 'react'
8
+
9
+ import { BlockBoundWitnessDetails } from './BlockBoundWitnessDetails.tsx'
10
+
11
+ export default {
12
+ title: 'BoundWitness/Block/Details/Flexbox',
13
+ component: BlockBoundWitnessDetails,
14
+ } as Meta
15
+
16
+ const blocks = await buildRandomBlockChain()
17
+
18
+ const Template: StoryFn<typeof BlockBoundWitnessDetails> = args => <BlockBoundWitnessDetails {...args} />
19
+
20
+ type EventData = {
21
+ data: string | undefined
22
+ noun: BlockHeaderEventNouns
23
+ verb: string
24
+ }
25
+
26
+ // TODO - bring back once we add events to the BlockBoundWitnessDetails tx table
27
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
28
+ const TemplateWithEvents: StoryFn<typeof BlockBoundWitnessDetails> = (args) => {
29
+ const [eventData, setEventData] = useState<EventData[]>([])
30
+ const [ref] = useBlockHeadingEvents<HTMLDivElement>((noun, verb, data) => {
31
+ setEventData(previous => [...previous, {
32
+ noun, verb, data,
33
+ }])
34
+ })
35
+
36
+ return (
37
+ <div ref={ref}>
38
+ <BlockBoundWitnessDetails {...args} />
39
+ <Stack gap={2} flexDirection="column">
40
+ {eventData.length > 0 && eventData.map(event => (
41
+ <Alert key={event.data} sx={{ display: 'flex' }}>
42
+ <AlertTitle>Event Data</AlertTitle>
43
+ <List>
44
+ <ListItem>
45
+ Noun:
46
+ {event.noun}
47
+ </ListItem>
48
+ <ListItem>
49
+ Verb:
50
+ {event.verb}
51
+ </ListItem>
52
+ </List>
53
+ <pre>
54
+ <code>{event.data}</code>
55
+ </pre>
56
+ </Alert>
57
+ ))}
58
+ </Stack>
59
+ </div>
60
+ )
61
+ }
62
+
63
+ const Default = Template.bind({})
64
+ Default.args = {}
65
+
66
+ const WithData = Template.bind({})
67
+ WithData.args = { block: blocks[3] }
68
+
69
+ // const WithDataEvents = TemplateWithEvents.bind({})
70
+ // WithDataEvents.args = { block: blocks[0], transactions: undefined }
71
+
72
+ export { Default, WithData }
@@ -0,0 +1,119 @@
1
+ import {
2
+ Divider, TableCell, TableHead, TableRow,
3
+ } from '@mui/material'
4
+ import { filterAs } from '@xylabs/array'
5
+ import { ErrorRender } from '@xylabs/react-error'
6
+ import type { FlexBoxProps } from '@xylabs/react-flexbox'
7
+ import { FlexCol } from '@xylabs/react-flexbox'
8
+ import { usePromise } from '@xylabs/react-promise'
9
+ import { isBoundWitness } from '@xyo-network/boundwitness-model'
10
+ import { PayloadBuilder } from '@xyo-network/payload-builder'
11
+ import {
12
+ BoundWitnessPayloadsTable,
13
+ BoundWitnessSignatureTable,
14
+ BWActions,
15
+ HashHeadingPaper,
16
+ HeadingPaper,
17
+ } from '@xyo-network/react-boundwitness-plugin'
18
+ import { useTxsFromBlock } from '@xyo-network/react-chain-blockchain'
19
+ import { HashTableCell, usePayloadHash } from '@xyo-network/react-shared'
20
+ import { TableEx } from '@xyo-network/react-table'
21
+ import { isTransactionBoundWitness, type SignedHydratedBlock } from '@xyo-network/xl1-protocol'
22
+ import React from 'react'
23
+ import { FaSignature } from 'react-icons/fa'
24
+ import { GrTransaction } from 'react-icons/gr'
25
+ import { VscSymbolMethod, VscSymbolNamespace } from 'react-icons/vsc'
26
+
27
+ export interface BoundWitnessDetailsProps extends FlexBoxProps {
28
+ block?: SignedHydratedBlock
29
+ }
30
+
31
+ export const BlockBoundWitnessDetails = ({
32
+ ref, block, paper, children, ...props
33
+ }: BoundWitnessDetailsProps & { ref?: React.Ref<unknown | null> }) => {
34
+ const boundWitness = block?.[0]
35
+ const payloads = block?.[1]
36
+
37
+ const hash = usePayloadHash(boundWitness)
38
+
39
+ const [transactions, txFromBlockError] = useTxsFromBlock(block)
40
+
41
+ const [nonTxBoundWitnesses, bwsFromBlockError] = usePromise(async () => {
42
+ const bws = filterAs(payloads ?? [], payload =>
43
+ (!isTransactionBoundWitness(payload) && isBoundWitness(payload)) ? payload : undefined)
44
+ return await PayloadBuilder.hashPairs(bws)
45
+ }, [payloads])
46
+
47
+ const hasNonTxBoundWitnesses = (nonTxBoundWitnesses?.length ?? 0) > 0
48
+
49
+ return (
50
+ <FlexCol alignItems="stretch" rowGap={4} {...props}>
51
+ <ErrorRender error={txFromBlockError ?? bwsFromBlockError} scope="BlockBoundWitnessDetails.tsx" />
52
+ <HashHeadingPaper
53
+ hash={hash}
54
+ paperProps={{ sx: { p: 2 } }}
55
+ AdornmentEnd={<BWActions boundwitness={boundWitness} />}
56
+ identiconProps={{ p: 0.75, size: 24 }}
57
+ />
58
+ <Divider flexItem />
59
+ {transactions?.length && (
60
+ <FlexCol alignItems="stretch" rowGap={1} mb={1}>
61
+ <HeadingPaper IconComponent={<GrTransaction />} heading="Transactions" />
62
+ <TableEx>
63
+ <TableHead>
64
+ <TableRow>
65
+ <TableCell>
66
+ Hash
67
+ </TableCell>
68
+ </TableRow>
69
+ </TableHead>
70
+ {
71
+ transactions?.map(([, txHash]) => (
72
+ <TableRow
73
+ key={hash + txHash}
74
+ // onClick={() => handleOnClick(hash)} sx={{ cursor: 'pointer' }}
75
+ >
76
+ <HashTableCell title={hash}>{hash}</HashTableCell>
77
+ </TableRow>
78
+ ))
79
+ }
80
+ </TableEx>
81
+ </FlexCol>
82
+ )}
83
+ <FlexCol alignItems="stretch" rowGap={1} mb={1}>
84
+ <HeadingPaper IconComponent={<VscSymbolNamespace />} heading="Payloads" />
85
+ <BoundWitnessPayloadsTable boundwitness={boundWitness} />
86
+ </FlexCol>
87
+ {hasNonTxBoundWitnesses
88
+ ? (
89
+ <FlexCol alignItems="stretch" rowGap={1} mb={1}>
90
+ <HeadingPaper IconComponent={<VscSymbolMethod />} heading="Bound Witnesses" />
91
+ <TableEx>
92
+ <TableHead>
93
+ <TableRow>
94
+ <TableCell>
95
+ Schema
96
+ </TableCell>
97
+ </TableRow>
98
+ </TableHead>
99
+ {
100
+ nonTxBoundWitnesses?.map(([, bwHash]) => (
101
+ <TableRow
102
+ key={hash + bwHash}
103
+ // onClick={() => handleOnClick(hash)} sx={{ cursor: 'pointer' }}
104
+ >
105
+ <HashTableCell title={hash}>{hash}</HashTableCell>
106
+ </TableRow>
107
+ ))
108
+ }
109
+ </TableEx>
110
+ </FlexCol>
111
+ )
112
+ : null}
113
+ <FlexCol alignItems="stretch" rowGap={1} mb={1}>
114
+ <HeadingPaper IconComponent={<FaSignature />} heading="Signatures" />
115
+ <BoundWitnessSignatureTable block={boundWitness} />
116
+ </FlexCol>
117
+ </FlexCol>
118
+ )
119
+ }