@xyo-network/xl1-react-client-sdk 2.2.0 → 2.2.1

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
@@ -2183,27 +2196,29 @@ var InPageGatewaysProvider = ({ signerTransport, children }) => {
2183
2196
  useEffect5(() => {
2184
2197
  let cancelled = false;
2185
2198
  const buildAll = async () => {
2199
+ if (cancelled) return;
2186
2200
  const results = await Promise.allSettled(
2187
2201
  DefaultNetworks2.map(async (network) => {
2188
2202
  const gateway = await buildGateway(network.id, signerTransport);
2189
2203
  return { id: network.id, gateway };
2190
2204
  })
2191
2205
  );
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));
2206
+ if (!cancelled) {
2207
+ const nextGateways = {};
2208
+ const nextErrors = {};
2209
+ for (const [index, result] of results.entries()) {
2210
+ const networkId = DefaultNetworks2[index].id;
2211
+ if (result.status === "fulfilled") {
2212
+ nextGateways[networkId] = result.value.gateway;
2213
+ } else {
2214
+ nextErrors[networkId] = result.reason instanceof Error ? result.reason : new Error(String(result.reason));
2215
+ }
2201
2216
  }
2217
+ startTransition(() => {
2218
+ setGateways(nextGateways);
2219
+ setErrors(nextErrors);
2220
+ });
2202
2221
  }
2203
- startTransition(() => {
2204
- setGateways(nextGateways);
2205
- setErrors(nextErrors);
2206
- });
2207
2222
  };
2208
2223
  void buildAll();
2209
2224
  return () => {
@@ -2252,7 +2267,8 @@ var GatewayProvider = ({ gatewayName, children }) => {
2252
2267
  walletGateway: null
2253
2268
  }
2254
2269
  };
2255
- } else if (isDefinedNotNull11(gatewayFromWallet)) {
2270
+ }
2271
+ if (isDefinedNotNull11(gatewayFromWallet)) {
2256
2272
  return {
2257
2273
  defaultGateway: gatewayFromWallet,
2258
2274
  gateways: {
@@ -2363,15 +2379,15 @@ var ActiveMenuItem = ({
2363
2379
  "paddingLeft": 1,
2364
2380
  "marginBottom": 1,
2365
2381
  // 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",
2382
+ "borderLeft": `5px solid ${active === true ? theme.vars.palette.secondary.light : "transparent"}`,
2383
+ "backgroundColor": active === true ? theme.vars.palette.secondary.dark : "transparent",
2368
2384
  // force white text color for active state for improved readability with background color
2369
- "color": active ? "white" : "unset",
2385
+ "color": active === true ? "white" : "unset",
2370
2386
  "&:hover": {
2371
2387
  // overriding default hover color and backgroundColor since active state conflicts visually with
2372
2388
  // default styles of MenuItem hover
2373
- ...active ? { backgroundColor: theme.vars.palette.secondary.dark } : {},
2374
- color: active ? "white" : "unset"
2389
+ ...active === true && { backgroundColor: theme.vars.palette.secondary.dark },
2390
+ color: active === true ? "white" : "unset"
2375
2391
  },
2376
2392
  ...sx
2377
2393
  },
@@ -2526,9 +2542,12 @@ var LabelValueStack = ({
2526
2542
 
2527
2543
  // src/shared/decorators/IframeWalletWarningDecorator.tsx
2528
2544
  import { Alert as Alert13, Stack as Stack19 } from "@mui/material";
2529
- import { isDefined as isDefined16 } from "@xylabs/sdk-js";
2530
2545
  import { jsx as jsx23, jsxs as jsxs21 } from "react/jsx-runtime";
2531
- var inIframe = isDefined16(globalThis.self) && isDefined16(globalThis.top) && globalThis.self !== globalThis.top;
2546
+ function isInIframe() {
2547
+ const frameWindow = globalThis;
2548
+ return frameWindow.top != null && frameWindow.self !== frameWindow.top;
2549
+ }
2550
+ var inIframe = isInIframe();
2532
2551
  var IframeWalletWarningDecorator = (Story, args) => {
2533
2552
  const hasXyoGlobal = isXyoGlobal(globalThis.xyo);
2534
2553
  return /* @__PURE__ */ jsxs21(Stack19, { sx: { gap: 2 }, children: [