@cookill/wallet-adapter 2.5.4 → 3.0.0
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 +155 -165
- package/dist/ErrorBoundary.cjs +53 -110
- package/dist/ErrorBoundary.cjs.map +1 -1
- package/dist/ErrorBoundary.d.cts +11 -7
- package/dist/ErrorBoundary.d.ts +11 -7
- package/dist/ErrorBoundary.js +50 -85
- package/dist/ErrorBoundary.js.map +1 -1
- package/dist/LoadingStates.cjs +134 -267
- package/dist/LoadingStates.cjs.map +1 -1
- package/dist/LoadingStates.d.cts +11 -15
- package/dist/LoadingStates.d.ts +11 -15
- package/dist/LoadingStates.js +129 -239
- package/dist/LoadingStates.js.map +1 -1
- package/dist/index.cjs +287 -158
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +111 -63
- package/dist/index.d.ts +111 -63
- package/dist/index.js +267 -124
- package/dist/index.js.map +1 -1
- package/dist/react.cjs +251 -1030
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.cts +1 -118
- package/dist/react.d.ts +1 -118
- package/dist/react.js +243 -975
- package/dist/react.js.map +1 -1
- package/dist/standard.cjs +127 -121
- package/dist/standard.cjs.map +1 -1
- package/dist/standard.d.cts +6 -44
- package/dist/standard.d.ts +6 -44
- package/dist/standard.js +118 -91
- package/dist/standard.js.map +1 -1
- package/package.json +42 -36
package/dist/react.cjs
CHANGED
|
@@ -1,68 +1,6 @@
|
|
|
1
|
-
|
|
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);
|
|
29
|
-
|
|
30
|
-
// 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);
|
|
1
|
+
'use strict';
|
|
64
2
|
|
|
65
|
-
// src/
|
|
3
|
+
// src/core/types.ts
|
|
66
4
|
var NETWORKS = {
|
|
67
5
|
mainnet: {
|
|
68
6
|
chainId: "rialo:mainnet",
|
|
@@ -101,46 +39,36 @@ var NETWORKS = {
|
|
|
101
39
|
decimals: 9
|
|
102
40
|
}
|
|
103
41
|
};
|
|
104
|
-
|
|
42
|
+
|
|
43
|
+
// src/core/provider.ts
|
|
44
|
+
function isInstalled() {
|
|
105
45
|
if (typeof window === "undefined") return false;
|
|
106
|
-
|
|
46
|
+
try {
|
|
47
|
+
return !!window.rialo?.isRialo;
|
|
48
|
+
} catch {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
107
51
|
}
|
|
108
|
-
function
|
|
52
|
+
function getProvider() {
|
|
109
53
|
if (typeof window === "undefined") return void 0;
|
|
110
|
-
|
|
111
|
-
|
|
54
|
+
try {
|
|
55
|
+
const provider = window.rialo;
|
|
56
|
+
if (provider?.isRialo) return provider;
|
|
57
|
+
} catch {
|
|
58
|
+
}
|
|
59
|
+
return void 0;
|
|
112
60
|
}
|
|
113
|
-
function
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
const checkInterval = setInterval(() => {
|
|
121
|
-
if (isRialoInstalled() && !resolved) {
|
|
122
|
-
resolved = true;
|
|
123
|
-
clearInterval(checkInterval);
|
|
124
|
-
resolve(getRialoProvider());
|
|
125
|
-
}
|
|
126
|
-
}, 100);
|
|
127
|
-
setTimeout(() => {
|
|
128
|
-
if (!resolved) {
|
|
129
|
-
resolved = true;
|
|
130
|
-
clearInterval(checkInterval);
|
|
131
|
-
resolve(void 0);
|
|
132
|
-
}
|
|
133
|
-
}, timeout);
|
|
134
|
-
const handler = () => {
|
|
135
|
-
if (!resolved) {
|
|
136
|
-
resolved = true;
|
|
137
|
-
clearInterval(checkInterval);
|
|
138
|
-
resolve(getRialoProvider());
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
window.addEventListener("rialo#initialized", handler, { once: true });
|
|
61
|
+
function withTimeout(promise, ms, errorMessage = "Operation timed out") {
|
|
62
|
+
let timeoutId;
|
|
63
|
+
const timeout = new Promise((_, reject) => {
|
|
64
|
+
timeoutId = setTimeout(() => reject(new Error(errorMessage)), ms);
|
|
65
|
+
});
|
|
66
|
+
return Promise.race([promise, timeout]).finally(() => {
|
|
67
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
142
68
|
});
|
|
143
69
|
}
|
|
70
|
+
|
|
71
|
+
// src/core/utils.ts
|
|
144
72
|
function formatAddress(address, chars = 4) {
|
|
145
73
|
if (!address) return "";
|
|
146
74
|
if (address.length <= chars * 2 + 3) return address;
|
|
@@ -151,971 +79,264 @@ function formatBalance(kelvins, decimals = 4) {
|
|
|
151
79
|
const rlo = Number(value) / 1e9;
|
|
152
80
|
return rlo.toFixed(decimals);
|
|
153
81
|
}
|
|
82
|
+
function parseBalance(rlo) {
|
|
83
|
+
const value = typeof rlo === "string" ? parseFloat(rlo) : rlo;
|
|
84
|
+
return BigInt(Math.floor(value * 1e9));
|
|
85
|
+
}
|
|
154
86
|
function isValidAddress(address) {
|
|
155
87
|
if (!address || typeof address !== "string") return false;
|
|
156
88
|
if (address.length < 32 || address.length > 50) return false;
|
|
157
89
|
return /^[1-9A-HJ-NP-Za-km-z]+$/.test(address);
|
|
158
90
|
}
|
|
91
|
+
function normalizeAccounts(accounts) {
|
|
92
|
+
if (!Array.isArray(accounts)) return [];
|
|
93
|
+
return accounts.map((acc) => {
|
|
94
|
+
if (typeof acc === "string") {
|
|
95
|
+
return { address: acc, publicKey: acc };
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
address: acc.address,
|
|
99
|
+
publicKey: acc.publicKey || acc.address,
|
|
100
|
+
label: acc.label
|
|
101
|
+
};
|
|
102
|
+
});
|
|
103
|
+
}
|
|
159
104
|
|
|
160
|
-
// src/
|
|
161
|
-
var
|
|
162
|
-
var
|
|
163
|
-
var
|
|
105
|
+
// src/core/wallet.ts
|
|
106
|
+
var CONNECT_TIMEOUT = 2e4;
|
|
107
|
+
var OPERATION_TIMEOUT = 3e4;
|
|
108
|
+
var SheepWallet = class {
|
|
164
109
|
constructor() {
|
|
165
|
-
|
|
166
|
-
this.
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
this.
|
|
171
|
-
this.setState({ hasError: false, error: null });
|
|
172
|
-
};
|
|
110
|
+
this._connected = false;
|
|
111
|
+
this._accounts = [];
|
|
112
|
+
this._network = "devnet";
|
|
113
|
+
this._cleanupFns = [];
|
|
114
|
+
this._provider = getProvider();
|
|
115
|
+
this._setupEvents();
|
|
173
116
|
}
|
|
174
|
-
|
|
175
|
-
|
|
117
|
+
// =========================================================================
|
|
118
|
+
// Getters (all synchronous, never block)
|
|
119
|
+
// =========================================================================
|
|
120
|
+
get isInstalled() {
|
|
121
|
+
return isInstalled();
|
|
176
122
|
}
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
this.props.onError?.(error, errorInfo);
|
|
123
|
+
get connected() {
|
|
124
|
+
return this._connected;
|
|
180
125
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
if (this.props.fallback) {
|
|
184
|
-
return this.props.fallback;
|
|
185
|
-
}
|
|
186
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
187
|
-
"div",
|
|
188
|
-
{
|
|
189
|
-
style: {
|
|
190
|
-
padding: "20px",
|
|
191
|
-
borderRadius: "12px",
|
|
192
|
-
border: "1px solid #fee2e2",
|
|
193
|
-
backgroundColor: "#fef2f2",
|
|
194
|
-
textAlign: "center"
|
|
195
|
-
},
|
|
196
|
-
children: [
|
|
197
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
198
|
-
"div",
|
|
199
|
-
{
|
|
200
|
-
style: {
|
|
201
|
-
width: "48px",
|
|
202
|
-
height: "48px",
|
|
203
|
-
margin: "0 auto 12px",
|
|
204
|
-
borderRadius: "50%",
|
|
205
|
-
backgroundColor: "#fecaca",
|
|
206
|
-
display: "flex",
|
|
207
|
-
alignItems: "center",
|
|
208
|
-
justifyContent: "center"
|
|
209
|
-
},
|
|
210
|
-
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
211
|
-
"svg",
|
|
212
|
-
{
|
|
213
|
-
width: "24",
|
|
214
|
-
height: "24",
|
|
215
|
-
viewBox: "0 0 24 24",
|
|
216
|
-
fill: "none",
|
|
217
|
-
stroke: "#dc2626",
|
|
218
|
-
strokeWidth: "2",
|
|
219
|
-
strokeLinecap: "round",
|
|
220
|
-
strokeLinejoin: "round",
|
|
221
|
-
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" })
|
|
225
|
-
]
|
|
226
|
-
}
|
|
227
|
-
)
|
|
228
|
-
}
|
|
229
|
-
),
|
|
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)(
|
|
233
|
-
"button",
|
|
234
|
-
{
|
|
235
|
-
onClick: this.handleRetry,
|
|
236
|
-
style: {
|
|
237
|
-
padding: "8px 16px",
|
|
238
|
-
borderRadius: "8px",
|
|
239
|
-
border: "none",
|
|
240
|
-
backgroundColor: "#dc2626",
|
|
241
|
-
color: "white",
|
|
242
|
-
cursor: "pointer",
|
|
243
|
-
fontSize: "14px",
|
|
244
|
-
fontWeight: 500
|
|
245
|
-
},
|
|
246
|
-
children: "Try Again"
|
|
247
|
-
}
|
|
248
|
-
)
|
|
249
|
-
]
|
|
250
|
-
}
|
|
251
|
-
);
|
|
252
|
-
}
|
|
253
|
-
return this.props.children;
|
|
126
|
+
get accounts() {
|
|
127
|
+
return [...this._accounts];
|
|
254
128
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
// src/LoadingStates.tsx
|
|
258
|
-
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
259
|
-
function LoadingSpinner({ size = "md", color = "#6EB9A8", className = "" }) {
|
|
260
|
-
const sizes = {
|
|
261
|
-
sm: { container: 20, stroke: 2 },
|
|
262
|
-
md: { container: 32, stroke: 3 },
|
|
263
|
-
lg: { container: 48, stroke: 4 }
|
|
264
|
-
};
|
|
265
|
-
const { container, stroke } = sizes[size];
|
|
266
|
-
const radius = (container - stroke) / 2;
|
|
267
|
-
const circumference = radius * 2 * Math.PI;
|
|
268
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
269
|
-
"svg",
|
|
270
|
-
{
|
|
271
|
-
width: container,
|
|
272
|
-
height: container,
|
|
273
|
-
viewBox: `0 0 ${container} ${container}`,
|
|
274
|
-
className,
|
|
275
|
-
style: { animation: "wallet-spin 1s linear infinite" },
|
|
276
|
-
children: [
|
|
277
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("style", { children: `
|
|
278
|
-
@keyframes wallet-spin {
|
|
279
|
-
from { transform: rotate(0deg); }
|
|
280
|
-
to { transform: rotate(360deg); }
|
|
281
|
-
}
|
|
282
|
-
` }),
|
|
283
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
284
|
-
"circle",
|
|
285
|
-
{
|
|
286
|
-
cx: container / 2,
|
|
287
|
-
cy: container / 2,
|
|
288
|
-
r: radius,
|
|
289
|
-
fill: "none",
|
|
290
|
-
stroke: color,
|
|
291
|
-
strokeWidth: stroke,
|
|
292
|
-
strokeOpacity: 0.2
|
|
293
|
-
}
|
|
294
|
-
),
|
|
295
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
296
|
-
"circle",
|
|
297
|
-
{
|
|
298
|
-
cx: container / 2,
|
|
299
|
-
cy: container / 2,
|
|
300
|
-
r: radius,
|
|
301
|
-
fill: "none",
|
|
302
|
-
stroke: color,
|
|
303
|
-
strokeWidth: stroke,
|
|
304
|
-
strokeLinecap: "round",
|
|
305
|
-
strokeDasharray: circumference,
|
|
306
|
-
strokeDashoffset: circumference * 0.75
|
|
307
|
-
}
|
|
308
|
-
)
|
|
309
|
-
]
|
|
310
|
-
}
|
|
311
|
-
);
|
|
312
|
-
}
|
|
313
|
-
function ApprovalPending({
|
|
314
|
-
title = "Waiting for Approval",
|
|
315
|
-
message = "Please approve the request in your wallet",
|
|
316
|
-
walletName = "Sheep Wallet",
|
|
317
|
-
onCancel
|
|
318
|
-
}) {
|
|
319
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
320
|
-
"div",
|
|
321
|
-
{
|
|
322
|
-
style: {
|
|
323
|
-
padding: "32px 24px",
|
|
324
|
-
textAlign: "center",
|
|
325
|
-
backgroundColor: "#f8fafc",
|
|
326
|
-
borderRadius: "16px",
|
|
327
|
-
border: "1px solid #e2e8f0"
|
|
328
|
-
},
|
|
329
|
-
children: [
|
|
330
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
331
|
-
"div",
|
|
332
|
-
{
|
|
333
|
-
style: {
|
|
334
|
-
width: "80px",
|
|
335
|
-
height: "80px",
|
|
336
|
-
margin: "0 auto 20px",
|
|
337
|
-
borderRadius: "50%",
|
|
338
|
-
backgroundColor: "#011B29",
|
|
339
|
-
display: "flex",
|
|
340
|
-
alignItems: "center",
|
|
341
|
-
justifyContent: "center",
|
|
342
|
-
position: "relative"
|
|
343
|
-
},
|
|
344
|
-
children: [
|
|
345
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(LoadingSpinner, { size: "lg" }),
|
|
346
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
347
|
-
"div",
|
|
348
|
-
{
|
|
349
|
-
style: {
|
|
350
|
-
position: "absolute",
|
|
351
|
-
inset: "-4px",
|
|
352
|
-
borderRadius: "50%",
|
|
353
|
-
border: "2px solid transparent",
|
|
354
|
-
borderTopColor: "#6EB9A8",
|
|
355
|
-
animation: "wallet-spin 2s linear infinite"
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
)
|
|
359
|
-
]
|
|
360
|
-
}
|
|
361
|
-
),
|
|
362
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
363
|
-
"h3",
|
|
364
|
-
{
|
|
365
|
-
style: {
|
|
366
|
-
margin: "0 0 8px",
|
|
367
|
-
fontSize: "18px",
|
|
368
|
-
fontWeight: 600,
|
|
369
|
-
color: "#0f172a"
|
|
370
|
-
},
|
|
371
|
-
children: title
|
|
372
|
-
}
|
|
373
|
-
),
|
|
374
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
375
|
-
"p",
|
|
376
|
-
{
|
|
377
|
-
style: {
|
|
378
|
-
margin: "0 0 8px",
|
|
379
|
-
fontSize: "14px",
|
|
380
|
-
color: "#64748b"
|
|
381
|
-
},
|
|
382
|
-
children: message
|
|
383
|
-
}
|
|
384
|
-
),
|
|
385
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
386
|
-
"p",
|
|
387
|
-
{
|
|
388
|
-
style: {
|
|
389
|
-
margin: "0 0 24px",
|
|
390
|
-
fontSize: "12px",
|
|
391
|
-
color: "#94a3b8"
|
|
392
|
-
},
|
|
393
|
-
children: [
|
|
394
|
-
"Open ",
|
|
395
|
-
walletName,
|
|
396
|
-
" extension to continue"
|
|
397
|
-
]
|
|
398
|
-
}
|
|
399
|
-
),
|
|
400
|
-
onCancel && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
401
|
-
"button",
|
|
402
|
-
{
|
|
403
|
-
onClick: onCancel,
|
|
404
|
-
style: {
|
|
405
|
-
padding: "10px 24px",
|
|
406
|
-
borderRadius: "10px",
|
|
407
|
-
border: "1px solid #e2e8f0",
|
|
408
|
-
backgroundColor: "white",
|
|
409
|
-
color: "#64748b",
|
|
410
|
-
cursor: "pointer",
|
|
411
|
-
fontSize: "14px",
|
|
412
|
-
fontWeight: 500,
|
|
413
|
-
transition: "all 0.2s ease"
|
|
414
|
-
},
|
|
415
|
-
onMouseEnter: (e) => {
|
|
416
|
-
e.currentTarget.style.backgroundColor = "#f1f5f9";
|
|
417
|
-
e.currentTarget.style.borderColor = "#cbd5e1";
|
|
418
|
-
},
|
|
419
|
-
onMouseLeave: (e) => {
|
|
420
|
-
e.currentTarget.style.backgroundColor = "white";
|
|
421
|
-
e.currentTarget.style.borderColor = "#e2e8f0";
|
|
422
|
-
},
|
|
423
|
-
children: "Cancel"
|
|
424
|
-
}
|
|
425
|
-
)
|
|
426
|
-
]
|
|
427
|
-
}
|
|
428
|
-
);
|
|
429
|
-
}
|
|
430
|
-
function ConnectionStatus({ status, message, onRetry }) {
|
|
431
|
-
const statusConfig = {
|
|
432
|
-
connecting: {
|
|
433
|
-
title: "Connecting",
|
|
434
|
-
defaultMessage: "Establishing connection to wallet...",
|
|
435
|
-
color: "#6EB9A8"
|
|
436
|
-
},
|
|
437
|
-
approving: {
|
|
438
|
-
title: "Approval Required",
|
|
439
|
-
defaultMessage: "Please approve the connection in Sheep Wallet",
|
|
440
|
-
color: "#f59e0b"
|
|
441
|
-
},
|
|
442
|
-
signing: {
|
|
443
|
-
title: "Signature Required",
|
|
444
|
-
defaultMessage: "Please sign the transaction in your wallet",
|
|
445
|
-
color: "#6EB9A8"
|
|
446
|
-
},
|
|
447
|
-
success: {
|
|
448
|
-
title: "Connected",
|
|
449
|
-
defaultMessage: "Successfully connected to wallet",
|
|
450
|
-
color: "#22c55e"
|
|
451
|
-
},
|
|
452
|
-
error: {
|
|
453
|
-
title: "Connection Failed",
|
|
454
|
-
defaultMessage: "Unable to connect. Please try again.",
|
|
455
|
-
color: "#ef4444"
|
|
456
|
-
}
|
|
457
|
-
};
|
|
458
|
-
const config = statusConfig[status];
|
|
459
|
-
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
|
|
460
|
-
"div",
|
|
461
|
-
{
|
|
462
|
-
style: {
|
|
463
|
-
padding: "20px",
|
|
464
|
-
borderRadius: "12px",
|
|
465
|
-
backgroundColor: `${config.color}10`,
|
|
466
|
-
border: `1px solid ${config.color}30`,
|
|
467
|
-
textAlign: "center"
|
|
468
|
-
},
|
|
469
|
-
children: [
|
|
470
|
-
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
471
|
-
"div",
|
|
472
|
-
{
|
|
473
|
-
style: {
|
|
474
|
-
width: "48px",
|
|
475
|
-
height: "48px",
|
|
476
|
-
margin: "0 auto 12px",
|
|
477
|
-
borderRadius: "50%",
|
|
478
|
-
backgroundColor: `${config.color}20`,
|
|
479
|
-
display: "flex",
|
|
480
|
-
alignItems: "center",
|
|
481
|
-
justifyContent: "center"
|
|
482
|
-
},
|
|
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 })
|
|
487
|
-
}
|
|
488
|
-
),
|
|
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)(
|
|
492
|
-
"button",
|
|
493
|
-
{
|
|
494
|
-
onClick: onRetry,
|
|
495
|
-
style: {
|
|
496
|
-
marginTop: "12px",
|
|
497
|
-
padding: "6px 16px",
|
|
498
|
-
borderRadius: "6px",
|
|
499
|
-
border: "none",
|
|
500
|
-
backgroundColor: config.color,
|
|
501
|
-
color: "white",
|
|
502
|
-
cursor: "pointer",
|
|
503
|
-
fontSize: "12px",
|
|
504
|
-
fontWeight: 500
|
|
505
|
-
},
|
|
506
|
-
children: "Retry"
|
|
507
|
-
}
|
|
508
|
-
)
|
|
509
|
-
]
|
|
510
|
-
}
|
|
511
|
-
);
|
|
512
|
-
}
|
|
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
|
-
var DEFAULT_WALLETS = [
|
|
518
|
-
{
|
|
519
|
-
id: "sheep-wallet",
|
|
520
|
-
name: "Sheep Wallet",
|
|
521
|
-
icon: SHEEP_WALLET_ICON,
|
|
522
|
-
downloadUrl: "https://rialo.io/wallet"
|
|
129
|
+
get activeAccount() {
|
|
130
|
+
return this._accounts[0];
|
|
523
131
|
}
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
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]);
|
|
546
|
-
const activeAccount = accounts[0] || null;
|
|
547
|
-
const isInstalled = isRialoInstalled();
|
|
548
|
-
const wallets = (0, import_react2.useMemo)(() => {
|
|
549
|
-
const installed = isRialoInstalled();
|
|
550
|
-
return [...DEFAULT_WALLETS, ...customWallets].map((w) => ({
|
|
551
|
-
...w,
|
|
552
|
-
installed: w.id === "sheep-wallet" ? installed : false
|
|
553
|
-
}));
|
|
554
|
-
}, [customWallets]);
|
|
555
|
-
(0, import_react2.useEffect)(() => {
|
|
556
|
-
const init = async () => {
|
|
557
|
-
const p = await waitForRialoProvider(3e3);
|
|
558
|
-
setProvider(p);
|
|
559
|
-
if (p) {
|
|
560
|
-
setSelectedWallet(wallets.find((w) => w.id === "sheep-wallet") || wallets[0] || null);
|
|
561
|
-
}
|
|
562
|
-
};
|
|
563
|
-
init();
|
|
564
|
-
}, [wallets]);
|
|
565
|
-
const refreshBalance = (0, import_react2.useCallback)(async () => {
|
|
566
|
-
if (!provider || !activeAccount) return;
|
|
567
|
-
try {
|
|
568
|
-
const result = await provider.getBalance(activeAccount.address);
|
|
569
|
-
const bal = typeof result === "string" ? result : result.balance;
|
|
570
|
-
setBalance(bal);
|
|
571
|
-
} catch (e) {
|
|
572
|
-
console.error("Balance fetch error:", e);
|
|
573
|
-
}
|
|
574
|
-
}, [provider, activeAccount]);
|
|
575
|
-
(0, import_react2.useEffect)(() => {
|
|
576
|
-
if (connected && activeAccount && provider) {
|
|
577
|
-
refreshBalance();
|
|
578
|
-
const interval = setInterval(refreshBalance, 3e4);
|
|
579
|
-
return () => clearInterval(interval);
|
|
580
|
-
}
|
|
581
|
-
}, [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();
|
|
587
|
-
}
|
|
588
|
-
}).catch(() => {
|
|
589
|
-
});
|
|
590
|
-
}
|
|
591
|
-
}, [provider, autoConnect, connected, connecting]);
|
|
592
|
-
(0, import_react2.useEffect)(() => {
|
|
593
|
-
if (!provider) return;
|
|
594
|
-
const cleanupFns = [];
|
|
595
|
-
cleanupFns.push(
|
|
596
|
-
provider.on("connect", (data) => {
|
|
597
|
-
console.log("[Adapter] Connect event received:", data);
|
|
598
|
-
const eventData = data;
|
|
599
|
-
if (eventData?.accounts) {
|
|
600
|
-
const normalized = eventData.accounts.map((a) => {
|
|
601
|
-
if (typeof a === "string") return { address: a, publicKey: a };
|
|
602
|
-
return { address: a.address, publicKey: a.publicKey || a.address };
|
|
603
|
-
});
|
|
604
|
-
setAccounts(normalized);
|
|
605
|
-
setConnected(true);
|
|
606
|
-
}
|
|
607
|
-
})
|
|
608
|
-
);
|
|
609
|
-
cleanupFns.push(
|
|
610
|
-
provider.on("disconnect", () => {
|
|
611
|
-
setConnected(false);
|
|
612
|
-
setAccounts([]);
|
|
613
|
-
setBalance(null);
|
|
614
|
-
onDisconnect?.();
|
|
615
|
-
})
|
|
616
|
-
);
|
|
617
|
-
cleanupFns.push(
|
|
618
|
-
provider.on("accountsChanged", (data) => {
|
|
619
|
-
console.log("[Adapter] Accounts changed:", data);
|
|
620
|
-
const rawAccounts = data;
|
|
621
|
-
const normalized = (rawAccounts || []).map((a) => {
|
|
622
|
-
if (typeof a === "string") return { address: a, publicKey: a };
|
|
623
|
-
return { address: a.address, publicKey: a.publicKey || a.address };
|
|
624
|
-
});
|
|
625
|
-
setAccounts(normalized);
|
|
626
|
-
})
|
|
627
|
-
);
|
|
628
|
-
cleanupFns.push(
|
|
629
|
-
provider.on("networkChanged", (data) => {
|
|
630
|
-
const { network: net } = data;
|
|
631
|
-
if (net) {
|
|
632
|
-
setNetwork(net);
|
|
633
|
-
onNetworkChange?.(net);
|
|
634
|
-
}
|
|
635
|
-
})
|
|
636
|
-
);
|
|
637
|
-
return () => {
|
|
638
|
-
cleanupFns.forEach((fn) => fn?.());
|
|
639
|
-
};
|
|
640
|
-
}, [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;
|
|
132
|
+
get address() {
|
|
133
|
+
return this._accounts[0]?.address;
|
|
134
|
+
}
|
|
135
|
+
get network() {
|
|
136
|
+
return this._network;
|
|
137
|
+
}
|
|
138
|
+
get chainId() {
|
|
139
|
+
return `rialo:${this._network}`;
|
|
140
|
+
}
|
|
141
|
+
// =========================================================================
|
|
142
|
+
// Connection (with timeout protection)
|
|
143
|
+
// =========================================================================
|
|
144
|
+
async connect() {
|
|
145
|
+
this._provider = getProvider();
|
|
146
|
+
if (!this._provider) {
|
|
147
|
+
throw new Error("Sheep Wallet not installed. Get it at https://rialo.io/wallet");
|
|
647
148
|
}
|
|
648
|
-
setConnecting(true);
|
|
649
|
-
setError(null);
|
|
650
149
|
try {
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
return {
|
|
659
|
-
address: acc.address,
|
|
660
|
-
publicKey: acc.publicKey || acc.address
|
|
661
|
-
};
|
|
662
|
-
});
|
|
663
|
-
setAccounts(walletAccounts);
|
|
664
|
-
setConnected(true);
|
|
665
|
-
setIsModalOpen(false);
|
|
150
|
+
const rawAccounts = await withTimeout(
|
|
151
|
+
this._provider.connect(),
|
|
152
|
+
CONNECT_TIMEOUT,
|
|
153
|
+
"Connection timed out. Please open Sheep Wallet extension and approve the request."
|
|
154
|
+
);
|
|
155
|
+
this._accounts = normalizeAccounts(rawAccounts);
|
|
156
|
+
this._connected = true;
|
|
666
157
|
try {
|
|
667
|
-
|
|
668
|
-
|
|
158
|
+
this._network = await withTimeout(
|
|
159
|
+
this._provider.getNetwork(),
|
|
160
|
+
5e3,
|
|
161
|
+
"Network request timed out"
|
|
162
|
+
);
|
|
669
163
|
} catch {
|
|
670
164
|
}
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
onError?.(err);
|
|
677
|
-
throw err;
|
|
678
|
-
} finally {
|
|
679
|
-
setConnecting(false);
|
|
165
|
+
return this._accounts;
|
|
166
|
+
} catch (error) {
|
|
167
|
+
this._connected = false;
|
|
168
|
+
this._accounts = [];
|
|
169
|
+
throw error;
|
|
680
170
|
}
|
|
681
|
-
}
|
|
682
|
-
|
|
171
|
+
}
|
|
172
|
+
async disconnect() {
|
|
683
173
|
try {
|
|
684
|
-
if (
|
|
685
|
-
await
|
|
174
|
+
if (this._provider) {
|
|
175
|
+
await withTimeout(
|
|
176
|
+
this._provider.disconnect(),
|
|
177
|
+
5e3,
|
|
178
|
+
"Disconnect timed out"
|
|
179
|
+
);
|
|
686
180
|
}
|
|
687
181
|
} catch {
|
|
688
182
|
}
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
if (
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
183
|
+
this._connected = false;
|
|
184
|
+
this._accounts = [];
|
|
185
|
+
}
|
|
186
|
+
// =========================================================================
|
|
187
|
+
// Silent session check (for auto-connect, never triggers approval)
|
|
188
|
+
// =========================================================================
|
|
189
|
+
async checkSession() {
|
|
190
|
+
if (!this._provider) return null;
|
|
191
|
+
try {
|
|
192
|
+
const isConn = await withTimeout(
|
|
193
|
+
this._provider.isConnected(),
|
|
194
|
+
3e3,
|
|
195
|
+
"Session check timed out"
|
|
196
|
+
);
|
|
197
|
+
if (!isConn) return null;
|
|
198
|
+
const rawAccounts = await withTimeout(
|
|
199
|
+
this._provider.getAccounts(),
|
|
200
|
+
3e3,
|
|
201
|
+
"Get accounts timed out"
|
|
202
|
+
);
|
|
203
|
+
const accounts = normalizeAccounts(rawAccounts);
|
|
204
|
+
if (accounts.length > 0) {
|
|
205
|
+
this._accounts = accounts;
|
|
206
|
+
this._connected = true;
|
|
207
|
+
try {
|
|
208
|
+
this._network = await this._provider.getNetwork();
|
|
209
|
+
} catch {
|
|
210
|
+
}
|
|
211
|
+
return accounts;
|
|
702
212
|
}
|
|
213
|
+
} catch {
|
|
703
214
|
}
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
// =========================================================================
|
|
218
|
+
// Transactions
|
|
219
|
+
// =========================================================================
|
|
220
|
+
async signMessage(message) {
|
|
221
|
+
this._ensureConnected();
|
|
222
|
+
return withTimeout(
|
|
223
|
+
this._provider.signMessage(message),
|
|
224
|
+
OPERATION_TIMEOUT,
|
|
225
|
+
"Sign message timed out. Please check Sheep Wallet."
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
async signTransaction(tx) {
|
|
229
|
+
this._ensureConnected();
|
|
230
|
+
const result = await withTimeout(
|
|
231
|
+
this._provider.signTransaction(tx),
|
|
232
|
+
OPERATION_TIMEOUT,
|
|
233
|
+
"Sign transaction timed out. Please check Sheep Wallet."
|
|
234
|
+
);
|
|
723
235
|
return result.signature;
|
|
724
|
-
}, [provider, connected]);
|
|
725
|
-
const handleSendTransaction = (0, import_react2.useCallback)(async (tx) => {
|
|
726
|
-
if (!provider || !connected) {
|
|
727
|
-
throw new Error("Wallet not connected");
|
|
728
|
-
}
|
|
729
|
-
return provider.sendTransaction(tx);
|
|
730
|
-
}, [provider, connected]);
|
|
731
|
-
const handleSignAndSendTransaction = (0, import_react2.useCallback)(async (tx) => {
|
|
732
|
-
if (!provider || !connected) {
|
|
733
|
-
throw new Error("Wallet not connected");
|
|
734
|
-
}
|
|
735
|
-
return provider.signAndSendTransaction(tx);
|
|
736
|
-
}, [provider, connected]);
|
|
737
|
-
const openModal = (0, import_react2.useCallback)(() => setIsModalOpen(true), []);
|
|
738
|
-
const closeModal = (0, import_react2.useCallback)(() => setIsModalOpen(false), []);
|
|
739
|
-
const value = {
|
|
740
|
-
connected,
|
|
741
|
-
connecting,
|
|
742
|
-
accounts,
|
|
743
|
-
activeAccount,
|
|
744
|
-
network,
|
|
745
|
-
chainId,
|
|
746
|
-
balance,
|
|
747
|
-
error,
|
|
748
|
-
wallets,
|
|
749
|
-
selectedWallet,
|
|
750
|
-
isInstalled,
|
|
751
|
-
connect: handleConnect,
|
|
752
|
-
disconnect: handleDisconnect,
|
|
753
|
-
selectWallet,
|
|
754
|
-
switchNetwork: handleSwitchNetwork,
|
|
755
|
-
refreshBalance,
|
|
756
|
-
signMessage: handleSignMessage,
|
|
757
|
-
signTransaction: handleSignTransaction,
|
|
758
|
-
sendTransaction: handleSendTransaction,
|
|
759
|
-
signAndSendTransaction: handleSignAndSendTransaction,
|
|
760
|
-
isModalOpen,
|
|
761
|
-
openModal,
|
|
762
|
-
closeModal
|
|
763
|
-
};
|
|
764
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(WalletContext.Provider, { value, children: [
|
|
765
|
-
children,
|
|
766
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(WalletModal, {})
|
|
767
|
-
] });
|
|
768
|
-
}
|
|
769
|
-
function useWallet() {
|
|
770
|
-
const context = (0, import_react2.useContext)(WalletContext);
|
|
771
|
-
if (!context) {
|
|
772
|
-
throw new Error("useWallet must be used within WalletProvider");
|
|
773
236
|
}
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
function useNetwork() {
|
|
797
|
-
const { network, chainId } = useWallet();
|
|
798
|
-
return {
|
|
799
|
-
network,
|
|
800
|
-
chainId,
|
|
801
|
-
config: NETWORKS[network]
|
|
802
|
-
};
|
|
803
|
-
}
|
|
804
|
-
function useChainId() {
|
|
805
|
-
const { chainId } = useWallet();
|
|
806
|
-
return chainId;
|
|
807
|
-
}
|
|
808
|
-
function useSwitchNetwork() {
|
|
809
|
-
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) => {
|
|
813
|
-
setSwitching(true);
|
|
814
|
-
setError(null);
|
|
815
|
-
try {
|
|
816
|
-
await switchNetwork(newNetwork);
|
|
817
|
-
} catch (e) {
|
|
818
|
-
setError(e);
|
|
819
|
-
throw e;
|
|
820
|
-
} finally {
|
|
821
|
-
setSwitching(false);
|
|
822
|
-
}
|
|
823
|
-
}, [switchNetwork]);
|
|
824
|
-
return { switchNetwork: doSwitch, switching, error, currentNetwork: network };
|
|
825
|
-
}
|
|
826
|
-
function useConnectWallet() {
|
|
827
|
-
const { connect, connecting, openModal, isInstalled, error } = useWallet();
|
|
828
|
-
const handleConnect = (0, import_react2.useCallback)(() => {
|
|
829
|
-
openModal();
|
|
830
|
-
}, [openModal]);
|
|
831
|
-
return {
|
|
832
|
-
connect: handleConnect,
|
|
833
|
-
connectDirect: connect,
|
|
834
|
-
connecting,
|
|
835
|
-
isInstalled,
|
|
836
|
-
error,
|
|
837
|
-
openModal
|
|
838
|
-
};
|
|
839
|
-
}
|
|
840
|
-
function useDisconnectWallet() {
|
|
841
|
-
const { disconnect, connected } = useWallet();
|
|
842
|
-
return { disconnect, connected };
|
|
843
|
-
}
|
|
844
|
-
function useSignMessage() {
|
|
845
|
-
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) => {
|
|
850
|
-
if (!connected) {
|
|
851
|
-
setError(new Error("Wallet not connected"));
|
|
852
|
-
return null;
|
|
853
|
-
}
|
|
854
|
-
setSigning(true);
|
|
855
|
-
setError(null);
|
|
856
|
-
try {
|
|
857
|
-
const result = await signMessage(message);
|
|
858
|
-
setSignature(result.signature);
|
|
859
|
-
return result;
|
|
860
|
-
} catch (err) {
|
|
861
|
-
setError(err);
|
|
862
|
-
return null;
|
|
863
|
-
} finally {
|
|
864
|
-
setSigning(false);
|
|
865
|
-
}
|
|
866
|
-
}, [signMessage, connected]);
|
|
867
|
-
return { sign, signing, signature, error, address: activeAccount?.address };
|
|
868
|
-
}
|
|
869
|
-
function useSendTransaction() {
|
|
870
|
-
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) => {
|
|
875
|
-
if (!connected) {
|
|
876
|
-
setError(new Error("Wallet not connected"));
|
|
877
|
-
return null;
|
|
878
|
-
}
|
|
879
|
-
setSending(true);
|
|
880
|
-
setError(null);
|
|
881
|
-
try {
|
|
882
|
-
const result = await signAndSendTransaction(tx);
|
|
883
|
-
setTxHash(result.hash);
|
|
884
|
-
return result;
|
|
885
|
-
} catch (err) {
|
|
886
|
-
setError(err);
|
|
887
|
-
return null;
|
|
888
|
-
} finally {
|
|
889
|
-
setSending(false);
|
|
890
|
-
}
|
|
891
|
-
}, [signAndSendTransaction, connected]);
|
|
892
|
-
return { send, sending, txHash, error, reset: () => {
|
|
893
|
-
setTxHash(null);
|
|
894
|
-
setError(null);
|
|
895
|
-
} };
|
|
896
|
-
}
|
|
897
|
-
function useSignTransaction() {
|
|
898
|
-
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) => {
|
|
903
|
-
if (!connected) {
|
|
904
|
-
setError(new Error("Wallet not connected"));
|
|
905
|
-
return null;
|
|
237
|
+
async sendTransaction(tx) {
|
|
238
|
+
this._ensureConnected();
|
|
239
|
+
return withTimeout(
|
|
240
|
+
this._provider.sendTransaction(tx),
|
|
241
|
+
OPERATION_TIMEOUT,
|
|
242
|
+
"Send transaction timed out. Please check Sheep Wallet."
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
async signAndSendTransaction(tx) {
|
|
246
|
+
this._ensureConnected();
|
|
247
|
+
return withTimeout(
|
|
248
|
+
this._provider.signAndSendTransaction(tx),
|
|
249
|
+
OPERATION_TIMEOUT,
|
|
250
|
+
"Transaction timed out. Please check Sheep Wallet."
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
// =========================================================================
|
|
254
|
+
// Balance & Network
|
|
255
|
+
// =========================================================================
|
|
256
|
+
async getBalance(address) {
|
|
257
|
+
if (!this._provider) {
|
|
258
|
+
throw new Error("Wallet not available");
|
|
906
259
|
}
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
setSigning(false);
|
|
260
|
+
const result = await withTimeout(
|
|
261
|
+
this._provider.getBalance(address),
|
|
262
|
+
1e4,
|
|
263
|
+
"Balance request timed out"
|
|
264
|
+
);
|
|
265
|
+
return typeof result === "string" ? result : result.balance;
|
|
266
|
+
}
|
|
267
|
+
async switchNetwork(network) {
|
|
268
|
+
if (!this._provider) {
|
|
269
|
+
throw new Error("Wallet not available");
|
|
918
270
|
}
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
connectLabel = "Connect Wallet",
|
|
924
|
-
disconnectLabel = "Disconnect",
|
|
925
|
-
showAddress = true,
|
|
926
|
-
showBalance = false,
|
|
927
|
-
className = "",
|
|
928
|
-
style
|
|
929
|
-
}) {
|
|
930
|
-
const { connected, connecting, activeAccount, balance, openModal, disconnect } = useWallet();
|
|
931
|
-
const buttonStyle = {
|
|
932
|
-
padding: "10px 20px",
|
|
933
|
-
borderRadius: "8px",
|
|
934
|
-
border: "none",
|
|
935
|
-
cursor: "pointer",
|
|
936
|
-
fontWeight: 500,
|
|
937
|
-
fontSize: "14px",
|
|
938
|
-
transition: "all 0.2s ease",
|
|
939
|
-
...style
|
|
940
|
-
};
|
|
941
|
-
if (connecting) {
|
|
942
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
943
|
-
"button",
|
|
944
|
-
{
|
|
945
|
-
disabled: true,
|
|
946
|
-
className,
|
|
947
|
-
style: { ...buttonStyle, opacity: 0.7, cursor: "not-allowed" },
|
|
948
|
-
children: "Connecting..."
|
|
949
|
-
}
|
|
271
|
+
await withTimeout(
|
|
272
|
+
this._provider.switchNetwork(network),
|
|
273
|
+
1e4,
|
|
274
|
+
"Switch network timed out"
|
|
950
275
|
);
|
|
276
|
+
this._network = network;
|
|
277
|
+
}
|
|
278
|
+
// =========================================================================
|
|
279
|
+
// Events
|
|
280
|
+
// =========================================================================
|
|
281
|
+
on(event, callback) {
|
|
282
|
+
if (!this._provider) {
|
|
283
|
+
return () => {
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
const cleanup = this._provider.on(event, callback);
|
|
287
|
+
this._cleanupFns.push(cleanup);
|
|
288
|
+
return cleanup;
|
|
951
289
|
}
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
className,
|
|
958
|
-
style: {
|
|
959
|
-
...buttonStyle,
|
|
960
|
-
background: "linear-gradient(135deg, #6EB9A8 0%, #4A9A8A 100%)",
|
|
961
|
-
color: "white"
|
|
962
|
-
},
|
|
963
|
-
children: [
|
|
964
|
-
showBalance && balance && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("span", { style: { marginRight: 8 }, children: [
|
|
965
|
-
formatBalance(balance),
|
|
966
|
-
" RLO"
|
|
967
|
-
] }),
|
|
968
|
-
showAddress ? formatAddress(activeAccount.address) : disconnectLabel
|
|
969
|
-
]
|
|
290
|
+
destroy() {
|
|
291
|
+
this._cleanupFns.forEach((fn) => {
|
|
292
|
+
try {
|
|
293
|
+
fn();
|
|
294
|
+
} catch {
|
|
970
295
|
}
|
|
971
|
-
);
|
|
296
|
+
});
|
|
297
|
+
this._cleanupFns = [];
|
|
298
|
+
this._connected = false;
|
|
299
|
+
this._accounts = [];
|
|
972
300
|
}
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
...buttonStyle,
|
|
980
|
-
background: "linear-gradient(135deg, #6EB9A8 0%, #4A9A8A 100%)",
|
|
981
|
-
color: "white"
|
|
982
|
-
},
|
|
983
|
-
children: connectLabel
|
|
301
|
+
// =========================================================================
|
|
302
|
+
// Private
|
|
303
|
+
// =========================================================================
|
|
304
|
+
_ensureConnected() {
|
|
305
|
+
if (!this._provider) {
|
|
306
|
+
throw new Error("Sheep Wallet not installed");
|
|
984
307
|
}
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
var walletModalOwnerToken = null;
|
|
988
|
-
function WalletModal({ title = "Connect Wallet", className = "" }) {
|
|
989
|
-
const ownerRef = import_react2.default.useRef({});
|
|
990
|
-
const [isOwner] = (0, import_react2.useState)(() => {
|
|
991
|
-
if (!walletModalOwnerToken) {
|
|
992
|
-
walletModalOwnerToken = ownerRef.current;
|
|
993
|
-
return true;
|
|
308
|
+
if (!this._connected || this._accounts.length === 0) {
|
|
309
|
+
throw new Error("Wallet not connected");
|
|
994
310
|
}
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
}
|
|
311
|
+
}
|
|
312
|
+
_setupEvents() {
|
|
313
|
+
if (!this._provider) return;
|
|
314
|
+
const onDisconnect = () => {
|
|
315
|
+
this._connected = false;
|
|
316
|
+
this._accounts = [];
|
|
1002
317
|
};
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
padding: "24px",
|
|
1028
|
-
maxWidth: "400px",
|
|
1029
|
-
width: "90%",
|
|
1030
|
-
maxHeight: "80vh",
|
|
1031
|
-
overflow: "auto"
|
|
1032
|
-
},
|
|
1033
|
-
onClick: (e) => e.stopPropagation(),
|
|
1034
|
-
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)(
|
|
1038
|
-
"button",
|
|
1039
|
-
{
|
|
1040
|
-
onClick: closeModal,
|
|
1041
|
-
style: { background: "none", border: "none", fontSize: "24px", cursor: "pointer", padding: 0 },
|
|
1042
|
-
children: "\xD7"
|
|
1043
|
-
}
|
|
1044
|
-
)
|
|
1045
|
-
] }),
|
|
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)(
|
|
1047
|
-
"button",
|
|
1048
|
-
{
|
|
1049
|
-
onClick: () => selectWallet(wallet.id),
|
|
1050
|
-
disabled: connecting,
|
|
1051
|
-
style: {
|
|
1052
|
-
display: "flex",
|
|
1053
|
-
alignItems: "center",
|
|
1054
|
-
gap: "12px",
|
|
1055
|
-
padding: "16px",
|
|
1056
|
-
borderRadius: "12px",
|
|
1057
|
-
border: "1px solid #e5e5e5",
|
|
1058
|
-
background: "white",
|
|
1059
|
-
cursor: connecting ? "not-allowed" : "pointer",
|
|
1060
|
-
opacity: connecting ? 0.7 : 1,
|
|
1061
|
-
transition: "all 0.2s ease"
|
|
1062
|
-
},
|
|
1063
|
-
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" })
|
|
1068
|
-
] }),
|
|
1069
|
-
!wallet.installed && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { style: { fontSize: "12px", color: "#6EB9A8" }, children: "Install \u2192" })
|
|
1070
|
-
]
|
|
1071
|
-
},
|
|
1072
|
-
wallet.id
|
|
1073
|
-
)) }),
|
|
1074
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { marginTop: "20px", textAlign: "center", fontSize: "12px", color: "#999" }, children: "Powered by CookilLabs" })
|
|
1075
|
-
]
|
|
1076
|
-
}
|
|
1077
|
-
)
|
|
1078
|
-
}
|
|
1079
|
-
);
|
|
1080
|
-
}
|
|
1081
|
-
function withWalletErrorBoundary(WrappedComponent, fallback) {
|
|
1082
|
-
return function WithErrorBoundary(props) {
|
|
1083
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(WalletErrorBoundary, { fallback, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(WrappedComponent, { ...props }) });
|
|
1084
|
-
};
|
|
1085
|
-
}
|
|
1086
|
-
function SafeWalletProvider(props) {
|
|
1087
|
-
const { errorFallback, ...providerProps } = props;
|
|
1088
|
-
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(WalletErrorBoundary, { fallback: errorFallback, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(WalletProvider, { ...providerProps }) });
|
|
1089
|
-
}
|
|
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
|
-
});
|
|
318
|
+
const onAccountsChanged = (data) => {
|
|
319
|
+
const raw = data;
|
|
320
|
+
this._accounts = normalizeAccounts(raw);
|
|
321
|
+
};
|
|
322
|
+
const onNetworkChanged = (data) => {
|
|
323
|
+
const { network } = data;
|
|
324
|
+
if (network) this._network = network;
|
|
325
|
+
};
|
|
326
|
+
this._cleanupFns.push(
|
|
327
|
+
this._provider.on("disconnect", onDisconnect),
|
|
328
|
+
this._provider.on("accountsChanged", onAccountsChanged),
|
|
329
|
+
this._provider.on("networkChanged", onNetworkChanged)
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
|
|
334
|
+
exports.NETWORKS = NETWORKS;
|
|
335
|
+
exports.SheepWallet = SheepWallet;
|
|
336
|
+
exports.formatAddress = formatAddress;
|
|
337
|
+
exports.formatBalance = formatBalance;
|
|
338
|
+
exports.isInstalled = isInstalled;
|
|
339
|
+
exports.isValidAddress = isValidAddress;
|
|
340
|
+
exports.parseBalance = parseBalance;
|
|
341
|
+
//# sourceMappingURL=react.cjs.map
|
|
1121
342
|
//# sourceMappingURL=react.cjs.map
|