@xyo-network/react-chain-provider 1.20.14 → 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 (84) hide show
  1. package/README.md +9 -3302
  2. package/dist/browser/hooks/account/BalanceHistoryItemFormatted.d.ts +1 -0
  3. package/dist/browser/hooks/account/BalanceHistoryItemFormatted.d.ts.map +1 -1
  4. package/dist/browser/hooks/account/helpers/formatAccountBalanceHistory.d.ts.map +1 -1
  5. package/dist/browser/hooks/gateway/useNetwork.d.ts +1 -1
  6. package/dist/browser/hooks/gateway/useNetwork.d.ts.map +1 -1
  7. package/dist/browser/hooks/gateway/useRunner.d.ts +1 -1
  8. package/dist/browser/hooks/gateway/useRunner.d.ts.map +1 -1
  9. package/dist/browser/hooks/gateway/useViewer.d.ts +1 -1
  10. package/dist/browser/hooks/gateway/useViewer.d.ts.map +1 -1
  11. package/dist/browser/index.mjs +3 -0
  12. package/dist/browser/index.mjs.map +1 -1
  13. package/package.json +155 -45
  14. package/src/components/connected/ConnectAccountsStack.stories.tsx +0 -16
  15. package/src/components/connected/ConnectAccountsStack.tsx +0 -92
  16. package/src/components/connected/account/Connected.tsx +0 -19
  17. package/src/components/connected/account/index.ts +0 -1
  18. package/src/components/connected/index.ts +0 -2
  19. package/src/components/index.ts +0 -1
  20. package/src/contexts/current-block/Provider.stories.tsx +0 -38
  21. package/src/contexts/current-block/Provider.tsx +0 -36
  22. package/src/contexts/current-block/context.ts +0 -5
  23. package/src/contexts/current-block/index.ts +0 -5
  24. package/src/contexts/current-block/state.ts +0 -16
  25. package/src/contexts/current-block/use.ts +0 -5
  26. package/src/contexts/current-block/usePollCurrentBlock.ts +0 -61
  27. package/src/contexts/gateway/Provider.tsx +0 -81
  28. package/src/contexts/gateway/context.ts +0 -5
  29. package/src/contexts/gateway/index.ts +0 -4
  30. package/src/contexts/gateway/state.ts +0 -15
  31. package/src/contexts/gateway/story/GatewayStats.tsx +0 -33
  32. package/src/contexts/gateway/story/GatewayStatus.tsx +0 -53
  33. package/src/contexts/gateway/story/Provider.stories.tsx +0 -38
  34. package/src/contexts/gateway/story/ProviderWithWallet.stories.tsx +0 -43
  35. package/src/contexts/gateway/use.ts +0 -5
  36. package/src/contexts/in-page-gateways/Provider.tsx +0 -86
  37. package/src/contexts/in-page-gateways/context.ts +0 -5
  38. package/src/contexts/in-page-gateways/index.ts +0 -4
  39. package/src/contexts/in-page-gateways/state.ts +0 -12
  40. package/src/contexts/in-page-gateways/use.ts +0 -5
  41. package/src/contexts/index.ts +0 -3
  42. package/src/global.d.ts +0 -9
  43. package/src/hooks/account/BalanceHistoryItemFormatted.ts +0 -17
  44. package/src/hooks/account/helpers/formatAccountBalanceHistory.ts +0 -44
  45. package/src/hooks/account/helpers/index.ts +0 -1
  46. package/src/hooks/account/index.ts +0 -3
  47. package/src/hooks/account/useAccountBalanceHistory.ts +0 -51
  48. package/src/hooks/client/helpers/findCaveat.ts +0 -2
  49. package/src/hooks/client/helpers/index.ts +0 -1
  50. package/src/hooks/client/index.ts +0 -3
  51. package/src/hooks/client/permissions/index.ts +0 -2
  52. package/src/hooks/client/permissions/usePermissions.ts +0 -2
  53. package/src/hooks/client/permissions/usePermissionsAccounts.ts +0 -2
  54. package/src/hooks/client/useClientFromWallet.ts +0 -2
  55. package/src/hooks/client/useGatewayFromWallet.ts +0 -2
  56. package/src/hooks/gateway/index.ts +0 -3
  57. package/src/hooks/gateway/useNetwork.ts +0 -6
  58. package/src/hooks/gateway/useRunner.ts +0 -6
  59. package/src/hooks/gateway/useViewer.ts +0 -6
  60. package/src/hooks/helpers/getXyoClient.ts +0 -2
  61. package/src/hooks/helpers/index.ts +0 -2
  62. package/src/hooks/helpers/transaction/Confirmation.ts +0 -125
  63. package/src/hooks/helpers/transaction/index.ts +0 -1
  64. package/src/hooks/index.ts +0 -11
  65. package/src/hooks/useAddressBalance.ts +0 -86
  66. package/src/hooks/useConfirmTransactionBase.ts +0 -64
  67. package/src/hooks/useConnectAccount.ts +0 -36
  68. package/src/hooks/useCurrentBlock.ts +0 -27
  69. package/src/hooks/useNetwork.ts +0 -13
  70. package/src/hooks/useSigner.ts +0 -9
  71. package/src/hooks/viewer/UseStepRewardWeightTest.stories.tsx +0 -87
  72. package/src/hooks/viewer/ViewerWithDataLake.ts +0 -51
  73. package/src/hooks/viewer/index.ts +0 -2
  74. package/src/hooks/viewer/useCheckRpc.ts +0 -61
  75. package/src/index.ts +0 -5
  76. package/src/lib/balanceForRange.ts +0 -16
  77. package/src/lib/buildGateway.ts +0 -29
  78. package/src/lib/findMinimumBlock.ts +0 -9
  79. package/src/lib/index.ts +0 -3
  80. package/src/story/GatewayDecorator.tsx +0 -36
  81. package/src/story/index.ts +0 -1
  82. package/src/types/ContextGatewayType.ts +0 -4
  83. package/src/types/GatewayFromWallet.ts +0 -2
  84. package/src/types/index.ts +0 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xyo-network/react-chain-provider",
