@xyo-network/xl1-react-client-sdk 2.2.0 → 2.2.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.
@@ -8,7 +8,7 @@ import { EthAddressWrapper } from "@xylabs/eth-address";
8
8
  import { BlockiesAvatarAddress } from "@xyo-network/xl1-blockies";
9
9
  import { jsx, jsxs } from "react/jsx-runtime";
10
10
  var ConnectedAccount = ({ address }) => {
11
- const shortenedAddress = `${EthAddressWrapper.fromString(address)?.toShortString(4)}`;
11
+ const shortenedAddress = EthAddressWrapper.fromString(address)?.toShortString(4) ?? "";
12
12
  return /* @__PURE__ */ jsxs(
13
13
  Stack,
14
14
  {
@@ -81,12 +81,13 @@ var listenForClientInjection = (onClientReady, timeout, onTimeout) => {
81
81
  onClientReady();
82
82
  resolved = true;
83
83
  };
84
- globalThis.addEventListener("xyo:plugin-ready", listener);
84
+ addEventListener("xyo:plugin-ready", listener);
85
85
  setTimeout(() => {
86
- if (!resolved) {
87
- globalThis.removeEventListener("xyo:plugin-ready", listener);
88
- onTimeout();
86
+ if (resolved) {
87
+ return;
89
88
  }
89
+ removeEventListener("xyo:plugin-ready", listener);
90
+ onTimeout();
90
91
  }, timeout);
91
92
  };
92
93
  async function getXyoClient(timeout = CLIENT_LISTENER_TIMEOUT) {
@@ -127,22 +128,24 @@ var useClientFromWallet = (timeout) => {
127
128
  };
128
129
  });
129
130
  try {
130
- const client = await getXyoClient(timeout);
131
131
  if (cancelled) return;
132
- if (client === null) {
133
- setState({
134
- client: null,
135
- timedout: true,
136
- isLoading: false,
137
- error: null
138
- });
139
- } else {
140
- setState({
141
- client,
142
- isLoading: false,
143
- error: null,
144
- timedout: false
145
- });
132
+ const client = await getXyoClient(timeout);
133
+ if (!cancelled) {
134
+ if (client === null) {
135
+ setState({
136
+ client: null,
137
+ timedout: true,
138
+ isLoading: false,
139
+ error: null
140
+ });
141
+ } else {
142
+ setState({
143
+ client,
144
+ isLoading: false,
145
+ error: null,
146
+ timedout: false
147
+ });
148
+ }
146
149
  }
147
150
  } catch (error) {
148
151
  if (cancelled) return;
@@ -165,10 +168,11 @@ var useClientFromWallet = (timeout) => {
165
168
  error: null
166
169
  });
167
170
  };
168
- globalThis.addEventListener("xyo:plugin-ready", onPluginReady);
171
+ const controller = new AbortController();
172
+ addEventListener("xyo:plugin-ready", onPluginReady, { signal: controller.signal });
169
173
  return () => {
170
174
  cancelled = true;
171
- globalThis.removeEventListener("xyo:plugin-ready", onPluginReady);
175
+ controller.abort();
172
176
  };
173
177
  }, [timeout]);
174
178
  return state;
@@ -466,6 +470,11 @@ var renderCaveatValue = (caveat) => {
466
470
  };
