@xyo-network/react-chain-provider 1.20.4 → 1.20.5
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/in-page-gateways/Provider.d.ts.map +1 -1
- package/dist/browser/hooks/index.d.ts +0 -1
- package/dist/browser/hooks/index.d.ts.map +1 -1
- package/dist/browser/hooks/viewer/index.d.ts +0 -2
- package/dist/browser/hooks/viewer/index.d.ts.map +1 -1
- package/dist/browser/index.mjs +15 -116
- package/dist/browser/index.mjs.map +1 -1
- package/dist/browser/story/GatewayDecorator.d.ts +5 -0
- package/dist/browser/story/GatewayDecorator.d.ts.map +1 -0
- package/dist/browser/story/index.d.ts +2 -0
- package/dist/browser/story/index.d.ts.map +1 -0
- package/package.json +11 -11
- package/src/contexts/current-block/Provider.stories.tsx +9 -4
- package/src/contexts/in-page-gateways/Provider.tsx +4 -0
- package/src/hooks/index.ts +0 -1
- package/src/hooks/viewer/UseStepRewardWeightTest.stories.tsx +7 -6
- package/src/hooks/viewer/index.ts +0 -2
- package/src/story/GatewayDecorator.tsx +36 -0
- package/src/story/index.ts +1 -0
- package/dist/browser/hooks/useHttpRpcRunner.d.ts +0 -3
- package/dist/browser/hooks/useHttpRpcRunner.d.ts.map +0 -1
- package/dist/browser/hooks/viewer/useHttpRpcViewer.d.ts +0 -4
- package/dist/browser/hooks/viewer/useHttpRpcViewer.d.ts.map +0 -1
- package/dist/browser/hooks/viewer/useViewerFromWallet.d.ts +0 -9
- package/dist/browser/hooks/viewer/useViewerFromWallet.d.ts.map +0 -1
- package/src/hooks/useHttpRpcRunner.ts +0 -27
- package/src/hooks/viewer/useHttpRpcViewer.stories.tsx +0 -67
- package/src/hooks/viewer/useHttpRpcViewer.ts +0 -76
- package/src/hooks/viewer/useViewerFromWallet.stories.tsx +0 -75
- package/src/hooks/viewer/useViewerFromWallet.ts +0 -39
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Decorator } from '@storybook/react-vite'
|
|
2
|
+
import {
|
|
3
|
+
LocalNetwork, MainNetwork, SequenceNetwork,
|
|
4
|
+
} from '@xyo-network/xl1-sdk'
|
|
5
|
+
|
|
6
|
+
import { GatewayProvider, InPageGatewaysProvider } from '../contexts/index.ts'
|
|
7
|
+
|
|
8
|
+
export const MainnetGatewayDecorator: Decorator = (Story, ...args) => {
|
|
9
|
+
return (
|
|
10
|
+
<InPageGatewaysProvider>
|
|
11
|
+
<GatewayProvider gatewayName={MainNetwork.id}>
|
|
12
|
+
<Story {...args} />
|
|
13
|
+
</GatewayProvider>
|
|
14
|
+
</InPageGatewaysProvider>
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const SequenceGatewayDecorator: Decorator = (Story, ...args) => {
|
|
19
|
+
return (
|
|
20
|
+
<InPageGatewaysProvider>
|
|
21
|
+
<GatewayProvider gatewayName={SequenceNetwork.id}>
|
|
22
|
+
<Story {...args} />
|
|
23
|
+
</GatewayProvider>
|
|
24
|
+
</InPageGatewaysProvider>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const LocalGatewayDecorator: Decorator = (Story, ...args) => {
|
|
29
|
+
return (
|
|
30
|
+
<InPageGatewaysProvider>
|
|
31
|
+
<GatewayProvider gatewayName={LocalNetwork.id}>
|
|
32
|
+
<Story {...args} />
|
|
33
|
+
</GatewayProvider>
|
|
34
|
+
</InPageGatewaysProvider>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './GatewayDecorator.tsx'
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import type { JsonRpcXyoRunner } from '@xyo-network/xl1-sdk';
|
|
2
|
-
export declare const useHttpRpcRunner: (url?: string) => [import("@xyo-network/xl1-sdk").CreatableProviderInstance<JsonRpcXyoRunner> | undefined, Error | undefined, import("@xylabs/react-promise").UsePromiseState | undefined];
|
|
3
|
-
//# sourceMappingURL=useHttpRpcRunner.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useHttpRpcRunner.d.ts","sourceRoot":"","sources":["../../../src/hooks/useHttpRpcRunner.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EACjB,MAAM,sBAAsB,CAAA;AAM7B,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,6KAgB5C,CAAA"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { NetworkBootstrap, XyoViewer } from '@xyo-network/xl1-sdk';
|
|
2
|
-
/** @deprecated - use useViewerFromGateway */
|
|
3
|
-
export declare const useHttpRpcViewer: (urlOrNetwork?: string | NetworkBootstrap) => XyoViewer | undefined;
|
|
4
|
-
//# sourceMappingURL=useHttpRpcViewer.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useHttpRpcViewer.d.ts","sourceRoot":"","sources":["../../../../src/hooks/viewer/useHttpRpcViewer.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EACV,gBAAgB,EAEhB,SAAS,EACV,MAAM,sBAAsB,CAAA;AAiD7B,6CAA6C;AAC7C,eAAO,MAAM,gBAAgB,GAAI,eAAe,MAAM,GAAG,gBAAgB,KAAG,SAAS,GAAG,SAiBvF,CAAA"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { GatewayName } from '@xyo-network/xl1-sdk';
|
|
2
|
-
/**
|
|
3
|
-
* Creates a JsonRpcXyoViewer instance based on the provided networkId.
|
|
4
|
-
* @param networkId - a network id like 'sequence', 'local', etc.
|
|
5
|
-
* @returns An instance of XyoViewer if the networkId is found in wallet gateways
|
|
6
|
-
* otherwise undefined.
|
|
7
|
-
*/
|
|
8
|
-
export declare const useViewerFromWallet: (networkId?: GatewayName, timeout?: number) => [import("@xyo-network/xl1-sdk").XyoViewer | null | undefined, Error | undefined, import("@xylabs/react-promise").UsePromiseState | undefined];
|
|
9
|
-
//# sourceMappingURL=useViewerFromWallet.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useViewerFromWallet.d.ts","sourceRoot":"","sources":["../../../../src/hooks/viewer/useViewerFromWallet.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAA;AAIvD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAC9B,YAAY,WAAW,EACvB,UAAU,MAAM,kJAsBjB,CAAA"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { usePromise } from '@xylabs/react-promise'
|
|
2
|
-
import { isUndefined } from '@xylabs/sdk-js'
|
|
3
|
-
import type {
|
|
4
|
-
JsonRpcXyoRunner, RpcSchemaMap, TransportFactory,
|
|
5
|
-
} from '@xyo-network/xl1-sdk'
|
|
6
|
-
import {
|
|
7
|
-
AccountBalanceViewerRpcSchemas, buildJsonRpcProviderLocator, HttpRpcTransport, JsonRpcAccountBalanceViewer, SimpleTransactionViewer, XyoRunnerMoniker,
|
|
8
|
-
} from '@xyo-network/xl1-sdk'
|
|
9
|
-
|
|
10
|
-
/* @deprecated use useRunnerFromGateway */
|
|
11
|
-
export const useHttpRpcRunner = (url?: string) => {
|
|
12
|
-
return usePromise(async () => {
|
|
13
|
-
if (isUndefined(url)) {
|
|
14
|
-
return
|
|
15
|
-
}
|
|
16
|
-
const transportFactory: TransportFactory = (schemas: RpcSchemaMap) => new HttpRpcTransport(`${url}/rpc`, schemas)
|
|
17
|
-
const locator = await buildJsonRpcProviderLocator({ transportFactory })
|
|
18
|
-
|
|
19
|
-
// Additional dependencies to get working viewer
|
|
20
|
-
locator.register(SimpleTransactionViewer.factory<SimpleTransactionViewer>(SimpleTransactionViewer.dependencies, {}))
|
|
21
|
-
locator.register(JsonRpcAccountBalanceViewer.factory<JsonRpcAccountBalanceViewer>(
|
|
22
|
-
JsonRpcAccountBalanceViewer.dependencies,
|
|
23
|
-
{ transport: await transportFactory(AccountBalanceViewerRpcSchemas) },
|
|
24
|
-
))
|
|
25
|
-
return await locator.getInstance<JsonRpcXyoRunner>(XyoRunnerMoniker)
|
|
26
|
-
}, [url])
|
|
27
|
-
}
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Alert, Button, Stack,
|
|
3
|
-
} from '@mui/material'
|
|
4
|
-
import type { Meta, StoryFn } from '@storybook/react-vite'
|
|
5
|
-
import { isDefined } from '@xylabs/sdk-js'
|
|
6
|
-
import { isXyoGlobal } from '@xyo-network/react-chain-model'
|
|
7
|
-
import type { HydratedBlock } from '@xyo-network/xl1-sdk'
|
|
8
|
-
import { SequenceNetwork } from '@xyo-network/xl1-sdk'
|
|
9
|
-
import React, { useState } from 'react'
|
|
10
|
-
|
|
11
|
-
import { useHttpRpcViewer } from './useHttpRpcViewer.ts'
|
|
12
|
-
|
|
13
|
-
const hasXyoGlobal = isXyoGlobal(globalThis.xyo)
|
|
14
|
-
const inIframe = globalThis.self !== window.top
|
|
15
|
-
|
|
16
|
-
const UseHttpRpcViewerStoryTemplate: React.FC = () => {
|
|
17
|
-
const viewer = useHttpRpcViewer(SequenceNetwork.url)
|
|
18
|
-
const [error, setError] = useState<Error | null>(null)
|
|
19
|
-
const [result, setResult] = useState<HydratedBlock | null | undefined>()
|
|
20
|
-
|
|
21
|
-
const handleClick = async () => {
|
|
22
|
-
if (isDefined(viewer)) {
|
|
23
|
-
try {
|
|
24
|
-
const block = await viewer.currentBlock()
|
|
25
|
-
setError(null)
|
|
26
|
-
setResult(block)
|
|
27
|
-
} catch (err) {
|
|
28
|
-
setError(err as Error)
|
|
29
|
-
setResult(undefined)
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return (
|
|
35
|
-
<Stack gap={2} alignItems="center">
|
|
36
|
-
{inIframe
|
|
37
|
-
? (
|
|
38
|
-
<Alert severity="warning">
|
|
39
|
-
This story is running in an iframe. Please run it in a standalone browser window to test the wallet extension.
|
|
40
|
-
</Alert>
|
|
41
|
-
)
|
|
42
|
-
: null}
|
|
43
|
-
<Alert severity="info">
|
|
44
|
-
{hasXyoGlobal ? 'Wallet extension found. Using it for viewer.' : 'No wallet extension found. Falling back to the default viewer.'}
|
|
45
|
-
</Alert>
|
|
46
|
-
<Button variant="contained" onClick={() => void handleClick()} disabled={!isDefined(viewer)}>
|
|
47
|
-
Get Current Block
|
|
48
|
-
</Button>
|
|
49
|
-
<pre>
|
|
50
|
-
{JSON.stringify(result, null, 2)}
|
|
51
|
-
</pre>
|
|
52
|
-
{error ? <Alert severity="error">{error.message}</Alert> : null}
|
|
53
|
-
</Stack>
|
|
54
|
-
)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export default {
|
|
58
|
-
title: 'provider/useHttpRpcViewer',
|
|
59
|
-
component: UseHttpRpcViewerStoryTemplate,
|
|
60
|
-
} as Meta
|
|
61
|
-
|
|
62
|
-
export const Template: StoryFn<typeof UseHttpRpcViewerStoryTemplate> = args => <UseHttpRpcViewerStoryTemplate {...args} />
|
|
63
|
-
|
|
64
|
-
const Default = Template.bind({})
|
|
65
|
-
Default.args = {}
|
|
66
|
-
|
|
67
|
-
export { Default }
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { usePromise } from '@xylabs/react-promise'
|
|
2
|
-
import {
|
|
3
|
-
isDefined, isString, isUndefined,
|
|
4
|
-
} from '@xylabs/sdk-js'
|
|
5
|
-
import type {
|
|
6
|
-
NetworkBootstrap, RestDataLakeViewerParams, RpcSchemaMap,
|
|
7
|
-
TransportFactory,
|
|
8
|
-
XyoViewer,
|
|
9
|
-
} from '@xyo-network/xl1-sdk'
|
|
10
|
-
import {
|
|
11
|
-
AccountBalanceViewerRpcSchemas,
|
|
12
|
-
buildJsonRpcProviderLocator, HttpRpcTransport, JsonRpcAccountBalanceViewer,
|
|
13
|
-
JsonRpcXyoViewer, NetworkDataLakeUrls, RestDataLakeViewer, SimpleTransactionViewer, XyoViewerMoniker, XyoViewerRpcSchemas,
|
|
14
|
-
} from '@xyo-network/xl1-sdk'
|
|
15
|
-
|
|
16
|
-
import { ViewerWithDataLake } from './ViewerWithDataLake.ts'
|
|
17
|
-
|
|
18
|
-
const buildLocatorParams = (urlOrNetwork: string | NetworkBootstrap) => {
|
|
19
|
-
// conditionally build params for transport factory and datalake viewer based on if urlOrNetwork is a string or NetworkBootstrap
|
|
20
|
-
let transportFactory: TransportFactory
|
|
21
|
-
let dataLakeViewerParams: { endpoint: string } | undefined
|
|
22
|
-
if (isString(urlOrNetwork)) {
|
|
23
|
-
const url = urlOrNetwork
|
|
24
|
-
transportFactory = (schemas: RpcSchemaMap) => new HttpRpcTransport(`${url}/rpc`, schemas)
|
|
25
|
-
} else {
|
|
26
|
-
transportFactory = (schemas: RpcSchemaMap) => new HttpRpcTransport(`${urlOrNetwork.url}/rpc`, schemas)
|
|
27
|
-
dataLakeViewerParams = { endpoint: NetworkDataLakeUrls[urlOrNetwork.id] }
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return { transportFactory, dataLakeViewerParams }
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const buildLocator = async (transportFactory: TransportFactory, dataLakeViewerParams: { endpoint: string } | undefined) => {
|
|
34
|
-
// build locator with transport factory
|
|
35
|
-
const locator = await buildJsonRpcProviderLocator({ transportFactory })
|
|
36
|
-
|
|
37
|
-
locator.register(JsonRpcAccountBalanceViewer.factory<JsonRpcAccountBalanceViewer>(
|
|
38
|
-
JsonRpcAccountBalanceViewer.dependencies,
|
|
39
|
-
{ transport: await transportFactory(AccountBalanceViewerRpcSchemas) },
|
|
40
|
-
))
|
|
41
|
-
locator.register(SimpleTransactionViewer.factory<SimpleTransactionViewer>(SimpleTransactionViewer.dependencies, {}))
|
|
42
|
-
|
|
43
|
-
// If the network has a datalake endpoint, register the RestDataLakeViewer with the locator
|
|
44
|
-
if (isDefined(dataLakeViewerParams)) {
|
|
45
|
-
locator.register(
|
|
46
|
-
RestDataLakeViewer.factory<RestDataLakeViewer>(RestDataLakeViewer.dependencies, dataLakeViewerParams as RestDataLakeViewerParams),
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
// register the viewer with data lake as the JsonRpcXyoViewer
|
|
51
|
-
locator.register(
|
|
52
|
-
ViewerWithDataLake.factory<JsonRpcXyoViewer>(JsonRpcXyoViewer.dependencies, { transport: await transportFactory(XyoViewerRpcSchemas) }),
|
|
53
|
-
)
|
|
54
|
-
|
|
55
|
-
return locator
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/** @deprecated - use useViewerFromGateway */
|
|
59
|
-
export const useHttpRpcViewer = (urlOrNetwork?: string | NetworkBootstrap): XyoViewer | undefined => {
|
|
60
|
-
const [resolvedViewer] = usePromise(async () => {
|
|
61
|
-
if (isUndefined(urlOrNetwork)) {
|
|
62
|
-
return
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// conditionally build params for transport factory and datalake viewer based on if urlOrNetwork is a string or NetworkBootstrap
|
|
66
|
-
const { transportFactory, dataLakeViewerParams } = buildLocatorParams(urlOrNetwork)
|
|
67
|
-
|
|
68
|
-
// get and return the viewer from the locator
|
|
69
|
-
const locator = await buildLocator(transportFactory, dataLakeViewerParams)
|
|
70
|
-
|
|
71
|
-
// return viewer instance from locator
|
|
72
|
-
return await locator.getInstance<JsonRpcXyoViewer>(XyoViewerMoniker)
|
|
73
|
-
}, [urlOrNetwork])
|
|
74
|
-
|
|
75
|
-
return resolvedViewer as XyoViewer | undefined
|
|
76
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { Alert, Stack } from '@mui/material'
|
|
2
|
-
import type { StoryFn } from '@storybook/react-vite'
|
|
3
|
-
import { ButtonEx } from '@xylabs/react-button'
|
|
4
|
-
import { isDefined, isDefinedNotNull } from '@xylabs/sdk-js'
|
|
5
|
-
import { isXyoGlobal } from '@xyo-network/react-chain-model'
|
|
6
|
-
import type { HydratedBlock } from '@xyo-network/xl1-sdk'
|
|
7
|
-
import { MainNetwork } from '@xyo-network/xl1-sdk'
|
|
8
|
-
import React, { useState } from 'react'
|
|
9
|
-
|
|
10
|
-
import { useViewerFromWallet } from './useViewerFromWallet.ts'
|
|
11
|
-
|
|
12
|
-
const hasXyoGlobal = isXyoGlobal(globalThis.xyo)
|
|
13
|
-
const inIframe = globalThis.self !== window.top
|
|
14
|
-
|
|
15
|
-
const UseViewerFromWalletStoryTemplate: React.FC = () => {
|
|
16
|
-
const defaultDestination = MainNetwork.id
|
|
17
|
-
const [viewer] = useViewerFromWallet(defaultDestination)
|
|
18
|
-
const [error, setError] = useState<Error | null>(null)
|
|
19
|
-
const [result, setResult] = useState<HydratedBlock | null | undefined>()
|
|
20
|
-
const [loading, setLoading] = useState(false)
|
|
21
|
-
|
|
22
|
-
const handleClick = async () => {
|
|
23
|
-
if (isDefinedNotNull(viewer)) {
|
|
24
|
-
try {
|
|
25
|
-
setLoading(true)
|
|
26
|
-
const block = await viewer.currentBlock()
|
|
27
|
-
setError(null)
|
|
28
|
-
setResult(block)
|
|
29
|
-
setLoading(false)
|
|
30
|
-
} catch (err) {
|
|
31
|
-
setError(err as Error)
|
|
32
|
-
setResult(undefined)
|
|
33
|
-
setLoading(false)
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return (
|
|
39
|
-
<Stack gap={2} alignItems="center">
|
|
40
|
-
{inIframe
|
|
41
|
-
? (
|
|
42
|
-
<Alert severity="warning">
|
|
43
|
-
This story is running in an iframe. Please run it in a standalone browser window to test the wallet extension.
|
|
44
|
-
</Alert>
|
|
45
|
-
)
|
|
46
|
-
: null}
|
|
47
|
-
{hasXyoGlobal
|
|
48
|
-
? null
|
|
49
|
-
: (
|
|
50
|
-
<Alert severity="warning">
|
|
51
|
-
No wallet extension found. Please install the Xyo Wallet Chrome Extension.
|
|
52
|
-
</Alert>
|
|
53
|
-
)}
|
|
54
|
-
<ButtonEx loading={loading} variant="contained" onClick={() => void handleClick()} disabled={!isDefined(viewer)}>
|
|
55
|
-
Get Current Block
|
|
56
|
-
</ButtonEx>
|
|
57
|
-
<pre>
|
|
58
|
-
{JSON.stringify(result, null, 2)}
|
|
59
|
-
</pre>
|
|
60
|
-
{error ? <Alert severity="error">{error.message}</Alert> : null}
|
|
61
|
-
</Stack>
|
|
62
|
-
)
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export default {
|
|
66
|
-
title: 'provider/useViewerFromWallet',
|
|
67
|
-
component: UseViewerFromWalletStoryTemplate,
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export const Template: StoryFn<typeof UseViewerFromWalletStoryTemplate> = args => <UseViewerFromWalletStoryTemplate {...args} />
|
|
71
|
-
|
|
72
|
-
const Default = Template.bind({})
|
|
73
|
-
Default.args = {}
|
|
74
|
-
|
|
75
|
-
export { Default }
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { usePromise } from '@xylabs/react-promise'
|
|
2
|
-
import {
|
|
3
|
-
isDefined, isDefinedNotNull, isNull,
|
|
4
|
-
} from '@xylabs/sdk-js'
|
|
5
|
-
import type { GatewayName } from '@xyo-network/xl1-sdk'
|
|
6
|
-
|
|
7
|
-
import { useGatewayFromWallet } from '../client/index.ts'
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Creates a JsonRpcXyoViewer instance based on the provided networkId.
|
|
11
|
-
* @param networkId - a network id like 'sequence', 'local', etc.
|
|
12
|
-
* @returns An instance of XyoViewer if the networkId is found in wallet gateways
|
|
13
|
-
* otherwise undefined.
|
|
14
|
-
*/
|
|
15
|
-
export const useViewerFromWallet = (
|
|
16
|
-
networkId?: GatewayName,
|
|
17
|
-
timeout?: number,
|
|
18
|
-
) => {
|
|
19
|
-
const {
|
|
20
|
-
gateway, error, isLoading, timedout,
|
|
21
|
-
} = useGatewayFromWallet(networkId, timeout)
|
|
22
|
-
|
|
23
|
-
const result = usePromise(async () => {
|
|
24
|
-
await Promise.resolve() // ensure async
|
|
25
|
-
// if there is an error, bail early and return null
|
|
26
|
-
if (isDefinedNotNull(error)) return null
|
|
27
|
-
// if the request timed out and there is no gateway, return null
|
|
28
|
-
if (timedout && isNull(gateway)) return null
|
|
29
|
-
// if the check is still loading, return undefined
|
|
30
|
-
if (isLoading) return
|
|
31
|
-
// if the gateway was found and networkId passed, return the viewer from the gateway
|
|
32
|
-
if (isDefined(gateway) && isDefined(networkId)) {
|
|
33
|
-
const connection = gateway?.connection
|
|
34
|
-
return connection?.viewer
|
|
35
|
-
}
|
|
36
|
-
}, [gateway, networkId, timeout])
|
|
37
|
-
|
|
38
|
-
return result
|
|
39
|
-
}
|