3
- "version": "1.20.14",
3
+ "version": "1.20.16",
4
4
  "description": "XYO Layer One API",
5
5
  "homepage": "https://xylabs.com",
6
6
  "bugs": {
@@ -24,83 +24,193 @@
24
24
  "types": "./dist/browser/index.d.ts",
25
25
  "browser": {
26
26
  "types": "./dist/browser/index.d.ts",
27
- "source": "./src/index.ts",
28
27
  "default": "./dist/browser/index.mjs"
29
28
  },
30
- "source": "./src/index.ts",
31
29
  "default": "./dist/browser/index.mjs"
32
30
  },
33
31
  "./package.json": "./package.json"
34
32
  },
35
33
  "module": "./dist/browser/index.mjs",
36
- "source": "./src/index.ts",
37
34
  "types": "./dist/browser/index.d.ts",
38
35
  "files": [
39
36
  "dist",
40
- "src",
41
37
  "!**/*.bench.*",
42
38
  "!**/*.spec.*",
43
- "!**/*.test.*"
39
+ "!**/*.test.*",
40
+ "README.md"
44
41
  ],
45
42
  "dependencies": {
46
- "@storybook/react-vite": "^10.3.3",
47
- "@xylabs/react-button": "~7.1.17",
48
- "@xylabs/react-promise": "~7.1.17",
49
- "@xylabs/react-shared": "~7.1.17",
50
- "@xyo-network/chain-orchestration": "~1.20.14",
51
- "@xyo-network/react-chain-blockies": "~1.20.14",
52
- "@xyo-network/react-chain-client": "~1.20.14",
53
- "@xyo-network/react-error": "~7.5.8"
43
+ "@storybook/react-vite": "^10.3.5",
44
+ "@xylabs/react-button": "~7.1.20",
45
+ "@xylabs/react-shared": "~7.1.20",
46
+ "@xyo-network/react-error": "~7.5.8",
47
+ "@xyo-network/xl1-sdk": "^1.26.19",
48
+ "@xyo-network/chain-orchestration": "~1.20.16"
54
49
  },
