@cookill/wallet-adapter 2.4.0 → 2.4.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.
- package/README.md +130 -272
- package/dist/ErrorBoundary.cjs +107 -0
- package/dist/ErrorBoundary.cjs.map +1 -0
- package/dist/ErrorBoundary.d.cts +21 -0
- package/dist/ErrorBoundary.d.ts +21 -0
- package/dist/ErrorBoundary.js +102 -0
- package/dist/ErrorBoundary.js.map +1 -0
- package/dist/LoadingStates.cjs +269 -0
- package/dist/LoadingStates.cjs.map +1 -0
- package/dist/LoadingStates.d.cts +32 -0
- package/dist/LoadingStates.d.ts +32 -0
- package/dist/LoadingStates.js +262 -0
- package/dist/LoadingStates.js.map +1 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +369 -2
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +11 -2
- package/dist/react.d.ts +11 -2
- package/dist/react.js +366 -5
- package/dist/react.js.map +1 -1
- package/dist/standard.cjs +6 -6
- package/dist/standard.cjs.map +1 -1
- package/dist/standard.d.cts +3 -3
- package/dist/standard.d.ts +3 -3
- package/dist/standard.js +6 -6
- package/dist/standard.js.map +1 -1
- package/package.json +2 -2
package/dist/react.cjs
CHANGED
|
@@ -99,6 +99,353 @@ function isValidAddress(address) {
|
|
|
99
99
|
if (address.length < 32 || address.length > 50) return false;
|
|
100
100
|
return /^[1-9A-HJ-NP-Za-km-z]+$/.test(address);
|
|
101
101
|
}
|
|
102
|
+
var WalletErrorBoundary = class extends react.Component {
|
|
103
|
+
constructor() {
|
|
104
|
+
super(...arguments);
|
|
105
|
+
this.state = {
|
|
106
|
+
hasError: false,
|
|
107
|
+
error: null
|
|
108
|
+
};
|
|
109
|
+
this.handleRetry = () => {
|
|
110
|
+
this.setState({ hasError: false, error: null });
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
static getDerivedStateFromError(error) {
|
|
114
|
+
return { hasError: true, error };
|
|
115
|
+
}
|
|
116
|
+
componentDidCatch(error, errorInfo) {
|
|
117
|
+
console.error("[WalletAdapter] Error caught by boundary:", error, errorInfo);
|
|
118
|
+
this.props.onError?.(error, errorInfo);
|
|
119
|
+
}
|
|
120
|
+
render() {
|
|
121
|
+
if (this.state.hasError) {
|
|
122
|
+
if (this.props.fallback) {
|
|
123
|
+
return this.props.fallback;
|
|
124
|
+
}
|
|
125
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
126
|
+
"div",
|
|
127
|
+
{
|
|
128
|
+
style: {
|
|
129
|
+
padding: "20px",
|
|
130
|
+
borderRadius: "12px",
|
|
131
|
+
border: "1px solid #fee2e2",
|
|
132
|
+
backgroundColor: "#fef2f2",
|
|
133
|
+
textAlign: "center"
|
|
134
|
+
},
|
|
135
|
+
children: [
|
|
136
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
137
|
+
"div",
|
|
138
|
+
{
|
|
139
|
+
style: {
|
|
140
|
+
width: "48px",
|
|
141
|
+
height: "48px",
|
|
142
|
+
margin: "0 auto 12px",
|
|
143
|
+
borderRadius: "50%",
|
|
144
|
+
backgroundColor: "#fecaca",
|
|
145
|
+
display: "flex",
|
|
146
|
+
alignItems: "center",
|
|
147
|
+
justifyContent: "center"
|
|
148
|
+
},
|
|
149
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
150
|
+
"svg",
|
|
151
|
+
{
|
|
152
|
+
width: "24",
|
|
153
|
+
height: "24",
|
|
154
|
+
viewBox: "0 0 24 24",
|
|
155
|
+
fill: "none",
|
|
156
|
+
stroke: "#dc2626",
|
|
157
|
+
strokeWidth: "2",
|
|
158
|
+
strokeLinecap: "round",
|
|
159
|
+
strokeLinejoin: "round",
|
|
160
|
+
children: [
|
|
161
|
+
/* @__PURE__ */ jsxRuntime.jsx("circle", { cx: "12", cy: "12", r: "10" }),
|
|
162
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "12", y1: "8", x2: "12", y2: "12" }),
|
|
163
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "12", y1: "16", x2: "12.01", y2: "16" })
|
|
164
|
+
]
|
|
165
|
+
}
|
|
166
|
+
)
|
|
167
|
+
}
|
|
168
|
+
),
|
|
169
|
+
/* @__PURE__ */ jsxRuntime.jsx("h3", { style: { margin: "0 0 8px", fontSize: "16px", fontWeight: 600, color: "#991b1b" }, children: "Wallet Connection Error" }),
|
|
170
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { style: { margin: "0 0 16px", fontSize: "14px", color: "#b91c1c" }, children: this.state.error?.message || "Something went wrong" }),
|
|
171
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
172
|
+
"button",
|
|
173
|
+
{
|
|
174
|
+
onClick: this.handleRetry,
|
|
175
|
+
style: {
|
|
176
|
+
padding: "8px 16px",
|
|
177
|
+
borderRadius: "8px",
|
|
178
|
+
border: "none",
|
|
179
|
+
backgroundColor: "#dc2626",
|
|
180
|
+
color: "white",
|
|
181
|
+
cursor: "pointer",
|
|
182
|
+
fontSize: "14px",
|
|
183
|
+
fontWeight: 500
|
|
184
|
+
},
|
|
185
|
+
children: "Try Again"
|
|
186
|
+
}
|
|
187
|
+
)
|
|
188
|
+
]
|
|
189
|
+
}
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
return this.props.children;
|
|
193
|
+
}
|
|
194
|
+
};
|
|
195
|
+
function LoadingSpinner({ size = "md", color = "#6EB9A8", className = "" }) {
|
|
196
|
+
const sizes = {
|
|
197
|
+
sm: { container: 20, stroke: 2 },
|
|
198
|
+
md: { container: 32, stroke: 3 },
|
|
199
|
+
lg: { container: 48, stroke: 4 }
|
|
200
|
+
};
|
|
201
|
+
const { container, stroke } = sizes[size];
|
|
202
|
+
const radius = (container - stroke) / 2;
|
|
203
|
+
const circumference = radius * 2 * Math.PI;
|
|
204
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
205
|
+
"svg",
|
|
206
|
+
{
|
|
207
|
+
width: container,
|
|
208
|
+
height: container,
|
|
209
|
+
viewBox: `0 0 ${container} ${container}`,
|
|
210
|
+
className,
|
|
211
|
+
style: { animation: "wallet-spin 1s linear infinite" },
|
|
212
|
+
children: [
|
|
213
|
+
/* @__PURE__ */ jsxRuntime.jsx("style", { children: `
|
|
214
|
+
@keyframes wallet-spin {
|
|
215
|
+
from { transform: rotate(0deg); }
|
|
216
|
+
to { transform: rotate(360deg); }
|
|
217
|
+
}
|
|
218
|
+
` }),
|
|
219
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
220
|
+
"circle",
|
|
221
|
+
{
|
|
222
|
+
cx: container / 2,
|
|
223
|
+
cy: container / 2,
|
|
224
|
+
r: radius,
|
|
225
|
+
fill: "none",
|
|
226
|
+
stroke: color,
|
|
227
|
+
strokeWidth: stroke,
|
|
228
|
+
strokeOpacity: 0.2
|
|
229
|
+
}
|
|
230
|
+
),
|
|
231
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
232
|
+
"circle",
|
|
233
|
+
{
|
|
234
|
+
cx: container / 2,
|
|
235
|
+
cy: container / 2,
|
|
236
|
+
r: radius,
|
|
237
|
+
fill: "none",
|
|
238
|
+
stroke: color,
|
|
239
|
+
strokeWidth: stroke,
|
|
240
|
+
strokeLinecap: "round",
|
|
241
|
+
strokeDasharray: circumference,
|
|
242
|
+
strokeDashoffset: circumference * 0.75
|
|
243
|
+
}
|
|
244
|
+
)
|
|
245
|
+
]
|
|
246
|
+
}
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
function ApprovalPending({
|
|
250
|
+
title = "Waiting for Approval",
|
|
251
|
+
message = "Please approve the request in your wallet",
|
|
252
|
+
walletName = "Sheep Wallet",
|
|
253
|
+
onCancel
|
|
254
|
+
}) {
|
|
255
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
256
|
+
"div",
|
|
257
|
+
{
|
|
258
|
+
style: {
|
|
259
|
+
padding: "32px 24px",
|
|
260
|
+
textAlign: "center",
|
|
261
|
+
backgroundColor: "#f8fafc",
|
|
262
|
+
borderRadius: "16px",
|
|
263
|
+
border: "1px solid #e2e8f0"
|
|
264
|
+
},
|
|
265
|
+
children: [
|
|
266
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
267
|
+
"div",
|
|
268
|
+
{
|
|
269
|
+
style: {
|
|
270
|
+
width: "80px",
|
|
271
|
+
height: "80px",
|
|
272
|
+
margin: "0 auto 20px",
|
|
273
|
+
borderRadius: "50%",
|
|
274
|
+
backgroundColor: "#011B29",
|
|
275
|
+
display: "flex",
|
|
276
|
+
alignItems: "center",
|
|
277
|
+
justifyContent: "center",
|
|
278
|
+
position: "relative"
|
|
279
|
+
},
|
|
280
|
+
children: [
|
|
281
|
+
/* @__PURE__ */ jsxRuntime.jsx(LoadingSpinner, { size: "lg" }),
|
|
282
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
283
|
+
"div",
|
|
284
|
+
{
|
|
285
|
+
style: {
|
|
286
|
+
position: "absolute",
|
|
287
|
+
inset: "-4px",
|
|
288
|
+
borderRadius: "50%",
|
|
289
|
+
border: "2px solid transparent",
|
|
290
|
+
borderTopColor: "#6EB9A8",
|
|
291
|
+
animation: "wallet-spin 2s linear infinite"
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
)
|
|
295
|
+
]
|
|
296
|
+
}
|
|
297
|
+
),
|
|
298
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
299
|
+
"h3",
|
|
300
|
+
{
|
|
301
|
+
style: {
|
|
302
|
+
margin: "0 0 8px",
|
|
303
|
+
fontSize: "18px",
|
|
304
|
+
fontWeight: 600,
|
|
305
|
+
color: "#0f172a"
|
|
306
|
+
},
|
|
307
|
+
children: title
|
|
308
|
+
}
|
|
309
|
+
),
|
|
310
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
311
|
+
"p",
|
|
312
|
+
{
|
|
313
|
+
style: {
|
|
314
|
+
margin: "0 0 8px",
|
|
315
|
+
fontSize: "14px",
|
|
316
|
+
color: "#64748b"
|
|
317
|
+
},
|
|
318
|
+
children: message
|
|
319
|
+
}
|
|
320
|
+
),
|
|
321
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
322
|
+
"p",
|
|
323
|
+
{
|
|
324
|
+
style: {
|
|
325
|
+
margin: "0 0 24px",
|
|
326
|
+
fontSize: "12px",
|
|
327
|
+
color: "#94a3b8"
|
|
328
|
+
},
|
|
329
|
+
children: [
|
|
330
|
+
"Open ",
|
|
331
|
+
walletName,
|
|
332
|
+
" extension to continue"
|
|
333
|
+
]
|
|
334
|
+
}
|
|
335
|
+
),
|
|
336
|
+
onCancel && /* @__PURE__ */ jsxRuntime.jsx(
|
|
337
|
+
"button",
|
|
338
|
+
{
|
|
339
|
+
onClick: onCancel,
|
|
340
|
+
style: {
|
|
341
|
+
padding: "10px 24px",
|
|
342
|
+
borderRadius: "10px",
|
|
343
|
+
border: "1px solid #e2e8f0",
|
|
344
|
+
backgroundColor: "white",
|
|
345
|
+
color: "#64748b",
|
|
346
|
+
cursor: "pointer",
|
|
347
|
+
fontSize: "14px",
|
|
348
|
+
fontWeight: 500,
|
|
349
|
+
transition: "all 0.2s ease"
|
|
350
|
+
},
|
|
351
|
+
onMouseEnter: (e) => {
|
|
352
|
+
e.currentTarget.style.backgroundColor = "#f1f5f9";
|
|
353
|
+
e.currentTarget.style.borderColor = "#cbd5e1";
|
|
354
|
+
},
|
|
355
|
+
onMouseLeave: (e) => {
|
|
356
|
+
e.currentTarget.style.backgroundColor = "white";
|
|
357
|
+
e.currentTarget.style.borderColor = "#e2e8f0";
|
|
358
|
+
},
|
|
359
|
+
children: "Cancel"
|
|
360
|
+
}
|
|
361
|
+
)
|
|
362
|
+
]
|
|
363
|
+
}
|
|
364
|
+
);
|
|
365
|
+
}
|
|
366
|
+
function ConnectionStatus({ status, message, onRetry }) {
|
|
367
|
+
const statusConfig = {
|
|
368
|
+
connecting: {
|
|
369
|
+
title: "Connecting",
|
|
370
|
+
defaultMessage: "Establishing connection to wallet...",
|
|
371
|
+
color: "#6EB9A8"
|
|
372
|
+
},
|
|
373
|
+
approving: {
|
|
374
|
+
title: "Approval Required",
|
|
375
|
+
defaultMessage: "Please approve the connection in Sheep Wallet",
|
|
376
|
+
color: "#f59e0b"
|
|
377
|
+
},
|
|
378
|
+
signing: {
|
|
379
|
+
title: "Signature Required",
|
|
380
|
+
defaultMessage: "Please sign the transaction in your wallet",
|
|
381
|
+
color: "#6EB9A8"
|
|
382
|
+
},
|
|
383
|
+
success: {
|
|
384
|
+
title: "Connected",
|
|
385
|
+
defaultMessage: "Successfully connected to wallet",
|
|
386
|
+
color: "#22c55e"
|
|
387
|
+
},
|
|
388
|
+
error: {
|
|
389
|
+
title: "Connection Failed",
|
|
390
|
+
defaultMessage: "Unable to connect. Please try again.",
|
|
391
|
+
color: "#ef4444"
|
|
392
|
+
}
|
|
393
|
+
};
|
|
394
|
+
const config = statusConfig[status];
|
|
395
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
396
|
+
"div",
|
|
397
|
+
{
|
|
398
|
+
style: {
|
|
399
|
+
padding: "20px",
|
|
400
|
+
borderRadius: "12px",
|
|
401
|
+
backgroundColor: `${config.color}10`,
|
|
402
|
+
border: `1px solid ${config.color}30`,
|
|
403
|
+
textAlign: "center"
|
|
404
|
+
},
|
|
405
|
+
children: [
|
|
406
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
407
|
+
"div",
|
|
408
|
+
{
|
|
409
|
+
style: {
|
|
410
|
+
width: "48px",
|
|
411
|
+
height: "48px",
|
|
412
|
+
margin: "0 auto 12px",
|
|
413
|
+
borderRadius: "50%",
|
|
414
|
+
backgroundColor: `${config.color}20`,
|
|
415
|
+
display: "flex",
|
|
416
|
+
alignItems: "center",
|
|
417
|
+
justifyContent: "center"
|
|
418
|
+
},
|
|
419
|
+
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: [
|
|
420
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "18", y1: "6", x2: "6", y2: "18" }),
|
|
421
|
+
/* @__PURE__ */ jsxRuntime.jsx("line", { x1: "6", y1: "6", x2: "18", y2: "18" })
|
|
422
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsx(LoadingSpinner, { size: "sm", color: config.color })
|
|
423
|
+
}
|
|
424
|
+
),
|
|
425
|
+
/* @__PURE__ */ jsxRuntime.jsx("h4", { style: { margin: "0 0 4px", fontSize: "14px", fontWeight: 600, color: config.color }, children: config.title }),
|
|
426
|
+
/* @__PURE__ */ jsxRuntime.jsx("p", { style: { margin: 0, fontSize: "12px", color: "#64748b" }, children: message || config.defaultMessage }),
|
|
427
|
+
status === "error" && onRetry && /* @__PURE__ */ jsxRuntime.jsx(
|
|
428
|
+
"button",
|
|
429
|
+
{
|
|
430
|
+
onClick: onRetry,
|
|
431
|
+
style: {
|
|
432
|
+
marginTop: "12px",
|
|
433
|
+
padding: "6px 16px",
|
|
434
|
+
borderRadius: "6px",
|
|
435
|
+
border: "none",
|
|
436
|
+
backgroundColor: config.color,
|
|
437
|
+
color: "white",
|
|
438
|
+
cursor: "pointer",
|
|
439
|
+
fontSize: "12px",
|
|
440
|
+
fontWeight: 500
|
|
441
|
+
},
|
|
442
|
+
children: "Retry"
|
|
443
|
+
}
|
|
444
|
+
)
|
|
445
|
+
]
|
|
446
|
+
}
|
|
447
|
+
);
|
|
448
|
+
}
|
|
102
449
|
var DEFAULT_WALLETS = [
|
|
103
450
|
{
|
|
104
451
|
id: "sheep-wallet",
|
|
@@ -407,11 +754,16 @@ function useSwitchNetwork() {
|
|
|
407
754
|
}
|
|
408
755
|
function useConnectWallet() {
|
|
409
756
|
const { connect, connecting, openModal, isInstalled, error } = useWallet();
|
|
757
|
+
const handleConnect = react.useCallback(() => {
|
|
758
|
+
openModal();
|
|
759
|
+
}, [openModal]);
|
|
410
760
|
return {
|
|
411
|
-
connect:
|
|
761
|
+
connect: handleConnect,
|
|
762
|
+
connectDirect: connect,
|
|
412
763
|
connecting,
|
|
413
764
|
isInstalled,
|
|
414
|
-
error
|
|
765
|
+
error,
|
|
766
|
+
openModal
|
|
415
767
|
};
|
|
416
768
|
}
|
|
417
769
|
function useDisconnectWallet() {
|
|
@@ -638,9 +990,23 @@ function WalletModal({ title = "Connect Wallet", className = "" }) {
|
|
|
638
990
|
}
|
|
639
991
|
);
|
|
640
992
|
}
|
|
993
|
+
function withWalletErrorBoundary(WrappedComponent, fallback) {
|
|
994
|
+
return function WithErrorBoundary(props) {
|
|
995
|
+
return /* @__PURE__ */ jsxRuntime.jsx(WalletErrorBoundary, { fallback, children: /* @__PURE__ */ jsxRuntime.jsx(WrappedComponent, { ...props }) });
|
|
996
|
+
};
|
|
997
|
+
}
|
|
998
|
+
function SafeWalletProvider(props) {
|
|
999
|
+
const { errorFallback, ...providerProps } = props;
|
|
1000
|
+
return /* @__PURE__ */ jsxRuntime.jsx(WalletErrorBoundary, { fallback: errorFallback, children: /* @__PURE__ */ jsxRuntime.jsx(WalletProvider, { ...providerProps }) });
|
|
1001
|
+
}
|
|
641
1002
|
|
|
1003
|
+
exports.ApprovalPending = ApprovalPending;
|
|
642
1004
|
exports.ConnectButton = ConnectButton;
|
|
1005
|
+
exports.ConnectionStatus = ConnectionStatus;
|
|
1006
|
+
exports.LoadingSpinner = LoadingSpinner;
|
|
643
1007
|
exports.NETWORKS = NETWORKS;
|
|
1008
|
+
exports.SafeWalletProvider = SafeWalletProvider;
|
|
1009
|
+
exports.WalletErrorBoundary = WalletErrorBoundary;
|
|
644
1010
|
exports.WalletModal = WalletModal;
|
|
645
1011
|
exports.WalletProvider = WalletProvider;
|
|
646
1012
|
exports.formatAddress = formatAddress;
|
|
@@ -661,5 +1027,6 @@ exports.useSignMessage = useSignMessage;
|
|
|
661
1027
|
exports.useSignTransaction = useSignTransaction;
|
|
662
1028
|
exports.useSwitchNetwork = useSwitchNetwork;
|
|
663
1029
|
exports.useWallet = useWallet;
|
|
1030
|
+
exports.withWalletErrorBoundary = withWalletErrorBoundary;
|
|
664
1031
|
//# sourceMappingURL=react.cjs.map
|
|
665
1032
|
//# sourceMappingURL=react.cjs.map
|