@cookill/wallet-adapter 2.5.1 → 2.5.3

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/react.cjs CHANGED
@@ -1,66 +1,13 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
1
+ 'use strict';
2
+
3
+ var React2 = require('react');
4
+ var jsxRuntime = require('react/jsx-runtime');
5
+
6
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
7
+
8
+ var React2__default = /*#__PURE__*/_interopDefault(React2);
29
9
 
30
10
  // src/react.tsx
31
- var react_exports = {};
32
- __export(react_exports, {
33
- ApprovalPending: () => ApprovalPending,
34
- ConnectButton: () => ConnectButton,
35
- ConnectionStatus: () => ConnectionStatus,
36
- LoadingSpinner: () => LoadingSpinner,
37
- NETWORKS: () => NETWORKS,
38
- SafeWalletProvider: () => SafeWalletProvider,
39
- WalletErrorBoundary: () => WalletErrorBoundary,
40
- WalletModal: () => WalletModal,
41
- WalletProvider: () => WalletProvider,
42
- formatAddress: () => formatAddress,
43
- formatBalance: () => formatBalance,
44
- getRialoProvider: () => getRialoProvider,
45
- isRialoInstalled: () => isRialoInstalled,
46
- isValidAddress: () => isValidAddress,
47
- useAccounts: () => useAccounts,
48
- useActiveAccount: () => useActiveAccount,
49
- useBalance: () => useBalance,
50
- useChainId: () => useChainId,
51
- useConnectWallet: () => useConnectWallet,
52
- useDisconnectWallet: () => useDisconnectWallet,
53
- useIsConnected: () => useIsConnected,
54
- useNetwork: () => useNetwork,
55
- useSendTransaction: () => useSendTransaction,
56
- useSignMessage: () => useSignMessage,
57
- useSignTransaction: () => useSignTransaction,
58
- useSwitchNetwork: () => useSwitchNetwork,
59
- useWallet: () => useWallet,
60
- withWalletErrorBoundary: () => withWalletErrorBoundary
61
- });
62
- module.exports = __toCommonJS(react_exports);
63
- var import_react2 = __toESM(require("react"), 1);
64
11
 
65
12
  // src/index.ts
