@xyo-network/react-chain-blockchain 1.20.15 → 1.20.16

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 (196) hide show
  1. package/README.md +9 -8854
  2. package/dist/browser/components/block/table/cell/NumberChip.d.ts.map +1 -1
  3. package/dist/browser/components/chain/controls/PulseSvgIcon.d.ts +5 -2
  4. package/dist/browser/components/chain/controls/PulseSvgIcon.d.ts.map +1 -1
  5. package/dist/browser/components/chain/hooks/useOnBlock.d.ts +7 -7
  6. package/dist/browser/components/chain/styled/BlockListWrapperFlexbox.d.ts +6 -1
  7. package/dist/browser/components/chain/styled/BlockListWrapperFlexbox.d.ts.map +1 -1
  8. package/dist/browser/components/table/StyledLinkableTableRow.d.ts +5 -4
  9. package/dist/browser/components/table/StyledLinkableTableRow.d.ts.map +1 -1
  10. package/dist/browser/context/analyzer/context.d.ts +3 -3
  11. package/dist/browser/context/analyzer/use.d.ts +1 -1
  12. package/dist/browser/context/chain/Context.d.ts +3 -3
  13. package/dist/browser/context/chain/use.d.ts +1 -1
  14. package/dist/browser/hooks/useBaseContext.d.ts +2 -8
  15. package/dist/browser/hooks/useBaseContext.d.ts.map +1 -1
  16. package/dist/browser/hooks/useTxsFromBlock.d.ts +1 -1
  17. package/dist/browser/hooks/useTxsFromBlock.d.ts.map +1 -1
  18. package/dist/browser/index.mjs.map +1 -1
  19. package/package.json +167 -58
  20. package/src/components/FeatureNotAvailable.tsx +0 -20
  21. package/src/components/account/BalanceHistoryFlexbox.stories.tsx +0 -25
  22. package/src/components/account/BalanceHistoryFlexbox.tsx +0 -53
  23. package/src/components/account/helpers/formatBalanceMagnitude.ts +0 -14
  24. package/src/components/account/helpers/index.ts +0 -1
  25. package/src/components/account/hooks/index.ts +0 -1
  26. package/src/components/account/hooks/usePagedAccountBalanceHistory.ts +0 -39
  27. package/src/components/account/index.ts +0 -4
  28. package/src/components/account/table/BalanceHistoryTableEx.stories.tsx +0 -111
  29. package/src/components/account/table/BalanceHistoryTableEx.tsx +0 -37
  30. package/src/components/account/table/BalanceHistoryTableRow.stories.tsx +0 -53
  31. package/src/components/account/table/BalanceHistoryTableRow.tsx +0 -60
  32. package/src/components/account/table/RawAmountTableCell.tsx +0 -53
  33. package/src/components/account/table/cell/AddressTableCell.tsx +0 -27
  34. package/src/components/account/table/cell/BlockNumber.tsx +0 -39
  35. package/src/components/account/table/cell/HashTableCell.tsx +0 -46
  36. package/src/components/account/table/cell/index.ts +0 -3
  37. package/src/components/account/table/hooks/index.ts +0 -1
  38. package/src/components/account/table/hooks/useLinkedBalanceHistoryItem.tsx +0 -29
  39. package/src/components/account/table/index.ts +0 -5
  40. package/src/components/account/table/types/index.ts +0 -18
  41. package/src/components/block/BlockHeadingFlexbox.stories.tsx +0 -75
  42. package/src/components/block/BlockHeadingFlexbox.tsx +0 -56
  43. package/src/components/block/ChipSkeleton.tsx +0 -7
  44. package/src/components/block/LinkedDivider.tsx +0 -27
  45. package/src/components/block/ProducerChip.tsx +0 -45
  46. package/src/components/block/helpers/blockProducer.ts +0 -5
  47. package/src/components/block/helpers/buildBlockChainRenderComponent.tsx +0 -32
  48. package/src/components/block/helpers/index.ts +0 -3
  49. package/src/components/block/helpers/payloadCountsFromBlock.ts +0 -10
  50. package/src/components/block/hooks/index.ts +0 -4
  51. package/src/components/block/hooks/useAnchorElement.ts +0 -19
  52. package/src/components/block/hooks/useBlockHeadingEvents.ts +0 -11
  53. package/src/components/block/hooks/useBlockProducer.ts +0 -11
  54. package/src/components/block/hooks/usePayloadCountsFromBlock.ts +0 -13
  55. package/src/components/block/index.ts +0 -6
  56. package/src/components/block/menu/Expanded.tsx +0 -34
  57. package/src/components/block/menu/index.ts +0 -1
  58. package/src/components/block/table/Ex.stories.tsx +0 -64
  59. package/src/components/block/table/Ex.tsx +0 -21
  60. package/src/components/block/table/cell/BlockNumber.tsx +0 -35
  61. package/src/components/block/table/cell/Epoch.tsx +0 -46
  62. package/src/components/block/table/cell/Hash.tsx +0 -46
  63. package/src/components/block/table/cell/JsonView.tsx +0 -44
  64. package/src/components/block/table/cell/NumberChip.tsx +0 -12
  65. package/src/components/block/table/cell/PayloadCounts.tsx +0 -65
  66. package/src/components/block/table/cell/Producer.tsx +0 -63
  67. package/src/components/block/table/cell/TransactionCount.tsx +0 -56
  68. package/src/components/block/table/cell/Verification.tsx +0 -25
  69. package/src/components/block/table/cell/helpers/index.ts +0 -1
  70. package/src/components/block/table/cell/helpers/timeFunctions.ts +0 -44
  71. package/src/components/block/table/cell/hooks/index.ts +0 -1
  72. package/src/components/block/table/cell/hooks/useLinkedBlockItem.tsx +0 -25
  73. package/src/components/block/table/cell/index.ts +0 -8
  74. package/src/components/block/table/cell/lib/BlockTableCellProps.ts +0 -7
  75. package/src/components/block/table/cell/lib/index.ts +0 -1
  76. package/src/components/block/table/head/TableHead.tsx +0 -48
  77. package/src/components/block/table/head/index.ts +0 -1
  78. package/src/components/block/table/index.ts +0 -4
  79. package/src/components/block/table/row/TableRow.stories.tsx +0 -34
  80. package/src/components/block/table/row/TableRow.tsx +0 -46
  81. package/src/components/block/table/row/index.ts +0 -1
  82. package/src/components/chain/controls/PollingControlsFlexbox.tsx +0 -76
  83. package/src/components/chain/controls/PulseSvgIcon.tsx +0 -71
  84. package/src/components/chain/controls/index.ts +0 -2
  85. package/src/components/chain/dialog/Dialog.tsx +0 -20
  86. package/src/components/chain/dialog/index.ts +0 -1
  87. package/src/components/chain/hooks/index.ts +0 -1
  88. package/src/components/chain/hooks/useOnBlock.ts +0 -55
  89. package/src/components/chain/index.ts +0 -6
  90. package/src/components/chain/list/Animated.tsx +0 -19
  91. package/src/components/chain/list/TableEx.tsx +0 -12
  92. package/src/components/chain/list/index.ts +0 -2
  93. package/src/components/chain/pagination/BlockChainPagination.tsx +0 -11
  94. package/src/components/chain/pagination/hooks/index.ts +0 -1
  95. package/src/components/chain/pagination/hooks/usePagination.tsx +0 -22
  96. package/src/components/chain/pagination/index.ts +0 -2
  97. package/src/components/chain/stats/Dialog.tsx +0 -49
  98. package/src/components/chain/stats/index.ts +0 -1
  99. package/src/components/chain/stats/producer/ProducerFlexbox.tsx +0 -32
  100. package/src/components/chain/stats/producer/Table.tsx +0 -39
  101. package/src/components/chain/stats/producer/index.ts +0 -2
  102. package/src/components/chain/styled/BlockListWrapperFlexbox.tsx +0 -15
  103. package/src/components/chain/styled/index.ts +0 -1
  104. package/src/components/index.ts +0 -7
  105. package/src/components/payload/builder/BuilderComponentProps.ts +0 -5
  106. package/src/components/payload/builder/Flexbox.tsx +0 -30
  107. package/src/components/payload/builder/index.ts +0 -4
  108. package/src/components/payload/builder/producer-intent/Flexbox.stories.tsx +0 -14
  109. package/src/components/payload/builder/producer-intent/Flexbox.tsx +0 -15
  110. package/src/components/payload/builder/producer-intent/Form.tsx +0 -69
  111. package/src/components/payload/builder/producer-intent/index.ts +0 -1
  112. package/src/components/payload/builder/transfer/Flexbox.stories.tsx +0 -14
  113. package/src/components/payload/builder/transfer/Flexbox.tsx +0 -15
  114. package/src/components/payload/builder/transfer/Form.tsx +0 -82
  115. package/src/components/payload/builder/transfer/Transfer.ts +0 -3
  116. package/src/components/payload/builder/transfer/builder/SingleFlexbox.tsx +0 -51
  117. package/src/components/payload/builder/transfer/builder/index.ts +0 -1
  118. package/src/components/payload/builder/transfer/index.ts +0 -2
  119. package/src/components/payload/fields/BlockNumberTextField.tsx +0 -40
  120. package/src/components/payload/fields/XyoAddressTextField.tsx +0 -71
  121. package/src/components/payload/fields/index.ts +0 -2
  122. package/src/components/payload/index.ts +0 -2
  123. package/src/components/rate/SpanTypography.tsx +0 -20
  124. package/src/components/rate/SpeedTypography.tsx +0 -17
  125. package/src/components/rate/TimeTypography.tsx +0 -17
  126. package/src/components/rate/flexbox/FlexBox.stories.tsx +0 -46
  127. package/src/components/rate/flexbox/FlexBox.tsx +0 -31
  128. package/src/components/rate/flexbox/index.ts +0 -1
  129. package/src/components/rate/gauge/Container.stories.tsx +0 -80
  130. package/src/components/rate/gauge/Container.tsx +0 -75
  131. package/src/components/rate/gauge/Pointer.tsx +0 -67
  132. package/src/components/rate/gauge/Ticks.tsx +0 -122
  133. package/src/components/rate/gauge/WithLabel.stories.tsx +0 -73
  134. package/src/components/rate/gauge/WithLabel.tsx +0 -20
  135. package/src/components/rate/gauge/helpers/blockRateConversions.ts +0 -104
  136. package/src/components/rate/gauge/helpers/index.ts +0 -1
  137. package/src/components/rate/gauge/index.ts +0 -4
  138. package/src/components/rate/index.ts +0 -6
  139. package/src/components/rate/support/MetricTypography.tsx +0 -78
  140. package/src/components/rate/support/index.ts +0 -1
  141. package/src/components/table/StyledLinkableTableRow.tsx +0 -12
  142. package/src/components/table/index.ts +0 -1
  143. package/src/components/transactions/TransactionCountChip.tsx +0 -34
  144. package/src/components/transactions/TransactionsQuickTipButton.tsx +0 -86
  145. package/src/components/transactions/index.ts +0 -3
  146. package/src/components/transactions/submit/Builder.tsx +0 -55
  147. package/src/components/transactions/submit/Network.tsx +0 -36
  148. package/src/components/transactions/submit/SubmitChain.stories.tsx +0 -14
  149. package/src/components/transactions/submit/SubmitChain.tsx +0 -91
  150. package/src/components/transactions/submit/index.ts +0 -3
  151. package/src/context/analyzer/Provider.tsx +0 -41
  152. package/src/context/analyzer/context.ts +0 -5
  153. package/src/context/analyzer/index.ts +0 -5
  154. package/src/context/analyzer/state.ts +0 -13
  155. package/src/context/analyzer/use.ts +0 -6
  156. package/src/context/chain/Context.ts +0 -5
  157. package/src/context/chain/Provider.tsx +0 -49
  158. package/src/context/chain/State.ts +0 -8
  159. package/src/context/chain/index.ts +0 -4
  160. package/src/context/chain/use.ts +0 -6
  161. package/src/context/index.ts +0 -3
  162. package/src/context/polling/Provider.tsx +0 -27
  163. package/src/context/polling/context.ts +0 -5
  164. package/src/context/polling/index.ts +0 -4
  165. package/src/context/polling/state.ts +0 -8
  166. package/src/context/polling/use.ts +0 -5
  167. package/src/helpers/index.ts +0 -1
  168. package/src/helpers/rate/index.ts +0 -1
  169. package/src/helpers/rate/rateUnitToLabel.ts +0 -27
  170. package/src/helpers/txsFromBlock.ts +0 -12
  171. package/src/hooks/chain-iterator/index.ts +0 -1
  172. package/src/hooks/chain-iterator/useChainIteratorParams.ts +0 -55
  173. package/src/hooks/index.ts +0 -3
  174. package/src/hooks/useBaseContext.ts +0 -8
  175. package/src/hooks/useTxsFromBlock.ts +0 -12
  176. package/src/index.ts +0 -3
  177. package/src/lib/getChainArchivist.ts +0 -20
  178. package/src/lib/getChainId.ts +0 -8
  179. package/src/lib/index.ts +0 -2
  180. package/src/stories/ChainArchivistDecorator.tsx +0 -43
  181. package/src/stories/ChainArchivistDelayedInsertDecorator.tsx +0 -71
  182. package/src/stories/index.ts +0 -2
  183. package/src/types/BlockComponentProps.ts +0 -13
  184. package/src/types/BlockComponents.ts +0 -7
  185. package/src/types/BlockListComponentProps.ts +0 -6
  186. package/src/types/global.d.ts +0 -1
  187. package/src/types/index.ts +0 -4
  188. package/src/types/render/BlockChainRenderProps.ts +0 -28
  189. package/src/types/render/RemoteArchivistProps.ts +0 -5
  190. package/src/types/render/flexbox/BlockChainRenderFlexboxProps.ts +0 -8
  191. package/src/types/render/flexbox/RenderFlexboxProps.ts +0 -5
  192. package/src/types/render/flexbox/index.ts +0 -2
  193. package/src/types/render/index.ts +0 -4
  194. package/src/types/render/table/BlockChainRenderTableExProps.ts +0 -8
  195. package/src/types/render/table/RenderTableProps.ts +0 -5
  196. package/src/types/render/table/index.ts +0 -2
