@cookill/wallet-adapter 2.4.0 → 2.4.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.
package/dist/react.js CHANGED
@@ -1,5 +1,5 @@
1
- import { createContext, useState, useMemo, useEffect, useCallback, useContext } from 'react';
2
- import { jsx, jsxs } from 'react/jsx-runtime';
1
+ import React2, { createContext, Component, useState, useMemo, useEffect, useCallback, useContext } from 'react';
2
+ import { jsxs, jsx } from 'react/jsx-runtime';
3
3
 
4
4
  // src/react.tsx
5
5
 
@@ -97,11 +97,359 @@ function isValidAddress(address) {
97
97
  if (address.length < 32 || address.length > 50) return false;
98
98
  return /^[1-9A-HJ-NP-Za-km-z]+$/.test(address);
99
99
  }
100
+ var WalletErrorBoundary = class extends Component {
101
+ constructor() {
102
+ super(...arguments);
103
+ this.state = {
104
+ hasError: false,
105
+ error: null
106
+ };
107
+ this.handleRetry = () => {
108
+ this.setState({ hasError: false, error: null });
109
+ };
110
+ }
111
+ static getDerivedStateFromError(error) {
112
+ return { hasError: true, error };
113
+ }
114
+ componentDidCatch(error, errorInfo) {
115
+ console.error("[WalletAdapter] Error caught by boundary:", error, errorInfo);
116
+ this.props.onError?.(error, errorInfo);
117
+ }
118
+ render() {
119
+ if (this.state.hasError) {
120
+ if (this.props.fallback) {
121
+ return this.props.fallback;
122
+ }
123
+ return /* @__PURE__ */ jsxs(
124
+ "div",
125
+ {
126
+ style: {
127
+ padding: "20px",
128
+ borderRadius: "12px",
129
+ border: "1px solid #fee2e2",
130
+ backgroundColor: "#fef2f2",
131
+ textAlign: "center"
132
+ },
133
+ children: [
134
+ /* @__PURE__ */ jsx(
135
+ "div",
136
+ {
137
+ style: {
138
+ width: "48px",
139
+ height: "48px",
140
+ margin: "0 auto 12px",
141
+ borderRadius: "50%",
142
+ backgroundColor: "#fecaca",
143
+ display: "flex",
144
+ alignItems: "center",
145
+ justifyContent: "center"
146
+ },
147
+ children: /* @__PURE__ */ jsxs(
148
+ "svg",
149
+ {
150
+ width: "24",
151
+ height: "24",
152
+ viewBox: "0 0 24 24",
153
+ fill: "none",
154
+ stroke: "#dc2626",
155
+ strokeWidth: "2",
156
+ strokeLinecap: "round",
157
+ strokeLinejoin: "round",
158
+ children: [
159
+ /* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "10" }),
160
+ /* @__PURE__ */ jsx("line", { x1: "12", y1: "8", x2: "12", y2: "12" }),
161
+ /* @__PURE__ */ jsx("line", { x1: "12", y1: "16", x2: "12.01", y2: "16" })
162
+ ]
163
+ }
164
+ )
165
+ }
166
+ ),
167
+ /* @__PURE__ */ jsx("h3", { style: { margin: "0 0 8px", fontSize: "16px", fontWeight: 600, color: "#991b1b" }, children: "Wallet Connection Error" }),
168
+ /* @__PURE__ */ jsx("p", { style: { margin: "0 0 16px", fontSize: "14px", color: "#b91c1c" }, children: this.state.error?.message || "Something went wrong" }),
169
+ /* @__PURE__ */ jsx(
170
+ "button",
171
+ {
172
+ onClick: this.handleRetry,
173
+ style: {
174
+ padding: "8px 16px",
175
+ borderRadius: "8px",
176
+ border: "none",
177
+ backgroundColor: "#dc2626",
178
+ color: "white",
179
+ cursor: "pointer",
180
+ fontSize: "14px",
181
+ fontWeight: 500
182
+ },
183
+ children: "Try Again"
184
+ }
185
+ )
186
+ ]
187
+ }
188
+ );
189
+ }
190
+ return this.props.children;
191
+ }
192
+ };
193
+ function LoadingSpinner({ size = "md", color = "#6EB9A8", className = "" }) {
194
+ const sizes = {
195
+ sm: { container: 20, stroke: 2 },
196
+ md: { container: 32, stroke: 3 },
197
+ lg: { container: 48, stroke: 4 }
198
+ };
199
+ const { container, stroke } = sizes[size];
200
+ const radius = (container - stroke) / 2;
201
+ const circumference = radius * 2 * Math.PI;
202
+ return /* @__PURE__ */ jsxs(
203
+ "svg",
204
+ {
205
+ width: container,
206
+ height: container,
207
+ viewBox: `0 0 ${container} ${container}`,
208
+ className,
209
+ style: { animation: "wallet-spin 1s linear infinite" },
210
+ children: [
211
+ /* @__PURE__ */ jsx("style", { children: `
212
+ @keyframes wallet-spin {
213
+ from { transform: rotate(0deg); }
214
+ to { transform: rotate(360deg); }
215
+ }
216
+ ` }),
217
+ /* @__PURE__ */ jsx(
218
+ "circle",
219
+ {
220
+ cx: container / 2,
221
+ cy: container / 2,
222
+ r: radius,
223
+ fill: "none",
224
+ stroke: color,
225
+ strokeWidth: stroke,
226
+ strokeOpacity: 0.2
227
+ }
228
+ ),
229
+ /* @__PURE__ */ jsx(
230
+ "circle",
231
+ {
232
+ cx: container / 2,
233
+ cy: container / 2,
234
+ r: radius,
235
+ fill: "none",
236
+ stroke: color,
237
+ strokeWidth: stroke,
238
+ strokeLinecap: "round",
239
+ strokeDasharray: circumference,
240
+ strokeDashoffset: circumference * 0.75
241
+ }
242
+ )
243
+ ]
244
+ }
245
+ );
246
+ }
247
+ function ApprovalPending({
248
+ title = "Waiting for Approval",
249
+ message = "Please approve the request in your wallet",
250
+ walletName = "Sheep Wallet",
251
+ onCancel
252
+ }) {
253
+ return /* @__PURE__ */ jsxs(
254
+ "div",
255
+ {
256
+ style: {
257
+ padding: "32px 24px",
258
+ textAlign: "center",
259
+ backgroundColor: "#f8fafc",
260
+ borderRadius: "16px",
261
+ border: "1px solid #e2e8f0"
262
+ },
263
+ children: [
264
+ /* @__PURE__ */ jsxs(
265
+ "div",
266
+ {
267
+ style: {
268
+ width: "80px",
269
+ height: "80px",
270
+ margin: "0 auto 20px",
271
+ borderRadius: "50%",
272
+ backgroundColor: "#011B29",
273
+ display: "flex",
274
+ alignItems: "center",
275
+ justifyContent: "center",
276
+ position: "relative"
277
+ },
278
+ children: [
279
+ /* @__PURE__ */ jsx(LoadingSpinner, { size: "lg" }),
280
+ /* @__PURE__ */ jsx(
281
+ "div",
282
+ {
283
+ style: {
284
+ position: "absolute",
285
+ inset: "-4px",
286
+ borderRadius: "50%",
287
+ border: "2px solid transparent",
288
+ borderTopColor: "#6EB9A8",
289
+ animation: "wallet-spin 2s linear infinite"
290
+ }
291
+ }
292
+ )
293
+ ]
294
+ }
295
+ ),
296
+ /* @__PURE__ */ jsx(
297
+ "h3",
298
+ {
299
+ style: {
300
+ margin: "0 0 8px",
301
+ fontSize: "18px",
302
+ fontWeight: 600,
303
+ color: "#0f172a"
304
+ },
305
+ children: title
306
+ }
307
+ ),
308
+ /* @__PURE__ */ jsx(
309
+ "p",
310
+ {
311
+ style: {
312
+ margin: "0 0 8px",
313
+ fontSize: "14px",
314
+ color: "#64748b"
315
+ },
316
+ children: message
317
+ }
318
+ ),
319
+ /* @__PURE__ */ jsxs(
320
+ "p",
321
+ {
322
+ style: {
323
+ margin: "0 0 24px",
324
+ fontSize: "12px",
325
+ color: "#94a3b8"
326
+ },
327
+ children: [
328
+ "Open ",
329
+ walletName,
330
+ " extension to continue"
331
+ ]
332
+ }
333
+ ),
334
+ onCancel && /* @__PURE__ */ jsx(
335
+ "button",
336
+ {
337
+ onClick: onCancel,
338
+ style: {
339
+ padding: "10px 24px",
340
+ borderRadius: "10px",
341
+ border: "1px solid #e2e8f0",
342
+ backgroundColor: "white",
343
+ color: "#64748b",
344
+ cursor: "pointer",
345
+ fontSize: "14px",
346
+ fontWeight: 500,
347
+ transition: "all 0.2s ease"
348
+ },
349
+ onMouseEnter: (e) => {
350
+ e.currentTarget.style.backgroundColor = "#f1f5f9";
351
+ e.currentTarget.style.borderColor = "#cbd5e1";
352
+ },
353
+ onMouseLeave: (e) => {
354
+ e.currentTarget.style.backgroundColor = "white";
355
+ e.currentTarget.style.borderColor = "#e2e8f0";
356
+ },
357
+ children: "Cancel"
358
+ }
359
+ )
360
+ ]
361
+ }
362
+ );
363
+ }
364
+ function ConnectionStatus({ status, message, onRetry }) {
365
+ const statusConfig = {
366
+ connecting: {
367
+ title: "Connecting",
368
+ defaultMessage: "Establishing connection to wallet...",
369
+ color: "#6EB9A8"
370
+ },
371
+ approving: {
372
+ title: "Approval Required",
373
+ defaultMessage: "Please approve the connection in Sheep Wallet",
374
+ color: "#f59e0b"
375
+ },
376
+ signing: {
377
+ title: "Signature Required",
378
+ defaultMessage: "Please sign the transaction in your wallet",
379
+ color: "#6EB9A8"
380
+ },
381
+ success: {
382
+ title: "Connected",
383
+ defaultMessage: "Successfully connected to wallet",
384
+ color: "#22c55e"
385
+ },
386
+ error: {
387
+ title: "Connection Failed",
388
+ defaultMessage: "Unable to connect. Please try again.",
389
+ color: "#ef4444"
390
+ }
391
+ };
392
+ const config = statusConfig[status];
393
+ return /* @__PURE__ */ jsxs(
394
+ "div",
395
+ {
396
+ style: {
397
+ padding: "20px",
398
+ borderRadius: "12px",
399
+ backgroundColor: `${config.color}10`,
400
+ border: `1px solid ${config.color}30`,
401
+ textAlign: "center"
402
+ },
403
+ children: [
404
+ /* @__PURE__ */ jsx(
405
+ "div",
406
+ {
407
+ style: {
408
+ width: "48px",
409
+ height: "48px",
410
+ margin: "0 auto 12px",
411
+ borderRadius: "50%",
412
+ backgroundColor: `${config.color}20`,
413
+ display: "flex",
414
+ alignItems: "center",
415
+ justifyContent: "center"
416
+ },
417
+ children: status === "success" ? /* @__PURE__ */ jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: config.color, strokeWidth: "2", children: /* @__PURE__ */ jsx("polyline", { points: "20,6 9,17 4,12" }) }) : status === "error" ? /* @__PURE__ */ jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: config.color, strokeWidth: "2", children: [
418
+ /* @__PURE__ */ jsx("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
419
+ /* @__PURE__ */ jsx("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
420
+ ] }) : /* @__PURE__ */ jsx(LoadingSpinner, { size: "sm", color: config.color })
421
+ }
422
+ ),
423
+ /* @__PURE__ */ jsx("h4", { style: { margin: "0 0 4px", fontSize: "14px", fontWeight: 600, color: config.color }, children: config.title }),
424
+ /* @__PURE__ */ jsx("p", { style: { margin: 0, fontSize: "12px", color: "#64748b" }, children: message || config.defaultMessage }),
425
+ status === "error" && onRetry && /* @__PURE__ */ jsx(
426
+ "button",
427
+ {
428
+ onClick: onRetry,
429
+ style: {
430
+ marginTop: "12px",
431
+ padding: "6px 16px",
432
+ borderRadius: "6px",
433
+ border: "none",
434
+ backgroundColor: config.color,
435
+ color: "white",
436
+ cursor: "pointer",
437
+ fontSize: "12px",
438
+ fontWeight: 500
439
+ },
440
+ children: "Retry"
441
+ }
442
+ )
443
+ ]
444
+ }
445
+ );
446
+ }
447
+ var SHEEP_WALLET_ICON = "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZpZXdCb3g9IjAgMCAzMiAzMiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHJ4PSI4IiBmaWxsPSIjMUExQTFBIi8+PGNpcmNsZSBjeD0iMTYiIGN5PSIxNCIgcj0iOCIgZmlsbD0iI0ZGRjhGMCIvPjxjaXJjbGUgY3g9IjEyIiBjeT0iMTAiIHI9IjQiIGZpbGw9IiNGRkY4RjAiLz48Y2lyY2xlIGN4PSIyMCIgY3k9IjEwIiByPSI0IiBmaWxsPSIjRkZGOEYwIi8+PGNpcmNsZSBjeD0iMTMiIGN5PSIxMyIgcj0iMS41IiBmaWxsPSIjMzMzIi8+PGNpcmNsZSBjeD0iMTkiIGN5PSIxMyIgcj0iMS41IiBmaWxsPSIjMzMzIi8+PGVsbGlwc2UgY3g9IjE2IiBjeT0iMTciIHJ4PSIyIiByeT0iMS41IiBmaWxsPSIjRkZDMENCIi8+PHBhdGggZD0iTTE0IDI0QzE0IDIyLjkgMTQuOSAyMiAxNiAyMkMxNy4xIDIyIDE4IDIyLjkgMTggMjRWMjZIMTRWMjRaIiBmaWxsPSIjNkVCOUE4Ii8+PC9zdmc+";
100
448
  var DEFAULT_WALLETS = [
101
449
  {
102
450
  id: "sheep-wallet",
103
451
  name: "Sheep Wallet",
104
- icon: "data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHZpZXdCb3g9IjAgMCAzMiAzMiIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iMzIiIGhlaWdodD0iMzIiIHJ4PSI4IiBmaWxsPSIjMDExQjI5Ii8+PHRleHQgeD0iNTAlIiB5PSI1NSUiIGRvbWluYW50LWJhc2VsaW5lPSJtaWRkbGUiIHRleHQtYW5jaG9yPSJtaWRkbGUiIGZvbnQtZmFtaWx5PSJzYW5zLXNlcmlmIiBmb250LXdlaWdodD0iYm9sZCIgZm9udC1zaXplPSIxNiIgZmlsbD0iIzZFQjlBOCI+Uzwvc2VsZj48L3N2Zz4=",
452
+ icon: SHEEP_WALLET_ICON,
105
453
  downloadUrl: "https://rialo.io/wallet"
106
454
  }
107
455
  ];