55
50
  "devDependencies": {
56
51
  "@emotion/react": "~11.14.0",
57
52
  "@emotion/styled": "~11.14.1",
58
53
  "@mui/icons-material": "^7.3.9",
59
54
  "@mui/material": "~7.3.9",
60
- "@storybook/react-vite": "^10.3.3",
55
+ "@opentelemetry/api": "^1",
56
+ "@types/node": "^25.5.2",
61
57
  "@types/react": "~19.2.14",
62
- "@xylabs/react-button": "~7.1.17",
63
- "@xylabs/sdk-js": "~5.0.90",
64
- "@xylabs/ts-scripts-common": "~7.5.11",
65
- "@xylabs/ts-scripts-yarn3": "~7.5.11",
66
- "@xylabs/tsconfig": "~7.5.11",
67
- "@xylabs/tsconfig-dom": "~7.5.11",
68
- "@xylabs/tsconfig-react": "~7.5.11",
69
- "@xyo-network/react-chain-model": "~1.20.14",
70
- "@xyo-network/react-chain-shared": "~1.20.14",
71
- "@xyo-network/react-error": "~7.5.8",
72
- "@xyo-network/sdk-js": "~5.3.20",
73
- "@xyo-network/xl1-sdk": "~1.26.11",
74
- "axios": "^1.13.6",
75
- "dotenv": "~17.3.1",
58
+ "@xylabs/express": "^5.0.95",
59
+ "@xylabs/mongo": "^5.0.95",
60
+ "@xylabs/react-async-effect": "~7.1.20",
61
+ "@xylabs/react-dialogs": "~7.1.20",
62
+ "@xylabs/react-promise": "~7.1.20",
63
+ "@xylabs/react-quick-tip-button": "~7.1.20",
64
+ "@xylabs/sdk-js": "~5.0.95",
65
+ "@xylabs/ts-scripts-common": "~7.9.3",
66
+ "@xylabs/ts-scripts-pnpm": "~7.9.3",
67
+ "@xylabs/tsconfig": "~7.9.3",
68
+ "@xylabs/tsconfig-dom": "~7.9.3",
69
+ "@xylabs/tsconfig-react": "~7.9.3",
70
+ "@xylabs/zod": "~5.0.95",
71
+ "@xyo-network/account": "~5.3.30",
72
+ "@xyo-network/account-model": "~5.3",
73
+ "@xyo-network/api-models": "~5.3.30",
74
+ "@xyo-network/archivist-abstract": "~5.3",
75
+ "@xyo-network/archivist-generic": "~5.3.30",
76
+ "@xyo-network/archivist-memory": "~5.3.30",
77
+ "@xyo-network/archivist-model": "~5.3",
78
+ "@xyo-network/archivist-view": "~5.3.30",
79
+ "@xyo-network/archivist-wrapper": "~5.3",
80
+ "@xyo-network/boundwitness-builder": "~5.3.30",
81
+ "@xyo-network/boundwitness-validator": "~5.3",
82
+ "@xyo-network/bridge-abstract": "~5.3.30",
83
+ "@xyo-network/bridge-model": "~5.3.30",
84
+ "@xyo-network/config-payload-plugin": "~5.3.30",
85
+ "@xyo-network/data": "~5.3.30",
86
+ "@xyo-network/diviner-abstract": "~5.3",
87
+ "@xyo-network/diviner-boundwitness-memory": "~5.3.30",
88
+ "@xyo-network/diviner-identity": "~5.3.30",
89
+ "@xyo-network/diviner-model": "~5.3.30",
90
+ "@xyo-network/diviner-payload-generic": "~5.3.30",
91
+ "@xyo-network/diviner-payload-model": "~5.3.30",
92
+ "@xyo-network/diviner-wrapper": "~5.3",
93
+ "@xyo-network/dns": "~5.3.30",
94
+ "@xyo-network/domain-payload-plugin": "~5.3.30",
95
+ "@xyo-network/elliptic": "~5.3.30",
96
+ "@xyo-network/hash": "~5.3",
97
+ "@xyo-network/huri": "~5.3.30",
98
+ "@xyo-network/manifest-model": "~5.3",
99
+ "@xyo-network/module-abstract": "~5.3",
100
+ "@xyo-network/module-model": "~5.3",
101
+ "@xyo-network/module-model-mongodb": "~5.3",
102
+ "@xyo-network/module-resolver": "~5.3.30",
103
+ "@xyo-network/module-wrapper": "~5.3",
104
+ "@xyo-network/network": "~5.3.30",
105
+ "@xyo-network/node-abstract": "~5.3.30",
106
+ "@xyo-network/node-memory": "~5.3.30",
107
+ "@xyo-network/node-model": "~5.3.30",
108
+ "@xyo-network/node-view": "~5.3.30",
109
+ "@xyo-network/node-wrapper": "~5.3",
110
+ "@xyo-network/payload-builder": "~5.3",
111
+ "@xyo-network/payload-model": "~5.3.30",
112
+ "@xyo-network/payload-validator": "~5.3",
113
+ "@xyo-network/previous-hash-store-model": "~5.3.30",
114
+ "@xyo-network/sdk-js": "~5.3.30",
115
+ "@xyo-network/sentinel-abstract": "~5.3.30",
116
+ "@xyo-network/sentinel-memory": "~5.3.30",
117
+ "@xyo-network/sentinel-model": "~5.3.30",
118
+ "@xyo-network/wallet-model": "~5.3.30",
119
+ "@xyo-network/wasm": "~5.3.30",
120
+ "@xyo-network/witness-adhoc": "~5.3.30",
121
+ "@xyo-network/witness-model": "~5.3.30",
122
+ "ajv": "^8",
123
+ "axios": "^1.14.0",
124
+ "dotenv": "~17.4.1",
125
+ "esbuild": "*",
76
126
  "ethers": "^6.16.0",
127
+ "lmdb": "^3",
128
+ "mongodb": "^7.1.1",
129
+ "pako": "~2.1.0",
77
130
  "react": "~19.2.4",
78
131
  "react-dom": "^19.2.4",
79
- "react-router-dom": "^7.13.2",
132
+ "react-router-dom": "^7.14.0",
80
133
  "rollbar": "^3.1.0",
81
- "storybook": "^10.3.3",
134
+ "storybook": "^10.3.5",
82
135
  "typescript": "~5.9.3",
83
- "vite": "^8.0.3",
84
- "vitest": "^4.1.2",
85
- "zod": "^4.3.6"
136
+ "vite": "^8.0.7",
137
+ "vitest": "^4.1.3",
138
+ "zod": "^4.3.6",
139
+ "@xyo-network/chain-services": "~1.20.16",
140
+ "@xyo-network/react-chain-blockies": "~1.20.16",
141
+ "@xyo-network/chain-telemetry": "~1.20.16",
142
+ "@xyo-network/react-chain-client": "~1.20.16",
143
+ "@xyo-network/react-chain-model": "~1.20.16",
144
+ "@xyo-network/react-chain-shared": "~1.20.16"
86
145
  },