@@ -1,36 +0,0 @@
1
- import type { StandardTextFieldProps } from '@mui/material'
2
- import {
3
- FormControl, FormHelperText,
4
- TextField,
5
- } from '@mui/material'
6
- import type { ChangeEventHandler } from 'react'
7
- import React, { useState } from 'react'
8
-
9
- export interface ChainTransactionNetworkProps extends StandardTextFieldProps {
10
- network?: URL
11
- onNetworkChange?: (url: URL) => void
12
- }
13
-
14
- export const ChainTransactionNetwork: React.FC<ChainTransactionNetworkProps> = ({
15
- network, onNetworkChange, ...props
16
- }) => {
17
- const [error, setError] = useState<Error>()
18
-
19
- const handleChange: ChangeEventHandler<HTMLInputElement> = (event) => {
20
- try {
21
- const url = new URL(event.target.value)
22
- setError(undefined)
23
- onNetworkChange?.(url)
24
- } catch (error) {
25
- console.error(error)
26
- setError(error as Error)
27
- }
28
- }
29
-
30
- return (
31
- <FormControl fullWidth>
32
- <TextField label="Network" name="network" onChange={handleChange} required value={network} {...props} />
33
- <FormHelperText sx={{ color: error ? 'red' : undefined }}>{error ? 'Not a valid url' : 'Enter full url of archivist'}</FormHelperText>
34
- </FormControl>
35
- )
36
- }
@@ -1,14 +0,0 @@
1
- import type { Meta, StoryFn } from '@storybook/react-vite'
2
- import React from 'react'
3
-
4
- import { SubmitChainTransaction } from './SubmitChain.tsx'
5
-
6
- export default {
7
- title: 'Transaction/Submit',
8
- component: SubmitChainTransaction,
9
- } as Meta
10
-
11
- const Template: StoryFn<typeof SubmitChainTransaction> = args => <SubmitChainTransaction {...args} />
12
-
13
- export const Default = Template.bind({})
14
- Default.args = {}
@@ -1,91 +0,0 @@
1
- import {
2
- Alert, Grid, Typography,
3
- } from '@mui/material'
4
- import { ErrorRender } from '@xylabs/react-error'
5
- import { FlexGrowCol } from '@xylabs/react-flexbox'
6
- import { axiosJsonConfig } from '@xylabs/sdk-js'
7
- import type {
8
- ApiEnvelope, ModuleQueryResult, Payload,
9
- } from '@xyo-network/sdk-js'
10
- import {
11
- Account, ArchivistInsertQuerySchema,
12
- PayloadBuilder, QueryBoundWitnessBuilder,
13
- } from '@xyo-network/sdk-js'
14
- import type { TransactionBoundWitnessFields } from '@xyo-network/xl1-sdk'
15
- import { buildTransaction } from '@xyo-network/xl1-sdk'
16
- import { Axios } from 'axios'
17
- import React, { useState } from 'react'
18
-
19
- import { ChainTransactionBuilder } from './Builder.tsx'
20
- import { ChainTransactionNetwork } from './Network.tsx'
21
-
22
- const BETA_PENDING_TRANSACTIONS_ARCHIVIST = 'https://beta.api.chain.xyo.network/8050fee682a2762f504d5449d8269a6f17f0b693'
23
- const defaultNetwork = new URL(BETA_PENDING_TRANSACTIONS_ARCHIVIST)
24
-
25
- export const SubmitChainTransaction: React.FC = () => {
26
- const [network, setNetwork] = useState<URL | undefined>(defaultNetwork)
27
- const [result, setResult] = useState<ModuleQueryResult>()
28
- const [error, setError] = useState<Error>()
29
-
30
- const onSubmitTx = async (chainTx: Omit<TransactionBoundWitnessFields, 'from'>) => {
31
- if (network) {
32
- const randomAccount = await Account.random()
33
- const [transactionBoundWitness] = await buildTransaction(
34
- chainTx.chain,
35
- [],
36
- [],
37
- randomAccount,
38
- chainTx.nbf,
39
- chainTx.exp,
40
- )
41
-
42
- const insertQuery = new PayloadBuilder({ schema: ArchivistInsertQuerySchema }).build()
43
- const [queryBoundWitness] = await new QueryBoundWitnessBuilder()
44
- .payloads([transactionBoundWitness as Payload])
45
- .query(insertQuery)
46
- .signer(randomAccount)
47
- .build()
48
-
49
- const response = await new Axios(axiosJsonConfig()).post<ApiEnvelope<ModuleQueryResult>>(
50
- network.href,
51
- [queryBoundWitness, [insertQuery, transactionBoundWitness, chainTx]],
52
- )
53
- if (response.data.errors.length > 0) {
54
- setError(new Error(response.data.errors.map(e => e.message).join('\n')))
55
- } else {
56
- setResult(response.data.data)
57
- }
58
- }
59
- }
60
-
61
- const onNetworkChange = (url: URL) => {
62
- setNetwork(url)
63
- }
64
-
65
- return (
66
- <Grid container>
67
- <Grid size={{
68
- xs: 12, sm: 6, md: 4,
69
- }}
70
- >
71
- <FlexGrowCol alignItems="start" gap={2}>
72
- <ChainTransactionNetwork network={network} onNetworkChange={onNetworkChange} />
73
- {network ? <ChainTransactionBuilder onSubmitTx={onSubmitTx} /> : null}
74
- {result?.[2].length === 0 ? <Alert severity="success">Success</Alert> : null}
75
-
76
- {error ? <ErrorRender error={error} /> : null}
77
- {result?.[2] && result?.[2].length > 0 ? <ErrorRender error={new Error('Failed insert...see result below')} /> : null}
78
-
79
- {result
80
- ? (
81
- <>
82
- <Typography variant="h6">Result:</Typography>
83
- <pre>{JSON.stringify(result, null, 2)}</pre>
84
- </>
85
- )
86
- : null}
87
- </FlexGrowCol>
88
- </Grid>
89
- </Grid>
90
- )
91
- }
@@ -1,3 +0,0 @@
1
- export * from './Builder.tsx'
2
- export * from './Network.tsx'
3
- export * from './SubmitChain.tsx'
@@ -1,41 +0,0 @@
1
- import { isUndefined } from '@xylabs/sdk-js'
2
- import type { HydratedBlock } from '@xyo-network/xl1-sdk'
3
- import type { PropsWithChildren } from 'react'
4
- import React, {
5
- useCallback, useMemo, useState,
6
- } from 'react'
7
-
8
- import { ChainAnalyzersContext } from './context.ts'
9
- import type { ChainAnalyzers, ChainAnalyzersState } from './state.ts'
10
-
11
- export interface ChainAnalyzersProviderProps extends PropsWithChildren {
12
- analyzers?: ChainAnalyzers
13
- }
14
-
15
- export const ChainAnalyzersProvider: React.FC<ChainAnalyzersProviderProps> = ({ analyzers: analyzersProp, children }) => {
16
- const [analyzersState, setAnalyzersState] = useState<ChainAnalyzers>(analyzersProp ?? {} as ChainAnalyzers)
17
- const [statsUpdated, setStatsUpdated] = useState(1)
18
-
19
- const analyzers = useMemo(() => ({ ...analyzersProp, ...analyzersState }), [analyzersProp, analyzersState])
20
-
21
- const addAnalyzers: ChainAnalyzersState['addAnalyzers'] = useCallback((analyzers: ChainAnalyzersState['analyzers']) => {
22
- if (isUndefined(analyzers)) return
23
- setAnalyzersState(prev => ({ ...prev, ...analyzers }))
24
- }, [])
25
-
26
- const onBlock = useCallback(async (hydratedBlock: HydratedBlock) => {
27
- await Promise.resolve()
28
- for (const analyzer of Object.values(analyzers)) {
29
- void analyzer.onBlock(hydratedBlock)
30
- setStatsUpdated(Date.now())
31
- }
32
- }, [analyzers])
33
-
34
- const value: ChainAnalyzersState = useMemo(() => ({
35
- analyzers, addAnalyzers, onBlock, statsUpdated, provided: true,
36
- }), [analyzers, addAnalyzers, onBlock, statsUpdated])
37
-
38
- return (
39
- <ChainAnalyzersContext value={value}>{children}</ChainAnalyzersContext>
40
- )
41
- }
@@ -1,5 +0,0 @@
1
- import { createContextEx } from '@xylabs/react-shared'
2
-
3
- import type { ChainAnalyzersState } from './state.ts'
4
-
5
- export const ChainAnalyzersContext = createContextEx<ChainAnalyzersState>()
@@ -1,5 +0,0 @@
1
- export * from './context.ts'
2
- export * from './Provider.tsx'
3
- export * from './Provider.tsx'
4
- export * from './state.ts'
5
- export * from './use.ts'
@@ -1,13 +0,0 @@
1
- import type { ContextExState } from '@xylabs/react-shared'
2
- import type { ChainAnalyzer, HydratedBlock } from '@xyo-network/xl1-sdk'
3
-
4
- export type ChainAnalyzerIds = 'producers'
5
-
6
- export type ChainAnalyzers = Record<ChainAnalyzerIds, ChainAnalyzer>
7
-
8
- export type ChainAnalyzersState = ContextExState<{
9
- addAnalyzers: (analyzers: ChainAnalyzers) => void
10
- analyzers: ChainAnalyzers
11
- onBlock: (block: HydratedBlock) => Promise<void>
12
- statsUpdated: number
13
- }>
@@ -1,6 +0,0 @@
1
- import { useContextEx } from '@xylabs/react-shared'
2
-
3
- import { ChainAnalyzersContext } from './context.ts'
4
- import type { ChainAnalyzersState } from './state.ts'
5
-
6
- export const useChainAnalyzersContext = (required = false) => useContextEx<ChainAnalyzersState>(ChainAnalyzersContext, 'ChainAnalyzers', required)
@@ -1,5 +0,0 @@
1
- import { createContextEx } from '@xylabs/react-shared'
2
-
3
- import type { ChainInfoState } from './State.ts'
4
-
5
- export const ChainInfoContext = createContextEx<ChainInfoState>()
@@ -1,49 +0,0 @@
1
- import { isDefined } from '@xylabs/sdk-js'
2
- import type { PropsWithChildren } from 'react'
3
- import React, {
4
- useCallback, useMemo, useState,
5
- } from 'react'
6
-
7
- import { ChainInfoContext } from './Context.ts'
8
- import type { ChainInfoState } from './State.ts'
9
-
10
- interface ChainInfoProviderProps extends PropsWithChildren, Omit<ChainInfoState, 'provided'> {}
11
-
12
- export const ChainInfoProvider: React.FC<ChainInfoProviderProps> = ({
13
- children, chainArchivist: chainArchivistProp, chainId: chainIdProp,
14
- }) => {
15
- const [chainArchivist, setChainArchivist] = useState<ChainInfoState['chainArchivist']>(chainArchivistProp)
16
- const [previousChainArchivist, setPreviousChainArchivist] = useState<ChainInfoState['chainArchivist']>(chainArchivistProp)
17
- if (isDefined(chainArchivistProp) && chainArchivistProp !== previousChainArchivist) {
18
- setChainArchivist(chainArchivistProp)
19
- setPreviousChainArchivist(chainArchivistProp)
20
- }
21
-
22
- const [chainId, setChainId] = useState<ChainInfoState['chainId']>(chainIdProp)
23
- const [previousChainId, setPreviousChainId] = useState<ChainInfoState['chainId']>(chainIdProp)
24
- if (isDefined(chainIdProp) && chainIdProp !== previousChainId) {
25
- setChainId(chainIdProp)
26
- setPreviousChainId(chainIdProp)
27
- }
28
-
29
- const updateChainArchivist = useCallback((chainArchivist: ChainInfoState['chainArchivist']) => {
30
- setChainArchivist(chainArchivist)
31
- }, [])
32
- const updateChainId = useCallback((chainId: ChainInfoState['chainId']) => {
33
- setChainId(chainId)
34
- }, [])
35
-
36
- const chainState: ChainInfoState = useMemo(() => ({
37
- chainArchivist,
38
- chainId,
39
- updateChainArchivist,
40
- updateChainId,
41
- provided: true,
42
- }), [chainArchivist, chainId, updateChainArchivist, updateChainId])
43
-
44
- return (
45
- <ChainInfoContext value={chainState}>
46
- {children}
47
- </ChainInfoContext>
48
- )
49
- }
@@ -1,8 +0,0 @@
1
- import type { ContextExState } from '@xylabs/react-shared'
2
- import type { ArchivistInstance } from '@xyo-network/sdk-js'
3
- import type { ChainId } from '@xyo-network/xl1-sdk'
4
-
5
- export type ChainInfoState = ContextExState<{
6
- chainArchivist?: ArchivistInstance
7
- chainId?: ChainId
8
- }>
@@ -1,4 +0,0 @@
1
- export * from './Context.ts'
2
- export * from './Provider.tsx'
3
- export * from './State.ts'
4
- export * from './use.ts'
@@ -1,6 +0,0 @@
1
- import { useContextEx } from '@xylabs/react-shared'
2
-
3
- import { ChainInfoContext } from './Context.ts'
4
- import type { ChainInfoState } from './State.ts'
5
-
6
- export const useChainInfo = (required = false) => useContextEx<ChainInfoState>(ChainInfoContext, 'ChainState', required)
@@ -1,3 +0,0 @@
1
- export * from './analyzer/index.ts'
2
- export * from './chain/index.ts'
3
- export * from './polling/index.ts'
@@ -1,27 +0,0 @@
1
- import type { PropsWithChildren } from 'react'
2
- import React, {
3
- useCallback, useMemo, useState,
4
- } from 'react'
5
-
6
- import { ChainPollingContext } from './context.ts'
7
- import type { ChainPollingState, PollingState } from './state.ts'
8
-
9
- export interface ChainPollingProviderProps extends PropsWithChildren {
10
- pollingState?: PollingState
11
- }
12
-
13
- export const ChainPollingProvider: React.FC<ChainPollingProviderProps> = ({ children, pollingState: pollingStateProp = 'running' }) => {
14
- const [pollingState, setPollingState] = useState<PollingState>(pollingStateProp)
15
-
16
- const updatePollingState = useCallback((newPollingState: PollingState) => {
17
- setPollingState(newPollingState)
18
- }, [])
19
-
20
- const value: ChainPollingState = useMemo(() => ({
21
- pollingState,
22
- provided: true,
23
- updatePollingState,
24
- }), [pollingState, updatePollingState])
25
-
26
- return <ChainPollingContext value={value}>{children}</ChainPollingContext>
27
- }
@@ -1,5 +0,0 @@
1
- import { createContextEx } from '@xylabs/react-shared'
2
-
3
- import type { ChainPollingState } from './state.ts'
4
-
5
- export const ChainPollingContext = createContextEx<ChainPollingState>()
@@ -1,4 +0,0 @@
1
- export * from './context.ts'
2
- export * from './Provider.tsx'
3
- export * from './state.ts'
4
- export * from './use.ts'
@@ -1,8 +0,0 @@
1
- import type { ContextExState } from '@xylabs/react-shared'
2
-
3
- export type PollingState = 'paused' | 'running'
4
-
5
- export type ChainPollingState = ContextExState<{
6
- pollingState?: PollingState
7
- updatePollingState?: (newState: PollingState) => void
8
- }>
@@ -1,5 +0,0 @@
1
- import { useContextEx } from '@xylabs/react-shared'
2
-
3
- import { ChainPollingContext } from './context.ts'
4
-
5
- export const useChainPollingContext = (required = false) => useContextEx(ChainPollingContext, 'ChainPolling', required)
@@ -1 +0,0 @@
1
- export * from './txsFromBlock.ts'
@@ -1 +0,0 @@
1
- export * from './rateUnitToLabel.ts'
@@ -1,27 +0,0 @@
1
- import type { TimeDurations } from '@xyo-network/xl1-sdk'
2
-
3
- export const rateUnitToLabel = (rateUnit: keyof TimeDurations) => {
4
- switch (rateUnit) {
5
- case 'millis': {
6
- return 'b/ms'
7
- }
8
- case 'seconds': {
9
- return 'b/s'
10
- }
11
- case 'minutes': {
12
- return 'b/m'
13
- }
14
- case 'hours': {
15
- return 'b/h'
16
- }
17
- case 'days': {
18
- return 'b/d'
19
- }
20
- case 'weeks': {
21
- return 'b/w'
22
- }
23
- default: {
24
- return rateUnit
25
- }
26
- }
27
- }
@@ -1,12 +0,0 @@
1
- import type { Hash } from '@xylabs/sdk-js'
2
- import { HydratedBlockWrapper } from '@xyo-network/chain-wrappers'
3
- import type { Payload } from '@xyo-network/sdk-js'
4
- import { PayloadBuilder } from '@xyo-network/sdk-js'
5
- import type { HydratedBlockWithHashMeta } from '@xyo-network/xl1-sdk'
6
-
7
- export const txsFromBlock = async (block: HydratedBlockWithHashMeta): Promise<[Payload, Hash][]> => {
8
- const wrapper = await HydratedBlockWrapper.parse(block)
9
- const txs = wrapper.transactions
10
- const txPayloads = txs.map(tx => tx.boundWitness)
11
- return await PayloadBuilder.hashPairs(txPayloads)
12
- }
@@ -1 +0,0 @@
1
- export * from './useChainIteratorParams.ts'
@@ -1,55 +0,0 @@
1
- import type { UsePromiseState } from '@xylabs/react-promise'
2
- import { usePromise } from '@xylabs/react-promise'
3
- import { type Hash, isHash } from '@xylabs/sdk-js'
4
- import { assertEx, isDefined } from '@xylabs/sdk-js'
5
- import type {
6
- Payload, ReadArchivist, WithHashMeta, WithStorageMeta,
7
- } from '@xyo-network/sdk-js'
8
- import { BoundWitnessBuilder } from '@xyo-network/sdk-js'
9
- import type {
10
- BlockBoundWitness, ChainId, Config, PayloadMapRead,
11
- } from '@xyo-network/xl1-sdk'
12
- import { ConfigZod, isBlockBoundWitness } from '@xyo-network/xl1-sdk'
13
-
14
- import type { BlockChainIterator } from '../../types/index.ts'
15
-
16
- export const resolveDefinedHead = async (head: Hash, chainArchivist: ReadArchivist) => {
17
- // get the head from the chain archivist
18
- const [headPayload] = await chainArchivist.get([head])
19
- // if the head is undefined, we need to create a new one
20
- if (headPayload === undefined) {
21
- const [currentHead] = await new BoundWitnessBuilder<BlockBoundWitness>().build()
22
- return currentHead
23
- } else {
24
- // if the head is a block bound witness, we can use it
25
- return assertEx(isBlockBoundWitness(headPayload)
26
- ? headPayload
27
- : undefined, () => `Expected a block bound witness: ${JSON.stringify(headPayload)}`)
28
- }
29
- }
30
-
31
- export const useChainIteratorParams = ({
32
- chainMap, chainId, head, name,
33
- }: BlockChainIterator): [{
34
- chainId: ChainId
35
- chainMap: PayloadMapRead<WithStorageMeta<Payload>>
36
- config: Config
37
- head: WithHashMeta<BlockBoundWitness>
38
- name: string
39
- } | undefined, Error | undefined, UsePromiseState | undefined] => {
40
- return usePromise(async () => {
41
- if (isDefined(chainMap) && isDefined(chainId) && isHash(head)) {
42
- const result = await chainMap.get(head)
43
- const foundResult = assertEx(result, () => `Head not found: ${head}`)
44
- const resolvedHead = assertEx(
45
- isBlockBoundWitness(foundResult) ? foundResult : undefined,
46
- () => `Head is not a boundwitness: ${JSON.stringify(foundResult)}`,
47
- )
48
- const config = ConfigZod.parse({})
49
- config.chain.id = chainId
50
- return {
51
- chainMap, chainId, config, head: resolvedHead, name,
52
- }
53
- }
54
- }, [chainMap, chainId, head])
55
- }
@@ -1,3 +0,0 @@
1
- export * from './chain-iterator/index.ts'
2
- export * from './useBaseContext.ts'
3
- export * from './useTxsFromBlock.ts'
@@ -1,8 +0,0 @@
1
- import type { BaseContext } from '@xyo-network/xl1-sdk'
2
- import { useState } from 'react'
3
-
4
- export const useBaseContext = () => {
5
- const [context] = useState<BaseContext>({ caches: {}, singletons: {} })
6
- // TODO: Update to use actual rect context when available
7
- return context
8
- }
@@ -1,12 +0,0 @@
1
- import { usePromise } from '@xylabs/react-promise'
2
- import type { HydratedBlockWithHashMeta } from '@xyo-network/xl1-sdk'
3
-
4
- import { txsFromBlock } from '../helpers/index.ts'
5
-
6
- export const useTxsFromBlock = (block?: HydratedBlockWithHashMeta) => {
7
- return usePromise(async () => {
8
- if (block) {
9
- return await txsFromBlock(block)
10
- }
11
- }, [block])
12
- }
package/src/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from './components/index.ts'
2
- export * from './hooks/index.ts'
3
- export * from './stories/index.ts'
@@ -1,20 +0,0 @@
1
- import { assertEx } from '@xylabs/sdk-js'
2
- import type { HttpBridgeConfig } from '@xyo-network/bridge-http'
3
- import { HttpBridge, HttpBridgeConfigSchema } from '@xyo-network/bridge-http'
4
- import type { ArchivistInstance, ModuleIdentifier } from '@xyo-network/sdk-js'
5
- import { asArchivistInstance } from '@xyo-network/sdk-js'
6
-
7
- export interface BridgedChainArchivistParams {
8
- chainArchivistModuleId: ModuleIdentifier
9
- url: string
10
- }
11
-
12
- export const getChainArchivistFromBridge = async (params: BridgedChainArchivistParams): Promise<ArchivistInstance> => {
13
- const { url, chainArchivistModuleId } = params
14
- const config: HttpBridgeConfig = { schema: HttpBridgeConfigSchema, client: { url } }
15
- const bridge = await HttpBridge.create({ config })
16
-
17
- const resolved = await bridge.resolve(chainArchivistModuleId)
18
- const mod = assertEx(resolved, () => `Module ${chainArchivistModuleId} not found`)
19
- return assertEx(asArchivistInstance(mod), () => `Module ${chainArchivistModuleId} is not an archivist`)
20
- }
@@ -1,8 +0,0 @@
1
- import type { Address, Promisable } from '@xylabs/sdk-js'
2
- import { toAddress } from '@xylabs/sdk-js'
3
-
4
- const id = toAddress('ce080bf3043a40c6c8838c7e813c00ab53df1684')
5
-
6
- export const getChainId = (): Promisable<Address> => {
7
- return id
8
- }
package/src/lib/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './getChainArchivist.ts'
2
- export * from './getChainId.ts'
@@ -1,43 +0,0 @@
1
- import { CircularProgress } from '@mui/material'
2
- import type { Decorator } from '@storybook/react-vite'
3
- import { usePromise } from '@xylabs/react-promise'
4
- import { buildRandomBlockChain } from '@xyo-network/react-chain-shared'
5
- import { ArchivistConfigSchema, MemoryArchivist } from '@xyo-network/sdk-js'
6
- import { flattenHydratedBlocks } from '@xyo-network/xl1-sdk'
7
- import React, { useEffect } from 'react'
8
-
9
- import { getChainId } from '../lib/index.ts'
10
- import type { BlockChainRenderBaseProps } from '../types/index.ts'
11
-
12
- export const ChainArchivistDecorator: Decorator = (Story, { args, ...context }) => {
13
- const [randomBlockChain] = usePromise(async () => await buildRandomBlockChain(), [])
14
- const [blockChainRenderProps, blockChainRenderPropsError] = usePromise(async () => {
15
- if (randomBlockChain) {
16
- const chainArchivist = await MemoryArchivist.create({ config: { schema: ArchivistConfigSchema, name: 'ChainArchivist' } })
17
- const flattened = flattenHydratedBlocks(randomBlockChain)
18
- await chainArchivist.insert(flattened)
19
- const chainId = await getChainId()
20
- return { chainArchivist, chainId }
21
- }
22
- }, [randomBlockChain])
23
-
24
- useEffect(() => {
25
- if (blockChainRenderPropsError) {
26
- console.error(blockChainRenderPropsError)
27
- }
28
- }, [blockChainRenderPropsError])
29
-
30
- const props = {
31
- ...context,
32
- args: {
33
- ...args,
34
- blockChainRenderProps: {
35
- ...(args.blockChainRenderProps as BlockChainRenderBaseProps),
36
- ...blockChainRenderProps,
37
- head: randomBlockChain?.toReversed()[0][0]._hash,
38
- },
39
- },
40
- }
41
-
42
- return blockChainRenderProps?.chainArchivist ? <Story {...props} /> : <CircularProgress />
43
- }