@xyo-network/react-chain-provider 1.20.1 → 1.20.2
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/contexts/gateway/Provider.d.ts +10 -0
- package/dist/browser/contexts/gateway/Provider.d.ts.map +1 -0
- package/dist/browser/contexts/gateway/context.d.ts +8 -0
- package/dist/browser/contexts/gateway/context.d.ts.map +1 -0
- package/dist/browser/contexts/gateway/index.d.ts +5 -0
- package/dist/browser/contexts/gateway/index.d.ts.map +1 -0
- package/dist/browser/contexts/gateway/state.d.ts +14 -0
- package/dist/browser/contexts/gateway/state.d.ts.map +1 -0
- package/dist/browser/contexts/gateway/story/GatewayStats.d.ts +9 -0
- package/dist/browser/contexts/gateway/story/GatewayStats.d.ts.map +1 -0
- package/dist/browser/contexts/gateway/story/GatewayStatus.d.ts +3 -0
- package/dist/browser/contexts/gateway/story/GatewayStatus.d.ts.map +1 -0
- package/dist/browser/contexts/gateway/use.d.ts +4 -0
- package/dist/browser/contexts/gateway/use.d.ts.map +1 -0
- package/dist/browser/contexts/index.d.ts +1 -0
- package/dist/browser/contexts/index.d.ts.map +1 -1
- package/dist/browser/hooks/client/helpers/buildGateway.d.ts +4 -0
- package/dist/browser/hooks/client/helpers/buildGateway.d.ts.map +1 -0
- package/dist/browser/hooks/client/helpers/index.d.ts +1 -0
- package/dist/browser/hooks/client/helpers/index.d.ts.map +1 -1
- package/dist/browser/hooks/client/index.d.ts +3 -2
- package/dist/browser/hooks/client/index.d.ts.map +1 -1
- package/dist/browser/hooks/client/{useClient.d.ts → useClientFromWallet.d.ts} +3 -1
- package/dist/browser/hooks/client/useClientFromWallet.d.ts.map +1 -0
- package/dist/browser/hooks/client/useGatewayFromConfig.d.ts +9 -0
- package/dist/browser/hooks/client/useGatewayFromConfig.d.ts.map +1 -0
- package/dist/browser/hooks/client/useGatewayFromWallet.d.ts +6 -0
- package/dist/browser/hooks/client/useGatewayFromWallet.d.ts.map +1 -0
- package/dist/browser/hooks/gateway/index.d.ts +4 -0
- package/dist/browser/hooks/gateway/index.d.ts.map +1 -0
- package/dist/browser/hooks/gateway/useNetwork.d.ts +2 -0
- package/dist/browser/hooks/gateway/useNetwork.d.ts.map +1 -0
- package/dist/browser/hooks/gateway/useRunner.d.ts +2 -0
- package/dist/browser/hooks/gateway/useRunner.d.ts.map +1 -0
- package/dist/browser/hooks/gateway/useViewer.d.ts +2 -0
- package/dist/browser/hooks/gateway/useViewer.d.ts.map +1 -0
- package/dist/browser/hooks/index.d.ts +1 -0
- package/dist/browser/hooks/index.d.ts.map +1 -1
- package/dist/browser/hooks/useCurrentBlock.d.ts +33 -0
- package/dist/browser/hooks/useCurrentBlock.d.ts.map +1 -1
- package/dist/browser/hooks/useHttpRpcRunner.d.ts.map +1 -1
- package/dist/browser/hooks/viewer/useCheckRpc.d.ts.map +1 -1
- package/dist/browser/hooks/viewer/useHttpRpcViewer.d.ts +1 -0
- package/dist/browser/hooks/viewer/useHttpRpcViewer.d.ts.map +1 -1
- package/dist/browser/index.mjs +353 -197
- package/dist/browser/index.mjs.map +1 -1
- package/dist/browser/types/GatewayFromWallet.d.ts +8 -0
- package/dist/browser/types/GatewayFromWallet.d.ts.map +1 -0
- package/dist/browser/types/index.d.ts +2 -0
- package/dist/browser/types/index.d.ts.map +1 -0
- package/package.json +20 -18
- package/src/contexts/gateway/Provider.tsx +73 -0
- package/src/contexts/gateway/context.ts +5 -0
- package/src/contexts/gateway/index.ts +4 -0
- package/src/contexts/gateway/state.ts +17 -0
- package/src/contexts/gateway/story/GatewayStats.tsx +30 -0
- package/src/contexts/gateway/story/GatewayStatus.tsx +53 -0
- package/src/contexts/gateway/story/Provider.stories.tsx +38 -0
- package/src/contexts/gateway/story/ProviderWithWallet.stories.tsx +46 -0
- package/src/contexts/gateway/use.ts +5 -0
- package/src/contexts/index.ts +1 -0
- package/src/hooks/client/helpers/buildGateway.ts +29 -0
- package/src/hooks/client/helpers/index.ts +1 -0
- package/src/hooks/client/index.ts +3 -2
- package/src/hooks/client/permissions/usePermissions.ts +2 -2
- package/src/hooks/client/{useClient.ts → useClientFromWallet.ts} +4 -1
- package/src/hooks/client/useGatewayFromConfig.ts +43 -0
- package/src/hooks/client/{useGateway.ts → useGatewayFromWallet.ts} +7 -3
- package/src/hooks/gateway/index.ts +3 -0
- package/src/hooks/gateway/useNetwork.ts +6 -0
- package/src/hooks/gateway/useRunner.ts +6 -0
- package/src/hooks/gateway/useViewer.ts +6 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useConnectAccount.ts +2 -2
- package/src/hooks/useCurrentBlock.ts +13 -0
- package/src/hooks/useHttpRpcRunner.ts +1 -0
- package/src/hooks/viewer/useCheckRpc.ts +8 -17
- package/src/hooks/viewer/useHttpRpcViewer.ts +1 -0
- package/src/hooks/viewer/useViewerFromWallet.ts +2 -2
- package/src/types/GatewayFromWallet.ts +8 -0
- package/src/types/index.ts +1 -0
- package/dist/browser/components/connected/ConnectAccountsStack.stories.d.ts +0 -6
- package/dist/browser/components/connected/ConnectAccountsStack.stories.d.ts.map +0 -1
- package/dist/browser/contexts/current-block/Provider.stories.d.ts +0 -7
- package/dist/browser/contexts/current-block/Provider.stories.d.ts.map +0 -1
- package/dist/browser/hooks/client/useClient.d.ts.map +0 -1
- package/dist/browser/hooks/client/useGateway.d.ts +0 -8
- package/dist/browser/hooks/client/useGateway.d.ts.map +0 -1
- package/dist/browser/hooks/viewer/UseStepRewardWeightTest.stories.d.ts +0 -12
- package/dist/browser/hooks/viewer/UseStepRewardWeightTest.stories.d.ts.map +0 -1
- package/dist/browser/hooks/viewer/useHttpRpcViewer.stories.d.ts +0 -9
- package/dist/browser/hooks/viewer/useHttpRpcViewer.stories.d.ts.map +0 -1
- package/dist/browser/hooks/viewer/useViewerFromWallet.stories.d.ts +0 -12
- package/dist/browser/hooks/viewer/useViewerFromWallet.stories.d.ts.map +0 -1
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Stack, Typography } from '@mui/material'
|
|
2
|
+
import type { AccountInstance } from '@xyo-network/sdk-js'
|
|
3
|
+
import type { GatewayName } from '@xyo-network/xl1-sdk'
|
|
4
|
+
|
|
5
|
+
import { GatewayProvider } from '../Provider.tsx'
|
|
6
|
+
import { GatewayStatus } from './GatewayStatus.tsx'
|
|
7
|
+
|
|
8
|
+
export interface GatewayStatsProps {
|
|
9
|
+
account?: AccountInstance
|
|
10
|
+
id?: GatewayName
|
|
11
|
+
url?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const GatewayStats: React.FC<GatewayStatsProps> = ({
|
|
15
|
+
account, id, url,
|
|
16
|
+
}) => {
|
|
17
|
+
return (
|
|
18
|
+
<GatewayProvider key={id} gatewayName={id} account={account}>
|
|
19
|
+
<Stack gap={1}>
|
|
20
|
+
<Typography variant="subtitle1">
|
|
21
|
+
<strong>{id}</strong>
|
|
22
|
+
</Typography>
|
|
23
|
+
<Typography variant="caption" color="text.secondary">
|
|
24
|
+
{url}
|
|
25
|
+
</Typography>
|
|
26
|
+
<GatewayStatus />
|
|
27
|
+
</Stack>
|
|
28
|
+
</GatewayProvider>
|
|
29
|
+
)
|
|
30
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Alert, Chip, Stack, Typography,
|
|
3
|
+
} from '@mui/material'
|
|
4
|
+
|
|
5
|
+
import { useProvidedGateway } from '../use.ts'
|
|
6
|
+
|
|
7
|
+
/** Inner component that consumes the GatewayContext to display load status */
|
|
8
|
+
export const GatewayStatus: React.FC = () => {
|
|
9
|
+
const { defaultGateway: gateway, error } = useProvidedGateway(false) ?? {}
|
|
10
|
+
|
|
11
|
+
if (error) {
|
|
12
|
+
return (
|
|
13
|
+
<Alert severity="error">
|
|
14
|
+
<Typography variant="body2">
|
|
15
|
+
Failed to load gateway:
|
|
16
|
+
{' '}
|
|
17
|
+
{error.message}
|
|
18
|
+
</Typography>
|
|
19
|
+
</Alert>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (gateway === undefined) {
|
|
24
|
+
return (
|
|
25
|
+
<Alert severity="info">
|
|
26
|
+
<Typography variant="body2">Gateway loading...</Typography>
|
|
27
|
+
</Alert>
|
|
28
|
+
)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (gateway === null) {
|
|
32
|
+
return (
|
|
33
|
+
<Alert severity="warning">
|
|
34
|
+
<Typography variant="body2">Gateway not available</Typography>
|
|
35
|
+
</Alert>
|
|
36
|
+
)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<Alert severity="success">
|
|
41
|
+
<Stack direction="row" gap={1} alignItems="center">
|
|
42
|
+
<Typography variant="body2">Gateway loaded</Typography>
|
|
43
|
+
<Chip label="connected" color="success" size="small" />
|
|
44
|
+
{gateway?.connection?.viewer && (
|
|
45
|
+
<Chip label="viewer available" color="success" size="small" />
|
|
46
|
+
)}
|
|
47
|
+
{gateway?.connection.runner && (
|
|
48
|
+
<Chip label="runner available" color="success" size="small" />
|
|
49
|
+
)}
|
|
50
|
+
</Stack>
|
|
51
|
+
</Alert>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Stack } from '@mui/material'
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
3
|
+
import { Account } from '@xyo-network/sdk-js'
|
|
4
|
+
import { DefaultNetworks } from '@xyo-network/xl1-sdk'
|
|
5
|
+
|
|
6
|
+
import type { GatewayProviderProps } from '../Provider.tsx'
|
|
7
|
+
import { GatewayProvider } from '../Provider.tsx'
|
|
8
|
+
import { GatewayStats } from './GatewayStats.tsx'
|
|
9
|
+
|
|
10
|
+
const meta: Meta<GatewayProviderProps> = {
|
|
11
|
+
title: 'provider/GatewayProvider',
|
|
12
|
+
component: GatewayProvider,
|
|
13
|
+
// eslint-disable-next-line @stylistic/max-len
|
|
14
|
+
parameters: { docs: { description: { component: 'Wraps children with a `GatewayContext` populated from the given `gatewayName` and show the gateways from the default networks if available.' } } },
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default meta
|
|
18
|
+
|
|
19
|
+
const account = await Account.random()
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Convenience story that proves ALL default networks are represented.
|
|
23
|
+
* Each row corresponds to one entry in DefaultNetworks.
|
|
24
|
+
*/
|
|
25
|
+
const AllDefaultNetworks: StoryObj<GatewayProviderProps> = {
|
|
26
|
+
name: 'All Default Networks',
|
|
27
|
+
render: () => {
|
|
28
|
+
return (
|
|
29
|
+
<Stack gap={3} p={2}>
|
|
30
|
+
{DefaultNetworks.map(network => (
|
|
31
|
+
<GatewayStats key={network.id} id={network.id} url={network.url} account={account} />
|
|
32
|
+
))}
|
|
33
|
+
</Stack>
|
|
34
|
+
)
|
|
35
|
+
},
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { AllDefaultNetworks }
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Alert, Stack } from '@mui/material'
|
|
2
|
+
import type { Meta, StoryObj } from '@storybook/react-vite'
|
|
3
|
+
import { isDefinedNotNull } from '@xylabs/sdk-js'
|
|
4
|
+
import { IframeWalletWarningDecorator } from '@xyo-network/react-chain-shared'
|
|
5
|
+
import type { GatewayName } from '@xyo-network/xl1-sdk'
|
|
6
|
+
|
|
7
|
+
import { useClientFromWallet } from '../../../hooks/index.ts'
|
|
8
|
+
import type { GatewayProviderProps } from '../Provider.tsx'
|
|
9
|
+
import { GatewayProvider } from '../Provider.tsx'
|
|
10
|
+
import { GatewayStats } from './GatewayStats.tsx'
|
|
11
|
+
|
|
12
|
+
const meta: Meta<GatewayProviderProps> = {
|
|
13
|
+
title: 'provider/GatewayProvider',
|
|
14
|
+
component: GatewayProvider,
|
|
15
|
+
decorators: [IframeWalletWarningDecorator],
|
|
16
|
+
// eslint-disable-next-line @stylistic/max-len
|
|
17
|
+
parameters: { docs: { description: { component: 'Wraps children with a `GatewayContext` populated from the given `gatewayName` and show the wallet-provided gateways if available.' } } },
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export default meta
|
|
21
|
+
|
|
22
|
+
type Story = StoryObj<GatewayProviderProps>
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Convenience story that proves ALL client gateways are represented.
|
|
26
|
+
* Each row corresponds to one entry in the client's gateways.
|
|
27
|
+
*/
|
|
28
|
+
const AllClientGateways: Story = {
|
|
29
|
+
name: 'All Client Gateways',
|
|
30
|
+
render: () => {
|
|
31
|
+
const { client } = useClientFromWallet()
|
|
32
|
+
const foundClient = isDefinedNotNull(client)
|
|
33
|
+
return (
|
|
34
|
+
<Stack gap={3} p={2}>
|
|
35
|
+
<Alert severity={foundClient ? 'success' : 'error'}>
|
|
36
|
+
{foundClient ? 'Client found, displaying gateways:' : 'No client found. Please ensure your wallet is connected and has access to the current page.'}
|
|
37
|
+
</Alert>
|
|
38
|
+
{Object.keys(client?.gateways || {}).map(id => (
|
|
39
|
+
<GatewayStats key={id} id={id as GatewayName} />
|
|
40
|
+
))}
|
|
41
|
+
</Stack>
|
|
42
|
+
)
|
|
43
|
+
},
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export { AllClientGateways }
|
package/src/contexts/index.ts
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { assertEx, isDefined } from '@xylabs/sdk-js'
|
|
2
|
+
import { basicRemoteRunnerLocator, basicRemoteViewerLocator } from '@xyo-network/chain-orchestration'
|
|
3
|
+
import type { AccountInstance } from '@xyo-network/sdk-js'
|
|
4
|
+
import type {
|
|
5
|
+
GatewayName, RemoteConfig, SimpleXyoGateway,
|
|
6
|
+
} from '@xyo-network/xl1-sdk'
|
|
7
|
+
import {
|
|
8
|
+
DefaultNetworks, NetworkDataLakeUrls, XyoGatewayMoniker,
|
|
9
|
+
} from '@xyo-network/xl1-sdk'
|
|
10
|
+
|
|
11
|
+
export const buildGateway = async (gatewayName: GatewayName, account?: AccountInstance) => {
|
|
12
|
+
const network = DefaultNetworks.find(network => network.id === gatewayName)
|
|
13
|
+
const resolvedNetwork = assertEx(network, () => `No network found for id ${gatewayName}`)
|
|
14
|
+
|
|
15
|
+
const remoteConfig: RemoteConfig = {
|
|
16
|
+
rpc: {
|
|
17
|
+
protocol: 'http',
|
|
18
|
+
url: `${resolvedNetwork.url}/rpc`,
|
|
19
|
+
},
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const dataLakeEndpoint = NetworkDataLakeUrls[gatewayName]
|
|
23
|
+
|
|
24
|
+
const locator = isDefined(account)
|
|
25
|
+
? await basicRemoteRunnerLocator(gatewayName, remoteConfig, account, dataLakeEndpoint)
|
|
26
|
+
: await basicRemoteViewerLocator(gatewayName, remoteConfig, dataLakeEndpoint)
|
|
27
|
+
|
|
28
|
+
return await locator.getInstance<SimpleXyoGateway>(XyoGatewayMoniker)
|
|
29
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useClientFromWallet } from '../useClientFromWallet.ts'
|
|
2
2
|
|
|
3
3
|
export const usePermissions = () => {
|
|
4
4
|
const {
|
|
5
5
|
client, isLoading, error, timedout,
|
|
6
|
-
} =
|
|
6
|
+
} = useClientFromWallet()
|
|
7
7
|
const permissions = client?.permissions
|
|
8
8
|
return {
|
|
9
9
|
permissions,
|
|
@@ -63,7 +63,7 @@ const subscribe = (listener: () => void, timeout?: number) => {
|
|
|
63
63
|
|
|
64
64
|
const getSnapshot = (): ClientState => currentState
|
|
65
65
|
|
|
66
|
-
export const
|
|
66
|
+
export const useClientFromWallet = (timeout?: number) => {
|
|
67
67
|
const subscribeWithTimeout = useCallback((listener: () => void) => subscribe(listener, timeout), [timeout])
|
|
68
68
|
const clientState = useSyncExternalStore(subscribeWithTimeout, getSnapshot)
|
|
69
69
|
|
|
@@ -91,3 +91,6 @@ export const useClient = (timeout?: number) => {
|
|
|
91
91
|
|
|
92
92
|
return clientState
|
|
93
93
|
}
|
|
94
|
+
|
|
95
|
+
/** @deprecated - use useClientFromWallet instead */
|
|
96
|
+
export const useClient = useClientFromWallet
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { usePromise } from '@xylabs/react-promise'
|
|
2
|
+
import { isDefined } from '@xylabs/sdk-js'
|
|
3
|
+
import type { AccountInstance } from '@xyo-network/sdk-js'
|
|
4
|
+
import type { GatewayName } from '@xyo-network/xl1-sdk'
|
|
5
|
+
import { useState } from 'react'
|
|
6
|
+
|
|
7
|
+
import type { ContextGatewayType } from '../../contexts/index.ts'
|
|
8
|
+
import { buildGateway } from './helpers/index.ts'
|
|
9
|
+
|
|
10
|
+
export const useGatewayFromConfig = (gatewayName?: GatewayName, account?: AccountInstance) => {
|
|
11
|
+
const [gatewayCache, setGatewayCache] = useState<Record<GatewayName, ContextGatewayType>>({})
|
|
12
|
+
const clearGateways = () => setGatewayCache({})
|
|
13
|
+
|
|
14
|
+
// if the account changes, we should clear the gateway cache since the gateway is built with the account
|
|
15
|
+
const [previousAccount, setPreviousAccount] = useState<AccountInstance | undefined>(account)
|
|
16
|
+
if (previousAccount !== account) {
|
|
17
|
+
clearGateways()
|
|
18
|
+
setPreviousAccount(account)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const builtGatewayResults = usePromise(async () => {
|
|
22
|
+
if (isDefined(gatewayName)) {
|
|
23
|
+
// if gateway already built and cached, return it
|
|
24
|
+
if (isDefined(gatewayCache[gatewayName])) {
|
|
25
|
+
return gatewayCache[gatewayName]
|
|
26
|
+
} else {
|
|
27
|
+
// otherwise build the gateway and cache it
|
|
28
|
+
const gateway = await buildGateway(gatewayName, account)
|
|
29
|
+
setGatewayCache(prev => ({ ...prev, [gatewayName]: gateway }))
|
|
30
|
+
return gateway
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}, [gatewayName, account, gatewayCache])
|
|
34
|
+
|
|
35
|
+
const [gateway, error, state] = builtGatewayResults
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
gateway,
|
|
39
|
+
error,
|
|
40
|
+
state,
|
|
41
|
+
clearGateways,
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { isDefined, isNull } from '@xylabs/sdk-js'
|
|
2
2
|
import type { GatewayName } from '@xyo-network/xl1-sdk'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import type { GatewayFromWallet } from '../../types/index.ts'
|
|
5
|
+
import { useClientFromWallet } from './useClientFromWallet.ts'
|
|
5
6
|
|
|
6
|
-
export const
|
|
7
|
+
export const useGatewayFromWallet = (gatewayName?: GatewayName, timeout?: number): GatewayFromWallet => {
|
|
7
8
|
const {
|
|
8
9
|
client, isLoading, error, timedout,
|
|
9
|
-
} =
|
|
10
|
+
} = useClientFromWallet(timeout)
|
|
10
11
|
|
|
11
12
|
const resolveGateway = () => {
|
|
12
13
|
// null client means we do not have to wait for timedout
|
|
@@ -24,3 +25,6 @@ export const useGateway = (gatewayName?: GatewayName, timeout?: number) => {
|
|
|
24
25
|
timedout,
|
|
25
26
|
}
|
|
26
27
|
}
|
|
28
|
+
|
|
29
|
+
/** @deprecated - useGatewayFromWallet */
|
|
30
|
+
export const useGateway = useGatewayFromWallet
|
package/src/hooks/index.ts
CHANGED
|
@@ -4,14 +4,14 @@ import type { GatewayName } from '@xyo-network/xl1-sdk'
|
|
|
4
4
|
import { MainNetwork } from '@xyo-network/xl1-sdk'
|
|
5
5
|
import { useCallback, useState } from 'react'
|
|
6
6
|
|
|
7
|
-
import { useAccountPermissions,
|
|
7
|
+
import { useAccountPermissions, useGatewayFromWallet } from './client/index.ts'
|
|
8
8
|
|
|
9
9
|
export const useConnectAccount = (gatewayName: GatewayName = MainNetwork.id, timeout?: number) => {
|
|
10
10
|
const [connectError, setConnectError] = useState<Error>()
|
|
11
11
|
|
|
12
12
|
const {
|
|
13
13
|
gateway, error, timedout,
|
|
14
|
-
} =
|
|
14
|
+
} = useGatewayFromWallet(gatewayName, timeout)
|
|
15
15
|
|
|
16
16
|
const [accountPermissions, accountPermissionsError] = useAccountPermissions()
|
|
17
17
|
|
|
@@ -3,6 +3,9 @@ import { usePromise } from '@xylabs/react-promise'
|
|
|
3
3
|
import { isDefinedNotNull } from '@xylabs/sdk-js'
|
|
4
4
|
import type { HydratedBlockWithHashMeta, XyoViewer } from '@xyo-network/xl1-sdk'
|
|
5
5
|
|
|
6
|
+
import { useViewerFromGateway } from './gateway/index.ts'
|
|
7
|
+
|
|
8
|
+
/* @deprecated - use useCurrentBlockFromGateway instead */
|
|
6
9
|
export const useCurrentBlock = (refresh = 1, viewer?: XyoViewer | null): [HydratedBlockWithHashMeta | undefined,
|
|
7
10
|
Error | undefined, UsePromiseState | undefined] => {
|
|
8
11
|
return usePromise(async () => {
|
|
@@ -12,3 +15,13 @@ export const useCurrentBlock = (refresh = 1, viewer?: XyoViewer | null): [Hydrat
|
|
|
12
15
|
}
|
|
13
16
|
}, [viewer, refresh])
|
|
14
17
|
}
|
|
18
|
+
|
|
19
|
+
export const useCurrentBlockFromGateway = (refresh = 1) => {
|
|
20
|
+
const viewer = useViewerFromGateway()
|
|
21
|
+
return usePromise(async () => {
|
|
22
|
+
if (isDefinedNotNull(viewer) && refresh > 0) {
|
|
23
|
+
const block = await viewer.currentBlock()
|
|
24
|
+
return block
|
|
25
|
+
}
|
|
26
|
+
}, [viewer, refresh])
|
|
27
|
+
}
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
AccountBalanceViewerRpcSchemas, buildJsonRpcProviderLocator, HttpRpcTransport, JsonRpcAccountBalanceViewer, SimpleTransactionViewer, XyoRunnerMoniker,
|
|
8
8
|
} from '@xyo-network/xl1-sdk'
|
|
9
9
|
|
|
10
|
+
/* @deprecated use useRunnerFromGateway */
|
|
10
11
|
export const useHttpRpcRunner = (url?: string) => {
|
|
11
12
|
return usePromise(async () => {
|
|
12
13
|
if (isUndefined(url)) {
|
|
@@ -2,13 +2,12 @@ import { usePromise } from '@xylabs/react-promise'
|
|
|
2
2
|
import {
|
|
3
3
|
delay, isDefined, isUndefined,
|
|
4
4
|
} from '@xylabs/sdk-js'
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
} from '@xyo-network/xl1-sdk'
|
|
5
|
+
import { basicRemoteViewerLocator } from '@xyo-network/chain-orchestration'
|
|
6
|
+
import type { JsonRpcXyoViewer } from '@xyo-network/xl1-sdk'
|
|
8
7
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
LocalNetwork,
|
|
9
|
+
SequenceNetwork,
|
|
10
|
+
XyoViewerMoniker,
|
|
12
11
|
} from '@xyo-network/xl1-sdk'
|
|
13
12
|
import { useEffect, useState } from 'react'
|
|
14
13
|
|
|
@@ -23,8 +22,8 @@ export const useCheckLocalRpc = () => {
|
|
|
23
22
|
}
|
|
24
23
|
|
|
25
24
|
export const useCheckSequenceRpc = () => {
|
|
26
|
-
const
|
|
27
|
-
return
|
|
25
|
+
const isSequenceRpc = useCheckRpc(sequenceRpcEndpoint)
|
|
26
|
+
return isSequenceRpc
|
|
28
27
|
}
|
|
29
28
|
|
|
30
29
|
export const useCheckRpc = (endpoint?: string) => {
|
|
@@ -34,15 +33,7 @@ export const useCheckRpc = (endpoint?: string) => {
|
|
|
34
33
|
const [viewer] = usePromise(async () => {
|
|
35
34
|
if (isUndefined(endpoint)) return
|
|
36
35
|
|
|
37
|
-
const
|
|
38
|
-
const locator = await buildJsonRpcProviderLocator({ transportFactory })
|
|
39
|
-
|
|
40
|
-
// Additional dependencies to get working viewer
|
|
41
|
-
locator.register(SimpleTransactionViewer.factory<SimpleTransactionViewer>(SimpleTransactionViewer.dependencies, {}))
|
|
42
|
-
locator.register(JsonRpcAccountBalanceViewer.factory<JsonRpcAccountBalanceViewer>(
|
|
43
|
-
JsonRpcAccountBalanceViewer.dependencies,
|
|
44
|
-
{ transport: await transportFactory(AccountBalanceViewerRpcSchemas) },
|
|
45
|
-
))
|
|
36
|
+
const locator = await basicRemoteViewerLocator(endpoint, { rpc: { protocol: 'http', url: endpoint } })
|
|
46
37
|
|
|
47
38
|
const viewer = await locator.getInstance<JsonRpcXyoViewer>(XyoViewerMoniker)
|
|
48
39
|
return viewer
|
|
@@ -55,6 +55,7 @@ const buildLocator = async (transportFactory: TransportFactory, dataLakeViewerPa
|
|
|
55
55
|
return locator
|
|
56
56
|
}
|
|
57
57
|
|
|
58
|
+
/** @deprecated - use useViewerFromGateway */
|
|
58
59
|
export const useHttpRpcViewer = (urlOrNetwork?: string | NetworkBootstrap): XyoViewer | undefined => {
|
|
59
60
|
const [resolvedViewer] = usePromise(async () => {
|
|
60
61
|
if (isUndefined(urlOrNetwork)) {
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
} from '@xylabs/sdk-js'
|
|
5
5
|
import type { GatewayName } from '@xyo-network/xl1-sdk'
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import { useGatewayFromWallet } from '../client/index.ts'
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Creates a JsonRpcXyoViewer instance based on the provided networkId.
|
|
@@ -18,7 +18,7 @@ export const useViewerFromWallet = (
|
|
|
18
18
|
) => {
|
|
19
19
|
const {
|
|
20
20
|
gateway, error, isLoading, timedout,
|
|
21
|
-
} =
|
|
21
|
+
} = useGatewayFromWallet(networkId, timeout)
|
|
22
22
|
|
|
23
23
|
const result = usePromise(async () => {
|
|
24
24
|
await Promise.resolve() // ensure async
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './GatewayFromWallet.ts'
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { Meta } from '@storybook/react-vite';
|
|
2
|
-
declare const _default: Meta;
|
|
3
|
-
export default _default;
|
|
4
|
-
declare const Default: import("storybook/internal/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("./ConnectAccountsStack.tsx").ConnectClientAccountsStackProps>;
|
|
5
|
-
export { Default };
|
|
6
|
-
//# sourceMappingURL=ConnectAccountsStack.stories.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectAccountsStack.stories.d.ts","sourceRoot":"","sources":["../../../../src/components/connected/ConnectAccountsStack.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAW,MAAM,uBAAuB,CAAA;wBAQrD,IAAI;AAHT,wBAGS;AAIT,QAAA,MAAM,OAAO,mKAAoB,CAAA;AAGjC,OAAO,EAAE,OAAO,EAAE,CAAA"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import type { Meta } from '@storybook/react-vite';
|
|
2
|
-
import { XL1CurrentBlockProvider } from './Provider.tsx';
|
|
3
|
-
declare const _default: Meta<typeof XL1CurrentBlockProvider>;
|
|
4
|
-
export default _default;
|
|
5
|
-
declare const Default: import("storybook/internal/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("./Provider.tsx").XL1CurrentBlockProviderProps>;
|
|
6
|
-
export { Default };
|
|
7
|
-
//# sourceMappingURL=Provider.stories.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Provider.stories.d.ts","sourceRoot":"","sources":["../../../../src/contexts/current-block/Provider.stories.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAW,MAAM,uBAAuB,CAAA;AAI1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAA;wBAMnD,IAAI,CAAC,OAAO,uBAAuB,CAAC;AAHzC,wBAGyC;AAkBzC,QAAA,MAAM,OAAO,oJAAoB,CAAA;AAGjC,OAAO,EAAE,OAAO,EAAE,CAAA"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useClient.d.ts","sourceRoot":"","sources":["../../../../src/hooks/client/useClient.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAOrD,UAAU,WAAW;IACnB,MAAM,CAAC,EAAE,SAAS,CAAA;IAClB,KAAK,EAAE,KAAK,GAAG,IAAI,CAAA;IACnB,SAAS,EAAE,OAAO,CAAA;IAClB,QAAQ,EAAE,OAAO,CAAA;CAClB;AAoDD,eAAO,MAAM,SAAS,GAAI,UAAU,MAAM,gBA2BzC,CAAA"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { GatewayName } from '@xyo-network/xl1-sdk';
|
|
2
|
-
export declare const useGateway: (gatewayName?: GatewayName, timeout?: number) => {
|
|
3
|
-
gateway: import("@xyo-network/xl1-sdk").XyoGatewayRunner | null | undefined;
|
|
4
|
-
isLoading: boolean;
|
|
5
|
-
error: Error | null;
|
|
6
|
-
timedout: boolean;
|
|
7
|
-
};
|
|
8
|
-
//# sourceMappingURL=useGateway.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useGateway.d.ts","sourceRoot":"","sources":["../../../../src/hooks/client/useGateway.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAIvD,eAAO,MAAM,UAAU,GAAI,cAAc,WAAW,EAAE,UAAU,MAAM;;;;;CAoBrE,CAAA"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { StoryFn } from '@storybook/react-vite';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
declare const UseStepRewardWeightTest: React.FC;
|
|
4
|
-
declare const _default: {
|
|
5
|
-
title: string;
|
|
6
|
-
component: React.FC<{}>;
|
|
7
|
-
};
|
|
8
|
-
export default _default;
|
|
9
|
-
export declare const Template: StoryFn<typeof UseStepRewardWeightTest>;
|
|
10
|
-
declare const Default: import("storybook/internal/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, {}>;
|
|
11
|
-
export { Default };
|
|
12
|
-
//# sourceMappingURL=UseStepRewardWeightTest.stories.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"UseStepRewardWeightTest.stories.d.ts","sourceRoot":"","sources":["../../../../src/hooks/viewer/UseStepRewardWeightTest.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AASpD,OAAO,KAAmB,MAAM,OAAO,CAAA;AAWvC,QAAA,MAAM,uBAAuB,EAAE,KAAK,CAAC,EAiDpC,CAAA;;;;;AAED,wBAGC;AAED,eAAO,MAAM,QAAQ,EAAE,OAAO,CAAC,OAAO,uBAAuB,CAAiD,CAAA;AAE9G,QAAA,MAAM,OAAO,iGAAoB,CAAA;AAGjC,OAAO,EAAE,OAAO,EAAE,CAAA"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { Meta, StoryFn } from '@storybook/react-vite';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
declare const UseHttpRpcViewerStoryTemplate: React.FC;
|
|
4
|
-
declare const _default: Meta;
|
|
5
|
-
export default _default;
|
|
6
|
-
export declare const Template: StoryFn<typeof UseHttpRpcViewerStoryTemplate>;
|
|
7
|
-
declare const Default: import("storybook/internal/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, {}>;
|
|
8
|
-
export { Default };
|
|
9
|
-
//# sourceMappingURL=useHttpRpcViewer.stories.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useHttpRpcViewer.stories.d.ts","sourceRoot":"","sources":["../../../../src/hooks/viewer/useHttpRpcViewer.stories.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAK1D,OAAO,KAAmB,MAAM,OAAO,CAAA;AAOvC,QAAA,MAAM,6BAA6B,EAAE,KAAK,CAAC,EAuC1C,CAAA;wBAKI,IAAI;AAHT,wBAGS;AAET,eAAO,MAAM,QAAQ,EAAE,OAAO,CAAC,OAAO,6BAA6B,CAAuD,CAAA;AAE1H,QAAA,MAAM,OAAO,iGAAoB,CAAA;AAGjC,OAAO,EAAE,OAAO,EAAE,CAAA"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { StoryFn } from '@storybook/react-vite';
|
|
2
|
-
import React from 'react';
|
|
3
|
-
declare const UseViewerFromWalletStoryTemplate: React.FC;
|
|
4
|
-
declare const _default: {
|
|
5
|
-
title: string;
|
|
6
|
-
component: React.FC<{}>;
|
|
7
|
-
};
|
|
8
|
-
export default _default;
|
|
9
|
-
export declare const Template: StoryFn<typeof UseViewerFromWalletStoryTemplate>;
|
|
10
|
-
declare const Default: import("storybook/internal/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, {}>;
|
|
11
|
-
export { Default };
|
|
12
|
-
//# sourceMappingURL=useViewerFromWallet.stories.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useViewerFromWallet.stories.d.ts","sourceRoot":"","sources":["../../../../src/hooks/viewer/useViewerFromWallet.stories.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAMpD,OAAO,KAAmB,MAAM,OAAO,CAAA;AAOvC,QAAA,MAAM,gCAAgC,EAAE,KAAK,CAAC,EAgD7C,CAAA;;;;;AAED,wBAGC;AAED,eAAO,MAAM,QAAQ,EAAE,OAAO,CAAC,OAAO,gCAAgC,CAA0D,CAAA;AAEhI,QAAA,MAAM,OAAO,iGAAoB,CAAA;AAGjC,OAAO,EAAE,OAAO,EAAE,CAAA"}
|