87
146
  "peerDependencies": {
88
- "@mui/material": "^7",
89
- "@xylabs/sdk-js": "^5",
90
- "@xyo-network/sdk-js": "^5",
91
- "@xyo-network/xl1-sdk": "^1",
92
- "react": "^19",
93
- "zod": "^4"
147
+ "@mui/material": "~7.3.9",
148
+ "@xylabs/express": "^5.0.95",
149
+ "@xylabs/react-async-effect": "~7.1.20",
150
+ "@xylabs/react-promise": "~7.1.20",
151
+ "@xylabs/react-quick-tip-button": "~7.1.20",
152
+ "@xylabs/sdk-js": "~5.0.93",
153
+ "@xylabs/zod": "~5.0.95",
154
+ "@xyo-network/account": "~5.3.30",
155
+ "@xyo-network/account-model": "~5.3",
156
+ "@xyo-network/api-models": "~5.3.30",
157
+ "@xyo-network/archivist-abstract": "~5.3",
158
+ "@xyo-network/archivist-generic": "~5.3.30",
159
+ "@xyo-network/archivist-memory": "~5.3.30",
160
+ "@xyo-network/archivist-model": "~5.3",
161
+ "@xyo-network/archivist-view": "~5.3.30",
162
+ "@xyo-network/boundwitness-builder": "~5.3.30",
163
+ "@xyo-network/boundwitness-validator": "~5.3",
164
+ "@xyo-network/bridge-abstract": "~5.3.30",
165
+ "@xyo-network/bridge-model": "~5.3.30",
166
+ "@xyo-network/config-payload-plugin": "~5.3.30",
167
+ "@xyo-network/data": "~5.3.30",
168
+ "@xyo-network/diviner-boundwitness-memory": "~5.3.30",
169
+ "@xyo-network/diviner-identity": "~5.3.30",
170
+ "@xyo-network/diviner-model": "~5.3.30",
171
+ "@xyo-network/diviner-payload-generic": "~5.3.30",
172
+ "@xyo-network/diviner-payload-model": "~5.3.30",
173
+ "@xyo-network/dns": "~5.3.30",
174
+ "@xyo-network/domain-payload-plugin": "~5.3.30",
175
+ "@xyo-network/elliptic": "~5.3.30",
176
+ "@xyo-network/hash": "~5.3",
177
+ "@xyo-network/huri": "~5.3.30",
178
+ "@xyo-network/manifest-model": "~5.3",
179
+ "@xyo-network/module-abstract": "~5.3",
180
+ "@xyo-network/module-model": "~5.3",
181
+ "@xyo-network/module-model-mongodb": "~5.3",
182
+ "@xyo-network/module-resolver": "~5.3.30",
183
+ "@xyo-network/network": "~5.3.30",
184
+ "@xyo-network/node-abstract": "~5.3.30",
185
+ "@xyo-network/node-memory": "~5.3.30",
186
+ "@xyo-network/node-model": "~5.3.30",
187
+ "@xyo-network/node-view": "~5.3.30",
188
+ "@xyo-network/payload-builder": "~5.3",
189
+ "@xyo-network/payload-model": "~5.3.30",
190
+ "@xyo-network/payload-validator": "~5.3",
191
+ "@xyo-network/previous-hash-store-model": "~5.3.30",
192
+ "@xyo-network/sdk-js": "~5.3.25",
193
+ "@xyo-network/sentinel-abstract": "~5.3.30",
194
+ "@xyo-network/sentinel-memory": "~5.3.30",
195
+ "@xyo-network/sentinel-model": "~5.3.30",
196
+ "@xyo-network/wallet-model": "~5.3.30",
197
+ "@xyo-network/wasm": "~5.3.30",
198
+ "@xyo-network/witness-adhoc": "~5.3.30",
199
+ "@xyo-network/witness-model": "~5.3.30",
200
+ "pako": "~2.1.0",
201
+ "react": "~19.2.4",
202
+ "@xyo-network/chain-services": "~1.20.16",
203
+ "@xyo-network/react-chain-client": "~1.20.16",
204
+ "@xyo-network/react-chain-blockies": "~1.20.16",
205
+ "@xyo-network/chain-telemetry": "~1.20.16"
94
206
  },