467
471
  var renderPermission = (permission) => {
468
472
  const caveats = permission.caveats ?? [];
473
+ let grantedAt;
474
+ if (isDefined4(permission.date)) {
475
+ const grantedDate = new Date(permission.date);
476
+ grantedAt = grantedDate.toLocaleString();
477
+ }
469
478
  return /* @__PURE__ */ jsxs3(Stack3, { sx: { gap: 1 }, children: [
470
479
  /* @__PURE__ */ jsxs3(
471
480
  Stack3,
@@ -478,11 +487,11 @@ var renderPermission = (permission) => {
478
487
  },
479
488
  children: [
480
489
  /* @__PURE__ */ jsx3(Typography3, { variant: "subtitle2", sx: { fontFamily: "monospace" }, children: permission.parentCapability }),
481
- isDefined4(permission.date) ? /* @__PURE__ */ jsxs3(Typography3, { variant: "caption", sx: { color: "text.secondary" }, children: [
490
+ grantedAt == null ? null : /* @__PURE__ */ jsxs3(Typography3, { variant: "caption", sx: { color: "text.secondary" }, children: [
482
491
  "granted",
483
492
  " ",
484
- new Date(permission.date).toLocaleString()
485
- ] }) : null
493
+ grantedAt
494
+ ] })
486
495
  ]
487
496
  }
488
497
  ),
@@ -754,7 +763,8 @@ async function runBurst(gateway, offChainSchema, burstSize, onProgress) {
754
763
  const collected = [];
755
764
  for (let index = 0; index < burstSize; index++) {
756
765
  try {
757
- const content = new PayloadBuilder({ schema }).fields({ move: index, ts: Date.now() }).build();
766
+ const builder = new PayloadBuilder({ schema });
767
+ const content = builder.fields({ move: index, ts: Date.now() }).build();
758
768
  const [txHash] = await gateway.addPayloadsToChain([], [content]);
759
769
  collected.push({ index, txHash });
760
770
  } catch (e) {
@@ -1068,8 +1078,9 @@ var PANEL_PERMISSIONS = [
1068
1078
  { [DataLakesInsertMethod]: { dataLakeAccess: {} } }
1069
1079
  ];
1070
1080
  async function buildDefaultPayload(schema) {
1071
- const builder = new PayloadBuilder2({ schema }).fields({ value: 1 });
1072
- const payload = builder.build();
1081
+ const builder = new PayloadBuilder2({ schema });
1082
+ const configured = builder.fields({ value: 1 });
1083
+ const payload = configured.build();
1073
1084
  return JSON.stringify(payload, null, 2);
1074
1085
  }
1075
1086
  function parsePayload(raw) {
@@ -1261,7 +1272,8 @@ var DataLakeAddToChainPanel = ({
1261
1272
  const canAddToChain = isDefined8(storedHash) && isDefined8(storedPayload) && isDefinedNotNull5(gateway) && !addingToChain;
1262
1273
  const explorerTxUrl = useMemo2(() => {
1263
1274
  if (!isDefined8(txHash)) return;
1264
- return new ExplorerLinks2(explorerUrl, gatewayName).transaction(txHash);
1275
+ const links = new ExplorerLinks2(explorerUrl, gatewayName);
1276
+ return links.transaction(txHash);
1265
1277
  }, [txHash, explorerUrl, gatewayName]);
1266
1278
  const handleInsert = async () => {
1267
1279
  if (!canInsert || !parse.ok || !isDefinedNotNull5(dataLakes)) return;
@@ -1611,11 +1623,12 @@ import {
1611
1623
  import { useMemo as useMemo4, useState as useState10 } from "react";
1612
1624
  import { jsx as jsx11, jsxs as jsxs11 } from "react/jsx-runtime";
1613
1625
  function buildDefaultPayload2() {
1626
+ const now = /* @__PURE__ */ new Date();
1614
1627
  return JSON.stringify(
1615
1628
  {
1616
1629
  schema: "network.xyo.observation.v2",
1617
1630
  value: 1,
1618
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
1631
+ timestamp: now.toISOString()
1619
1632
  },
1620
1633
  null,
1621
1634
  2
@@ -2153,7 +2166,7 @@ import {
2153
2166
  DefaultNetworks,
2154
2167
  XyoGatewayMoniker
2155
2168
  } from "@xyo-network/xl1-sdk";
2156
- var buildGateway = async (gatewayName, signerTransport) => {
2169
+ var buildGateway = async (gatewayName, signerTransport, signerFactory) => {
2157
2170
  const network = DefaultNetworks.find((network2) => network2.id === gatewayName);
2158
2171
  const resolvedNetwork = assertEx3(network, () => `No network found for id ${gatewayName}`);
2159
2172
  const remoteConfig = {
@@ -2162,13 +2175,17 @@ var buildGateway = async (gatewayName, signerTransport) => {
2162
2175
  url: `${resolvedNetwork.url}/rpc`
2163
2176
  }
2164
2177
  };
2165
- const locator = isDefined14(signerTransport) ? await basicRemoteRunnerLocator(gatewayName, remoteConfig, signerTransport) : await basicRemoteViewerLocator(gatewayName, remoteConfig);
2178
+ const locator = isDefined14(signerTransport) ? await basicRemoteRunnerLocator(gatewayName, remoteConfig, signerTransport, void 0, { signerFactory }) : await basicRemoteViewerLocator(gatewayName, remoteConfig);
2166
2179
  return await locator.getInstance(XyoGatewayMoniker);
2167
2180
  };
2168
2181
 
2169
2182
  // src/client/context/in-page/Provider.tsx
2170
2183
  import { jsx as jsx17 } from "react/jsx-runtime";
2171
- var InPageGatewaysProvider = ({ signerTransport, children }) => {
2184
+ var InPageGatewaysProvider = ({
2185
+ signerFactory,
2186
+ signerTransport,
2187
+ children
2188
+ }) => {
2172
2189
  const [gateways, setGateways] = useState15({});
2173
2190
  const [errors, setErrors] = useState15({});
2174
2191
  const [previousSignerTransport, setPreviousSignerTransport] = useState15(signerTransport);
@@ -2183,33 +2200,35 @@ var InPageGatewaysProvider = ({ signerTransport, children }) => {
2183
2200
  useEffect5(() => {
2184
2201
  let cancelled = false;
2185
2202
  const buildAll = async () => {
2203
+ if (cancelled) return;
2186
2204
  const results = await Promise.allSettled(
2187
2205
  DefaultNetworks2.map(async (network) => {
2188
- const gateway = await buildGateway(network.id, signerTransport);
2206
+ const gateway = await buildGateway(network.id, signerTransport, signerFactory);
2189
2207
  return { id: network.id, gateway };
2190
2208
  })
2191
2209
  );
2192
- if (cancelled) return;
2193
- const nextGateways = {};
2194
- const nextErrors = {};
2195
- for (const [index, result] of results.entries()) {
2196
- const networkId = DefaultNetworks2[index].id;
2197
- if (result.status === "fulfilled") {
2198
- nextGateways[networkId] = result.value.gateway;
2199
- } else {
2200
- nextErrors[networkId] = result.reason instanceof Error ? result.reason : new Error(String(result.reason));
2210
+ if (!cancelled) {
2211
+ const nextGateways = {};
2212
+ const nextErrors = {};
2213
+ for (const [index, result] of results.entries()) {
2214
+ const networkId = DefaultNetworks2[index].id;
2215
+ if (result.status === "fulfilled") {
2216
+ nextGateways[networkId] = result.value.gateway;
2217
+ } else {
2218
+ nextErrors[networkId] = result.reason instanceof Error ? result.reason : new Error(String(result.reason));
2219
+ }
2201
2220
  }
2221
+ startTransition(() => {
2222
+ setGateways(nextGateways);
2223
+ setErrors(nextErrors);
2224
+ });
2202
2225
  }
2203
- startTransition(() => {
2204
- setGateways(nextGateways);
2205
- setErrors(nextErrors);
2206
- });
2207
2226
  };
2208
2227
  void buildAll();
2209
2228
  return () => {
2210
2229
  cancelled = true;
2211
2230
  };
2212
- }, [signerTransport]);
2231
+ }, [signerFactory, signerTransport]);
2213
2232
  const value = useMemo6(() => {
2214
2233
  const value2 = {
2215
2234
  clearAll,
@@ -2252,7 +2271,8 @@ var GatewayProvider = ({ gatewayName, children }) => {
2252
2271
  walletGateway: null
2253
2272
  }
2254
2273
  };
2255
- } else if (isDefinedNotNull11(gatewayFromWallet)) {
2274
+ }
2275
+ if (isDefinedNotNull11(gatewayFromWallet)) {
2256
2276
  return {
2257
2277
  defaultGateway: gatewayFromWallet,
2258
2278
  gateways: {
@@ -2363,15 +2383,15 @@ var ActiveMenuItem = ({
2363
2383
  "paddingLeft": 1,
2364
2384
  "marginBottom": 1,
2365
2385
  // left border color and background color for active state
2366
- "borderLeft": `5px solid ${active ? theme.vars.palette.secondary.light : "transparent"}`,
2367
- "backgroundColor": active ? theme.vars.palette.secondary.dark : "transparent",
2386
+ "borderLeft": `5px solid ${active === true ? theme.vars.palette.secondary.light : "transparent"}`,
2387
+ "backgroundColor": active === true ? theme.vars.palette.secondary.dark : "transparent",
2368
2388
  // force white text color for active state for improved readability with background color
2369
- "color": active ? "white" : "unset",
2389
+ "color": active === true ? "white" : "unset",
2370
2390
  "&:hover": {
2371
2391
  // overriding default hover color and backgroundColor since active state conflicts visually with
2372
2392
  // default styles of MenuItem hover
2373
- ...active ? { backgroundColor: theme.vars.palette.secondary.dark } : {},
2374
- color: active ? "white" : "unset"
2393
+ ...active === true && { backgroundColor: theme.vars.palette.secondary.dark },
2394
+ color: active === true ? "white" : "unset"
2375
2395
  },
2376
2396
  ...sx
2377
2397
  },
@@ -2526,9 +2546,12 @@ var LabelValueStack = ({
2526
2546
 
2527
2547
  // src/shared/decorators/IframeWalletWarningDecorator.tsx
2528
2548
  import { Alert as Alert13, Stack as Stack19 } from "@mui/material";
2529
- import { isDefined as isDefined16 } from "@xylabs/sdk-js";
2530
2549
  import { jsx as jsx23, jsxs as jsxs21 } from "react/jsx-runtime";
2531
- var inIframe = isDefined16(globalThis.self) && isDefined16(globalThis.top) && globalThis.self !== globalThis.top;
2550
+ function isInIframe() {
2551
+ const frameWindow = globalThis;
2552
+ return frameWindow.top != null && frameWindow.self !== frameWindow.top;
2553
+ }
2554
+ var inIframe = isInIframe();
2532
2555
  var IframeWalletWarningDecorator = (Story, args) => {
2533
2556
  const hasXyoGlobal = isXyoGlobal(globalThis.xyo);
2534
2557
  return /* @__PURE__ */ jsxs21(Stack19, { sx: { gap: 2 }, children: [