66
13
  var NETWORKS = {
@@ -156,11 +103,7 @@ function isValidAddress(address) {
156
103
  if (address.length < 32 || address.length > 50) return false;
157
104
  return /^[1-9A-HJ-NP-Za-km-z]+$/.test(address);
158
105
  }
159
-
160
- // src/ErrorBoundary.tsx
161
- var import_react = require("react");
162
- var import_jsx_runtime = require("react/jsx-runtime");
163
- var WalletErrorBoundary = class extends import_react.Component {
106
+ var WalletErrorBoundary = class extends React2.Component {
164
107
  constructor() {
165
108
  super(...arguments);
166
109
  this.state = {
@@ -183,7 +126,7 @@ var WalletErrorBoundary = class extends import_react.Component {
183
126
  if (this.props.fallback) {
184
127
  return this.props.fallback;
185
128
  }
186
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
129
+ return /* @__PURE__ */ jsxRuntime.jsxs(
187
130
  "div",
188
131
  {
189
132
  style: {
@@ -194,7 +137,7 @@ var WalletErrorBoundary = class extends import_react.Component {
194
137
  textAlign: "center"
195
138
  },
196
139
  children: [
197
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
140
+ /* @__PURE__ */ jsxRuntime.jsx(
198
141
  "div",
199
142
  {
200
143
  style: {
@@ -207,7 +150,7 @@ var WalletErrorBoundary = class extends import_react.Component {
207
150
  alignItems: "center",
208
151
  justifyContent: "center"
209
152
  },
210
- children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
153
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
211
154
  "svg",
212
155
  {
213
156
  width: "24",
@@ -219,17 +162,17 @@ var WalletErrorBoundary = class extends import_react.Component {
219
162
  strokeLinecap: "round",
220
163
  strokeLinejoin: "round",
221
164
  children: [
222
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("circle", { cx: "12", cy: "12", r: "10" }),
223
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "12", y1: "8", x2: "12", y2: "12" }),
224
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("line", { x1: "12", y1: "16", x2: "12.01", y2: "16" })
165
+ /* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "10" }),
166
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "12", y1: "8", x2: "12", y2: "12" }),
167
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "12", y1: "16", x2: "12.01", y2: "16" })
225
168
  ]
226
169
  }
227
170
  )
228
171
  }
229
172
  ),
230
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h3", { style: { margin: "0 0 8px", fontSize: "16px", fontWeight: 600, color: "#991b1b" }, children: "Wallet Connection Error" }),
231
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { style: { margin: "0 0 16px", fontSize: "14px", color: "#b91c1c" }, children: this.state.error?.message || "Something went wrong" }),
232
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
173
+ /* @__PURE__ */ jsxRuntime.jsx("h3", { style: { margin: "0 0 8px", fontSize: "16px", fontWeight: 600, color: "#991b1b" }, children: "Wallet Connection Error" }),
174
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { margin: "0 0 16px", fontSize: "14px", color: "#b91c1c" }, children: this.state.error?.message || "Something went wrong" }),
175
+ /* @__PURE__ */ jsxRuntime.jsx(
233
176
  "button",
234
177
  {
235
178
  onClick: this.handleRetry,
@@ -253,9 +196,6 @@ var WalletErrorBoundary = class extends import_react.Component {
253
196
  return this.props.children;
254
197
  }
255
198
  };
256
-
257
- // src/LoadingStates.tsx
258
- var import_jsx_runtime2 = require("react/jsx-runtime");
259
199
  function LoadingSpinner({ size = "md", color = "#6EB9A8", className = "" }) {
260
200
  const sizes = {
261
201
  sm: { container: 20, stroke: 2 },
@@ -265,7 +205,7 @@ function LoadingSpinner({ size = "md", color = "#6EB9A8", className = "" }) {
265
205
  const { container, stroke } = sizes[size];
266
206
  const radius = (container - stroke) / 2;
267
207
  const circumference = radius * 2 * Math.PI;
268
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
208
+ return /* @__PURE__ */ jsxRuntime.jsxs(
269
209
  "svg",
270
210
  {
271
211
  width: container,
@@ -274,13 +214,13 @@ function LoadingSpinner({ size = "md", color = "#6EB9A8", className = "" }) {
274
214
  className,
275
215
  style: { animation: "wallet-spin 1s linear infinite" },
276
216
  children: [
277
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("style", { children: `
217
+ /* @__PURE__ */ jsxRuntime.jsx("style", { children: `
278
218
  @keyframes wallet-spin {
279
219
  from { transform: rotate(0deg); }
280
220
  to { transform: rotate(360deg); }
281
221
  }
282
222
  ` }),
283
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
223
+ /* @__PURE__ */ jsxRuntime.jsx(
284
224
  "circle",
285
225
  {
286
226
  cx: container / 2,
@@ -292,7 +232,7 @@ function LoadingSpinner({ size = "md", color = "#6EB9A8", className = "" }) {
292
232
  strokeOpacity: 0.2
293
233
  }
294
234
  ),
295
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
235
+ /* @__PURE__ */ jsxRuntime.jsx(
296
236
  "circle",
297
237
  {
298
238
  cx: container / 2,
@@ -316,7 +256,7 @@ function ApprovalPending({
316
256
  walletName = "Sheep Wallet",
317
257
  onCancel
318
258
  }) {
319
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
259
+ return /* @__PURE__ */ jsxRuntime.jsxs(
320
260
  "div",
321
261
  {
322
262
  style: {
@@ -327,7 +267,7 @@ function ApprovalPending({
327
267
  border: "1px solid #e2e8f0"
328
268
  },
329
269
  children: [
330
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
270
+ /* @__PURE__ */ jsxRuntime.jsxs(
331
271
  "div",
332
272
  {
333
273
  style: {
@@ -342,8 +282,8 @@ function ApprovalPending({
342
282
  position: "relative"
343
283
  },
344
284
  children: [
345
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(LoadingSpinner, { size: "lg" }),
346
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
285
+ /* @__PURE__ */ jsxRuntime.jsx(LoadingSpinner, { size: "lg" }),
286
+ /* @__PURE__ */ jsxRuntime.jsx(
347
287
  "div",
348
288
  {
349
289
  style: {
@@ -359,7 +299,7 @@ function ApprovalPending({
359
299
  ]
360
300
  }
361
301
  ),
362
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
302
+ /* @__PURE__ */ jsxRuntime.jsx(
363
303
  "h3",
364
304
  {
365
305
  style: {
@@ -371,7 +311,7 @@ function ApprovalPending({
371
311
  children: title
372
312
  }
373
313
  ),
374
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
314
+ /* @__PURE__ */ jsxRuntime.jsx(
375
315
  "p",
376
316
  {
377
317
  style: {
@@ -382,7 +322,7 @@ function ApprovalPending({
382
322
  children: message
383
323
  }
384
324
  ),
385
- /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
325
+ /* @__PURE__ */ jsxRuntime.jsxs(
386
326
  "p",
387
327
  {
388
328
  style: {
@@ -397,7 +337,7 @@ function ApprovalPending({
397
337
  ]
398
338
  }
399
339
  ),
400
- onCancel && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
340
+ onCancel && /* @__PURE__ */ jsxRuntime.jsx(
401
341
  "button",
402
342
  {
403
343
  onClick: onCancel,
@@ -456,7 +396,7 @@ function ConnectionStatus({ status, message, onRetry }) {
456
396
  }
457
397
  };
458
398
  const config = statusConfig[status];
459
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
399
+ return /* @__PURE__ */ jsxRuntime.jsxs(
460
400
  "div",
461
401
  {
462
402
  style: {
@@ -467,7 +407,7 @@ function ConnectionStatus({ status, message, onRetry }) {
467
407
  textAlign: "center"
468
408
  },
469
409
  children: [
470
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
410
+ /* @__PURE__ */ jsxRuntime.jsx(
471
411
  "div",
472
412
  {
473
413
  style: {
@@ -480,15 +420,15 @@ function ConnectionStatus({ status, message, onRetry }) {
480
420
  alignItems: "center",
481
421
  justifyContent: "center"
482
422
  },
483
- children: status === "success" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: config.color, strokeWidth: "2", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("polyline", { points: "20,6 9,17 4,12" }) }) : status === "error" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: config.color, strokeWidth: "2", children: [
484
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
485
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
486
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(LoadingSpinner, { size: "sm", color: config.color })
423
+ children: status === "success" ? /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: config.color, strokeWidth: "2", children: /* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "20,6 9,17 4,12" }) }) : status === "error" ? /* @__PURE__ */ jsxRuntime.jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: config.color, strokeWidth: "2", children: [
424
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
425
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
426
+ ] }) : /* @__PURE__ */ jsxRuntime.jsx(LoadingSpinner, { size: "sm", color: config.color })
487
427
  }
488
428
  ),
489
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h4", { style: { margin: "0 0 4px", fontSize: "14px", fontWeight: 600, color: config.color }, children: config.title }),
490
- /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { style: { margin: 0, fontSize: "12px", color: "#64748b" }, children: message || config.defaultMessage }),
491
- status === "error" && onRetry && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
429
+ /* @__PURE__ */ jsxRuntime.jsx("h4", { style: { margin: "0 0 4px", fontSize: "14px", fontWeight: 600, color: config.color }, children: config.title }),
430
+ /* @__PURE__ */ jsxRuntime.jsx("p", { style: { margin: 0, fontSize: "12px", color: "#64748b" }, children: message || config.defaultMessage }),
431
+ status === "error" && onRetry && /* @__PURE__ */ jsxRuntime.jsx(
492
432
  "button",
493
433
  {
494
434
  onClick: onRetry,
@@ -510,19 +450,25 @@ function ConnectionStatus({ status, message, onRetry }) {
510
450
  }
511
451
  );
512
452
  }
513
-
514
- // src/react.tsx
515
- var import_jsx_runtime3 = require("react/jsx-runtime");
516
- var SHEEP_WALLET_ICON = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZpZXdCb3g9IjAgMCAzMiAzMiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHJ4PSI4IiBmaWxsPSIjMUExQTFBIi8+PGNpcmNsZSBjeD0iMTYiIGN5PSIxNCIgcj0iOCIgZmlsbD0iI0ZGRjhGMCIvPjxjaXJjbGUgY3g9IjEyIiBjeT0iMTAiIHI9IjQiIGZpbGw9IiNGRkY4RjAiLz48Y2lyY2xlIGN4PSIyMCIgY3k9IjEwIiByPSI0IiBmaWxsPSIjRkZGOEYwIi8+PGNpcmNsZSBjeD0iMTMiIGN5PSIxMyIgcj0iMS41IiBmaWxsPSIjMzMzIi8+PGNpcmNsZSBjeD0iMTkiIGN5PSIxMyIgcj0iMS41IiBmaWxsPSIjMzMzIi8+PGVsbGlwc2UgY3g9IjE2IiBjeT0iMTciIHJ4PSIyIiByeT0iMS41IiBmaWxsPSIjRkZDMENCIi8+PHBhdGggZD0iTTE0IDI0QzE0IDIyLjkgMTQuOSAyMiAxNiAyMkMxNy4xIDIyIDE4IDIyLjkgMTggMjRWMjZIMTRWMjRaIiBmaWxsPSIjNkVCOUE4Ii8+PC9zdmc+";
517
453
  var DEFAULT_WALLETS = [
518
454
  {
519
455
  id: "sheep-wallet",
520
456
  name: "Sheep Wallet",
521
- icon: SHEEP_WALLET_ICON,
457
+ icon: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZpZXdCb3g9IjAgMCAzMiAzMiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHJ4PSI4IiBmaWxsPSIjMDExQjI5Ii8+PHRleHQgeD0iNTAlIiB5PSI1NSUiIGRvbWluYW50LWJhc2VsaW5lPSJtaWRkbGUiIHRleHQtYW5jaG9yPSJtaWRkbGUiIGZvbnQtZmFtaWx5PSJzYW5zLXNlcmlmIiBmb250LXdlaWdodD0iYm9sZCIgZm9udC1zaXplPSIxNiIgZmlsbD0iIzZFQjlBOCI+Uzwvc2VsZj48L3N2Zz4=",
522
458
  downloadUrl: "https://rialo.io/wallet"
523
459
  }
524
460
  ];
525
- var WalletContext = (0, import_react2.createContext)(null);
461
+ var CONNECT_TIMEOUT_MS = 2e4;
462
+ function withTimeout(promise, ms, message) {
463
+ let timeoutId;
464
+ const timeout = new Promise((_, reject) => {
465
+ timeoutId = setTimeout(() => reject(new Error(message)), ms);
466
+ });
467
+ return Promise.race([promise, timeout]).finally(() => {
468
+ if (timeoutId) clearTimeout(timeoutId);
469
+ });
470
+ }
471
+ var WalletContext = React2.createContext(null);
526
472
  function WalletProvider({
527
473
  children,
528
474
  network: initialNetwork = "devnet",
@@ -533,26 +479,27 @@ function WalletProvider({
533
479
  onError,
534
480
  onNetworkChange
535
481
  }) {
536
- const [connected, setConnected] = (0, import_react2.useState)(false);
537
- const [connecting, setConnecting] = (0, import_react2.useState)(false);
538
- const [accounts, setAccounts] = (0, import_react2.useState)([]);
539
- const [network, setNetwork] = (0, import_react2.useState)(initialNetwork);
540
- const [balance, setBalance] = (0, import_react2.useState)(null);
541
- const [selectedWallet, setSelectedWallet] = (0, import_react2.useState)(null);
542
- const [isModalOpen, setIsModalOpen] = (0, import_react2.useState)(false);
543
- const [provider, setProvider] = (0, import_react2.useState)();
544
- const [error, setError] = (0, import_react2.useState)(null);
545
- const chainId = (0, import_react2.useMemo)(() => `rialo:${network}`, [network]);
482
+ const [connected, setConnected] = React2.useState(false);
483
+ const [connecting, setConnecting] = React2.useState(false);
484
+ const [accounts, setAccounts] = React2.useState([]);
485
+ const [network, setNetwork] = React2.useState(initialNetwork);
486
+ const [balance, setBalance] = React2.useState(null);
487
+ const [selectedWallet, setSelectedWallet] = React2.useState(null);
488
+ const [isModalOpen, setIsModalOpen] = React2.useState(false);
489
+ const [provider, setProvider] = React2.useState();
490
+ const [error, setError] = React2.useState(null);
491
+ const connectPromiseRef = React2.useRef(null);
492
+ const chainId = React2.useMemo(() => `rialo:${network}`, [network]);
546
493
  const activeAccount = accounts[0] || null;
547
494
  const isInstalled = isRialoInstalled();
548
- const wallets = (0, import_react2.useMemo)(() => {
495
+ const wallets = React2.useMemo(() => {
549
496
  const installed = isRialoInstalled();
550
497
  return [...DEFAULT_WALLETS, ...customWallets].map((w) => ({
551
498
  ...w,
552
499
  installed: w.id === "sheep-wallet" ? installed : false
553
500
  }));
554
501
  }, [customWallets]);
555
- (0, import_react2.useEffect)(() => {
502
+ React2.useEffect(() => {
556
503
  const init = async () => {
557
504
  const p = await waitForRialoProvider(3e3);
558
505
  setProvider(p);
@@ -562,7 +509,7 @@ function WalletProvider({
562
509
  };
563
510
  init();
564
511
  }, [wallets]);
565
- const refreshBalance = (0, import_react2.useCallback)(async () => {
512
+ const refreshBalance = React2.useCallback(async () => {
566
513
  if (!provider || !activeAccount) return;
567
514
  try {
568
515
  const result = await provider.getBalance(activeAccount.address);
@@ -572,24 +519,42 @@ function WalletProvider({
572
519
  console.error("Balance fetch error:", e);
573
520
  }
574
521
  }, [provider, activeAccount]);
575
- (0, import_react2.useEffect)(() => {
522
+ React2.useEffect(() => {
576
523
  if (connected && activeAccount && provider) {
577
524
  refreshBalance();
578
525
  const interval = setInterval(refreshBalance, 3e4);
579
526
  return () => clearInterval(interval);
580
527
  }
581
528
  }, [connected, activeAccount, provider, refreshBalance]);
582
- (0, import_react2.useEffect)(() => {
583
- if (autoConnect && provider && !connected && !connecting) {
584
- provider.isConnected().then((isConn) => {
585
- if (isConn) {
586
- handleConnect();
529
+ React2.useEffect(() => {
530
+ if (!autoConnect || !provider || connected || connecting) return;
531
+ let cancelled = false;
532
+ provider.isConnected().then(async (isConn) => {
533
+ if (!isConn || cancelled) return;
534
+ try {
535
+ const rawAccounts = await withTimeout(provider.getAccounts(), 5e3, "Auto-connect timed out");
536
+ const normalized = (rawAccounts || []).map((acc) => {
537
+ if (typeof acc === "string") return { address: acc, publicKey: acc };
538
+ return { address: acc.address, publicKey: acc.publicKey || acc.address };
539
+ });
540
+ if (cancelled) return;
541
+ setAccounts(normalized);
542
+ setConnected(true);
543
+ try {
544
+ const net = await provider.getNetwork();
545
+ if (!cancelled) setNetwork(net);
546
+ } catch {
587
547
  }
588
- }).catch(() => {
589
- });
590
- }
591
- }, [provider, autoConnect, connected, connecting]);
592
- (0, import_react2.useEffect)(() => {
548
+ onConnect?.(normalized);
549
+ } catch {
550
+ }
551
+ }).catch(() => {
552
+ });
553
+ return () => {
554
+ cancelled = true;
555
+ };
556
+ }, [provider, autoConnect, connected, connecting, onConnect]);
557
+ React2.useEffect(() => {
593
558
  if (!provider) return;
594
559
  const cleanupFns = [];
595
560
  cleanupFns.push(
@@ -638,48 +603,65 @@ function WalletProvider({
638
603
  cleanupFns.forEach((fn) => fn?.());
639
604
  };
640
605
  }, [provider, onDisconnect, onNetworkChange]);
641
- const handleConnect = (0, import_react2.useCallback)(async () => {
642
- if (!provider) {
643
- const err = new Error("Rialo Wallet not installed");
644
- setError(err);
645
- onError?.(err);
646
- throw err;
606
+ const handleConnect = React2.useCallback(async () => {
607
+ if (connectPromiseRef.current) {
608
+ return connectPromiseRef.current;
647
609
  }
648
- setConnecting(true);
649
- setError(null);
650
- try {
651
- console.log("[Adapter] Calling provider.connect()...");
652
- const result = await provider.connect();
653
- console.log("[Adapter] Connect result:", result);
654
- const walletAccounts = result.map((acc) => {
655
- if (typeof acc === "string") {
656
- return { address: acc, publicKey: acc };
657
- }
658
- return {
659
- address: acc.address,
660
- publicKey: acc.publicKey || acc.address
661
- };
662
- });
663
- setAccounts(walletAccounts);
664
- setConnected(true);
665
- setIsModalOpen(false);
610
+ const run = (async () => {
611
+ if (!provider) {
612
+ const err = new Error("Rialo Wallet not installed");
613
+ setError(err);
614
+ onError?.(err);
615
+ throw err;
616
+ }
617
+ setIsModalOpen(true);
618
+ setConnecting(true);
619
+ setError(null);
666
620
  try {
667
- const net = await provider.getNetwork();
668
- setNetwork(net);
669
- } catch {
621
+ console.log("[Adapter] Calling provider.connect()...");
622
+ const result = await withTimeout(
623
+ provider.connect(),
624
+ CONNECT_TIMEOUT_MS,
625
+ "Connect timed out. Please open Sheep Wallet extension and approve the request."
626
+ );
627
+ console.log("[Adapter] Connect result:", result);
628
+ const walletAccounts = result.map((acc) => {
629
+ if (typeof acc === "string") {
630
+ return { address: acc, publicKey: acc };
631
+ }
632
+ return {
633
+ address: acc.address,
634
+ publicKey: acc.publicKey || acc.address
635
+ };
636
+ });
637
+ setAccounts(walletAccounts);
638
+ setConnected(true);
639
+ setIsModalOpen(false);
640
+ try {
641
+ const net = await withTimeout(provider.getNetwork(), 5e3, "Network request timed out");
642
+ setNetwork(net);
643
+ } catch {
644
+ }
645
+ onConnect?.(walletAccounts);
646
+ return walletAccounts;
647
+ } catch (e) {
648
+ const err = e;
649
+ setError(err);
650
+ onError?.(err);
651
+ setIsModalOpen(true);
652
+ throw err;
653
+ } finally {
654
+ setConnecting(false);
670
655
  }
671
- onConnect?.(walletAccounts);
672
- return walletAccounts;
673
- } catch (e) {
674
- const err = e;
675
- setError(err);
676
- onError?.(err);
677
- throw err;
656
+ })();
657
+ connectPromiseRef.current = run;
658
+ try {
659
+ return await run;
678
660
  } finally {
679
- setConnecting(false);
661
+ connectPromiseRef.current = null;
680
662
  }
681
663
  }, [provider, onConnect, onError]);
682
- const handleDisconnect = (0, import_react2.useCallback)(async () => {
664
+ const handleDisconnect = React2.useCallback(async () => {
683
665
  try {
684
666
  if (provider) {
685
667
  await provider.disconnect();
@@ -691,7 +673,7 @@ function WalletProvider({
691
673
  setBalance(null);
692
674
  onDisconnect?.();
693
675
  }, [provider, onDisconnect]);
694
- const selectWallet = (0, import_react2.useCallback)((walletId) => {
676
+ const selectWallet = React2.useCallback((walletId) => {
695
677
  const wallet = wallets.find((w) => w.id === walletId);
696
678
  if (wallet) {
697
679
  setSelectedWallet(wallet);
@@ -702,40 +684,40 @@ function WalletProvider({
702
684
  }
703
685
  }
704
686
  }, [wallets, handleConnect]);
705
- const handleSwitchNetwork = (0, import_react2.useCallback)(async (newNetwork) => {
687
+ const handleSwitchNetwork = React2.useCallback(async (newNetwork) => {
706
688
  if (provider) {
707
689
  await provider.switchNetwork(newNetwork);
708
690
  }
709
691
  setNetwork(newNetwork);
710
692
  onNetworkChange?.(newNetwork);
711
693
  }, [provider, onNetworkChange]);
712
- const handleSignMessage = (0, import_react2.useCallback)(async (message) => {
694
+ const handleSignMessage = React2.useCallback(async (message) => {
713
695
  if (!provider || !connected) {
714
696
  throw new Error("Wallet not connected");
715
697
  }
716
698
  return provider.signMessage(message);
717
699
  }, [provider, connected]);
718
- const handleSignTransaction = (0, import_react2.useCallback)(async (tx) => {
700
+ const handleSignTransaction = React2.useCallback(async (tx) => {
719
701
  if (!provider || !connected) {
720
702
  throw new Error("Wallet not connected");
721
703
  }
722
704
  const result = await provider.signTransaction(tx);
723
705
  return result.signature;
724
706
  }, [provider, connected]);
725
- const handleSendTransaction = (0, import_react2.useCallback)(async (tx) => {
707
+ const handleSendTransaction = React2.useCallback(async (tx) => {
726
708
  if (!provider || !connected) {
727
709
  throw new Error("Wallet not connected");
728
710
  }
729
711
  return provider.sendTransaction(tx);
730
712
  }, [provider, connected]);
731
- const handleSignAndSendTransaction = (0, import_react2.useCallback)(async (tx) => {
713
+ const handleSignAndSendTransaction = React2.useCallback(async (tx) => {
732
714
  if (!provider || !connected) {
733
715
  throw new Error("Wallet not connected");
734
716
  }
735
717
  return provider.signAndSendTransaction(tx);
736
718
  }, [provider, connected]);
737
- const openModal = (0, import_react2.useCallback)(() => setIsModalOpen(true), []);
738
- const closeModal = (0, import_react2.useCallback)(() => setIsModalOpen(false), []);
719
+ const openModal = React2.useCallback(() => setIsModalOpen(true), []);
720
+ const closeModal = React2.useCallback(() => setIsModalOpen(false), []);
739
721
  const value = {
740
722
  connected,
741
723
  connecting,
@@ -761,13 +743,13 @@ function WalletProvider({
761
743
  openModal,
762
744
  closeModal
763
745
  };
764
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(WalletContext.Provider, { value, children: [
746
+ return /* @__PURE__ */ jsxRuntime.jsxs(WalletContext.Provider, { value, children: [
765
747
  children,
766
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(WalletModal, {})
748
+ /* @__PURE__ */ jsxRuntime.jsx(WalletModal, {})
767
749
  ] });
768
750
  }
769
751
  function useWallet() {
770
- const context = (0, import_react2.useContext)(WalletContext);
752
+ const context = React2.useContext(WalletContext);
771
753
  if (!context) {
772
754
  throw new Error("useWallet must be used within WalletProvider");
773
755
  }
@@ -807,9 +789,9 @@ function useChainId() {
807
789
  }
808
790
  function useSwitchNetwork() {
809
791
  const { switchNetwork, network } = useWallet();
810
- const [switching, setSwitching] = (0, import_react2.useState)(false);
811
- const [error, setError] = (0, import_react2.useState)(null);
812
- const doSwitch = (0, import_react2.useCallback)(async (newNetwork) => {
792
+ const [switching, setSwitching] = React2.useState(false);
793
+ const [error, setError] = React2.useState(null);
794
+ const doSwitch = React2.useCallback(async (newNetwork) => {
813
795
  setSwitching(true);
814
796
  setError(null);
815
797
  try {
@@ -825,7 +807,7 @@ function useSwitchNetwork() {
825
807
  }
826
808
  function useConnectWallet() {
827
809
  const { connect, connecting, openModal, isInstalled, error } = useWallet();
828
- const handleConnect = (0, import_react2.useCallback)(() => {
810
+ const handleConnect = React2.useCallback(() => {
829
811
  openModal();
830
812
  }, [openModal]);
831
813
  return {
@@ -843,10 +825,10 @@ function useDisconnectWallet() {
843
825
  }
844
826
  function useSignMessage() {
845
827
  const { signMessage, connected, activeAccount } = useWallet();
846
- const [signing, setSigning] = (0, import_react2.useState)(false);
847
- const [signature, setSignature] = (0, import_react2.useState)(null);
848
- const [error, setError] = (0, import_react2.useState)(null);
849
- const sign = (0, import_react2.useCallback)(async (message) => {
828
+ const [signing, setSigning] = React2.useState(false);
829
+ const [signature, setSignature] = React2.useState(null);
830
+ const [error, setError] = React2.useState(null);
831
+ const sign = React2.useCallback(async (message) => {
850
832
  if (!connected) {
851
833
  setError(new Error("Wallet not connected"));
852
834
  return null;
@@ -868,10 +850,10 @@ function useSignMessage() {
868
850
  }
869
851
  function useSendTransaction() {
870
852
  const { signAndSendTransaction, connected } = useWallet();
871
- const [sending, setSending] = (0, import_react2.useState)(false);
872
- const [txHash, setTxHash] = (0, import_react2.useState)(null);
873
- const [error, setError] = (0, import_react2.useState)(null);
874
- const send = (0, import_react2.useCallback)(async (tx) => {
853
+ const [sending, setSending] = React2.useState(false);
854
+ const [txHash, setTxHash] = React2.useState(null);
855
+ const [error, setError] = React2.useState(null);
856
+ const send = React2.useCallback(async (tx) => {
875
857
  if (!connected) {
876
858
  setError(new Error("Wallet not connected"));
877
859
  return null;
@@ -896,10 +878,10 @@ function useSendTransaction() {
896
878
  }
897
879
  function useSignTransaction() {
898
880
  const { signTransaction, connected } = useWallet();
899
- const [signing, setSigning] = (0, import_react2.useState)(false);
900
- const [signature, setSignature] = (0, import_react2.useState)(null);
901
- const [error, setError] = (0, import_react2.useState)(null);
902
- const sign = (0, import_react2.useCallback)(async (tx) => {
881
+ const [signing, setSigning] = React2.useState(false);
882
+ const [signature, setSignature] = React2.useState(null);
883
+ const [error, setError] = React2.useState(null);
884
+ const sign = React2.useCallback(async (tx) => {
903
885
  if (!connected) {
904
886
  setError(new Error("Wallet not connected"));
905
887
  return null;
@@ -939,7 +921,7 @@ function ConnectButton({
939
921
  ...style
940
922
  };
941
923
  if (connecting) {
942
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
924
+ return /* @__PURE__ */ jsxRuntime.jsx(
943
925
  "button",
944
926
  {
945
927
  disabled: true,
@@ -950,7 +932,7 @@ function ConnectButton({
950
932
  );
951
933
  }
952
934
  if (connected && activeAccount) {
953
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
935
+ return /* @__PURE__ */ jsxRuntime.jsxs(
954
936
  "button",
955
937
  {
956
938
  onClick: () => disconnect(),
@@ -961,7 +943,7 @@ function ConnectButton({
961
943
  color: "white"
962
944
  },
963
945
  children: [
964
- showBalance && balance && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { style: { marginRight: 8 }, children: [
946
+ showBalance && balance && /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { marginRight: 8 }, children: [
965
947
  formatBalance(balance),
966
948
  " RLO"
967
949
  ] }),
@@ -970,7 +952,7 @@ function ConnectButton({
970
952
  }
971
953
  );
972
954
  }
973
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
955
+ return /* @__PURE__ */ jsxRuntime.jsx(
974
956
  "button",
975
957
  {
976
958
  onClick: openModal,
@@ -986,15 +968,15 @@ function ConnectButton({
986
968
  }
987
969
  var walletModalOwnerToken = null;
988
970
  function WalletModal({ title = "Connect Wallet", className = "" }) {
989
- const ownerRef = import_react2.default.useRef({});
990
- const [isOwner] = (0, import_react2.useState)(() => {
971
+ const ownerRef = React2__default.default.useRef({});
972
+ const [isOwner] = React2.useState(() => {
991
973
  if (!walletModalOwnerToken) {
992
974
  walletModalOwnerToken = ownerRef.current;
993
975
  return true;
994
976
  }
995
977
  return walletModalOwnerToken === ownerRef.current;
996
978
  });
997
- (0, import_react2.useEffect)(() => {
979
+ React2.useEffect(() => {
998
980
  return () => {
999
981
  if (isOwner && walletModalOwnerToken === ownerRef.current) {
1000
982
  walletModalOwnerToken = null;
@@ -1004,7 +986,7 @@ function WalletModal({ title = "Connect Wallet", className = "" }) {
1004
986
  if (!isOwner) return null;
1005
987
  const { isModalOpen, closeModal, wallets, selectWallet, connecting } = useWallet();
1006
988
  if (!isModalOpen) return null;
1007
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
989
+ return /* @__PURE__ */ jsxRuntime.jsx(
1008
990
  "div",
1009
991
  {
1010
992
  className,
@@ -1018,7 +1000,7 @@ function WalletModal({ title = "Connect Wallet", className = "" }) {
1018
1000
  backgroundColor: "rgba(0, 0, 0, 0.5)"
1019
1001
  },
1020
1002
  onClick: closeModal,
1021
- children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1003
+ children: /* @__PURE__ */ jsxRuntime.jsxs(
1022
1004
  "div",
1023
1005
  {
1024
1006
  style: {
@@ -1032,9 +1014,9 @@ function WalletModal({ title = "Connect Wallet", className = "" }) {
1032
1014
  },
1033
1015
  onClick: (e) => e.stopPropagation(),
1034
1016
  children: [
1035
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: "20px" }, children: [
1036
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h2", { style: { margin: 0, fontSize: "18px", fontWeight: 600 }, children: title }),
1037
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1017
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", justifyContent: "space-between", alignItems: "center", marginBottom: "20px" }, children: [
1018
+ /* @__PURE__ */ jsxRuntime.jsx("h2", { style: { margin: 0, fontSize: "18px", fontWeight: 600 }, children: title }),
1019
+ /* @__PURE__ */ jsxRuntime.jsx(
1038
1020
  "button",
1039
1021
  {
1040
1022
  onClick: closeModal,
@@ -1043,7 +1025,7 @@ function WalletModal({ title = "Connect Wallet", className = "" }) {
1043
1025
  }
1044
1026
  )
1045
1027
  ] }),
1046
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { display: "flex", flexDirection: "column", gap: "12px" }, children: wallets.map((wallet) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
1028
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { display: "flex", flexDirection: "column", gap: "12px" }, children: wallets.map((wallet) => /* @__PURE__ */ jsxRuntime.jsxs(
1047
1029
  "button",
1048
1030
  {
1049
1031
  onClick: () => selectWallet(wallet.id),
@@ -1061,17 +1043,17 @@ function WalletModal({ title = "Connect Wallet", className = "" }) {
1061
1043
  transition: "all 0.2s ease"
1062
1044
  },
1063
1045
  children: [
1064
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("img", { src: wallet.icon, alt: wallet.name, style: { width: 40, height: 40, borderRadius: 8 } }),
1065
- /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { textAlign: "left", flex: 1 }, children: [
1066
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontWeight: 500 }, children: wallet.name }),
1067
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { fontSize: "12px", color: "#666" }, children: wallet.installed ? "Detected" : "Not installed" })
1046
+ /* @__PURE__ */ jsxRuntime.jsx("img", { src: wallet.icon, alt: wallet.name, style: { width: 40, height: 40, borderRadius: 8 } }),
1047
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { style: { textAlign: "left", flex: 1 }, children: [
1048
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontWeight: 500 }, children: wallet.name }),
1049
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { fontSize: "12px", color: "#666" }, children: wallet.installed ? "Detected" : "Not installed" })
1068
1050
  ] }),
1069
- !wallet.installed && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontSize: "12px", color: "#6EB9A8" }, children: "Install \u2192" })
1051
+ !wallet.installed && /* @__PURE__ */ jsxRuntime.jsx("span", { style: { fontSize: "12px", color: "#6EB9A8" }, children: "Install \u2192" })
1070
1052
  ]
1071
1053
  },
1072
1054
  wallet.id
1073
1055
  )) }),
1074
- /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { marginTop: "20px", textAlign: "center", fontSize: "12px", color: "#999" }, children: "Powered by CookilLabs" })
1056
+ /* @__PURE__ */ jsxRuntime.jsx("div", { style: { marginTop: "20px", textAlign: "center", fontSize: "12px", color: "#999" }, children: "Powered by CookilLabs" })
1075
1057
  ]
1076
1058
  }
1077
1059
  )
@@ -1080,42 +1062,41 @@ function WalletModal({ title = "Connect Wallet", className = "" }) {
1080
1062
  }
1081
1063
  function withWalletErrorBoundary(WrappedComponent, fallback) {
1082
1064
  return function WithErrorBoundary(props) {
1083
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(WalletErrorBoundary, { fallback, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(WrappedComponent, { ...props }) });
1065
+ return /* @__PURE__ */ jsxRuntime.jsx(WalletErrorBoundary, { fallback, children: /* @__PURE__ */ jsxRuntime.jsx(WrappedComponent, { ...props }) });
1084
1066
  };
1085
1067
  }
1086
1068
  function SafeWalletProvider(props) {
1087
1069
  const { errorFallback, ...providerProps } = props;
1088
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(WalletErrorBoundary, { fallback: errorFallback, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(WalletProvider, { ...providerProps }) });
1070
+ return /* @__PURE__ */ jsxRuntime.jsx(WalletErrorBoundary, { fallback: errorFallback, children: /* @__PURE__ */ jsxRuntime.jsx(WalletProvider, { ...providerProps }) });
1089
1071
  }
1090
- // Annotate the CommonJS export names for ESM import in node:
1091
- 0 && (module.exports = {
1092
- ApprovalPending,
1093
- ConnectButton,
1094
- ConnectionStatus,
1095
- LoadingSpinner,
1096
- NETWORKS,
1097
- SafeWalletProvider,
1098
- WalletErrorBoundary,
1099
- WalletModal,
1100
- WalletProvider,
1101
- formatAddress,
1102
- formatBalance,
1103
- getRialoProvider,
1104
- isRialoInstalled,
1105
- isValidAddress,
1106
- useAccounts,
1107
- useActiveAccount,
1108
- useBalance,
1109
- useChainId,
1110
- useConnectWallet,
1111
- useDisconnectWallet,
1112
- useIsConnected,
1113
- useNetwork,
1114
- useSendTransaction,
1115
- useSignMessage,
1116
- useSignTransaction,
1117
- useSwitchNetwork,
1118
- useWallet,
1119
- withWalletErrorBoundary
1120
- });
1072
+
1073
+ exports.ApprovalPending = ApprovalPending;
1074
+ exports.ConnectButton = ConnectButton;
1075
+ exports.ConnectionStatus = ConnectionStatus;
1076
+ exports.LoadingSpinner = LoadingSpinner;
1077
+ exports.NETWORKS = NETWORKS;
1078
+ exports.SafeWalletProvider = SafeWalletProvider;
1079
+ exports.WalletErrorBoundary = WalletErrorBoundary;
1080
+ exports.WalletModal = WalletModal;
1081
+ exports.WalletProvider = WalletProvider;
1082
+ exports.formatAddress = formatAddress;
1083
+ exports.formatBalance = formatBalance;
1084
+ exports.getRialoProvider = getRialoProvider;
1085
+ exports.isRialoInstalled = isRialoInstalled;
1086
+ exports.isValidAddress = isValidAddress;
1087
+ exports.useAccounts = useAccounts;
1088
+ exports.useActiveAccount = useActiveAccount;
1089
+ exports.useBalance = useBalance;
1090
+ exports.useChainId = useChainId;
1091
+ exports.useConnectWallet = useConnectWallet;
1092
+ exports.useDisconnectWallet = useDisconnectWallet;
1093
+ exports.useIsConnected = useIsConnected;
1094
+ exports.useNetwork = useNetwork;
1095
+ exports.useSendTransaction = useSendTransaction;
1096
+ exports.useSignMessage = useSignMessage;
1097
+ exports.useSignTransaction = useSignTransaction;
1098
+ exports.useSwitchNetwork = useSwitchNetwork;
1099
+ exports.useWallet = useWallet;
1100
+ exports.withWalletErrorBoundary = withWalletErrorBoundary;
1101
+ //# sourceMappingURL=react.cjs.map
1121
1102
  //# sourceMappingURL=react.cjs.map