@xyo-network/react-chain-provider 1.6.3 → 1.6.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/index.mjs
CHANGED
|
@@ -73,10 +73,10 @@ import { useMemo as useMemo3 } from "react";
|
|
|
73
73
|
import { isDefined, isTruthy, isUndefined as isUndefined2 } from "@xylabs/typeof";
|
|
74
74
|
import { JsonRpcXyoViewer, PostMessageRpcTransport } from "@xyo-network/xl1-rpc";
|
|
75
75
|
import { useMemo as useMemo2 } from "react";
|
|
76
|
-
var walletConnections = globalThis.xyo?.connections;
|
|
76
|
+
var walletConnections = /* @__PURE__ */ __name(() => globalThis.xyo?.connections, "walletConnections");
|
|
77
77
|
var useHostViewerBase = /* @__PURE__ */ __name((networkId) => {
|
|
78
78
|
const networkConnection = useMemo2(() => {
|
|
79
|
-
if (isTruthy(networkId) && isDefined(walletConnections) && isDefined(walletConnections[networkId])) {
|
|
79
|
+
if (isTruthy(networkId) && isDefined(walletConnections()) && isDefined(walletConnections()?.[networkId])) {
|
|
80
80
|
return networkId;
|
|
81
81
|
}
|
|
82
82
|
}, [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/hooks/useAddressBalance.ts","../../src/hooks/useCurrentBlock.ts","../../src/hooks/useViewer.ts","../../src/hooks/useHostViewer.ts","../../src/hooks/useNetwork.ts","../../src/hooks/useRunner.ts","../../src/hooks/useSigner.ts"],"sourcesContent":["import type { Address } from '@xylabs/hex'\nimport { usePromise } from '@xylabs/react-promise'\nimport { isUndefined, isUndefinedOrNull } from '@xylabs/typeof'\nimport { ShiftedBigInt } from '@xyo-network/chain-wrappers'\nimport type {\n AttoXL1, NetworkId, XyoViewer,\n} from '@xyo-network/xl1-protocol'\nimport { useMemo, useState } from 'react'\n\nexport const useAddressBalance = (\n // address to get balance for\n address?: Address,\n // viewer to use for fetching balance\n viewer?: XyoViewer,\n // network ID to trigger a balance refresh\n networkId?: NetworkId,\n // refresh balance trigger\n refresh?: number,\n) => {\n const [balancesResult, setBalancesResult] = useState<AttoXL1 | null>()\n const [loading, setLoading] = useState(false)\n\n const [, balancesError] = usePromise(async () => {\n if (isUndefined(viewer) || isUndefined(address)) return\n setLoading(true)\n setBalancesResult(undefined)\n const balance = await viewer.accountBalance(address)\n setBalancesResult(balance as AttoXL1)\n setLoading(false)\n }, [address, viewer, networkId, refresh])\n\n useMemo(() => {\n if (balancesError) {\n setLoading(false)\n }\n }, [balancesError])\n\n const shiftedBigInt = useMemo(() => {\n if (typeof balancesResult !== 'bigint') return\n return new ShiftedBigInt(balancesResult, {\n places: 18, maxDecimal: 18, maxCharacters: 9, minDecimals: 1, locale: navigator.language,\n })\n }, [balancesResult])\n\n const balanceIntlFriendly = useMemo(() => {\n return shiftedBigInt?.toFullString()\n }, [shiftedBigInt])\n\n const shortBalanceIntlFriendly = useMemo(() => {\n return isUndefinedOrNull(balancesResult)\n ? undefined\n : (balancesResult < 1_000_000_000_000n && balancesResult > 0n) ? '<0.00001' : shiftedBigInt?.toShortString()\n }, [shiftedBigInt])\n\n return {\n address,\n balanceForAddress: balancesResult,\n balanceIntlFriendly,\n shortBalanceIntlFriendly,\n error: balancesError,\n loading,\n }\n}\n","import { usePromise } from '@xylabs/react-promise'\n\nimport { useViewerBase } from './useViewer.ts'\n\nexport const useCurrentBlockBase = (refresh = 1, id?: string, url?: string) => {\n const viewer = useViewerBase(id, url)\n return usePromise(async () => {\n if (viewer && refresh > 0) {\n const block = await viewer.currentBlock()\n return block\n }\n }, [viewer, refresh])\n}\n\n/** @deprecated - use useCurrentBlockBase instead but note this hook no longer relies on useChainNetwork */\nexport const useCurrentBlock = useCurrentBlockBase\n","import { isDefined, isUndefined } from '@xylabs/typeof'\nimport {\n AllRpcSchemas, HttpRpcTransport, JsonRpcXyoViewer,\n} from '@xyo-network/xl1-rpc'\nimport { useMemo } from 'react'\n\nimport { useHostViewerBase } from './useHostViewer.ts'\n\nexport const useViewerBase = (id?: string, url?: string) => {\n const hostViewer = useHostViewerBase(id)\n\n const resolvedViewer = useMemo(() => {\n if (isUndefined(url)) {\n return\n }\n if (isDefined(hostViewer)) {\n console.debug('Using host viewer:', hostViewer)\n return hostViewer\n }\n const transport = new HttpRpcTransport(`${url}/rpc`, AllRpcSchemas)\n return new JsonRpcXyoViewer(transport)\n }, [url, hostViewer])\n\n return resolvedViewer\n}\n\n/** @deprecated - use useViewerBase instead but note this hook no longer relies on useChainNetwork */\nexport const useViewer = useViewerBase\n","import {\n isDefined, isTruthy, isUndefined,\n} from '@xylabs/typeof'\nimport {\n JsonRpcXyoViewer,\n PostMessageRpcTransport,\n} from '@xyo-network/xl1-rpc'\nimport { useMemo } from 'react'\n\n// Get known wallet connections from the global Xyo object\nconst walletConnections = globalThis.xyo?.connections\n\n/**\n * Creates a JsonRpcXyoViewer instance based on the provided networkId.\n * @param networkId - a network id like 'sequence', 'local', etc.\n * @returns An instance of JsonRpcXyoViewer if the networkId is found in walletConnections,\n * otherwise undefined.\n */\nexport const useHostViewerBase = (networkId?: string) => {\n const networkConnection = useMemo(() => {\n if (isTruthy(networkId) && isDefined(walletConnections) && isDefined(walletConnections[networkId])) {\n return networkId\n }\n }, [networkId])\n\n const rpcProvider = useMemo(() => {\n if (isUndefined(networkConnection)) return\n const transport = new PostMessageRpcTransport(networkConnection)\n return new JsonRpcXyoViewer(transport)\n }, [networkConnection])\n\n return rpcProvider\n}\n\n/**\n * @deprecated - use useHostViewerBase instead but note this hook no longer relies on useChainNetwork\n */\nexport const useHostViewer = useHostViewerBase\n","import { isUndefined } from '@xylabs/typeof'\nimport type { DefaultNetworkIds } from '@xyo-network/xl1-protocol'\nimport { MemoryXyoNetwork } from '@xyo-network/xl1-rpc'\nimport { useMemo } from 'react'\n\nexport const useNetworkBase = (id?: DefaultNetworkIds) => {\n const network = useMemo(() => {\n if (isUndefined(id)) return\n return new MemoryXyoNetwork(id)\n }, [id])\n\n return network\n}\n\n/**\n * @deprecated - use useNetworkBase instead but note this hook no longer relies on useChainNetwork\n */\nexport const useNetwork = useNetworkBase\n","import { isUndefined } from '@xylabs/typeof'\nimport {\n AllRpcSchemas, HttpRpcTransport, JsonRpcXyoRunner,\n} from '@xyo-network/xl1-rpc'\nimport { useMemo } from 'react'\n\nexport const useRunnerBase = (url?: string) => {\n return useMemo(() => {\n if (isUndefined(url)) {\n return\n }\n const transport = new HttpRpcTransport(`${url}/rpc`, AllRpcSchemas)\n return new JsonRpcXyoRunner(transport)\n }, [url])\n}\n\n/** @deprecated - use useRunnerBase instead but note this hook no longer relies on useChainNetwork */\nexport const useRunner = useRunnerBase\n","import type { AccountInstance } from '@xyo-network/account-model'\nimport type { XyoProvider, XyoSigner } from '@xyo-network/xl1-protocol'\nimport { MemoryXyoSigner } from '@xyo-network/xl1-rpc'\nimport { useMemo } from 'react'\n\nexport const useSigner = (_provider?: XyoProvider, account?: AccountInstance) => {\n return useMemo<XyoSigner | undefined>(() => account ? new MemoryXyoSigner(account) : undefined, [account])\n}\n"],"mappings":";;;;AACA,SAASA,kBAAkB;AAC3B,SAASC,aAAaC,yBAAyB;AAC/C,SAASC,qBAAqB;AAI9B,SAASC,SAASC,gBAAgB;AAE3B,IAAMC,oBAAoB,wBAE/BC,SAEAC,QAEAC,WAEAC,YAAAA;AAEA,QAAM,CAACC,gBAAgBC,iBAAAA,IAAqBC,SAAAA;AAC5C,QAAM,CAACC,SAASC,UAAAA,IAAcF,SAAS,KAAA;AAEvC,QAAM,CAAA,EAAGG,aAAAA,IAAiBC,WAAW,YAAA;AACnC,QAAIC,YAAYV,MAAAA,KAAWU,YAAYX,OAAAA,EAAU;AACjDQ,eAAW,IAAA;AACXH,sBAAkBO,MAAAA;AAClB,UAAMC,UAAU,MAAMZ,OAAOa,eAAed,OAAAA;AAC5CK,sBAAkBQ,OAAAA;AAClBL,eAAW,KAAA;EACb,GAAG;IAACR;IAASC;IAAQC;IAAWC;GAAQ;AAExCY,UAAQ,MAAA;AACN,QAAIN,eAAe;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EjB,IAAMC,gBAAgB,wBAACC,QAAAA;AAC5B,SAAOC,SAAQ,MAAA;AACb,QAAIC,aAAYF,GAAAA,GAAM;AACpB;IACF;AACA,UAAMG,YAAY,IAAIC,kBAAiB,GAAGJ,GAAAA,QAAWK,cAAAA;AACrD,WAAO,IAAIC,iBAAiBH,SAAAA;EAC9B,GAAG;IAACH;GAAI;AACV,GAR6B;AAWtB,IAAMO,YAAYR;;;ACfzB,SAASS,uBAAuB;AAChC,SAASC,WAAAA,gBAAe;AAEjB,IAAMC,YAAY,wBAACC,WAAyBC,YAAAA;AACjD,SAAOC,SAA+B,MAAMD,UAAU,IAAIE,gBAAgBF,OAAAA,IAAWG,QAAW;IAACH;GAAQ;AAC3G,GAFyB;","names":["usePromise","isUndefined","isUndefinedOrNull","ShiftedBigInt","useMemo","useState","useAddressBalance","address","viewer","networkId","refresh","balancesResult","setBalancesResult","useState","loading","setLoading","balancesError","usePromise","isUndefined","undefined","balance","accountBalance","useMemo","shiftedBigInt","ShiftedBigInt","places","maxDecimal","maxCharacters","minDecimals","locale","navigator","language","balanceIntlFriendly","toFullString","shortBalanceIntlFriendly","isUndefinedOrNull","toShortString","balanceForAddress","error","usePromise","isDefined","isUndefined","AllRpcSchemas","HttpRpcTransport","JsonRpcXyoViewer","useMemo","isDefined","isTruthy","isUndefined","JsonRpcXyoViewer","PostMessageRpcTransport","useMemo","walletConnections","globalThis","xyo","connections","useHostViewerBase","networkId","networkConnection","useMemo","isTruthy","isDefined","rpcProvider","isUndefined","transport","PostMessageRpcTransport","JsonRpcXyoViewer","useHostViewer","useViewerBase","id","url","hostViewer","useHostViewerBase","resolvedViewer","useMemo","isUndefined","isDefined","console","debug","transport","HttpRpcTransport","AllRpcSchemas","JsonRpcXyoViewer","useViewer","useCurrentBlockBase","refresh","id","url","viewer","useViewerBase","usePromise","block","currentBlock","useCurrentBlock","isUndefined","MemoryXyoNetwork","useMemo","useNetworkBase","id","network","useMemo","isUndefined","MemoryXyoNetwork","useNetwork","isUndefined","AllRpcSchemas","HttpRpcTransport","JsonRpcXyoRunner","useMemo","useRunnerBase","url","useMemo","isUndefined","transport","HttpRpcTransport","AllRpcSchemas","JsonRpcXyoRunner","useRunner","MemoryXyoSigner","useMemo","useSigner","_provider","account","useMemo","MemoryXyoSigner","undefined"]}
|
|
1
|
+
{"version":3,"sources":["../../src/hooks/useAddressBalance.ts","../../src/hooks/useCurrentBlock.ts","../../src/hooks/useViewer.ts","../../src/hooks/useHostViewer.ts","../../src/hooks/useNetwork.ts","../../src/hooks/useRunner.ts","../../src/hooks/useSigner.ts"],"sourcesContent":["import type { Address } from '@xylabs/hex'\nimport { usePromise } from '@xylabs/react-promise'\nimport { isUndefined, isUndefinedOrNull } from '@xylabs/typeof'\nimport { ShiftedBigInt } from '@xyo-network/chain-wrappers'\nimport type {\n AttoXL1, NetworkId, XyoViewer,\n} from '@xyo-network/xl1-protocol'\nimport { useMemo, useState } from 'react'\n\nexport const useAddressBalance = (\n // address to get balance for\n address?: Address,\n // viewer to use for fetching balance\n viewer?: XyoViewer,\n // network ID to trigger a balance refresh\n networkId?: NetworkId,\n // refresh balance trigger\n refresh?: number,\n) => {\n const [balancesResult, setBalancesResult] = useState<AttoXL1 | null>()\n const [loading, setLoading] = useState(false)\n\n const [, balancesError] = usePromise(async () => {\n if (isUndefined(viewer) || isUndefined(address)) return\n setLoading(true)\n setBalancesResult(undefined)\n const balance = await viewer.accountBalance(address)\n setBalancesResult(balance as AttoXL1)\n setLoading(false)\n }, [address, viewer, networkId, refresh])\n\n useMemo(() => {\n if (balancesError) {\n setLoading(false)\n }\n }, [balancesError])\n\n const shiftedBigInt = useMemo(() => {\n if (typeof balancesResult !== 'bigint') return\n return new ShiftedBigInt(balancesResult, {\n places: 18, maxDecimal: 18, maxCharacters: 9, minDecimals: 1, locale: navigator.language,\n })\n }, [balancesResult])\n\n const balanceIntlFriendly = useMemo(() => {\n return shiftedBigInt?.toFullString()\n }, [shiftedBigInt])\n\n const shortBalanceIntlFriendly = useMemo(() => {\n return isUndefinedOrNull(balancesResult)\n ? undefined\n : (balancesResult < 1_000_000_000_000n && balancesResult > 0n) ? '<0.00001' : shiftedBigInt?.toShortString()\n }, [shiftedBigInt])\n\n return {\n address,\n balanceForAddress: balancesResult,\n balanceIntlFriendly,\n shortBalanceIntlFriendly,\n error: balancesError,\n loading,\n }\n}\n","import { usePromise } from '@xylabs/react-promise'\n\nimport { useViewerBase } from './useViewer.ts'\n\nexport const useCurrentBlockBase = (refresh = 1, id?: string, url?: string) => {\n const viewer = useViewerBase(id, url)\n return usePromise(async () => {\n if (viewer && refresh > 0) {\n const block = await viewer.currentBlock()\n return block\n }\n }, [viewer, refresh])\n}\n\n/** @deprecated - use useCurrentBlockBase instead but note this hook no longer relies on useChainNetwork */\nexport const useCurrentBlock = useCurrentBlockBase\n","import { isDefined, isUndefined } from '@xylabs/typeof'\nimport {\n AllRpcSchemas, HttpRpcTransport, JsonRpcXyoViewer,\n} from '@xyo-network/xl1-rpc'\nimport { useMemo } from 'react'\n\nimport { useHostViewerBase } from './useHostViewer.ts'\n\nexport const useViewerBase = (id?: string, url?: string) => {\n const hostViewer = useHostViewerBase(id)\n\n const resolvedViewer = useMemo(() => {\n if (isUndefined(url)) {\n return\n }\n if (isDefined(hostViewer)) {\n console.debug('Using host viewer:', hostViewer)\n return hostViewer\n }\n const transport = new HttpRpcTransport(`${url}/rpc`, AllRpcSchemas)\n return new JsonRpcXyoViewer(transport)\n }, [url, hostViewer])\n\n return resolvedViewer\n}\n\n/** @deprecated - use useViewerBase instead but note this hook no longer relies on useChainNetwork */\nexport const useViewer = useViewerBase\n","import {\n isDefined, isTruthy, isUndefined,\n} from '@xylabs/typeof'\nimport {\n JsonRpcXyoViewer,\n PostMessageRpcTransport,\n} from '@xyo-network/xl1-rpc'\nimport { useMemo } from 'react'\n\n// Get known wallet connections from the global Xyo object\nconst walletConnections = () => globalThis.xyo?.connections\n\n/**\n * Creates a JsonRpcXyoViewer instance based on the provided networkId.\n * @param networkId - a network id like 'sequence', 'local', etc.\n * @returns An instance of JsonRpcXyoViewer if the networkId is found in walletConnections,\n * otherwise undefined.\n */\nexport const useHostViewerBase = (networkId?: string) => {\n const networkConnection = useMemo(() => {\n if (isTruthy(networkId) && isDefined(walletConnections()) && isDefined(walletConnections()?.[networkId])) {\n return networkId\n }\n }, [networkId])\n\n const rpcProvider = useMemo(() => {\n if (isUndefined(networkConnection)) return\n const transport = new PostMessageRpcTransport(networkConnection)\n return new JsonRpcXyoViewer(transport)\n }, [networkConnection])\n\n return rpcProvider\n}\n\n/**\n * @deprecated - use useHostViewerBase instead but note this hook no longer relies on useChainNetwork\n */\nexport const useHostViewer = useHostViewerBase\n","import { isUndefined } from '@xylabs/typeof'\nimport type { DefaultNetworkIds } from '@xyo-network/xl1-protocol'\nimport { MemoryXyoNetwork } from '@xyo-network/xl1-rpc'\nimport { useMemo } from 'react'\n\nexport const useNetworkBase = (id?: DefaultNetworkIds) => {\n const network = useMemo(() => {\n if (isUndefined(id)) return\n return new MemoryXyoNetwork(id)\n }, [id])\n\n return network\n}\n\n/**\n * @deprecated - use useNetworkBase instead but note this hook no longer relies on useChainNetwork\n */\nexport const useNetwork = useNetworkBase\n","import { isUndefined } from '@xylabs/typeof'\nimport {\n AllRpcSchemas, HttpRpcTransport, JsonRpcXyoRunner,\n} from '@xyo-network/xl1-rpc'\nimport { useMemo } from 'react'\n\nexport const useRunnerBase = (url?: string) => {\n return useMemo(() => {\n if (isUndefined(url)) {\n return\n }\n const transport = new HttpRpcTransport(`${url}/rpc`, AllRpcSchemas)\n return new JsonRpcXyoRunner(transport)\n }, [url])\n}\n\n/** @deprecated - use useRunnerBase instead but note this hook no longer relies on useChainNetwork */\nexport const useRunner = useRunnerBase\n","import type { AccountInstance } from '@xyo-network/account-model'\nimport type { XyoProvider, XyoSigner } from '@xyo-network/xl1-protocol'\nimport { MemoryXyoSigner } from '@xyo-network/xl1-rpc'\nimport { useMemo } from 'react'\n\nexport const useSigner = (_provider?: XyoProvider, account?: AccountInstance) => {\n return useMemo<XyoSigner | undefined>(() => account ? new MemoryXyoSigner(account) : undefined, [account])\n}\n"],"mappings":";;;;AACA,SAASA,kBAAkB;AAC3B,SAASC,aAAaC,yBAAyB;AAC/C,SAASC,qBAAqB;AAI9B,SAASC,SAASC,gBAAgB;AAE3B,IAAMC,oBAAoB,wBAE/BC,SAEAC,QAEAC,WAEAC,YAAAA;AAEA,QAAM,CAACC,gBAAgBC,iBAAAA,IAAqBC,SAAAA;AAC5C,QAAM,CAACC,SAASC,UAAAA,IAAcF,SAAS,KAAA;AAEvC,QAAM,CAAA,EAAGG,aAAAA,IAAiBC,WAAW,YAAA;AACnC,QAAIC,YAAYV,MAAAA,KAAWU,YAAYX,OAAAA,EAAU;AACjDQ,eAAW,IAAA;AACXH,sBAAkBO,MAAAA;AAClB,UAAMC,UAAU,MAAMZ,OAAOa,eAAed,OAAAA;AAC5CK,sBAAkBQ,OAAAA;AAClBL,eAAW,KAAA;EACb,GAAG;IAACR;IAASC;IAAQC;IAAWC;GAAQ;AAExCY,UAAQ,MAAA;AACN,QAAIN,eAAe;AACjBD,iBAAW,KAAA;IACb;EACF,GAAG;IAACC;GAAc;AAElB,QAAMO,gBAAgBD,QAAQ,MAAA;AAC5B,QAAI,OAAOX,mBAAmB,SAAU;AACxC,WAAO,IAAIa,cAAcb,gBAAgB;MACvCc,QAAQ;MAAIC,YAAY;MAAIC,eAAe;MAAGC,aAAa;MAAGC,QAAQC,UAAUC;IAClF,CAAA;EACF,GAAG;IAACpB;GAAe;AAEnB,QAAMqB,sBAAsBV,QAAQ,MAAA;AAClC,WAAOC,eAAeU,aAAAA;EACxB,GAAG;IAACV;GAAc;AAElB,QAAMW,2BAA2BZ,QAAQ,MAAA;AACvC,WAAOa,kBAAkBxB,cAAAA,IACrBQ,SACCR,iBAAiB,kBAAsBA,iBAAiB,KAAM,aAAaY,eAAea,cAAAA;EACjG,GAAG;IAACb;GAAc;AAElB,SAAO;IACLhB;IACA8B,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ressBalance","address","viewer","networkId","refresh","balancesResult","setBalancesResult","useState","loading","setLoading","balancesError","usePromise","isUndefined","undefined","balance","accountBalance","useMemo","shiftedBigInt","ShiftedBigInt","places","maxDecimal","maxCharacters","minDecimals","locale","navigator","language","balanceIntlFriendly","toFullString","shortBalanceIntlFriendly","isUndefinedOrNull","toShortString","balanceForAddress","error","usePromise","isDefined","isUndefined","AllRpcSchemas","HttpRpcTransport","JsonRpcXyoViewer","useMemo","isDefined","isTruthy","isUndefined","JsonRpcXyoViewer","PostMessageRpcTransport","useMemo","walletConnections","globalThis","xyo","connections","useHostViewerBase","networkId","networkConnection","useMemo","isTruthy","isDefined","rpcProvider","isUndefined","transport","PostMessageRpcTransport","JsonRpcXyoViewer","useHostViewer","useViewerBase","id","url","hostViewer","useHostViewerBase","resolvedViewer","useMemo","isUndefined","isDefined","console","debug","transport","HttpRpcTransport","AllRpcSchemas","JsonRpcXyoViewer","useViewer","useCurrentBlockBase","refresh","id","url","viewer","useViewerBase","usePromise","block","currentBlock","useCurrentBlock","isUndefined","MemoryXyoNetwork","useMemo","useNetworkBase","id","network","useMemo","isUndefined","MemoryXyoNetwork","useNetwork","isUndefined","AllRpcSchemas","HttpRpcTransport","JsonRpcXyoRunner","useMemo","useRunnerBase","url","useMemo","isUndefined","transport","HttpRpcTransport","AllRpcSchemas","JsonRpcXyoRunner","useRunner","MemoryXyoSigner","useMemo","useSigner","_provider","account","useMemo","MemoryXyoSigner","undefined"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"$schema": "http://json.schemastore.org/package.json",
|
|
3
3
|
"name": "@xyo-network/react-chain-provider",
|
|
4
|
-
"version": "1.6.
|
|
4
|
+
"version": "1.6.5",
|
|
5
5
|
"description": "XYO Layer One API",
|
|
6
6
|
"homepage": "https://xylabs.com",
|
|
7
7
|
"bugs": {
|
|
@@ -38,9 +38,9 @@
|
|
|
38
38
|
"@xylabs/react-promise": "^6.3.7",
|
|
39
39
|
"@xylabs/typeof": "^4.12.44",
|
|
40
40
|
"@xyo-network/account-model": "^4.0.2",
|
|
41
|
-
"@xyo-network/chain-wrappers": "^1.6.
|
|
41
|
+
"@xyo-network/chain-wrappers": "^1.6.5",
|
|
42
42
|
"@xyo-network/xl1-protocol": "^1.6.1",
|
|
43
|
-
"@xyo-network/xl1-rpc": "^1.6.
|
|
43
|
+
"@xyo-network/xl1-rpc": "^1.6.5",
|
|
44
44
|
"react": "^19.1.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
@@ -51,8 +51,8 @@
|
|
|
51
51
|
"@types/react": "^19.1.8",
|
|
52
52
|
"@xylabs/ts-scripts-yarn3": "^6.5.18",
|
|
53
53
|
"@xylabs/tsconfig-react": "^6.5.18",
|
|
54
|
-
"@xyo-network/chain-network-model": "^1.6.
|
|
55
|
-
"@xyo-network/react-chain-model": "^1.6.
|
|
54
|
+
"@xyo-network/chain-network-model": "^1.6.5",
|
|
55
|
+
"@xyo-network/react-chain-model": "^1.6.5",
|
|
56
56
|
"knip": "^5.61.3",
|
|
57
57
|
"typescript": "^5.8.3"
|
|
58
58
|
},
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
import { useMemo } from 'react'
|
|
9
9
|
|
|
10
10
|
// Get known wallet connections from the global Xyo object
|
|
11
|
-
const walletConnections = globalThis.xyo?.connections
|
|
11
|
+
const walletConnections = () => globalThis.xyo?.connections
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Creates a JsonRpcXyoViewer instance based on the provided networkId.
|
|
@@ -18,7 +18,7 @@ const walletConnections = globalThis.xyo?.connections
|
|
|
18
18
|
*/
|
|
19
19
|
export const useHostViewerBase = (networkId?: string) => {
|
|
20
20
|
const networkConnection = useMemo(() => {
|
|
21
|
-
if (isTruthy(networkId) && isDefined(walletConnections) && isDefined(walletConnections[networkId])) {
|
|
21
|
+
if (isTruthy(networkId) && isDefined(walletConnections()) && isDefined(walletConnections()?.[networkId])) {
|
|
22
22
|
return networkId
|
|
23
23
|
}
|
|
24
24
|
}, [networkId])
|