@xyo-network/react-chain-network 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/context/ActiveGatewayProvider.d.ts +8 -0
- package/dist/browser/context/ActiveGatewayProvider.d.ts.map +1 -0
- package/dist/browser/context/index.d.ts +1 -0
- package/dist/browser/context/index.d.ts.map +1 -1
- package/dist/browser/hooks/provider/useActiveNetworkCurrentBlock.d.ts.map +1 -1
- package/dist/browser/hooks/provider/useActiveNetworkNetwork.d.ts.map +1 -1
- package/dist/browser/hooks/provider/useActiveNetworkRunner.d.ts.map +1 -1
- package/dist/browser/hooks/provider/useViewerInPage.d.ts +1 -0
- package/dist/browser/hooks/provider/useViewerInPage.d.ts.map +1 -1
- package/dist/browser/hooks/provider/useViewerInWallet.d.ts +1 -0
- package/dist/browser/hooks/provider/useViewerInWallet.d.ts.map +1 -1
- package/dist/browser/index.mjs +95 -64
- package/dist/browser/index.mjs.map +1 -1
- package/package.json +19 -19
- package/src/context/ActiveGatewayProvider.tsx +19 -0
- package/src/context/index.ts +1 -0
- package/src/hooks/provider/UseViewerInPage.stories.tsx +5 -24
- package/src/hooks/provider/UseViewerInPageV2.stories.tsx +135 -0
- package/src/hooks/provider/useActiveNetworkCurrentBlock.ts +2 -0
- package/src/hooks/provider/useActiveNetworkNetwork.ts +1 -0
- package/src/hooks/provider/useActiveNetworkRunner.ts +1 -0
- package/src/hooks/provider/useViewerInPage.ts +35 -7
- package/src/hooks/provider/useViewerInWallet.ts +1 -0
- package/src/hooks/status/usePollNetworkStatus.ts +1 -1
- package/dist/browser/components/broadcast/details/SummaryStack.stories.d.ts +0 -8
- package/dist/browser/components/broadcast/details/SummaryStack.stories.d.ts.map +0 -1
- package/dist/browser/components/status/Alert.stories.d.ts +0 -10
- package/dist/browser/components/status/Alert.stories.d.ts.map +0 -1
- package/dist/browser/hooks/provider/UseViewerInPage.stories.d.ts +0 -10
- package/dist/browser/hooks/provider/UseViewerInPage.stories.d.ts.map +0 -1
|
@@ -2,6 +2,7 @@ import { useHttpRpcRunner } from '@xyo-network/react-chain-provider'
|
|
|
2
2
|
|
|
3
3
|
import { useChainNetwork } from '../../context/index.ts'
|
|
4
4
|
|
|
5
|
+
/* @deprecated use useRunnerFromGateway in @xyo-network/react-chain-provider */
|
|
5
6
|
export const useActiveNetworkRunner = () => {
|
|
6
7
|
const { activeNetwork } = useChainNetwork()
|
|
7
8
|
const runner = useHttpRpcRunner(activeNetwork?.url)
|
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
import {
|
|
2
2
|
isDefined, isNull, isUndefined,
|
|
3
3
|
} from '@xylabs/sdk-js'
|
|
4
|
-
import {
|
|
5
|
-
|
|
4
|
+
import {
|
|
5
|
+
useHttpRpcViewer, useProvidedGateway, useViewerFromWallet,
|
|
6
|
+
} from '@xyo-network/react-chain-provider'
|
|
7
|
+
import type { NetworkBootstrap, NetworkId } from '@xyo-network/xl1-sdk'
|
|
6
8
|
|
|
7
9
|
import type { ChainNetworkSettings } from '../../context/index.ts'
|
|
8
10
|
import { useChainNetwork } from '../../context/index.ts'
|
|
9
11
|
|
|
10
|
-
const shouldProxy = (networkSettings: ChainNetworkSettings,
|
|
11
|
-
return isDefined(
|
|
12
|
-
&& isDefined(networkSettings[
|
|
13
|
-
&& networkSettings[
|
|
12
|
+
const shouldProxy = (networkSettings: ChainNetworkSettings, networkId: NetworkId | undefined) => {
|
|
13
|
+
return isDefined(networkId)
|
|
14
|
+
&& isDefined(networkSettings[networkId])
|
|
15
|
+
&& networkSettings[networkId].proxy
|
|
14
16
|
}
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
19
|
* Get the viewer for the active network, first from the wallet or fallback to HTTP RPC
|
|
18
20
|
* @returns - XyoViewer for the active network
|
|
19
21
|
*/
|
|
22
|
+
/* @deprecated - use useViewerInPageV2 instead */
|
|
20
23
|
export const useViewerInPage = (networkOverride?: NetworkBootstrap) => {
|
|
21
24
|
let networkBootstrap: NetworkBootstrap | undefined
|
|
22
25
|
const { activeNetwork, networkSettings } = useChainNetwork()
|
|
@@ -28,7 +31,7 @@ export const useViewerInPage = (networkOverride?: NetworkBootstrap) => {
|
|
|
28
31
|
// If the wallet viewer is undefined, don't return it yet, useViewerFromWallet is still checking
|
|
29
32
|
if (isUndefined(walletRpcViewer)) return
|
|
30
33
|
|
|
31
|
-
if (shouldProxy(networkSettings, networkBootstrap)) {
|
|
34
|
+
if (shouldProxy(networkSettings, networkBootstrap?.id)) {
|
|
32
35
|
if (isNull(walletRpcViewer)) {
|
|
33
36
|
console.warn(`Network ${networkBootstrap?.id} is set to proxy but no wallet viewer is available, falling back to HTTP RPC viewer`)
|
|
34
37
|
return httpRpcViewer
|
|
@@ -40,3 +43,28 @@ export const useViewerInPage = (networkOverride?: NetworkBootstrap) => {
|
|
|
40
43
|
|
|
41
44
|
return httpRpcViewer
|
|
42
45
|
}
|
|
46
|
+
|
|
47
|
+
export const useViewerInPageV2 = () => {
|
|
48
|
+
const { networkSettings, activeNetwork } = useChainNetwork()
|
|
49
|
+
const { gateways } = useProvidedGateway()
|
|
50
|
+
|
|
51
|
+
const { inPageGateway, walletGateway } = gateways
|
|
52
|
+
|
|
53
|
+
const inPageViewer = inPageGateway?.connection?.viewer
|
|
54
|
+
const walletViewer = walletGateway?.connection?.viewer
|
|
55
|
+
|
|
56
|
+
// If the wallet viewer is undefined, don't return it yet, useViewerFromWallet is still checking
|
|
57
|
+
if (isUndefined(walletGateway)) return
|
|
58
|
+
|
|
59
|
+
if (shouldProxy(networkSettings, activeNetwork?.id)) {
|
|
60
|
+
if (isNull(walletGateway)) {
|
|
61
|
+
console.warn(`Network ${activeNetwork?.id} is set to proxy but no wallet viewer is available, falling back to HTTP RPC viewer`)
|
|
62
|
+
return inPageViewer
|
|
63
|
+
}
|
|
64
|
+
// If the network setting is to proxy and the wallet viewer is available,
|
|
65
|
+
// try to use the wallet viewer
|
|
66
|
+
return walletViewer
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return inPageViewer
|
|
70
|
+
}
|
|
@@ -6,6 +6,7 @@ import { useChainNetwork } from '../../context/index.ts'
|
|
|
6
6
|
* Get the viewer directly from the active network
|
|
7
7
|
* @returns - The viewer for the active network
|
|
8
8
|
*/
|
|
9
|
+
/** @deprecated use useViewerFromGateway in \@xyo-network/react-chain-provider */
|
|
9
10
|
export const useViewerInWallet = () => {
|
|
10
11
|
const { activeNetwork } = useChainNetwork()
|
|
11
12
|
const walletViewer = useHttpRpcViewer(activeNetwork?.url)
|
|
@@ -22,7 +22,7 @@ export const usePollNetworkStatus = () => {
|
|
|
22
22
|
setNetworkStatus(response)
|
|
23
23
|
setNetworkStatusError(undefined)
|
|
24
24
|
} catch (error) {
|
|
25
|
-
console.
|
|
25
|
+
console.info('Error fetching network status:', error)
|
|
26
26
|
setNetworkStatus(undefined)
|
|
27
27
|
setNetworkStatusError(error as Error)
|
|
28
28
|
}
|
|
@@ -1,8 +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("./SummaryStack.tsx").BroadcastRpcCallDetailsSummaryStackProps>;
|
|
5
|
-
declare const WithHashParam: import("storybook/internal/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("./SummaryStack.tsx").BroadcastRpcCallDetailsSummaryStackProps>;
|
|
6
|
-
declare const WithUnknownParam: import("storybook/internal/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("./SummaryStack.tsx").BroadcastRpcCallDetailsSummaryStackProps>;
|
|
7
|
-
export { Default, WithHashParam, WithUnknownParam, };
|
|
8
|
-
//# sourceMappingURL=SummaryStack.stories.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SummaryStack.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/broadcast/details/SummaryStack.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAW,MAAM,uBAAuB,CAAA;wBAQrD,IAAI;AAHT,wBAGS;AAIT,QAAA,MAAM,OAAO,oKAAoB,CAAA;AAGjC,QAAA,MAAM,aAAa,oKAAoB,CAAA;AASvC,QAAA,MAAM,gBAAgB,oKAAoB,CAAA;AAS1C,OAAO,EACL,OAAO,EAAE,aAAa,EAAE,gBAAgB,GACzC,CAAA"}
|
|
@@ -1,10 +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("./Alert.tsx").NetworkStatusAlertProps>;
|
|
5
|
-
declare const WithOnlineStatus: import("storybook/internal/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("./Alert.tsx").NetworkStatusAlertProps>;
|
|
6
|
-
declare const WithOfflineStatus: import("storybook/internal/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("./Alert.tsx").NetworkStatusAlertProps>;
|
|
7
|
-
declare const WithDegradedStatus: import("storybook/internal/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("./Alert.tsx").NetworkStatusAlertProps>;
|
|
8
|
-
declare const WithUnknownStatus: import("storybook/internal/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, import("./Alert.tsx").NetworkStatusAlertProps>;
|
|
9
|
-
export { Default, WithDegradedStatus, WithOfflineStatus, WithOnlineStatus, WithUnknownStatus, };
|
|
10
|
-
//# sourceMappingURL=Alert.stories.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Alert.stories.d.ts","sourceRoot":"","sources":["../../../../src/components/status/Alert.stories.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAW,MAAM,uBAAuB,CAAA;wBAoDrD,IAAI;AAHT,wBAGS;AAIT,QAAA,MAAM,OAAO,4IAAoB,CAAA;AAGjC,QAAA,MAAM,gBAAgB,4IAAoB,CAAA;AAG1C,QAAA,MAAM,iBAAiB,4IAAoB,CAAA;AAG3C,QAAA,MAAM,kBAAkB,4IAAoB,CAAA;AAG5C,QAAA,MAAM,iBAAiB,4IAAoB,CAAA;AAG3C,OAAO,EACL,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,iBAAiB,GACpF,CAAA"}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
declare const _default: {
|
|
3
|
-
title: string;
|
|
4
|
-
component: React.FC<{}>;
|
|
5
|
-
};
|
|
6
|
-
export default _default;
|
|
7
|
-
declare const Default: import("storybook/internal/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, {}>;
|
|
8
|
-
declare const Proxy: import("storybook/internal/csf").AnnotatedStoryFn<import("@storybook/react").ReactRenderer, {}>;
|
|
9
|
-
export { Default, Proxy };
|
|
10
|
-
//# sourceMappingURL=UseViewerInPage.stories.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"UseViewerInPage.stories.d.ts","sourceRoot":"","sources":["../../../../src/hooks/provider/UseViewerInPage.stories.tsx"],"names":[],"mappings":"AAgBA,OAAO,KAAgC,MAAM,OAAO,CAAA;;;;;AAqHpD,wBAGC;AAID,QAAA,MAAM,OAAO,iGAAoB,CAAA;AAGjC,QAAA,MAAM,KAAK,iGAAoB,CAAA;AAI/B,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAA"}
|