95
- "packageManager": "yarn@4.6.0",
96
207
  "engines": {
97
- "node": ">=22"
208
+ "node": ">=24"
98
209
  },
99
210
  "volta": {
100
- "node": "22.5.1",
101
- "yarn": "4.6.0"
211
+ "node": ">=24"
102
212
  },
103
213
  "publishConfig": {
104
214
  "access": "public"
105
215
  }
106
- }
216
+ }
@@ -1,16 +0,0 @@
1
- import type { Meta, StoryFn } from '@storybook/react-vite'
2
- import React from 'react'
3
-
4
- import { ConnectAccountsStack } from './ConnectAccountsStack.tsx'
5
-
6
- export default {
7
- title: 'Provider/Components/ConnectAccountsStack',
8
- component: ConnectAccountsStack,
9
- } as Meta
10
-
11
- const Template: StoryFn<typeof ConnectAccountsStack> = args => <ConnectAccountsStack {...args} />
12
-
13
- const Default = Template.bind({})
14
- Default.args = { timeout: 5000 }
15
-
16
- export { Default }
@@ -1,92 +0,0 @@
1
- import type { StackProps } from '@mui/material'
2
- import {
3
- Alert, AlertTitle, Button, Stack,
4
- Typography,
5
- } from '@mui/material'
6
- import type { ButtonExProps } from '@xylabs/react-button'
7
- import { ButtonEx } from '@xylabs/react-button'
8
- import type { Address } from '@xylabs/sdk-js'
9
- import { isDefined, isUndefined } from '@xylabs/sdk-js'
10
- import { ErrorRender } from '@xyo-network/react-error'
11
- import type { ComponentType, MouseEventHandler } from 'react'
12
- import React, { useEffect } from 'react'
13
-
14
- import { useConnectAccount } from '../../hooks/index.ts'
15
- import { ConnectedAccount } from './account/index.ts'
16
-
17
- const DefaultConnectComponent: React.FC<ButtonExProps> = props => (
18
- <ButtonEx variant="contained" size="small" {...props} />
19
- )
20
-
21
- const DefaultNoWalletInstalledComponent: React.FC = () => (
22
- <Alert severity="warning">
23
- <AlertTitle>XL1 Wallet Not Found</AlertTitle>
24
- <Typography gutterBottom>
25
- Please ensure that your XL1 Wallet is installed to connect your account.
26
- </Typography>
27
- <Button
28
- sx={{ display: 'flex', justifySelf: 'end' }}
29
- size="small"
30
- variant="outlined"
31
- href="https://chromewebstore.google.com/detail/xl1-wallet/fblbagcjeigmhakkfgjpdlcapcgmcfbm"
32
- target="_blank"
33
- rel="noopener"
34
- >
35
- Get XL1 Wallet
36
- </Button>
37
- </Alert>
38
- )
39
-
40
- export interface ConnectClientAccountsStackProps extends StackProps {
41
- AccountComponent?: ComponentType<{ account?: string }>
42
- ConnectComponent?: ComponentType<{ onClick?: MouseEventHandler<HTMLElement> }>
43
- NoWalletInstalledComponent?: ComponentType
44
- onAccountConnected?: (account: Address) => void
45
- onCancel?: () => void
46
- timeout?: number
47
- }
48
-
49
- export const ConnectAccountsStack: React.FC<ConnectClientAccountsStackProps> = ({
50
- AccountComponent = ConnectedAccount,
51
- ConnectComponent = DefaultConnectComponent,
52
- NoWalletInstalledComponent = DefaultNoWalletInstalledComponent,
53
- onAccountConnected,
54
- onCancel,
55
- timeout,
56
- ...props
57
- }) => {
58
- const {
59
- address, connectSigner, error, timedout,
60
- } = useConnectAccount(undefined, timeout)
61
-
62
- useEffect(() => {
63
- if (isDefined(error) && isDefined(onCancel)) {
64
- onCancel()
65
- }
66
- }, [error, onCancel])
67
-
68
- useEffect(() => {
69
- if (isDefined(address) && isDefined(onAccountConnected)) {
70
- onAccountConnected(address)
71
- }
72
- }, [address, onAccountConnected])
73
-
74
- return (
75
- <Stack direction="row" alignItems="start" spacing={2} {...props}>
76
- {isDefined(address)
77
- ? <AccountComponent address={address} />
78
- : null}
79
- {isUndefined(address) && !timedout
80
- ? (
81
- <ConnectComponent onClick={() => void connectSigner()}>Connect</ConnectComponent>
82
- )
83
- : null}
84
- {isUndefined(address) && timedout
85
- ? (
86
- <NoWalletInstalledComponent />
87
- )
88
- : null}
89
- <ErrorRender error={error} scope="ConnectSigner:error" />
90
- </Stack>
91
- )
92
- }
@@ -1,19 +0,0 @@
1
- import {
2
- Stack, Tooltip, Typography,
3
- } from '@mui/material'
4
- import { EthAddressWrapper } from '@xylabs/sdk-js'
5
- import { BlockiesAvatarAddress } from '@xyo-network/react-chain-blockies'
6
- import React from 'react'
7
-
8
- export const ConnectedAccount: React.FC<{ address: string }> = ({ address }) => {
9
- const shortenedAddress = `${EthAddressWrapper.fromString(address)?.toShortString(4)}`
10
-
11
- return (
12
- <Stack direction="row" alignItems="center" spacing={1}>
13
- <BlockiesAvatarAddress address={address} size={21} />
14
- <Tooltip title={address}>
15
- <Typography color="textSecondary" variant="caption" fontFamily="monospace">{shortenedAddress}</Typography>
16
- </Tooltip>
17
- </Stack>
18
- )
19
- }
@@ -1 +0,0 @@
1
- export * from './Connected.tsx'
@@ -1,2 +0,0 @@
1
- export * from './account/index.ts'
2
- export * from './ConnectAccountsStack.tsx'
@@ -1 +0,0 @@
1
- export * from './connected/index.ts'
@@ -1,38 +0,0 @@
1
- import { Typography } from '@mui/material'
2
- import type { Meta, StoryFn } from '@storybook/react-vite'
3
-
4
- import { useViewerFromGateway } from '../../hooks/index.ts'
5
- import { SequenceGatewayDecorator } from '../../story/index.ts'
6
- import { XL1CurrentBlockProvider } from './Provider.tsx'
7
- import { useXl1CurrentBlockContext } from './use.ts'
8
-
9
- export default {
10
- title: 'Provider/Contexts/CurrentBlock',
11
- component: XL1CurrentBlockProvider,
12
- decorators: [SequenceGatewayDecorator],
13
- } as Meta<typeof XL1CurrentBlockProvider>
14
-
15
- const CurrentBlockTypography: React.FC = () => {
16
- const contextValues = useXl1CurrentBlockContext()
17
-
18
- return (
19
- <Typography variant="body1">
20
- {`Current Block: ${contextValues.blockNumber ?? 'Loading...'}`}
21
- </Typography>
22
- )
23
- }
24
-
25
- const Template: StoryFn<typeof XL1CurrentBlockProvider> = (args) => {
26
- const viewer = useViewerFromGateway()
27
-
28
- return (
29
- <XL1CurrentBlockProvider viewer={viewer} {...args}>
30
- <CurrentBlockTypography />
31
- </XL1CurrentBlockProvider>
32
- )
33
- }
34
-
35
- const Default = Template.bind({})
36
- Default.args = {}
37
-
38
- export { Default }
@@ -1,36 +0,0 @@
1
- import type { XyoViewer } from '@xyo-network/xl1-sdk'
2
- import type { PropsWithChildren } from 'react'
3
- import React, { useMemo } from 'react'
4
-
5
- import { XL1CurrentBlockContext } from './context.ts'
6
- import type { XL1CurrentBlockPollingConfig, XL1CurrentBlockState } from './state.ts'
7
- import { usePollCurrentBlock } from './usePollCurrentBlock.ts'
8
-
9
- export const DEFAULT_POLLING_INTERVAL = 10_000
10
-
11
- export interface XL1CurrentBlockProviderProps extends PropsWithChildren {
12
- pollingConfig?: XL1CurrentBlockPollingConfig
13
- viewer?: XyoViewer | null
14
- }
15
-
16
- export const XL1CurrentBlockProvider: React.FC<XL1CurrentBlockProviderProps> = ({
17
- pollingConfig, viewer, children,
18
- }) => {
19
- const { interval } = useMemo(() => pollingConfig || { interval: DEFAULT_POLLING_INTERVAL }, [pollingConfig])
20
- const [currentBlock, currentBlockError] = usePollCurrentBlock(viewer, interval)
21
-
22
- const value: XL1CurrentBlockState = useMemo(() => ({
23
- block: currentBlock,
24
- blockNumber: currentBlock?.[0].block,
25
- chain: currentBlock?.[0].chain,
26
- error: currentBlockError,
27
- pollingConfig,
28
- provided: true,
29
- }), [currentBlock, currentBlockError, pollingConfig])
30
-
31
- return (
32
- <XL1CurrentBlockContext value={value}>
33
- {children}
34
- </XL1CurrentBlockContext>
35
- )
36
- }
@@ -1,5 +0,0 @@
1
- import { createContextEx } from '@xylabs/react-shared'
2
-
3
- import type { XL1CurrentBlockState } from './state.ts'
4
-
5
- export const XL1CurrentBlockContext = createContextEx<XL1CurrentBlockState>()
@@ -1,5 +0,0 @@
1
- export * from './context.ts'
2
- export * from './Provider.tsx'
3
- export * from './state.ts'
4
- export * from './use.ts'
5
- export * from './usePollCurrentBlock.ts'
@@ -1,16 +0,0 @@
1
- import type { ProvidedContextExState } from '@xylabs/react-shared'
2
- import type { ChainId, SignedHydratedBlock } from '@xyo-network/xl1-sdk'
3
-
4
- export interface XL1CurrentBlockPollingConfig {
5
- interval: number | undefined
6
- }
7
-
8
- export interface XL1CurrentBlockFields {
9
- block: SignedHydratedBlock | null | undefined
10
- blockNumber: number | undefined
11
- chain: ChainId | undefined
12
- error: Error | undefined
13
- pollingConfig?: XL1CurrentBlockPollingConfig
14
- }
15
-
16
- export type XL1CurrentBlockState = ProvidedContextExState<XL1CurrentBlockFields>
@@ -1,5 +0,0 @@
1
- import { useContextEx } from '@xylabs/react-shared'
2
-
3
- import { XL1CurrentBlockContext } from './context.ts'
4
-
5
- export const useXl1CurrentBlockContext = (required = true) => useContextEx(XL1CurrentBlockContext, 'XL1CurrentBlock', required)
@@ -1,61 +0,0 @@
1
- import { isDefinedNotNull, isUndefinedOrNull } from '@xylabs/sdk-js'
2
- import type { SignedHydratedBlock, XyoViewer } from '@xyo-network/xl1-sdk'
3
- import {
4
- startTransition, useEffect, useState,
5
- } from 'react'
6
-
7
- const DEFAULT_POLL_INTERVAL = 10_000
8
-
9
- export const usePollCurrentBlock = (viewer?: XyoViewer | null, interval = DEFAULT_POLL_INTERVAL, pause = false) => {
10
- const [currentBlock, setCurrentBlock] = useState<SignedHydratedBlock | null>(null)
11
- const [error, setError] = useState<Error>()
12
-
13
- useEffect(() => {
14
- let isMounted = true
15
- // Function to fetch the current block
16
- const fetchBlock = async () => {
17
- if (isDefinedNotNull(viewer)) {
18
- try {
19
- const block = await viewer.currentBlock()
20
- // Safety check to ensure component is still mounted before updating state
21
- if (isMounted) {
22
- startTransition(() => {
23
- setCurrentBlock((existingBlock) => {
24
- if (isUndefinedOrNull(existingBlock)) {
25
- return block
26
- }
27
- if (
28
- isDefinedNotNull(block) && existingBlock?.[0].block !== block[0].block
29
- ) {
30
- return block
31
- }
32
- return existingBlock
33
- })
34
- })
35
- }
36
- } catch (err) {
37
- startTransition(() => {
38
- setError(err as Error)
39
- })
40
- }
41
- }
42
- }
43
-
44
- // Initial fetch
45
- void fetchBlock()
46
-
47
- // Polling mechanism
48
- const id = setInterval(() => {
49
- if (!pause) {
50
- void fetchBlock()
51
- }
52
- }, interval)
53
-
54
- return () => {
55
- isMounted = false
56
- clearInterval(id)
57
- }
58
- }, [viewer, interval, pause])
59
-
60
- return [currentBlock, error] as const
61
- }
@@ -1,81 +0,0 @@
1
- import { isDefinedNotNull, isNull } from '@xylabs/sdk-js'
2
- import { useGatewayFromWallet } from '@xyo-network/react-chain-client'
3
- import { ErrorRender } from '@xyo-network/react-error'
4
- import type { GatewayName } from '@xyo-network/xl1-sdk'
5
- import type { PropsWithChildren } from 'react'
6
- import React, { useMemo } from 'react'
7
-
8
- import { useProvidedInPageGateways } from '../in-page-gateways/index.ts'
9
- import { GatewayContext } from './context.ts'
10
- import type { GatewayState } from './state.ts'
11
-
12
- export interface GatewayProviderProps extends PropsWithChildren {
13
- gatewayName?: GatewayName
14
- }
15
-
16
- export const GatewayProvider: React.FC<GatewayProviderProps> = ({ gatewayName, children }) => {
17
- const {
18
- gateway: gatewayFromWallet,
19
- error: gatewayFromWalletError,
20
- } = useGatewayFromWallet(gatewayName)
21
-
22
- const {
23
- gateways: allGateways,
24
- errors: allGatewayErrors,
25
- clearAll,
26
- } = useProvidedInPageGateways(true)
27
-
28
- const gatewayFromConfig = gatewayName ? allGateways[gatewayName] : undefined
29
- const gatewayFromConfigError = gatewayName ? allGatewayErrors[gatewayName] : undefined
30
-
31
- const { defaultGateway, gateways } = useMemo(() => {
32
- if (isNull(gatewayFromWallet)) {
33
- return {
34
- defaultGateway: gatewayFromConfig,
35
- gateways: {
36
- inPageGateway: gatewayFromConfig,
37
- walletGateway: null,
38
- },
39
- }
40
- } else if (isDefinedNotNull(gatewayFromWallet)) {
41
- return {
42
- defaultGateway: gatewayFromWallet,
43
- gateways: {
44
- inPageGateway: gatewayFromConfig,
45
- walletGateway: gatewayFromWallet,
46
- },
47
- }
48
- }
49
- return {
50
- defaultGateway: undefined,
51
- gateways: {
52
- inPageGateway: undefined,
53
- walletGateway: undefined,
54
- },
55
- }
56
- }, [gatewayFromConfig, gatewayFromWallet])
57
-
58
- const value = useMemo(() => {
59
- const value: GatewayState = {
60
- defaultGateway,
61
- error: gatewayFromWalletError || gatewayFromConfigError,
62
- gateways,
63
- provided: true,
64
- resetGatewaysFromConfig: clearAll,
65
- }
66
- return value
67
- }, [
68
- defaultGateway,
69
- gatewayFromWalletError,
70
- gatewayFromConfigError,
71
- gateways,
72
- clearAll,
73
- ])
74
-
75
- return (
76
- <GatewayContext value={value}>
77
- <ErrorRender error={gatewayFromConfigError} />
78
- {children}
79
- </GatewayContext>
80
- )
81
- }
@@ -1,5 +0,0 @@
1
- import { createContextEx } from '@xylabs/react-shared'
2
-
3
- import type { GatewayState } from './state.ts'
4
-
5
- export const GatewayContext = createContextEx<GatewayState>()
@@ -1,4 +0,0 @@
1
- export * from './context.ts'
2
- export * from './Provider.tsx'
3
- export * from './state.ts'
4
- export * from './use.ts'