@@ -344,7 +692,10 @@ function WalletProvider({
344
692
  openModal,
345
693
  closeModal
346
694
  };
347
- return /* @__PURE__ */ jsx(WalletContext.Provider, { value, children });
695
+ return /* @__PURE__ */ jsxs(WalletContext.Provider, { value, children: [
696
+ children,
697
+ /* @__PURE__ */ jsx(WalletModal, {})
698
+ ] });
348
699
  }
349
700
  function useWallet() {
350
701
  const context = useContext(WalletContext);
@@ -405,11 +756,16 @@ function useSwitchNetwork() {
405
756
  }
406
757
  function useConnectWallet() {
407
758
  const { connect, connecting, openModal, isInstalled, error } = useWallet();
759
+ const handleConnect = useCallback(() => {
760
+ openModal();
761
+ }, [openModal]);
408
762
  return {
409
- connect: isInstalled ? connect : openModal,
763
+ connect: handleConnect,
764
+ connectDirect: connect,
410
765
  connecting,
411
766
  isInstalled,
412
- error
767
+ error,
768
+ openModal
413
769
  };
414
770
  }
415
771
  function useDisconnectWallet() {
@@ -559,7 +915,24 @@ function ConnectButton({
559
915
  }
560
916
  );
561
917
  }
918
+ var walletModalOwnerToken = null;
562
919
  function WalletModal({ title = "Connect Wallet", className = "" }) {
920
+ const ownerRef = React2.useRef({});
921
+ const [isOwner] = useState(() => {
922
+ if (!walletModalOwnerToken) {
923
+ walletModalOwnerToken = ownerRef.current;
924
+ return true;
925
+ }
926
+ return walletModalOwnerToken === ownerRef.current;
927
+ });
928
+ useEffect(() => {
929
+ return () => {
930
+ if (isOwner && walletModalOwnerToken === ownerRef.current) {
931
+ walletModalOwnerToken = null;
932
+ }
933
+ };
934
+ }, [isOwner]);
935
+ if (!isOwner) return null;
563
936
  const { isModalOpen, closeModal, wallets, selectWallet, connecting } = useWallet();
564
937
  if (!isModalOpen) return null;
565
938
  return /* @__PURE__ */ jsx(
@@ -636,7 +1009,16 @@ function WalletModal({ title = "Connect Wallet", className = "" }) {
636
1009
  }
637
1010
  );
638
1011
  }
1012
+ function withWalletErrorBoundary(WrappedComponent, fallback) {
1013
+ return function WithErrorBoundary(props) {
1014
+ return /* @__PURE__ */ jsx(WalletErrorBoundary, { fallback, children: /* @__PURE__ */ jsx(WrappedComponent, { ...props }) });
1015
+ };
1016
+ }
1017
+ function SafeWalletProvider(props) {
1018
+ const { errorFallback, ...providerProps } = props;
1019
+ return /* @__PURE__ */ jsx(WalletErrorBoundary, { fallback: errorFallback, children: /* @__PURE__ */ jsx(WalletProvider, { ...providerProps }) });
1020
+ }
639
1021
 
640
- export { ConnectButton, NETWORKS, WalletModal, WalletProvider, formatAddress, formatBalance, getRialoProvider, isRialoInstalled, isValidAddress, useAccounts, useActiveAccount, useBalance, useChainId, useConnectWallet, useDisconnectWallet, useIsConnected, useNetwork, useSendTransaction, useSignMessage, useSignTransaction, useSwitchNetwork, useWallet };
1022
+ export { ApprovalPending, ConnectButton, ConnectionStatus, LoadingSpinner, NETWORKS, SafeWalletProvider, WalletErrorBoundary, WalletModal, WalletProvider, formatAddress, formatBalance, getRialoProvider, isRialoInstalled, isValidAddress, useAccounts, useActiveAccount, useBalance, useChainId, useConnectWallet, useDisconnectWallet, useIsConnected, useNetwork, useSendTransaction, useSignMessage, useSignTransaction, useSwitchNetwork, useWallet, withWalletErrorBoundary };
641
1023
  //# sourceMappingURL=react.js.map
642
1024
  //# sourceMappingURL=react.js.map