cilantro-react 0.1.3 → 0.1.4

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/index.mjs CHANGED
@@ -174,7 +174,6 @@ function CilantroAuthProvider({
174
174
  const [isLoading, setIsLoading] = useState(true);
175
175
  useEffect(() => {
176
176
  setAuthConfig({ platformApiKey: platformApiKey2, apiUrl: apiUrl2 });
177
- setSdkAuth(null);
178
177
  const storedToken = typeof window !== "undefined" ? localStorage.getItem(jwtStorageKey) : null;
179
178
  if (storedToken) {
180
179
  setToken(storedToken);
@@ -188,6 +187,8 @@ function CilantroAuthProvider({
188
187
  });
189
188
  } catch {
190
189
  }
190
+ } else {
191
+ setSdkAuth(null);
191
192
  }
192
193
  setIsLoading(false);
193
194
  }, [platformApiKey2, apiUrl2, jwtStorageKey]);
@@ -195,16 +196,16 @@ function CilantroAuthProvider({
195
196
  try {
196
197
  const result = await cilantroLogin({ usernameOrEmail, password });
197
198
  const data = result && typeof result === "object" && "data" in result ? result.data : void 0;
198
- if (!data?.jwt) throw new Error("No JWT token received from server");
199
- const jwt = data.jwt;
200
- const userType = data.userType;
199
+ const jwt = (data && "jwt" in data ? data.jwt : void 0) ?? (data && "accessToken" in data ? data.accessToken : void 0);
200
+ if (!jwt) throw new Error("No JWT token received from server");
201
+ const userType = data?.userType;
201
202
  setToken(jwt);
202
203
  setSdkAuth(jwt);
203
204
  if (typeof window !== "undefined") {
204
205
  localStorage.setItem(jwtStorageKey, jwt);
205
206
  document.cookie = `cilantro_jwt=${jwt}; path=/; max-age=${60 * 60 * 24 * 7}`;
206
207
  }
207
- if (data.user && typeof data.user === "object") {
208
+ if (data?.user && typeof data.user === "object") {
208
209
  const u = data.user;
209
210
  setUser({
210
211
  username: u.username,
@@ -286,12 +287,15 @@ function WalletProvider({ children, storageKey = DEFAULT_STORAGE_KEY }) {
286
287
  const [wallets, setWallets] = useState2([]);
287
288
  const [selectedWallet, setSelectedWallet] = useState2(null);
288
289
  const [isLoading, setIsLoading] = useState2(true);
290
+ const [error, setError] = useState2(null);
289
291
  useEffect2(() => {
290
292
  if (token) {
293
+ setSdkAuth(token);
291
294
  loadWallets();
292
295
  } else {
293
296
  setWallets([]);
294
297
  setSelectedWallet(null);
298
+ setError(null);
295
299
  setIsLoading(false);
296
300
  }
297
301
  }, [token]);
@@ -320,6 +324,7 @@ function WalletProvider({ children, storageKey = DEFAULT_STORAGE_KEY }) {
320
324
  const loadWallets = async () => {
321
325
  try {
322
326
  setIsLoading(true);
327
+ setError(null);
323
328
  if (token) setSdkAuth(token);
324
329
  const result = await findAllWallets();
325
330
  const walletsList = extractResponseData(result) ?? [];
@@ -331,9 +336,10 @@ function WalletProvider({ children, storageKey = DEFAULT_STORAGE_KEY }) {
331
336
  active: w.isActive
332
337
  }));
333
338
  setWallets(formattedWallets);
334
- } catch (error) {
335
- console.error("Failed to load wallets:", error);
339
+ } catch (err) {
340
+ console.error("Failed to load wallets:", err);
336
341
  setWallets([]);
342
+ setError(extractErrorMessage(err));
337
343
  } finally {
338
344
  setIsLoading(false);
339
345
  }
@@ -353,7 +359,8 @@ function WalletProvider({ children, storageKey = DEFAULT_STORAGE_KEY }) {
353
359
  wallets,
354
360
  selectWallet,
355
361
  refreshWallets,
356
- isLoading
362
+ isLoading,
363
+ error
357
364
  };
358
365
  return /* @__PURE__ */ jsx2(WalletContext.Provider, { value, children });
359
366
  }
@@ -1631,6 +1638,7 @@ function WalletSelector(props) {
1631
1638
  children
1632
1639
  } = props;
1633
1640
  const { wallets, selectedWallet, selectWallet, isLoading, refreshWallets } = useWallets();
1641
+ const isEmpty = !isLoading && wallets.length === 0;
1634
1642
  const effectiveValue = value ?? selectedWallet?.id ?? selectedWallet?.walletId ?? "";
1635
1643
  const selected = wallets.find((w) => w.id === effectiveValue || w.walletId === effectiveValue) ?? selectedWallet;
1636
1644
  const handleSelect = (wallet) => {
@@ -1682,6 +1690,23 @@ function WalletSelector(props) {
1682
1690
  }
1683
1691
  );
1684
1692
  }
1693
+ if (isEmpty) {
1694
+ return /* @__PURE__ */ jsxs2(
1695
+ "div",
1696
+ {
1697
+ className: cn(
1698
+ "rounded-md border border-input bg-muted/30 px-4 py-3 text-sm text-muted-foreground",
1699
+ className,
1700
+ classNames?.root
1701
+ ),
1702
+ "data-cilantro-wallet-selector": true,
1703
+ children: [
1704
+ /* @__PURE__ */ jsx6("p", { className: "font-medium text-foreground", children: "No wallets" }),
1705
+ /* @__PURE__ */ jsx6("p", { className: "mt-1", children: "Wallets are created by the platform when you sign in. If you just logged in, try refreshing." })
1706
+ ]
1707
+ }
1708
+ );
1709
+ }
1685
1710
  return /* @__PURE__ */ jsx6("div", { className: cn(className, classNames?.root), "data-cilantro-wallet-selector": true, children: /* @__PURE__ */ jsxs2(Select, { value: effectiveValue || void 0, onValueChange: handleValueChange, disabled: isLoading, children: [
1686
1711
  /* @__PURE__ */ jsx6(SelectTrigger, { className: classNames?.trigger, "aria-label": "Select wallet", children: /* @__PURE__ */ jsx6(SelectValue, { placeholder: isLoading ? "Loading..." : placeholder }) }),
1687
1712
  /* @__PURE__ */ jsx6(SelectContent, { className: classNames?.content, children: wallets.map((w) => {
@@ -3057,7 +3082,35 @@ function SignerList({
3057
3082
  i
3058
3083
  ))
3059
3084
  }
3060
- ) : isLoading ? /* @__PURE__ */ jsx22("p", { className: cn("text-sm text-muted-foreground", classNames?.message), children: "Loading signers..." }) : error ? /* @__PURE__ */ jsx22("p", { className: cn("text-sm text-destructive", classNames?.message), role: "alert", children: error }) : signers.length === 0 ? /* @__PURE__ */ jsx22("p", { className: cn("text-sm text-muted-foreground", classNames?.message), children: "No signers. Add one to get started." }) : /* @__PURE__ */ jsx22("ul", { className: cn("space-y-1", classNames?.list), role: "list", children: signers.map((signer) => /* @__PURE__ */ jsxs13("li", { className: cn("text-sm", classNames?.item), children: [
3085
+ ) : isLoading ? /* @__PURE__ */ jsx22("p", { className: cn("text-sm text-muted-foreground", classNames?.message), children: "Loading signers..." }) : error ? /* @__PURE__ */ jsxs13("div", { className: cn("rounded-md border border-destructive/50 bg-destructive/10 px-3 py-2", classNames?.message), role: "alert", children: [
3086
+ /* @__PURE__ */ jsx22("p", { className: "text-sm text-destructive", children: error }),
3087
+ /* @__PURE__ */ jsx22(
3088
+ Button,
3089
+ {
3090
+ type: "button",
3091
+ variant: "outline",
3092
+ size: "sm",
3093
+ className: "mt-2",
3094
+ onClick: () => refresh(),
3095
+ children: "Retry"
3096
+ }
3097
+ )
3098
+ ] }) : signers.length === 0 ? /* @__PURE__ */ jsxs13("div", { className: cn("rounded-md border border-input bg-muted/30 px-4 py-3 text-sm text-muted-foreground", classNames?.message), children: [
3099
+ /* @__PURE__ */ jsx22("p", { className: "font-medium text-foreground", children: "No signers" }),
3100
+ /* @__PURE__ */ jsx22("p", { className: "mt-1", children: "Add a signer to authorize transactions for this wallet." }),
3101
+ /* @__PURE__ */ jsx22(
3102
+ Button,
3103
+ {
3104
+ type: "button",
3105
+ size: "touch",
3106
+ variant: "outline",
3107
+ className: cn("mt-3", classNames?.addButton),
3108
+ onClick: () => setAddSignerOpen(true),
3109
+ "aria-label": "Add signer",
3110
+ children: "Add signer"
3111
+ }
3112
+ )
3113
+ ] }) : /* @__PURE__ */ jsx22("ul", { className: cn("space-y-1", classNames?.list), role: "list", children: signers.map((signer) => /* @__PURE__ */ jsxs13("li", { className: cn("text-sm", classNames?.item), children: [
3061
3114
  getSignerDisplayName(signer),
3062
3115
  " (",
3063
3116
  getSignerTypeLabel(signer.type || signer.signerType || ""),