@xyo-network/react-chain-client 2.0.17 → 3.0.0
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/components/connected/ConnectAccountsStack.d.ts +5 -53
- package/dist/browser/components/connected/ConnectAccountsStack.d.ts.map +1 -1
- package/dist/browser/components/connected/account/Connected.d.ts +4 -5
- package/dist/browser/components/connected/account/Connected.d.ts.map +1 -1
- package/dist/browser/components/connected/hooks/useConnectAccount.d.ts +4 -17
- package/dist/browser/components/connected/hooks/useConnectAccount.d.ts.map +1 -1
- package/dist/browser/context/GatewayContext.d.ts +4 -27
- package/dist/browser/context/GatewayContext.d.ts.map +1 -1
- package/dist/browser/context/GatewayProviderProps.d.ts +4 -6
- package/dist/browser/context/GatewayProviderProps.d.ts.map +1 -1
- package/dist/browser/context/GatewayProviderState.d.ts +4 -35
- package/dist/browser/context/GatewayProviderState.d.ts.map +1 -1
- package/dist/browser/context/in-page/InPageGatewaysContext.d.ts +4 -15
- package/dist/browser/context/in-page/InPageGatewaysContext.d.ts.map +1 -1
- package/dist/browser/context/in-page/InPageGatewaysState.d.ts +4 -23
- package/dist/browser/context/in-page/InPageGatewaysState.d.ts.map +1 -1
- package/dist/browser/context/in-page/Provider.d.ts +5 -62
- package/dist/browser/context/in-page/Provider.d.ts.map +1 -1
- package/dist/browser/context/in-page/useProvidedInPageGateways.d.ts +4 -13
- package/dist/browser/context/in-page/useProvidedInPageGateways.d.ts.map +1 -1
- package/dist/browser/context/providers/GatewayProvider.d.ts +4 -46
- package/dist/browser/context/providers/GatewayProvider.d.ts.map +1 -1
- package/dist/browser/context/providers/WalletGatewayProvider.d.ts +4 -33
- package/dist/browser/context/providers/WalletGatewayProvider.d.ts.map +1 -1
- package/dist/browser/context/useProvidedGateway.d.ts +4 -16
- package/dist/browser/context/useProvidedGateway.d.ts.map +1 -1
- package/dist/browser/hooks/client/helpers/findCaveat.d.ts +4 -3
- package/dist/browser/hooks/client/helpers/findCaveat.d.ts.map +1 -1
- package/dist/browser/hooks/client/permissions/usePermissions.d.ts +4 -7
- package/dist/browser/hooks/client/permissions/usePermissions.d.ts.map +1 -1
- package/dist/browser/hooks/client/story/mockWalletDecorator.d.ts.map +1 -1
- package/dist/browser/hooks/client/useClientFromWallet.d.ts +4 -12
- package/dist/browser/hooks/client/useClientFromWallet.d.ts.map +1 -1
- package/dist/browser/hooks/client/useGatewayFromWallet.d.ts +4 -19
- package/dist/browser/hooks/client/useGatewayFromWallet.d.ts.map +1 -1
- package/dist/browser/hooks/helpers/getXyoClient.d.ts +4 -9
- package/dist/browser/hooks/helpers/getXyoClient.d.ts.map +1 -1
- package/dist/browser/index.mjs +23 -463
- package/dist/browser/index.mjs.map +4 -4
- package/dist/browser/types/ContextGatewayType.d.ts +4 -5
- package/dist/browser/types/ContextGatewayType.d.ts.map +1 -1
- package/dist/browser/types/GatewayFromWallet.d.ts +4 -8
- package/dist/browser/types/GatewayFromWallet.d.ts.map +1 -1
- package/package.json +28 -40
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useClientFromWallet.d.ts","sourceRoot":"","sources":["../../../../src/hooks/client/useClientFromWallet.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useClientFromWallet.d.ts","sourceRoot":"","sources":["../../../../src/hooks/client/useClientFromWallet.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAA"}
|
|
@@ -1,22 +1,7 @@
|
|
|
1
|
-
import type { GatewayName } from '@xyo-network/xl1-sdk';
|
|
2
|
-
import type { GatewayFromWallet } from '../../types/index.ts';
|
|
3
1
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* - `undefined` — wallet detection is still in progress (isLoading=true),
|
|
8
|
-
* or no gatewayName was provided. Consumers should treat this as "not yet known"
|
|
9
|
-
* and avoid committing to either a present or absent UI state.
|
|
10
|
-
* - `null` — wallet is definitively absent. Either globalThis.xyo was never set,
|
|
11
|
-
* or detection timed out. Safe to show fallback UI (e.g. "Get XL1 Wallet").
|
|
12
|
-
* A late-recovery listener may still transition this to a real gateway if
|
|
13
|
-
* the extension loads after the timeout.
|
|
14
|
-
* - `XyoGatewayRunner` — wallet is present and exposes this gateway for the
|
|
15
|
-
* requested network. Ready to use for transactions and queries.
|
|
16
|
-
*
|
|
17
|
-
* @deprecated Use {@link useGatewayFromWallet} from `@xyo-network/xl1-react-client-sdk/client` instead.
|
|
2
|
+
* @deprecated Moved to `@xyo-network/xl1-react-client-sdk`. Import from
|
|
3
|
+
* `@xyo-network/xl1-react-client-sdk/client` instead. This re-export exists
|
|
4
|
+
* only for backward compatibility and will be removed in a future release.
|
|
18
5
|
*/
|
|
19
|
-
export
|
|
20
|
-
/** @deprecated - useGatewayFromWallet */
|
|
21
|
-
export declare const useGateway: (gatewayName?: GatewayName, timeout?: number) => GatewayFromWallet;
|
|
6
|
+
export { useGatewayFromWallet } from '@xyo-network/xl1-react-client-sdk/client';
|
|
22
7
|
//# sourceMappingURL=useGatewayFromWallet.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useGatewayFromWallet.d.ts","sourceRoot":"","sources":["../../../../src/hooks/client/useGatewayFromWallet.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useGatewayFromWallet.d.ts","sourceRoot":"","sources":["../../../../src/hooks/client/useGatewayFromWallet.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,0CAA0C,CAAA"}
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import type { XyoClient } from '@xyo-network/xl1-sdk';
|
|
2
1
|
/**
|
|
3
|
-
* @deprecated
|
|
2
|
+
* @deprecated Moved to `@xyo-network/xl1-react-client-sdk`. Import from
|
|
3
|
+
* `@xyo-network/xl1-react-client-sdk/client` instead. This re-export exists
|
|
4
|
+
* only for backward compatibility and will be removed in a future release.
|
|
4
5
|
*/
|
|
5
|
-
export
|
|
6
|
-
type ReturnType = XyoClient | undefined | null;
|
|
7
|
-
/**
|
|
8
|
-
* @deprecated Use {@link getXyoClient} from `@xyo-network/xl1-react-client-sdk/client` instead.
|
|
9
|
-
*/
|
|
10
|
-
export declare function getXyoClient(timeout?: number): Promise<ReturnType>;
|
|
11
|
-
export {};
|
|
6
|
+
export { getXyoClient, listenForClientInjection } from '@xyo-network/xl1-react-client-sdk/client';
|
|
12
7
|
//# sourceMappingURL=getXyoClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getXyoClient.d.ts","sourceRoot":"","sources":["../../../../src/hooks/helpers/getXyoClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getXyoClient.d.ts","sourceRoot":"","sources":["../../../../src/hooks/helpers/getXyoClient.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,YAAY,EAAE,wBAAwB,EAAE,MAAM,0CAA0C,CAAA"}
|
package/dist/browser/index.mjs
CHANGED
|
@@ -1,367 +1,46 @@
|
|
|
1
1
|
// src/components/connected/account/Connected.tsx
|
|
2
|
-
import {
|
|
3
|
-
Stack,
|
|
4
|
-
Tooltip,
|
|
5
|
-
Typography
|
|
6
|
-
} from "@mui/material";
|
|
7
|
-
import { shortenAddress } from "@xyo-network/react-chain-shared";
|
|
8
|
-
import { BlockiesAvatarAddress } from "@xyo-network/xl1-blockies";
|
|
9
|
-
import { jsx, jsxs } from "react/jsx-runtime";
|
|
10
|
-
var ConnectedAccount = ({ address }) => {
|
|
11
|
-
const shortenedAddress = shortenAddress(address, 4);
|
|
12
|
-
return /* @__PURE__ */ jsxs(
|
|
13
|
-
Stack,
|
|
14
|
-
{
|
|
15
|
-
direction: "row",
|
|
16
|
-
spacing: 1,
|
|
17
|
-
sx: { alignItems: "center" },
|
|
18
|
-
children: [
|
|
19
|
-
/* @__PURE__ */ jsx(BlockiesAvatarAddress, { address, size: 21 }),
|
|
20
|
-
/* @__PURE__ */ jsx(Tooltip, { title: address, children: /* @__PURE__ */ jsx(
|
|
21
|
-
Typography,
|
|
22
|
-
{
|
|
23
|
-
variant: "caption",
|
|
24
|
-
sx: {
|
|
25
|
-
color: "text.secondary",
|
|
26
|
-
fontFamily: "monospace"
|
|
27
|
-
},
|
|
28
|
-
children: shortenedAddress
|
|
29
|
-
}
|
|
30
|
-
) })
|
|
31
|
-
]
|
|
32
|
-
}
|
|
33
|
-
);
|
|
34
|
-
};
|
|
2
|
+
import { ConnectedAccount } from "@xyo-network/xl1-react-client-sdk/client";
|
|
35
3
|
|
|
36
4
|
// src/components/connected/ConnectAccountsStack.tsx
|
|
37
|
-
import {
|
|
38
|
-
Alert,
|
|
39
|
-
AlertTitle,
|
|
40
|
-
Button,
|
|
41
|
-
Stack as Stack2,
|
|
42
|
-
Typography as Typography2
|
|
43
|
-
} from "@mui/material";
|
|
44
|
-
import { ButtonEx } from "@xylabs/react-button";
|
|
45
|
-
import { ErrorRender } from "@xylabs/react-error";
|
|
46
|
-
import { isDefined, isUndefined } from "@xylabs/sdk-js";
|
|
47
|
-
import { ConnectedAccount as ConnectedAccount2, useConnectAccount } from "@xyo-network/xl1-react-client-sdk";
|
|
48
|
-
import { useEffect } from "react";
|
|
49
|
-
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
50
|
-
var DefaultConnectComponent = (props) => /* @__PURE__ */ jsx2(ButtonEx, { variant: "contained", size: "small", ...props });
|
|
51
|
-
var DefaultNoWalletInstalledComponent = () => /* @__PURE__ */ jsxs2(Alert, { severity: "warning", children: [
|
|
52
|
-
/* @__PURE__ */ jsx2(AlertTitle, { children: "XL1 Wallet Not Found" }),
|
|
53
|
-
/* @__PURE__ */ jsx2(Typography2, { gutterBottom: true, children: "Please ensure that your XL1 Wallet is installed to connect your account." }),
|
|
54
|
-
/* @__PURE__ */ jsx2(
|
|
55
|
-
Button,
|
|
56
|
-
{
|
|
57
|
-
sx: { display: "flex", justifySelf: "end" },
|
|
58
|
-
size: "small",
|
|
59
|
-
variant: "outlined",
|
|
60
|
-
href: "https://chromewebstore.google.com/detail/xl1-wallet/fblbagcjeigmhakkfgjpdlcapcgmcfbm",
|
|
61
|
-
target: "_blank",
|
|
62
|
-
rel: "noopener",
|
|
63
|
-
children: "Get XL1 Wallet"
|
|
64
|
-
}
|
|
65
|
-
)
|
|
66
|
-
] });
|
|
67
|
-
var ConnectAccountsStack = ({
|
|
68
|
-
AccountComponent = ConnectedAccount2,
|
|
69
|
-
ConnectComponent = DefaultConnectComponent,
|
|
70
|
-
NoWalletInstalledComponent = DefaultNoWalletInstalledComponent,
|
|
71
|
-
onAccountConnected,
|
|
72
|
-
onCancel,
|
|
73
|
-
timeout,
|
|
74
|
-
...props
|
|
75
|
-
}) => {
|
|
76
|
-
const {
|
|
77
|
-
address,
|
|
78
|
-
connectSigner,
|
|
79
|
-
error,
|
|
80
|
-
timedout
|
|
81
|
-
} = useConnectAccount(void 0, timeout);
|
|
82
|
-
useEffect(() => {
|
|
83
|
-
if (isDefined(error) && isDefined(onCancel)) {
|
|
84
|
-
onCancel();
|
|
85
|
-
}
|
|
86
|
-
}, [error, onCancel]);
|
|
87
|
-
useEffect(() => {
|
|
88
|
-
if (isDefined(address) && isDefined(onAccountConnected)) {
|
|
89
|
-
onAccountConnected(address);
|
|
90
|
-
}
|
|
91
|
-
}, [address, onAccountConnected]);
|
|
92
|
-
return /* @__PURE__ */ jsxs2(
|
|
93
|
-
Stack2,
|
|
94
|
-
{
|
|
95
|
-
direction: "row",
|
|
96
|
-
spacing: 2,
|
|
97
|
-
...props,
|
|
98
|
-
sx: [{ alignItems: "start" }, ...Array.isArray(props.sx) ? props.sx : [props.sx]],
|
|
99
|
-
children: [
|
|
100
|
-
isDefined(address) ? /* @__PURE__ */ jsx2(AccountComponent, { address }) : null,
|
|
101
|
-
isUndefined(address) && !timedout ? /* @__PURE__ */ jsx2(ConnectComponent, { onClick: () => void connectSigner(), children: "Connect" }) : null,
|
|
102
|
-
isUndefined(address) && timedout ? /* @__PURE__ */ jsx2(NoWalletInstalledComponent, {}) : null,
|
|
103
|
-
/* @__PURE__ */ jsx2(ErrorRender, { error, scope: "ConnectSigner:error" })
|
|
104
|
-
]
|
|
105
|
-
}
|
|
106
|
-
);
|
|
107
|
-
};
|
|
5
|
+
import { ConnectAccountsStack } from "@xyo-network/xl1-react-client-sdk/client";
|
|
108
6
|
|
|
109
7
|
// src/context/GatewayContext.ts
|
|
110
|
-
import {
|
|
111
|
-
var GatewayContext = createContextEx();
|
|
8
|
+
import { GatewayContext } from "@xyo-network/xl1-react-client-sdk/client";
|
|
112
9
|
|
|
113
10
|
// src/context/in-page/InPageGatewaysContext.ts
|
|
114
|
-
import {
|
|
115
|
-
var InPageGatewaysContext = createContextEx2();
|
|
11
|
+
import { InPageGatewaysContext } from "@xyo-network/xl1-react-client-sdk/client";
|
|
116
12
|
|
|
117
13
|
// src/context/in-page/Provider.tsx
|
|
118
|
-
import {
|
|
119
|
-
import {
|
|
120
|
-
startTransition,
|
|
121
|
-
useCallback,
|
|
122
|
-
useEffect as useEffect2,
|
|
123
|
-
useMemo,
|
|
124
|
-
useState
|
|
125
|
-
} from "react";
|
|
126
|
-
|
|
127
|
-
// src/context/in-page/lib/buildGateway.ts
|
|
128
|
-
import { assertEx, isDefined as isDefined2 } from "@xylabs/sdk-js";
|
|
129
|
-
import {
|
|
130
|
-
basicRemoteRunnerLocator,
|
|
131
|
-
basicRemoteViewerLocator,
|
|
132
|
-
DefaultNetworks,
|
|
133
|
-
NetworkDataLakeUrls,
|
|
134
|
-
XyoGatewayMoniker
|
|
135
|
-
} from "@xyo-network/xl1-sdk";
|
|
136
|
-
var buildGateway = async (gatewayName, signerTransport) => {
|
|
137
|
-
const network = DefaultNetworks.find((network2) => network2.id === gatewayName);
|
|
138
|
-
const resolvedNetwork = assertEx(network, () => `No network found for id ${gatewayName}`);
|
|
139
|
-
const remoteConfig = {
|
|
140
|
-
rpc: {
|
|
141
|
-
protocol: "http",
|
|
142
|
-
url: `${resolvedNetwork.url}/rpc`
|
|
143
|
-
}
|
|
144
|
-
};
|
|
145
|
-
const dataLakeEndpoint = NetworkDataLakeUrls[gatewayName];
|
|
146
|
-
const locator = isDefined2(signerTransport) ? await basicRemoteRunnerLocator(gatewayName, remoteConfig, signerTransport, dataLakeEndpoint) : await basicRemoteViewerLocator(gatewayName, remoteConfig, dataLakeEndpoint);
|
|
147
|
-
return await locator.getInstance(XyoGatewayMoniker);
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
// src/context/in-page/Provider.tsx
|
|
151
|
-
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
152
|
-
var InPageGatewaysProvider = ({ signerTransport, children }) => {
|
|
153
|
-
const [gateways, setGateways] = useState({});
|
|
154
|
-
const [errors, setErrors] = useState({});
|
|
155
|
-
const [previousSignerTransport, setPreviousSignerTransport] = useState(signerTransport);
|
|
156
|
-
const clearAll = useCallback(() => {
|
|
157
|
-
setGateways({});
|
|
158
|
-
setErrors({});
|
|
159
|
-
}, []);
|
|
160
|
-
if (previousSignerTransport !== signerTransport) {
|
|
161
|
-
clearAll();
|
|
162
|
-
setPreviousSignerTransport(signerTransport);
|
|
163
|
-
}
|
|
164
|
-
useEffect2(() => {
|
|
165
|
-
let cancelled = false;
|
|
166
|
-
const buildAll = async () => {
|
|
167
|
-
const results = await Promise.allSettled(
|
|
168
|
-
DefaultNetworks2.map(async (network) => {
|
|
169
|
-
const gateway = await buildGateway(network.id, signerTransport);
|
|
170
|
-
return { id: network.id, gateway };
|
|
171
|
-
})
|
|
172
|
-
);
|
|
173
|
-
if (cancelled) return;
|
|
174
|
-
const nextGateways = {};
|
|
175
|
-
const nextErrors = {};
|
|
176
|
-
for (const [index, result] of results.entries()) {
|
|
177
|
-
const networkId = DefaultNetworks2[index].id;
|
|
178
|
-
if (result.status === "fulfilled") {
|
|
179
|
-
nextGateways[networkId] = result.value.gateway;
|
|
180
|
-
} else {
|
|
181
|
-
nextErrors[networkId] = result.reason instanceof Error ? result.reason : new Error(String(result.reason));
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
startTransition(() => {
|
|
185
|
-
setGateways(nextGateways);
|
|
186
|
-
setErrors(nextErrors);
|
|
187
|
-
});
|
|
188
|
-
};
|
|
189
|
-
void buildAll();
|
|
190
|
-
return () => {
|
|
191
|
-
cancelled = true;
|
|
192
|
-
};
|
|
193
|
-
}, [signerTransport]);
|
|
194
|
-
const value = useMemo(() => {
|
|
195
|
-
const value2 = {
|
|
196
|
-
clearAll,
|
|
197
|
-
errors,
|
|
198
|
-
gateways,
|
|
199
|
-
provided: true
|
|
200
|
-
};
|
|
201
|
-
return value2;
|
|
202
|
-
}, [clearAll, errors, gateways]);
|
|
203
|
-
return /* @__PURE__ */ jsx3(InPageGatewaysContext, { value, children });
|
|
204
|
-
};
|
|
14
|
+
import { InPageGatewaysProvider } from "@xyo-network/xl1-react-client-sdk/client";
|
|
205
15
|
|
|
206
16
|
// src/context/in-page/useProvidedInPageGateways.ts
|
|
207
|
-
import {
|
|
208
|
-
var useProvidedInPageGateways = (required = true) => useContextEx(InPageGatewaysContext, "InPageGateways", required);
|
|
17
|
+
import { useProvidedInPageGateways } from "@xyo-network/xl1-react-client-sdk/client";
|
|
209
18
|
|
|
210
19
|
// src/context/providers/GatewayProvider.tsx
|
|
211
|
-
import {
|
|
212
|
-
import { isDefinedNotNull as isDefinedNotNull2, isNull as isNull2 } from "@xylabs/sdk-js";
|
|
213
|
-
import { useMemo as useMemo2 } from "react";
|
|
20
|
+
import { GatewayProvider } from "@xyo-network/xl1-react-client-sdk/client";
|
|
214
21
|
|
|
215
|
-
// src/
|
|
216
|
-
import {
|
|
217
|
-
var findCaveat = async (permissions, targetCapability, targetCaveatType) => {
|
|
218
|
-
const existingPermissions = await permissions.getPermissions();
|
|
219
|
-
if (isDefined3(existingPermissions) && existingPermissions.length > 0) {
|
|
220
|
-
const foundPermissions = existingPermissions.find((p) => p.parentCapability === targetCapability);
|
|
221
|
-
if (isDefined3(foundPermissions)) {
|
|
222
|
-
return foundPermissions.caveats?.find((caveat) => caveat.type === targetCaveatType)?.value ?? [];
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
return existingPermissions;
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
// src/hooks/client/useClientFromWallet.ts
|
|
229
|
-
import { isUndefined as isUndefined3 } from "@xylabs/sdk-js";
|
|
230
|
-
import { useEffect as useEffect3, useState as useState2 } from "react";
|
|
22
|
+
// src/context/providers/WalletGatewayProvider.tsx
|
|
23
|
+
import { WalletGatewayProvider } from "@xyo-network/xl1-react-client-sdk/client";
|
|
231
24
|
|
|
232
|
-
// src/
|
|
233
|
-
import {
|
|
234
|
-
var CLIENT_LISTENER_TIMEOUT = 2e3;
|
|
235
|
-
var hasXyoClient = () => {
|
|
236
|
-
return "client" in globalThis.xyo;
|
|
237
|
-
};
|
|
238
|
-
var listenForClientInjection = (onClientReady, timeout, onTimeout) => {
|
|
239
|
-
let resolved = false;
|
|
240
|
-
const listener = () => {
|
|
241
|
-
onClientReady();
|
|
242
|
-
resolved = true;
|
|
243
|
-
};
|
|
244
|
-
globalThis.addEventListener("xyo:plugin-ready", listener);
|
|
245
|
-
setTimeout(() => {
|
|
246
|
-
if (!resolved) {
|
|
247
|
-
globalThis.removeEventListener("xyo:plugin-ready", listener);
|
|
248
|
-
onTimeout();
|
|
249
|
-
}
|
|
250
|
-
}, timeout);
|
|
251
|
-
};
|
|
252
|
-
async function getXyoClient(timeout = CLIENT_LISTENER_TIMEOUT) {
|
|
253
|
-
if (isUndefined2(globalThis.xyo)) {
|
|
254
|
-
return null;
|
|
255
|
-
}
|
|
256
|
-
return hasXyoClient() ? globalThis.xyo.client : await new Promise((resolve) => {
|
|
257
|
-
listenForClientInjection(
|
|
258
|
-
() => {
|
|
259
|
-
resolve(globalThis.xyo.client);
|
|
260
|
-
},
|
|
261
|
-
timeout,
|
|
262
|
-
() => {
|
|
263
|
-
resolve(null);
|
|
264
|
-
}
|
|
265
|
-
);
|
|
266
|
-
});
|
|
267
|
-
}
|
|
25
|
+
// src/context/useProvidedGateway.ts
|
|
26
|
+
import { useProvidedGateway } from "@xyo-network/xl1-react-client-sdk/client";
|
|
268
27
|
|
|
269
|
-
// src/hooks/client/
|
|
270
|
-
|
|
271
|
-
client: void 0,
|
|
272
|
-
error: null,
|
|
273
|
-
isLoading: false,
|
|
274
|
-
timedout: false
|
|
275
|
-
};
|
|
276
|
-
var useClientFromWallet = (timeout) => {
|
|
277
|
-
const [state, setState] = useState2(initialState);
|
|
278
|
-
useEffect3(() => {
|
|
279
|
-
let cancelled = false;
|
|
280
|
-
const initialize = async () => {
|
|
281
|
-
setState((prev) => {
|
|
282
|
-
if (prev.isLoading) return prev;
|
|
283
|
-
return {
|
|
284
|
-
...prev,
|
|
285
|
-
isLoading: true,
|
|
286
|
-
error: null
|
|
287
|
-
};
|
|
288
|
-
});
|
|
289
|
-
try {
|
|
290
|
-
const client = await getXyoClient(timeout);
|
|
291
|
-
if (cancelled) return;
|
|
292
|
-
if (client === null) {
|
|
293
|
-
setState({
|
|
294
|
-
client: null,
|
|
295
|
-
timedout: true,
|
|
296
|
-
isLoading: false,
|
|
297
|
-
error: null
|
|
298
|
-
});
|
|
299
|
-
} else {
|
|
300
|
-
setState({
|
|
301
|
-
client,
|
|
302
|
-
isLoading: false,
|
|
303
|
-
error: null,
|
|
304
|
-
timedout: false
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
} catch (error) {
|
|
308
|
-
if (cancelled) return;
|
|
309
|
-
setState({
|
|
310
|
-
client: void 0,
|
|
311
|
-
isLoading: false,
|
|
312
|
-
error,
|
|
313
|
-
timedout: false
|
|
314
|
-
});
|
|
315
|
-
}
|
|
316
|
-
};
|
|
317
|
-
void initialize();
|
|
318
|
-
const onPluginReady = () => {
|
|
319
|
-
if (cancelled) return;
|
|
320
|
-
const client = isUndefined3(globalThis.xyo) ? null : globalThis.xyo?.client ?? null;
|
|
321
|
-
setState({
|
|
322
|
-
client,
|
|
323
|
-
isLoading: false,
|
|
324
|
-
timedout: false,
|
|
325
|
-
error: null
|
|
326
|
-
});
|
|
327
|
-
};
|
|
328
|
-
globalThis.addEventListener("xyo:plugin-ready", onPluginReady);
|
|
329
|
-
return () => {
|
|
330
|
-
cancelled = true;
|
|
331
|
-
globalThis.removeEventListener("xyo:plugin-ready", onPluginReady);
|
|
332
|
-
};
|
|
333
|
-
}, [timeout]);
|
|
334
|
-
return state;
|
|
335
|
-
};
|
|
336
|
-
var useClient = useClientFromWallet;
|
|
28
|
+
// src/hooks/client/helpers/findCaveat.ts
|
|
29
|
+
import { findCaveat } from "@xyo-network/xl1-react-client-sdk/client";
|
|
337
30
|
|
|
338
31
|
// src/hooks/client/permissions/usePermissions.ts
|
|
339
|
-
|
|
340
|
-
const {
|
|
341
|
-
client,
|
|
342
|
-
isLoading,
|
|
343
|
-
error,
|
|
344
|
-
timedout
|
|
345
|
-
} = useClientFromWallet();
|
|
346
|
-
const permissions = client?.permissions;
|
|
347
|
-
return {
|
|
348
|
-
permissions,
|
|
349
|
-
isLoading,
|
|
350
|
-
error,
|
|
351
|
-
timedout
|
|
352
|
-
};
|
|
353
|
-
};
|
|
32
|
+
import { usePermissions } from "@xyo-network/xl1-react-client-sdk/client";
|
|
354
33
|
|
|
355
34
|
// src/hooks/client/permissions/usePermissionsAccounts.ts
|
|
356
35
|
import { usePromise } from "@xylabs/react-promise";
|
|
357
36
|
import {
|
|
358
37
|
isArray,
|
|
359
|
-
isDefined
|
|
38
|
+
isDefined,
|
|
360
39
|
isDefinedNotNull,
|
|
361
40
|
isString
|
|
362
41
|
} from "@xylabs/sdk-js";
|
|
363
42
|
var validateRestrictedAccounts = (restrictedAccounts) => {
|
|
364
|
-
if (
|
|
43
|
+
if (isDefined(restrictedAccounts)) {
|
|
365
44
|
if (isArray(restrictedAccounts) && restrictedAccounts.every(isString)) {
|
|
366
45
|
return restrictedAccounts;
|
|
367
46
|
}
|
|
@@ -377,7 +56,7 @@ var useAccountPermissions = () => {
|
|
|
377
56
|
const { permissions, error } = usePermissions();
|
|
378
57
|
return usePromise(async () => {
|
|
379
58
|
if (isDefinedNotNull(error)) throw error;
|
|
380
|
-
if (
|
|
59
|
+
if (isDefined(permissions)) {
|
|
381
60
|
const restrictedAccounts = await findCaveat(
|
|
382
61
|
permissions,
|
|
383
62
|
// TODO - extract to constant in protocol package
|
|
@@ -389,131 +68,14 @@ var useAccountPermissions = () => {
|
|
|
389
68
|
}, [permissions]);
|
|
390
69
|
};
|
|
391
70
|
|
|
392
|
-
// src/hooks/client/
|
|
393
|
-
import {
|
|
394
|
-
var useGatewayFromWallet = (gatewayName, timeout) => {
|
|
395
|
-
const {
|
|
396
|
-
client,
|
|
397
|
-
isLoading,
|
|
398
|
-
error,
|
|
399
|
-
timedout
|
|
400
|
-
} = useClientFromWallet(timeout);
|
|
401
|
-
const resolveGateway = () => {
|
|
402
|
-
if (isNull(client)) return null;
|
|
403
|
-
return client?.gateways?.[gatewayName];
|
|
404
|
-
};
|
|
405
|
-
return {
|
|
406
|
-
// no gatewayName requested = undefined (opt-out, not "absent")
|
|
407
|
-
gateway: gatewayName ? resolveGateway() : void 0,
|
|
408
|
-
isLoading,
|
|
409
|
-
error,
|
|
410
|
-
timedout
|
|
411
|
-
};
|
|
412
|
-
};
|
|
413
|
-
var useGateway = useGatewayFromWallet;
|
|
414
|
-
|
|
415
|
-
// src/context/providers/GatewayProvider.tsx
|
|
416
|
-
import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
417
|
-
var GatewayProvider = ({ gatewayName, children }) => {
|
|
418
|
-
const {
|
|
419
|
-
gateway: gatewayFromWallet,
|
|
420
|
-
error: gatewayFromWalletError
|
|
421
|
-
} = useGatewayFromWallet(gatewayName);
|
|
422
|
-
const {
|
|
423
|
-
gateways: allGateways,
|
|
424
|
-
errors: allGatewayErrors,
|
|
425
|
-
clearAll
|
|
426
|
-
} = useProvidedInPageGateways(true);
|
|
427
|
-
const gatewayFromConfig = gatewayName ? allGateways[gatewayName] : void 0;
|
|
428
|
-
const gatewayFromConfigError = gatewayName ? allGatewayErrors[gatewayName] : void 0;
|
|
429
|
-
const { defaultGateway, gateways } = useMemo2(() => {
|
|
430
|
-
if (isNull2(gatewayFromWallet)) {
|
|
431
|
-
return {
|
|
432
|
-
defaultGateway: gatewayFromConfig,
|
|
433
|
-
gateways: {
|
|
434
|
-
inPageGateway: gatewayFromConfig,
|
|
435
|
-
walletGateway: null
|
|
436
|
-
}
|
|
437
|
-
};
|
|
438
|
-
} else if (isDefinedNotNull2(gatewayFromWallet)) {
|
|
439
|
-
return {
|
|
440
|
-
defaultGateway: gatewayFromWallet,
|
|
441
|
-
gateways: {
|
|
442
|
-
inPageGateway: gatewayFromConfig,
|
|
443
|
-
walletGateway: gatewayFromWallet
|
|
444
|
-
}
|
|
445
|
-
};
|
|
446
|
-
}
|
|
447
|
-
return {
|
|
448
|
-
defaultGateway: void 0,
|
|
449
|
-
gateways: {
|
|
450
|
-
inPageGateway: void 0,
|
|
451
|
-
walletGateway: void 0
|
|
452
|
-
}
|
|
453
|
-
};
|
|
454
|
-
}, [gatewayFromConfig, gatewayFromWallet]);
|
|
455
|
-
const value = useMemo2(() => {
|
|
456
|
-
const value2 = {
|
|
457
|
-
defaultGateway,
|
|
458
|
-
error: gatewayFromWalletError || gatewayFromConfigError,
|
|
459
|
-
gateways,
|
|
460
|
-
provided: true,
|
|
461
|
-
resetGatewaysFromConfig: clearAll
|
|
462
|
-
};
|
|
463
|
-
return value2;
|
|
464
|
-
}, [
|
|
465
|
-
defaultGateway,
|
|
466
|
-
gatewayFromWalletError,
|
|
467
|
-
gatewayFromConfigError,
|
|
468
|
-
gateways,
|
|
469
|
-
clearAll
|
|
470
|
-
]);
|
|
471
|
-
return /* @__PURE__ */ jsxs3(GatewayContext, { value, children: [
|
|
472
|
-
/* @__PURE__ */ jsx4(ErrorRender2, { error: gatewayFromConfigError }),
|
|
473
|
-
children
|
|
474
|
-
] });
|
|
475
|
-
};
|
|
71
|
+
// src/hooks/client/useClientFromWallet.ts
|
|
72
|
+
import { useClientFromWallet } from "@xyo-network/xl1-react-client-sdk/client";
|
|
476
73
|
|
|
477
|
-
// src/
|
|
478
|
-
import {
|
|
479
|
-
import { useMemo as useMemo3 } from "react";
|
|
480
|
-
import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
481
|
-
var WalletGatewayProvider = ({ gatewayName, children }) => {
|
|
482
|
-
const {
|
|
483
|
-
gateway: gatewayFromWallet,
|
|
484
|
-
error: gatewayFromWalletError
|
|
485
|
-
} = useGatewayFromWallet(gatewayName);
|
|
486
|
-
const { defaultGateway, gateways } = useMemo3(() => {
|
|
487
|
-
return {
|
|
488
|
-
defaultGateway: gatewayFromWallet,
|
|
489
|
-
gateways: {
|
|
490
|
-
inPageGateway: null,
|
|
491
|
-
walletGateway: gatewayFromWallet
|
|
492
|
-
}
|
|
493
|
-
};
|
|
494
|
-
}, [gatewayFromWallet]);
|
|
495
|
-
const value = useMemo3(() => {
|
|
496
|
-
const value2 = {
|
|
497
|
-
defaultGateway,
|
|
498
|
-
error: gatewayFromWalletError,
|
|
499
|
-
gateways,
|
|
500
|
-
provided: true
|
|
501
|
-
};
|
|
502
|
-
return value2;
|
|
503
|
-
}, [
|
|
504
|
-
defaultGateway,
|
|
505
|
-
gatewayFromWalletError,
|
|
506
|
-
gateways
|
|
507
|
-
]);
|
|
508
|
-
return /* @__PURE__ */ jsxs4(GatewayContext, { value, children: [
|
|
509
|
-
/* @__PURE__ */ jsx5(ErrorRender3, { error: gatewayFromWalletError }),
|
|
510
|
-
children
|
|
511
|
-
] });
|
|
512
|
-
};
|
|
74
|
+
// src/hooks/client/useGatewayFromWallet.ts
|
|
75
|
+
import { useGatewayFromWallet } from "@xyo-network/xl1-react-client-sdk/client";
|
|
513
76
|
|
|
514
|
-
// src/
|
|
515
|
-
import {
|
|
516
|
-
var useProvidedGateway = (required = true) => useContextEx2(GatewayContext, "Gateway", required);
|
|
77
|
+
// src/hooks/helpers/getXyoClient.ts
|
|
78
|
+
import { getXyoClient, listenForClientInjection } from "@xyo-network/xl1-react-client-sdk/client";
|
|
517
79
|
export {
|
|
518
80
|
ConnectAccountsStack,
|
|
519
81
|
ConnectedAccount,
|
|
@@ -526,9 +88,7 @@ export {
|
|
|
526
88
|
getXyoClient,
|
|
527
89
|
listenForClientInjection,
|
|
528
90
|
useAccountPermissions,
|
|
529
|
-
useClient,
|
|
530
91
|
useClientFromWallet,
|
|
531
|
-
useGateway,
|
|
532
92
|
useGatewayFromWallet,
|
|
533
93
|
usePermissions,
|
|
534
94
|
useProvidedGateway,
|