@solana/connector 0.1.10 → 0.2.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 +354 -98
- package/dist/{chunk-ATYK5OKR.js → chunk-4Z2F6ERB.js} +664 -232
- package/dist/chunk-4Z2F6ERB.js.map +1 -0
- package/dist/{chunk-MN7XNCYI.js → chunk-BJAVJQLK.js} +6 -6
- package/dist/{chunk-MN7XNCYI.js.map → chunk-BJAVJQLK.js.map} +1 -1
- package/dist/{chunk-6AJJJG5B.js → chunk-BZ2VBJCZ.js} +618 -415
- package/dist/chunk-BZ2VBJCZ.js.map +1 -0
- package/dist/{chunk-4JT24DIX.js → chunk-HN5AJF7F.js} +61 -20
- package/dist/chunk-HN5AJF7F.js.map +1 -0
- package/dist/{chunk-FVA4TUI4.mjs → chunk-HPQ5T32K.mjs} +4 -4
- package/dist/{chunk-FVA4TUI4.mjs.map → chunk-HPQ5T32K.mjs.map} +1 -1
- package/dist/{chunk-QOIQBWMP.mjs → chunk-IDTUFDNB.mjs} +531 -339
- package/dist/chunk-IDTUFDNB.mjs.map +1 -0
- package/dist/{chunk-WGZYKDXF.mjs → chunk-MDR4Y37Z.mjs} +584 -158
- package/dist/chunk-MDR4Y37Z.mjs.map +1 -0
- package/dist/{chunk-64LV76OK.js → chunk-SITQ4JWM.js} +23 -2
- package/dist/chunk-SITQ4JWM.js.map +1 -0
- package/dist/{chunk-7XHVZW2L.mjs → chunk-UCISIAOG.mjs} +60 -19
- package/dist/chunk-UCISIAOG.mjs.map +1 -0
- package/dist/{chunk-DKCZA2QI.mjs → chunk-ZZTY3O4N.mjs} +21 -3
- package/dist/chunk-ZZTY3O4N.mjs.map +1 -0
- package/dist/compat.d.mts +1 -1
- package/dist/compat.d.ts +1 -1
- package/dist/compat.js +2 -2
- package/dist/compat.mjs +1 -1
- package/dist/headless.d.mts +25 -7
- package/dist/headless.d.ts +25 -7
- package/dist/headless.js +196 -132
- package/dist/headless.mjs +4 -4
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +255 -175
- package/dist/index.mjs +5 -5
- package/dist/react.d.mts +244 -10
- package/dist/react.d.ts +244 -10
- package/dist/react.js +78 -42
- package/dist/react.mjs +2 -2
- package/dist/{standard-shim-BTUm7cur.d.mts → standard-shim-CGB88PPO.d.mts} +396 -54
- package/dist/{standard-shim-LsQ97i9T.d.ts → standard-shim-tmnQelaJ.d.ts} +396 -54
- package/dist/{transaction-signer-T-KVQFi8.d.ts → transaction-signer-7NaYmP5w.d.mts} +1 -0
- package/dist/{transaction-signer-T-KVQFi8.d.mts → transaction-signer-7NaYmP5w.d.ts} +1 -0
- package/dist/{walletconnect-D4JN6H2O.js → walletconnect-447EY3OJ.js} +8 -8
- package/dist/{walletconnect-D4JN6H2O.js.map → walletconnect-447EY3OJ.js.map} +1 -1
- package/dist/walletconnect-U455PO4I.mjs +3 -0
- package/dist/{walletconnect-I3PZUBTA.mjs.map → walletconnect-U455PO4I.mjs.map} +1 -1
- package/package.json +1 -1
- package/dist/chunk-4JT24DIX.js.map +0 -1
- package/dist/chunk-64LV76OK.js.map +0 -1
- package/dist/chunk-6AJJJG5B.js.map +0 -1
- package/dist/chunk-7XHVZW2L.mjs.map +0 -1
- package/dist/chunk-ATYK5OKR.js.map +0 -1
- package/dist/chunk-DKCZA2QI.mjs.map +0 -1
- package/dist/chunk-QOIQBWMP.mjs.map +0 -1
- package/dist/chunk-WGZYKDXF.mjs.map +0 -1
- package/dist/walletconnect-I3PZUBTA.mjs +0 -3
|
@@ -1,35 +1,309 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var
|
|
3
|
+
var chunkBZ2VBJCZ_js = require('./chunk-BZ2VBJCZ.js');
|
|
4
|
+
var chunkSITQ4JWM_js = require('./chunk-SITQ4JWM.js');
|
|
5
|
+
var React4 = require('react');
|
|
6
6
|
var jsxRuntime = require('react/jsx-runtime');
|
|
7
7
|
var addresses = require('@solana/addresses');
|
|
8
8
|
var keys = require('@solana/keys');
|
|
9
9
|
|
|
10
10
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var React4__default = /*#__PURE__*/_interopDefault(React4);
|
|
13
13
|
|
|
14
|
-
var
|
|
14
|
+
var logger = chunkSITQ4JWM_js.createLogger("ErrorBoundary");
|
|
15
|
+
var ErrorLogger = class {
|
|
16
|
+
static log(error, errorInfo, context) {
|
|
17
|
+
if (process.env.NODE_ENV === "development" && logger.error(error.message, {
|
|
18
|
+
error,
|
|
19
|
+
errorInfo,
|
|
20
|
+
context
|
|
21
|
+
}), process.env.NODE_ENV === "production" && typeof window < "u")
|
|
22
|
+
try {
|
|
23
|
+
let gtag = window.gtag;
|
|
24
|
+
typeof gtag == "function" && gtag("event", "exception", {
|
|
25
|
+
description: error.message,
|
|
26
|
+
fatal: false,
|
|
27
|
+
custom_map: { error_type: "wallet_error", ...context }
|
|
28
|
+
});
|
|
29
|
+
} catch {
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
function classifyError(error) {
|
|
34
|
+
if (chunkSITQ4JWM_js.isConnectorError(error)) {
|
|
35
|
+
let typeMapping = {
|
|
36
|
+
WALLET_NOT_CONNECTED: chunkSITQ4JWM_js.WalletErrorType.CONNECTION_FAILED,
|
|
37
|
+
WALLET_NOT_FOUND: chunkSITQ4JWM_js.WalletErrorType.WALLET_NOT_FOUND,
|
|
38
|
+
CONNECTION_FAILED: chunkSITQ4JWM_js.WalletErrorType.CONNECTION_FAILED,
|
|
39
|
+
USER_REJECTED: chunkSITQ4JWM_js.WalletErrorType.USER_REJECTED,
|
|
40
|
+
RPC_ERROR: chunkSITQ4JWM_js.WalletErrorType.NETWORK_ERROR,
|
|
41
|
+
NETWORK_TIMEOUT: chunkSITQ4JWM_js.WalletErrorType.NETWORK_ERROR,
|
|
42
|
+
SIGNING_FAILED: chunkSITQ4JWM_js.WalletErrorType.TRANSACTION_FAILED,
|
|
43
|
+
SEND_FAILED: chunkSITQ4JWM_js.WalletErrorType.TRANSACTION_FAILED
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
...error,
|
|
47
|
+
type: typeMapping[error.code] || chunkSITQ4JWM_js.WalletErrorType.UNKNOWN_ERROR,
|
|
48
|
+
recoverable: error.recoverable,
|
|
49
|
+
context: error.context
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
let walletError = error;
|
|
53
|
+
if (walletError.type) return walletError;
|
|
54
|
+
let type = chunkSITQ4JWM_js.WalletErrorType.UNKNOWN_ERROR, recoverable = false;
|
|
55
|
+
return error.message.includes("User rejected") || error.message.includes("User denied") ? (type = chunkSITQ4JWM_js.WalletErrorType.USER_REJECTED, recoverable = true) : error.message.includes("Insufficient funds") ? (type = chunkSITQ4JWM_js.WalletErrorType.INSUFFICIENT_FUNDS, recoverable = false) : error.message.includes("Network") || error.message.includes("fetch") ? (type = chunkSITQ4JWM_js.WalletErrorType.NETWORK_ERROR, recoverable = true) : error.message.includes("Wallet not found") || error.message.includes("not installed") ? (type = chunkSITQ4JWM_js.WalletErrorType.WALLET_NOT_FOUND, recoverable = true) : (error.message.includes("Failed to connect") || error.message.includes("Connection")) && (type = chunkSITQ4JWM_js.WalletErrorType.CONNECTION_FAILED, recoverable = true), {
|
|
56
|
+
...error,
|
|
57
|
+
type,
|
|
58
|
+
recoverable,
|
|
59
|
+
context: { originalMessage: error.message }
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
var ConnectorErrorBoundary = class extends React4.Component {
|
|
63
|
+
constructor(props) {
|
|
64
|
+
super(props);
|
|
65
|
+
chunkSITQ4JWM_js.__publicField(this, "retryTimeouts", /* @__PURE__ */ new Set());
|
|
66
|
+
chunkSITQ4JWM_js.__publicField(this, "retry", () => {
|
|
67
|
+
let { maxRetries = 3 } = this.props;
|
|
68
|
+
this.state.retryCount >= maxRetries || this.setState((prevState) => ({
|
|
69
|
+
hasError: false,
|
|
70
|
+
error: null,
|
|
71
|
+
errorInfo: null,
|
|
72
|
+
retryCount: prevState.retryCount + 1
|
|
73
|
+
}));
|
|
74
|
+
});
|
|
75
|
+
this.state = {
|
|
76
|
+
hasError: false,
|
|
77
|
+
error: null,
|
|
78
|
+
errorInfo: null,
|
|
79
|
+
errorId: "",
|
|
80
|
+
retryCount: 0
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
static getDerivedStateFromError(error) {
|
|
84
|
+
return {
|
|
85
|
+
hasError: true,
|
|
86
|
+
error,
|
|
87
|
+
errorId: `error_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
componentDidCatch(error, errorInfo) {
|
|
91
|
+
this.setState({ errorInfo }), ErrorLogger.log(error, errorInfo, {
|
|
92
|
+
retryCount: this.state.retryCount,
|
|
93
|
+
errorId: this.state.errorId,
|
|
94
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
95
|
+
}), this.props.onError?.(error, errorInfo);
|
|
96
|
+
}
|
|
97
|
+
componentWillUnmount() {
|
|
98
|
+
this.retryTimeouts.forEach((timeout) => clearTimeout(timeout));
|
|
99
|
+
}
|
|
100
|
+
render() {
|
|
101
|
+
if (this.state.hasError && this.state.error) {
|
|
102
|
+
let walletError = classifyError(this.state.error);
|
|
103
|
+
return this.props.fallback ? this.props.fallback(walletError, this.retry) : /* @__PURE__ */ jsxRuntime.jsx(DefaultErrorFallback, { error: walletError, onRetry: this.retry });
|
|
104
|
+
}
|
|
105
|
+
return this.props.children;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
function DefaultErrorFallback({ error, onRetry }) {
|
|
109
|
+
let [isPending, startTransition] = React4.useTransition(), [isRetrying, setIsRetrying] = React4.useState(false), handleRetry = React4.useCallback(() => {
|
|
110
|
+
setIsRetrying(true), startTransition(() => {
|
|
111
|
+
setTimeout(() => {
|
|
112
|
+
onRetry(), setIsRetrying(false);
|
|
113
|
+
}, 500);
|
|
114
|
+
});
|
|
115
|
+
}, [onRetry]), { title, message, actionText, showRetry } = React4.useMemo(() => {
|
|
116
|
+
switch (error.type) {
|
|
117
|
+
case chunkSITQ4JWM_js.WalletErrorType.USER_REJECTED:
|
|
118
|
+
return {
|
|
119
|
+
title: "Transaction Cancelled",
|
|
120
|
+
message: "You cancelled the transaction. No problem!",
|
|
121
|
+
actionText: "Try Again",
|
|
122
|
+
showRetry: true
|
|
123
|
+
};
|
|
124
|
+
case chunkSITQ4JWM_js.WalletErrorType.WALLET_NOT_FOUND:
|
|
125
|
+
return {
|
|
126
|
+
title: "Wallet Not Found",
|
|
127
|
+
message: "Please install a supported Solana wallet to continue.",
|
|
128
|
+
actionText: "Check Wallets",
|
|
129
|
+
showRetry: true
|
|
130
|
+
};
|
|
131
|
+
case chunkSITQ4JWM_js.WalletErrorType.NETWORK_ERROR:
|
|
132
|
+
return {
|
|
133
|
+
title: "Network Error",
|
|
134
|
+
message: "Having trouble connecting. Please check your internet connection.",
|
|
135
|
+
actionText: "Retry",
|
|
136
|
+
showRetry: true
|
|
137
|
+
};
|
|
138
|
+
case chunkSITQ4JWM_js.WalletErrorType.INSUFFICIENT_FUNDS:
|
|
139
|
+
return {
|
|
140
|
+
title: "Insufficient Funds",
|
|
141
|
+
message: "You don't have enough SOL for this transaction.",
|
|
142
|
+
actionText: "Add Funds",
|
|
143
|
+
showRetry: false
|
|
144
|
+
};
|
|
145
|
+
default:
|
|
146
|
+
return {
|
|
147
|
+
title: "Something went wrong",
|
|
148
|
+
message: "An unexpected error occurred. Please try again.",
|
|
149
|
+
actionText: "Retry",
|
|
150
|
+
showRetry: error.recoverable
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}, [error.type, error.recoverable]);
|
|
154
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
155
|
+
"div",
|
|
156
|
+
{
|
|
157
|
+
style: {
|
|
158
|
+
display: "flex",
|
|
159
|
+
flexDirection: "column",
|
|
160
|
+
alignItems: "center",
|
|
161
|
+
justifyContent: "center",
|
|
162
|
+
padding: "2rem",
|
|
163
|
+
textAlign: "center",
|
|
164
|
+
borderRadius: "12px",
|
|
165
|
+
border: "1px solid #e5e7eb",
|
|
166
|
+
backgroundColor: "#fafafa",
|
|
167
|
+
maxWidth: "400px",
|
|
168
|
+
margin: "0 auto"
|
|
169
|
+
},
|
|
170
|
+
children: [
|
|
171
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
172
|
+
"div",
|
|
173
|
+
{
|
|
174
|
+
style: {
|
|
175
|
+
width: "48px",
|
|
176
|
+
height: "48px",
|
|
177
|
+
borderRadius: "50%",
|
|
178
|
+
backgroundColor: "#fee2e2",
|
|
179
|
+
display: "flex",
|
|
180
|
+
alignItems: "center",
|
|
181
|
+
justifyContent: "center",
|
|
182
|
+
marginBottom: "1rem"
|
|
183
|
+
},
|
|
184
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "#dc2626", children: /* @__PURE__ */ jsxRuntime.jsx("path", { d: "M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126zM12 15.75h.007v.008H12v-.008z" }) })
|
|
185
|
+
}
|
|
186
|
+
),
|
|
187
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
188
|
+
"h3",
|
|
189
|
+
{
|
|
190
|
+
style: {
|
|
191
|
+
margin: "0 0 0.5rem 0",
|
|
192
|
+
fontSize: "1.125rem",
|
|
193
|
+
fontWeight: "600",
|
|
194
|
+
color: "#111827"
|
|
195
|
+
},
|
|
196
|
+
children: title
|
|
197
|
+
}
|
|
198
|
+
),
|
|
199
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
200
|
+
"p",
|
|
201
|
+
{
|
|
202
|
+
style: {
|
|
203
|
+
margin: "0 0 1.5rem 0",
|
|
204
|
+
fontSize: "0.875rem",
|
|
205
|
+
color: "#6b7280",
|
|
206
|
+
lineHeight: "1.5"
|
|
207
|
+
},
|
|
208
|
+
children: message
|
|
209
|
+
}
|
|
210
|
+
),
|
|
211
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { style: { display: "flex", gap: "0.75rem", flexWrap: "wrap" }, children: [
|
|
212
|
+
showRetry && /* @__PURE__ */ jsxRuntime.jsx(
|
|
213
|
+
"button",
|
|
214
|
+
{
|
|
215
|
+
onClick: handleRetry,
|
|
216
|
+
disabled: isPending || isRetrying,
|
|
217
|
+
style: {
|
|
218
|
+
padding: "0.5rem 1rem",
|
|
219
|
+
backgroundColor: "#3b82f6",
|
|
220
|
+
color: "white",
|
|
221
|
+
border: "none",
|
|
222
|
+
borderRadius: "6px",
|
|
223
|
+
fontSize: "0.875rem",
|
|
224
|
+
fontWeight: "500",
|
|
225
|
+
cursor: isPending || isRetrying ? "wait" : "pointer",
|
|
226
|
+
opacity: isPending || isRetrying ? 0.7 : 1,
|
|
227
|
+
transition: "all 0.2s"
|
|
228
|
+
},
|
|
229
|
+
children: isRetrying ? "Retrying..." : actionText
|
|
230
|
+
}
|
|
231
|
+
),
|
|
232
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
233
|
+
"button",
|
|
234
|
+
{
|
|
235
|
+
onClick: () => window.location.reload(),
|
|
236
|
+
style: {
|
|
237
|
+
padding: "0.5rem 1rem",
|
|
238
|
+
backgroundColor: "transparent",
|
|
239
|
+
color: "#6b7280",
|
|
240
|
+
border: "1px solid #d1d5db",
|
|
241
|
+
borderRadius: "6px",
|
|
242
|
+
fontSize: "0.875rem",
|
|
243
|
+
fontWeight: "500",
|
|
244
|
+
cursor: "pointer",
|
|
245
|
+
transition: "all 0.2s"
|
|
246
|
+
},
|
|
247
|
+
children: "Refresh Page"
|
|
248
|
+
}
|
|
249
|
+
)
|
|
250
|
+
] }),
|
|
251
|
+
process.env.NODE_ENV === "development" && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
252
|
+
"details",
|
|
253
|
+
{
|
|
254
|
+
style: {
|
|
255
|
+
marginTop: "1rem",
|
|
256
|
+
fontSize: "0.75rem",
|
|
257
|
+
color: "#6b7280",
|
|
258
|
+
width: "100%"
|
|
259
|
+
},
|
|
260
|
+
children: [
|
|
261
|
+
/* @__PURE__ */ jsxRuntime.jsx("summary", { style: { cursor: "pointer", marginBottom: "0.5rem" }, children: "Error Details" }),
|
|
262
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
263
|
+
"pre",
|
|
264
|
+
{
|
|
265
|
+
style: {
|
|
266
|
+
whiteSpace: "pre-wrap",
|
|
267
|
+
wordBreak: "break-all",
|
|
268
|
+
backgroundColor: "#f3f4f6",
|
|
269
|
+
padding: "0.5rem",
|
|
270
|
+
borderRadius: "4px",
|
|
271
|
+
overflow: "auto",
|
|
272
|
+
maxHeight: "200px"
|
|
273
|
+
},
|
|
274
|
+
children: error.message
|
|
275
|
+
}
|
|
276
|
+
)
|
|
277
|
+
]
|
|
278
|
+
}
|
|
279
|
+
)
|
|
280
|
+
]
|
|
281
|
+
}
|
|
282
|
+
);
|
|
283
|
+
}
|
|
284
|
+
function withErrorBoundary(Component2, errorBoundaryProps) {
|
|
285
|
+
let WrappedComponent = (props) => /* @__PURE__ */ jsxRuntime.jsx(ConnectorErrorBoundary, { ...errorBoundaryProps, children: /* @__PURE__ */ jsxRuntime.jsx(Component2, { ...props }) });
|
|
286
|
+
return WrappedComponent.displayName = `withErrorBoundary(${Component2.displayName || Component2.name})`, WrappedComponent;
|
|
287
|
+
}
|
|
288
|
+
var WalletConnectContext = React4.createContext(null);
|
|
15
289
|
function WalletConnectProvider({ children }) {
|
|
16
|
-
let [uri, setUriState] =
|
|
17
|
-
|
|
290
|
+
let [uri, setUriState] = React4.useState(null), isMountedRef = React4.useRef(false), pendingUriRef = React4.useRef(null);
|
|
291
|
+
React4.useEffect(() => (isMountedRef.current = true, pendingUriRef.current !== null && (setUriState(pendingUriRef.current), pendingUriRef.current = null), () => {
|
|
18
292
|
isMountedRef.current = false;
|
|
19
293
|
}), []);
|
|
20
|
-
let setUri =
|
|
294
|
+
let setUri = React4.useCallback((newUri) => {
|
|
21
295
|
if (!isMountedRef.current) {
|
|
22
296
|
pendingUriRef.current = newUri;
|
|
23
297
|
return;
|
|
24
298
|
}
|
|
25
299
|
setUriState(newUri);
|
|
26
|
-
}, []), clearUri =
|
|
300
|
+
}, []), clearUri = React4.useCallback(() => {
|
|
27
301
|
pendingUriRef.current = null, isMountedRef.current && setUriState(null);
|
|
28
302
|
}, []);
|
|
29
303
|
return /* @__PURE__ */ jsxRuntime.jsx(WalletConnectContext.Provider, { value: { uri, setUri, clearUri }, children });
|
|
30
304
|
}
|
|
31
305
|
function useWalletConnectUri() {
|
|
32
|
-
let context =
|
|
306
|
+
let context = React4.useContext(WalletConnectContext);
|
|
33
307
|
return context || {
|
|
34
308
|
uri: null,
|
|
35
309
|
setUri: () => {
|
|
@@ -38,22 +312,22 @@ function useWalletConnectUri() {
|
|
|
38
312
|
}
|
|
39
313
|
};
|
|
40
314
|
}
|
|
41
|
-
var
|
|
42
|
-
|
|
43
|
-
var ConnectorContext =
|
|
315
|
+
var logger2 = chunkSITQ4JWM_js.createLogger("ConnectorProvider");
|
|
316
|
+
chunkBZ2VBJCZ_js.installPolyfills();
|
|
317
|
+
var ConnectorContext = React4.createContext(null);
|
|
44
318
|
ConnectorContext.displayName = "ConnectorContext";
|
|
45
319
|
function ConnectorProviderInternal({
|
|
46
320
|
children,
|
|
47
321
|
config,
|
|
48
322
|
mobile
|
|
49
323
|
}) {
|
|
50
|
-
let clientRef =
|
|
324
|
+
let clientRef = React4.useRef(null), client = React4__default.default.useCallback(() => {
|
|
51
325
|
if (!clientRef.current)
|
|
52
326
|
try {
|
|
53
|
-
clientRef.current = new
|
|
327
|
+
clientRef.current = new chunkBZ2VBJCZ_js.ConnectorClient(config), typeof window < "u" && (window.__connectorClient = clientRef.current), config?.debug && logger2.info("Client initialized successfully");
|
|
54
328
|
} catch (error) {
|
|
55
329
|
let err = error;
|
|
56
|
-
|
|
330
|
+
logger2.error("Failed to initialize client", { error: err });
|
|
57
331
|
let extendedConfig = config;
|
|
58
332
|
return extendedConfig?.errorBoundary?.onError && extendedConfig.errorBoundary.onError(err, {
|
|
59
333
|
componentStack: "client-initialization",
|
|
@@ -62,7 +336,7 @@ function ConnectorProviderInternal({
|
|
|
62
336
|
}
|
|
63
337
|
return clientRef.current;
|
|
64
338
|
}, [config])();
|
|
65
|
-
return
|
|
339
|
+
return React4__default.default.useEffect(() => {
|
|
66
340
|
let currentClient = clientRef.current;
|
|
67
341
|
if (currentClient) {
|
|
68
342
|
let privateClient = currentClient;
|
|
@@ -71,7 +345,7 @@ function ConnectorProviderInternal({
|
|
|
71
345
|
return () => {
|
|
72
346
|
typeof window < "u" && (window.__connectorClient = void 0), currentClient && typeof currentClient.destroy == "function" && currentClient.destroy();
|
|
73
347
|
};
|
|
74
|
-
}, []),
|
|
348
|
+
}, []), React4__default.default.useEffect(() => {
|
|
75
349
|
if (!mobile) return;
|
|
76
350
|
let cancelled = false;
|
|
77
351
|
return (async () => {
|
|
@@ -110,7 +384,7 @@ function ConnectorProvider({
|
|
|
110
384
|
}) {
|
|
111
385
|
let errorBoundaryConfig = config?.errorBoundary;
|
|
112
386
|
return errorBoundaryConfig?.enabled ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
113
|
-
|
|
387
|
+
ConnectorErrorBoundary,
|
|
114
388
|
{
|
|
115
389
|
maxRetries: errorBoundaryConfig.maxRetries ?? 3,
|
|
116
390
|
onError: errorBoundaryConfig.onError,
|
|
@@ -120,38 +394,58 @@ function ConnectorProvider({
|
|
|
120
394
|
) : /* @__PURE__ */ jsxRuntime.jsx(ConnectorProviderInternal, { config, mobile, children });
|
|
121
395
|
}
|
|
122
396
|
function useConnector() {
|
|
123
|
-
let client =
|
|
397
|
+
let client = React4.useContext(ConnectorContext);
|
|
124
398
|
if (!client)
|
|
125
399
|
throw new Error(
|
|
126
400
|
"useConnector must be used within ConnectorProvider. Wrap your app with <ConnectorProvider> or <UnifiedProvider> to use connector hooks."
|
|
127
401
|
);
|
|
128
|
-
let { uri: walletConnectUri, clearUri: clearWalletConnectUri } = useWalletConnectUri(), state =
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
), methods =
|
|
402
|
+
let { uri: walletConnectUri, clearUri: clearWalletConnectUri } = useWalletConnectUri(), state = React4.useSyncExternalStore(
|
|
403
|
+
React4__default.default.useCallback((cb) => client.subscribe(cb), [client]),
|
|
404
|
+
React4__default.default.useCallback(() => client.getSnapshot(), [client]),
|
|
405
|
+
React4__default.default.useCallback(() => client.getSnapshot(), [client])
|
|
406
|
+
), methods = React4.useMemo(
|
|
133
407
|
() => ({
|
|
408
|
+
// Legacy (kept for backwards compatibility)
|
|
134
409
|
select: client.select.bind(client),
|
|
135
410
|
disconnect: client.disconnect.bind(client),
|
|
136
|
-
selectAccount: client.selectAccount.bind(client)
|
|
411
|
+
selectAccount: client.selectAccount.bind(client),
|
|
412
|
+
// vNext
|
|
413
|
+
connectWallet: client.connectWallet.bind(client),
|
|
414
|
+
disconnectWallet: client.disconnectWallet.bind(client)
|
|
137
415
|
}),
|
|
138
416
|
[client]
|
|
139
|
-
)
|
|
140
|
-
|
|
417
|
+
), vNextFields = React4.useMemo(() => {
|
|
418
|
+
let walletStatus = state.wallet, isConnected2 = walletStatus.status === "connected", isConnecting2 = walletStatus.status === "connecting", isError = walletStatus.status === "error", connectorId = null, account = null, sessionAccounts = [], walletError = null;
|
|
419
|
+
walletStatus.status === "connected" ? (connectorId = walletStatus.session.connectorId, account = walletStatus.session.selectedAccount.address, sessionAccounts = walletStatus.session.accounts) : walletStatus.status === "connecting" ? connectorId = walletStatus.connectorId : walletStatus.status === "error" && (walletError = walletStatus.error, connectorId = walletStatus.connectorId ?? null);
|
|
420
|
+
let connector = connectorId ? state.connectors.find((c) => c.id === connectorId) ?? null : null;
|
|
421
|
+
return {
|
|
422
|
+
walletStatus,
|
|
423
|
+
isConnected: isConnected2,
|
|
424
|
+
isConnecting: isConnecting2,
|
|
425
|
+
isError,
|
|
426
|
+
walletError,
|
|
427
|
+
account,
|
|
428
|
+
sessionAccounts,
|
|
429
|
+
connectorId,
|
|
430
|
+
connector
|
|
431
|
+
};
|
|
432
|
+
}, [state.wallet, state.connectors]);
|
|
433
|
+
return React4.useMemo(
|
|
141
434
|
() => ({
|
|
142
435
|
...state,
|
|
143
436
|
...methods,
|
|
437
|
+
...vNextFields,
|
|
144
438
|
walletConnectUri,
|
|
145
439
|
clearWalletConnectUri
|
|
146
440
|
}),
|
|
147
|
-
[state, methods, walletConnectUri, clearWalletConnectUri]
|
|
441
|
+
[state, methods, vNextFields, walletConnectUri, clearWalletConnectUri]
|
|
148
442
|
);
|
|
149
443
|
}
|
|
150
444
|
function useConnectorClient() {
|
|
151
|
-
return
|
|
445
|
+
return React4.useContext(ConnectorContext);
|
|
152
446
|
}
|
|
153
447
|
function AppProviderInner({ children, connectorConfig, mobile, providers = [] }) {
|
|
154
|
-
let { setUri, clearUri } = useWalletConnectUri(), enhancedConfig =
|
|
448
|
+
let { setUri, clearUri } = useWalletConnectUri(), enhancedConfig = React4.useMemo(() => {
|
|
155
449
|
if (!connectorConfig?.walletConnect?.enabled)
|
|
156
450
|
return connectorConfig;
|
|
157
451
|
let wcConfig = connectorConfig.walletConnect;
|
|
@@ -176,18 +470,104 @@ function AppProvider(props) {
|
|
|
176
470
|
return props.connectorConfig?.walletConnect?.enabled ? /* @__PURE__ */ jsxRuntime.jsx(WalletConnectProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(AppProviderInner, { ...props }) }) : /* @__PURE__ */ jsxRuntime.jsx(AppProviderInner, { ...props });
|
|
177
471
|
}
|
|
178
472
|
var UnifiedProvider = AppProvider;
|
|
473
|
+
function useWallet() {
|
|
474
|
+
let client = React4.useContext(ConnectorContext);
|
|
475
|
+
if (!client)
|
|
476
|
+
throw new Error(
|
|
477
|
+
"useWallet must be used within ConnectorProvider. Wrap your app with <ConnectorProvider> or <UnifiedProvider> to use wallet hooks."
|
|
478
|
+
);
|
|
479
|
+
let walletStatus = React4.useSyncExternalStore(
|
|
480
|
+
React4.useCallback((cb) => client.subscribe(cb), [client]),
|
|
481
|
+
React4.useCallback(() => client.getSnapshot().wallet, [client]),
|
|
482
|
+
React4.useCallback(() => client.getSnapshot().wallet, [client])
|
|
483
|
+
);
|
|
484
|
+
return React4.useMemo(() => {
|
|
485
|
+
let status = walletStatus.status, isConnected2 = status === "connected", isConnecting2 = status === "connecting", isError = status === "error", connectorId = null, account = null, accounts = [], session = null, error = null;
|
|
486
|
+
return walletStatus.status === "connected" ? (connectorId = walletStatus.session.connectorId, account = walletStatus.session.selectedAccount.address, accounts = walletStatus.session.accounts, session = walletStatus.session) : walletStatus.status === "connecting" ? connectorId = walletStatus.connectorId : walletStatus.status === "error" && (error = walletStatus.error, connectorId = walletStatus.connectorId ?? null), {
|
|
487
|
+
status,
|
|
488
|
+
walletStatus,
|
|
489
|
+
isConnected: isConnected2,
|
|
490
|
+
isConnecting: isConnecting2,
|
|
491
|
+
isError,
|
|
492
|
+
error,
|
|
493
|
+
connectorId,
|
|
494
|
+
account,
|
|
495
|
+
accounts,
|
|
496
|
+
session
|
|
497
|
+
};
|
|
498
|
+
}, [walletStatus]);
|
|
499
|
+
}
|
|
500
|
+
function useWalletConnectors() {
|
|
501
|
+
let client = React4.useContext(ConnectorContext);
|
|
502
|
+
if (!client)
|
|
503
|
+
throw new Error(
|
|
504
|
+
"useWalletConnectors must be used within ConnectorProvider. Wrap your app with <ConnectorProvider> or <UnifiedProvider> to use wallet hooks."
|
|
505
|
+
);
|
|
506
|
+
return React4.useSyncExternalStore(
|
|
507
|
+
React4.useCallback((cb) => client.subscribe(cb), [client]),
|
|
508
|
+
React4.useCallback(() => client.getSnapshot().connectors, [client]),
|
|
509
|
+
React4.useCallback(() => client.getSnapshot().connectors, [client])
|
|
510
|
+
);
|
|
511
|
+
}
|
|
512
|
+
function useConnectWallet() {
|
|
513
|
+
let client = React4.useContext(ConnectorContext), [isConnecting2, setIsConnecting] = React4.useState(false), [error, setError] = React4.useState(null);
|
|
514
|
+
if (!client)
|
|
515
|
+
throw new Error(
|
|
516
|
+
"useConnectWallet must be used within ConnectorProvider. Wrap your app with <ConnectorProvider> or <UnifiedProvider> to use wallet hooks."
|
|
517
|
+
);
|
|
518
|
+
let connect = React4.useCallback(
|
|
519
|
+
async (connectorId, options) => {
|
|
520
|
+
setIsConnecting(true), setError(null);
|
|
521
|
+
try {
|
|
522
|
+
await client.connectWallet(connectorId, options);
|
|
523
|
+
} catch (e) {
|
|
524
|
+
let connectError = e instanceof Error ? e : new Error(String(e));
|
|
525
|
+
throw setError(connectError), connectError;
|
|
526
|
+
} finally {
|
|
527
|
+
setIsConnecting(false);
|
|
528
|
+
}
|
|
529
|
+
},
|
|
530
|
+
[client]
|
|
531
|
+
), resetError = React4.useCallback(() => {
|
|
532
|
+
setError(null);
|
|
533
|
+
}, []);
|
|
534
|
+
return {
|
|
535
|
+
connect,
|
|
536
|
+
isConnecting: isConnecting2,
|
|
537
|
+
error,
|
|
538
|
+
resetError
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
function useDisconnectWallet() {
|
|
542
|
+
let client = React4.useContext(ConnectorContext), [isDisconnecting, setIsDisconnecting] = React4.useState(false);
|
|
543
|
+
if (!client)
|
|
544
|
+
throw new Error(
|
|
545
|
+
"useDisconnectWallet must be used within ConnectorProvider. Wrap your app with <ConnectorProvider> or <UnifiedProvider> to use wallet hooks."
|
|
546
|
+
);
|
|
547
|
+
return {
|
|
548
|
+
disconnect: React4.useCallback(async () => {
|
|
549
|
+
setIsDisconnecting(true);
|
|
550
|
+
try {
|
|
551
|
+
await client.disconnectWallet();
|
|
552
|
+
} finally {
|
|
553
|
+
setIsDisconnecting(false);
|
|
554
|
+
}
|
|
555
|
+
}, [client]),
|
|
556
|
+
isDisconnecting
|
|
557
|
+
};
|
|
558
|
+
}
|
|
179
559
|
function useCluster() {
|
|
180
560
|
let { cluster, clusters } = useConnector(), client = useConnectorClient();
|
|
181
561
|
if (!client)
|
|
182
562
|
throw new Error("useCluster must be used within ConnectorProvider");
|
|
183
|
-
let setCluster =
|
|
563
|
+
let setCluster = React4.useMemo(
|
|
184
564
|
() => async (id) => {
|
|
185
565
|
await client.setCluster(id);
|
|
186
566
|
},
|
|
187
567
|
[client]
|
|
188
568
|
);
|
|
189
|
-
return
|
|
190
|
-
let isMainnet = cluster ?
|
|
569
|
+
return React4.useMemo(() => {
|
|
570
|
+
let isMainnet = cluster ? chunkBZ2VBJCZ_js.isMainnetCluster(cluster) : false, isDevnet = cluster ? chunkBZ2VBJCZ_js.isDevnetCluster(cluster) : false, isTestnet = cluster ? chunkBZ2VBJCZ_js.isTestnetCluster(cluster) : false, isLocal = cluster ? chunkBZ2VBJCZ_js.isLocalCluster(cluster) : false, explorerUrl = cluster ? chunkBZ2VBJCZ_js.getClusterExplorerUrl(cluster) : "", type = cluster ? chunkBZ2VBJCZ_js.getClusterType(cluster) : null;
|
|
191
571
|
return {
|
|
192
572
|
cluster,
|
|
193
573
|
clusters,
|
|
@@ -202,10 +582,10 @@ function useCluster() {
|
|
|
202
582
|
}, [cluster, clusters, setCluster]);
|
|
203
583
|
}
|
|
204
584
|
function useAccount() {
|
|
205
|
-
let { selectedAccount, accounts, connected, selectAccount } = useConnector(), [copied, setCopied] =
|
|
585
|
+
let { selectedAccount, accounts, connected, selectAccount } = useConnector(), [copied, setCopied] = React4.useState(false), copyTimeoutRef = React4__default.default.useRef(void 0), account = React4.useMemo(
|
|
206
586
|
() => accounts.find((a) => a.address === selectedAccount) ?? null,
|
|
207
587
|
[accounts, selectedAccount]
|
|
208
|
-
), formatted =
|
|
588
|
+
), formatted = React4.useMemo(() => selectedAccount ? chunkBZ2VBJCZ_js.formatAddress(selectedAccount) : "", [selectedAccount]), copy = React4.useCallback(async () => selectedAccount ? (copyTimeoutRef.current && clearTimeout(copyTimeoutRef.current), await chunkBZ2VBJCZ_js.copyAddressToClipboard(selectedAccount, {
|
|
209
589
|
onSuccess: () => {
|
|
210
590
|
setCopied(true), copyTimeoutRef.current = setTimeout(() => setCopied(false), 2e3);
|
|
211
591
|
}
|
|
@@ -214,9 +594,9 @@ function useAccount() {
|
|
|
214
594
|
error: "empty_value" /* EMPTY_VALUE */,
|
|
215
595
|
errorMessage: "No account selected"
|
|
216
596
|
}, [selectedAccount]);
|
|
217
|
-
return
|
|
597
|
+
return React4__default.default.useEffect(() => () => {
|
|
218
598
|
copyTimeoutRef.current && clearTimeout(copyTimeoutRef.current);
|
|
219
|
-
}, []),
|
|
599
|
+
}, []), React4.useMemo(
|
|
220
600
|
() => ({
|
|
221
601
|
address: selectedAccount,
|
|
222
602
|
account,
|
|
@@ -231,17 +611,18 @@ function useAccount() {
|
|
|
231
611
|
);
|
|
232
612
|
}
|
|
233
613
|
function useWalletInfo() {
|
|
234
|
-
let { selectedWallet, wallets, connected, connecting } = useConnector(), mappedWallets =
|
|
614
|
+
let { selectedWallet, wallets, connected, connecting } = useConnector(), mappedWallets = React4.useMemo(
|
|
235
615
|
() => wallets.map(
|
|
236
616
|
(walletInfo) => ({
|
|
237
617
|
name: walletInfo.wallet.name,
|
|
618
|
+
connectorId: chunkBZ2VBJCZ_js.createConnectorId(walletInfo.wallet.name),
|
|
238
619
|
icon: walletInfo.wallet.icon,
|
|
239
620
|
installed: walletInfo.installed,
|
|
240
621
|
connectable: walletInfo.connectable
|
|
241
622
|
})
|
|
242
623
|
),
|
|
243
624
|
[wallets]
|
|
244
|
-
), selectedWalletInfo =
|
|
625
|
+
), selectedWalletInfo = React4.useMemo(() => {
|
|
245
626
|
if (!selectedWallet)
|
|
246
627
|
return {
|
|
247
628
|
name: null,
|
|
@@ -257,7 +638,7 @@ function useWalletInfo() {
|
|
|
257
638
|
connectable: walletInfo?.connectable ?? false
|
|
258
639
|
};
|
|
259
640
|
}, [selectedWallet, wallets]);
|
|
260
|
-
return
|
|
641
|
+
return React4.useMemo(
|
|
261
642
|
() => ({
|
|
262
643
|
...selectedWalletInfo,
|
|
263
644
|
connected,
|
|
@@ -268,10 +649,10 @@ function useWalletInfo() {
|
|
|
268
649
|
);
|
|
269
650
|
}
|
|
270
651
|
function useTransactionSigner() {
|
|
271
|
-
let { selectedWallet, selectedAccount, accounts, cluster, connected } = useConnector(), client = useConnectorClient(), account =
|
|
652
|
+
let { selectedWallet, selectedAccount, accounts, cluster, connected } = useConnector(), client = useConnectorClient(), account = React4.useMemo(
|
|
272
653
|
() => accounts.find((a) => a.address === selectedAccount)?.raw ?? null,
|
|
273
654
|
[accounts, selectedAccount]
|
|
274
|
-
), signer =
|
|
655
|
+
), signer = React4.useMemo(() => !connected || !selectedWallet || !account ? null : chunkBZ2VBJCZ_js.createTransactionSigner({
|
|
275
656
|
wallet: selectedWallet,
|
|
276
657
|
account,
|
|
277
658
|
cluster: cluster ?? void 0,
|
|
@@ -280,7 +661,7 @@ function useTransactionSigner() {
|
|
|
280
661
|
client.emitEvent(event);
|
|
281
662
|
}
|
|
282
663
|
} : void 0
|
|
283
|
-
}), [connected, selectedWallet, account, cluster, client]), capabilities =
|
|
664
|
+
}), [connected, selectedWallet, account, cluster, client]), capabilities = React4.useMemo(
|
|
284
665
|
() => signer?.getCapabilities() ?? {
|
|
285
666
|
canSign: false,
|
|
286
667
|
canSend: false,
|
|
@@ -299,27 +680,27 @@ function useTransactionSigner() {
|
|
|
299
680
|
function useKitTransactionSigner() {
|
|
300
681
|
let { signer: connectorSigner, ready } = useTransactionSigner();
|
|
301
682
|
return {
|
|
302
|
-
signer:
|
|
683
|
+
signer: React4.useMemo(() => connectorSigner ? chunkBZ2VBJCZ_js.createKitTransactionSigner(connectorSigner) : null, [connectorSigner]),
|
|
303
684
|
ready
|
|
304
685
|
};
|
|
305
686
|
}
|
|
306
687
|
var useGillTransactionSigner = useKitTransactionSigner;
|
|
307
|
-
var
|
|
688
|
+
var logger3 = chunkSITQ4JWM_js.createLogger("useSolanaClient");
|
|
308
689
|
function useSolanaClient() {
|
|
309
|
-
let { type } = useCluster(), connectorClient = useConnectorClient(), client =
|
|
690
|
+
let { type } = useCluster(), connectorClient = useConnectorClient(), client = React4.useMemo(() => {
|
|
310
691
|
if (!type || !connectorClient) return null;
|
|
311
692
|
try {
|
|
312
693
|
let rpcUrl = connectorClient.getRpcUrl();
|
|
313
|
-
return rpcUrl ?
|
|
694
|
+
return rpcUrl ? chunkSITQ4JWM_js.createSolanaClient({
|
|
314
695
|
urlOrMoniker: rpcUrl
|
|
315
|
-
}) : type !== "custom" ?
|
|
696
|
+
}) : type !== "custom" ? chunkSITQ4JWM_js.createSolanaClient({
|
|
316
697
|
urlOrMoniker: type
|
|
317
698
|
}) : null;
|
|
318
699
|
} catch (error) {
|
|
319
|
-
return
|
|
700
|
+
return logger3.error("Failed to create Solana client", { error }), null;
|
|
320
701
|
}
|
|
321
702
|
}, [type, connectorClient]);
|
|
322
|
-
return
|
|
703
|
+
return React4.useMemo(
|
|
323
704
|
() => ({
|
|
324
705
|
client,
|
|
325
706
|
ready: !!client,
|
|
@@ -330,11 +711,11 @@ function useSolanaClient() {
|
|
|
330
711
|
}
|
|
331
712
|
var useGillSolanaClient = useSolanaClient;
|
|
332
713
|
function useTransactionPreparer() {
|
|
333
|
-
let { client, ready } = useSolanaClient(), prepare =
|
|
714
|
+
let { client, ready } = useSolanaClient(), prepare = React4.useCallback(
|
|
334
715
|
async (transaction, options = {}) => {
|
|
335
716
|
if (!client)
|
|
336
|
-
throw new
|
|
337
|
-
return
|
|
717
|
+
throw new chunkSITQ4JWM_js.NetworkError("RPC_ERROR", "Solana client not available. Cannot prepare transaction.");
|
|
718
|
+
return chunkSITQ4JWM_js.prepareTransaction({
|
|
338
719
|
transaction,
|
|
339
720
|
rpc: client.rpc,
|
|
340
721
|
computeUnitLimitMultiplier: options.computeUnitLimitMultiplier,
|
|
@@ -344,7 +725,7 @@ function useTransactionPreparer() {
|
|
|
344
725
|
},
|
|
345
726
|
[client]
|
|
346
727
|
);
|
|
347
|
-
return
|
|
728
|
+
return React4.useMemo(
|
|
348
729
|
() => ({
|
|
349
730
|
prepare,
|
|
350
731
|
ready
|
|
@@ -483,13 +864,13 @@ function useSharedQuery(key, queryFn, options = {}) {
|
|
|
483
864
|
refetchOnMount = "stale",
|
|
484
865
|
refetchIntervalMs = false,
|
|
485
866
|
select
|
|
486
|
-
} = options, queryFnRef =
|
|
867
|
+
} = options, queryFnRef = React4.useRef(queryFn);
|
|
487
868
|
queryFnRef.current = queryFn;
|
|
488
|
-
let stableQueryFn =
|
|
869
|
+
let stableQueryFn = React4.useCallback((signal) => queryFnRef.current(signal), []), subscribe = React4.useCallback(
|
|
489
870
|
(onChange) => key ? subscribeSharedQuery(key, onChange, cacheTimeMs) : () => {
|
|
490
871
|
},
|
|
491
872
|
[key, cacheTimeMs]
|
|
492
|
-
), emptySnapshot =
|
|
873
|
+
), emptySnapshot = React4.useMemo(
|
|
493
874
|
() => ({
|
|
494
875
|
data: void 0,
|
|
495
876
|
error: null,
|
|
@@ -498,8 +879,8 @@ function useSharedQuery(key, queryFn, options = {}) {
|
|
|
498
879
|
isFetching: false
|
|
499
880
|
}),
|
|
500
881
|
[]
|
|
501
|
-
), getSnapshot =
|
|
502
|
-
|
|
882
|
+
), getSnapshot = React4.useCallback(() => key ? getOrCreateEntry(key).snapshot : emptySnapshot, [key, emptySnapshot]), snapshot = React4.useSyncExternalStore(subscribe, getSnapshot, getSnapshot), selectedData = React4.useMemo(() => select ? select(snapshot.data) : snapshot.data, [snapshot.data, select]), prevSelectedRef = React4.useRef(selectedData), stableSelectedData = React4.useMemo(() => Object.is(prevSelectedRef.current, selectedData) ? prevSelectedRef.current : (prevSelectedRef.current = selectedData, selectedData), [selectedData]), fetchedKeyRef = React4.useRef(null);
|
|
883
|
+
React4.useEffect(() => {
|
|
503
884
|
if (!key || !enabled) {
|
|
504
885
|
fetchedKeyRef.current = null;
|
|
505
886
|
return;
|
|
@@ -513,7 +894,7 @@ function useSharedQuery(key, queryFn, options = {}) {
|
|
|
513
894
|
force: refetchOnMount === true
|
|
514
895
|
}).catch(() => {
|
|
515
896
|
})) : fetchedKeyRef.current = key;
|
|
516
|
-
}, [key, enabled, staleTimeMs, refetchOnMount, stableQueryFn]),
|
|
897
|
+
}, [key, enabled, staleTimeMs, refetchOnMount, stableQueryFn]), React4.useEffect(() => {
|
|
517
898
|
if (!key || !enabled || refetchIntervalMs === false) return;
|
|
518
899
|
let entry = getOrCreateEntry(key);
|
|
519
900
|
entry.queryFn = stableQueryFn;
|
|
@@ -523,7 +904,7 @@ function useSharedQuery(key, queryFn, options = {}) {
|
|
|
523
904
|
count <= 1 ? entry.intervalCounts.delete(refetchIntervalMs) : entry.intervalCounts.set(refetchIntervalMs, count - 1), startOrRestartInterval(key, entry);
|
|
524
905
|
};
|
|
525
906
|
}, [key, enabled, refetchIntervalMs, stableQueryFn]);
|
|
526
|
-
let refetch =
|
|
907
|
+
let refetch = React4.useCallback(
|
|
527
908
|
async (refetchOptions) => {
|
|
528
909
|
if (key)
|
|
529
910
|
return fetchSharedQuery(key, stableQueryFn, {
|
|
@@ -532,12 +913,12 @@ function useSharedQuery(key, queryFn, options = {}) {
|
|
|
532
913
|
});
|
|
533
914
|
},
|
|
534
915
|
[key, stableQueryFn]
|
|
535
|
-
), abort =
|
|
916
|
+
), abort = React4.useCallback(() => {
|
|
536
917
|
if (!key) return;
|
|
537
918
|
let entry = store.get(key);
|
|
538
919
|
entry?.abortController && entry.abortController.abort();
|
|
539
920
|
}, [key]);
|
|
540
|
-
return
|
|
921
|
+
return React4.useMemo(
|
|
541
922
|
() => ({
|
|
542
923
|
data: stableSelectedData,
|
|
543
924
|
error: snapshot.error,
|
|
@@ -616,13 +997,13 @@ function useWalletAssets(options = {}) {
|
|
|
616
997
|
refetchIntervalMs = false,
|
|
617
998
|
client: clientOverride,
|
|
618
999
|
select
|
|
619
|
-
} = options, {
|
|
620
|
-
if (!enabled || !
|
|
1000
|
+
} = options, { account, isConnected: isConnected2 } = useWallet(), address = account ? String(account) : null, { client: providerClient } = useSolanaClient(), rpcClient = clientOverride ?? providerClient, key = React4.useMemo(() => {
|
|
1001
|
+
if (!enabled || !isConnected2 || !address || !rpcClient) return null;
|
|
621
1002
|
let rpcUrl = rpcClient.urlOrMoniker instanceof URL ? rpcClient.urlOrMoniker.toString() : String(rpcClient.urlOrMoniker);
|
|
622
1003
|
return getWalletAssetsQueryKey(rpcUrl, address);
|
|
623
|
-
}, [enabled,
|
|
1004
|
+
}, [enabled, isConnected2, address, rpcClient]), queryFn = React4.useCallback(
|
|
624
1005
|
async (signal) => {
|
|
625
|
-
if (!
|
|
1006
|
+
if (!isConnected2 || !address || !rpcClient)
|
|
626
1007
|
return { lamports: 0n, tokenAccounts: [] };
|
|
627
1008
|
if (signal.aborted)
|
|
628
1009
|
throw new DOMException("Query aborted", "AbortError");
|
|
@@ -638,12 +1019,12 @@ function useWalletAssets(options = {}) {
|
|
|
638
1019
|
if (signal.aborted)
|
|
639
1020
|
throw new DOMException("Query aborted", "AbortError");
|
|
640
1021
|
let tokenAccounts = [];
|
|
641
|
-
for (let
|
|
642
|
-
let parsed = parseTokenAccount(
|
|
1022
|
+
for (let account2 of tokenAccountsResult.value) {
|
|
1023
|
+
let parsed = parseTokenAccount(account2, "token");
|
|
643
1024
|
parsed && tokenAccounts.push(parsed);
|
|
644
1025
|
}
|
|
645
|
-
for (let
|
|
646
|
-
let parsed = parseTokenAccount(
|
|
1026
|
+
for (let account2 of token2022AccountsResult.value) {
|
|
1027
|
+
let parsed = parseTokenAccount(account2, "token-2022");
|
|
647
1028
|
parsed && tokenAccounts.push(parsed);
|
|
648
1029
|
}
|
|
649
1030
|
return {
|
|
@@ -651,7 +1032,7 @@ function useWalletAssets(options = {}) {
|
|
|
651
1032
|
tokenAccounts
|
|
652
1033
|
};
|
|
653
1034
|
},
|
|
654
|
-
[
|
|
1035
|
+
[isConnected2, address, rpcClient]
|
|
655
1036
|
), { data, error, status, updatedAt, isFetching, refetch, abort } = useSharedQuery(
|
|
656
1037
|
key,
|
|
657
1038
|
queryFn,
|
|
@@ -664,7 +1045,7 @@ function useWalletAssets(options = {}) {
|
|
|
664
1045
|
select
|
|
665
1046
|
}
|
|
666
1047
|
), isLoading = status === "loading" || status === "idle";
|
|
667
|
-
return
|
|
1048
|
+
return React4.useMemo(
|
|
668
1049
|
() => ({
|
|
669
1050
|
data,
|
|
670
1051
|
isLoading,
|
|
@@ -684,7 +1065,7 @@ function getBalanceQueryKey(rpcUrl, address) {
|
|
|
684
1065
|
}
|
|
685
1066
|
var LAMPORTS_PER_SOL2 = 1000000000n;
|
|
686
1067
|
function formatTokenAccount(account) {
|
|
687
|
-
let formatted =
|
|
1068
|
+
let formatted = chunkBZ2VBJCZ_js.formatBigIntBalance(account.amount, account.decimals, {
|
|
688
1069
|
maxDecimals: Math.min(account.decimals, 6)
|
|
689
1070
|
});
|
|
690
1071
|
return {
|
|
@@ -728,13 +1109,13 @@ function useBalance(options = {}) {
|
|
|
728
1109
|
refetchIntervalMs: autoRefresh ? refreshInterval : false,
|
|
729
1110
|
client: clientOverride,
|
|
730
1111
|
select: selectBalance
|
|
731
|
-
}), lamports = data?.lamports ?? 0n, tokens = data?.tokens ?? [], solBalance =
|
|
1112
|
+
}), lamports = data?.lamports ?? 0n, tokens = data?.tokens ?? [], solBalance = React4.useMemo(() => Number(lamports) / Number(LAMPORTS_PER_SOL2), [lamports]), formattedSol = React4.useMemo(() => chunkBZ2VBJCZ_js.formatLamportsToSolSafe(lamports, { maxDecimals: 4, suffix: true }), [lamports]), visibleError = updatedAt ? null : error, refetch = React4.useCallback(
|
|
732
1113
|
async (opts) => {
|
|
733
1114
|
await sharedRefetch(opts);
|
|
734
1115
|
},
|
|
735
1116
|
[sharedRefetch]
|
|
736
1117
|
);
|
|
737
|
-
return
|
|
1118
|
+
return React4.useMemo(
|
|
738
1119
|
() => ({
|
|
739
1120
|
solBalance,
|
|
740
1121
|
lamports,
|
|
@@ -1109,7 +1490,7 @@ function useTransactions(options = {}) {
|
|
|
1109
1490
|
// 5 minutes
|
|
1110
1491
|
refetchOnMount = "stale",
|
|
1111
1492
|
client: clientOverride
|
|
1112
|
-
} = options, {
|
|
1493
|
+
} = options, { account, isConnected: isConnected2 } = useWallet(), address = React4.useMemo(() => account ? String(account) : null, [account]), { cluster } = useCluster(), { client: providerClient } = useSolanaClient(), connectorClient = useConnectorClient(), [paginatedTransactions, setPaginatedTransactions] = React4.useState([]), [isPaginationLoading, setIsPaginationLoading] = React4.useState(false), [hasMore, setHasMore] = React4.useState(true), beforeSignatureRef = React4.useRef(void 0), rpcClient = clientOverride ?? providerClient, connectorConfig = connectorClient?.getConfig(), imageProxy = connectorConfig?.imageProxy, programLabels = connectorConfig?.programLabels, parseTransaction = React4.useCallback(
|
|
1113
1494
|
(tx, walletAddress, sig, blockTime, slot, err, explorerUrl) => {
|
|
1114
1495
|
let { date, time } = formatDate(blockTime), baseInfo = {
|
|
1115
1496
|
signature: sig,
|
|
@@ -1160,15 +1541,15 @@ function useTransactions(options = {}) {
|
|
|
1160
1541
|
}
|
|
1161
1542
|
},
|
|
1162
1543
|
[programLabels]
|
|
1163
|
-
), key =
|
|
1164
|
-
if (!enabled || !
|
|
1544
|
+
), key = React4.useMemo(() => {
|
|
1545
|
+
if (!enabled || !isConnected2 || !address || !rpcClient || !cluster) return null;
|
|
1165
1546
|
let rpcUrl = rpcClient.urlOrMoniker instanceof URL ? rpcClient.urlOrMoniker.toString() : String(rpcClient.urlOrMoniker);
|
|
1166
1547
|
return getTransactionsQueryKey({ rpcUrl, address, clusterId: cluster.id, limit, fetchDetails });
|
|
1167
|
-
}, [enabled,
|
|
1168
|
-
|
|
1548
|
+
}, [enabled, isConnected2, address, rpcClient, cluster, limit, fetchDetails]);
|
|
1549
|
+
React4.useEffect(() => {
|
|
1169
1550
|
beforeSignatureRef.current = void 0, setPaginatedTransactions([]), setIsPaginationLoading(false), setHasMore(true);
|
|
1170
1551
|
}, [key]);
|
|
1171
|
-
let fetchAndEnrichTransactions =
|
|
1552
|
+
let fetchAndEnrichTransactions = React4.useCallback(
|
|
1172
1553
|
async (beforeSignature, currentCluster, signal) => {
|
|
1173
1554
|
if (!rpcClient || !address)
|
|
1174
1555
|
return { transactions: [], hasMore: false };
|
|
@@ -1197,7 +1578,7 @@ function useTransactions(options = {}) {
|
|
|
1197
1578
|
blockTimeNum,
|
|
1198
1579
|
Number(sig.slot),
|
|
1199
1580
|
sig.err,
|
|
1200
|
-
|
|
1581
|
+
chunkBZ2VBJCZ_js.getTransactionUrl(String(sig.signature), currentCluster)
|
|
1201
1582
|
);
|
|
1202
1583
|
});
|
|
1203
1584
|
} else
|
|
@@ -1212,7 +1593,7 @@ function useTransactions(options = {}) {
|
|
|
1212
1593
|
type: "unknown",
|
|
1213
1594
|
formattedDate: date,
|
|
1214
1595
|
formattedTime: time,
|
|
1215
|
-
explorerUrl:
|
|
1596
|
+
explorerUrl: chunkBZ2VBJCZ_js.getTransactionUrl(String(sig.signature), currentCluster)
|
|
1216
1597
|
};
|
|
1217
1598
|
});
|
|
1218
1599
|
let mintsToFetch = [
|
|
@@ -1226,7 +1607,7 @@ function useTransactions(options = {}) {
|
|
|
1226
1607
|
throwIfAborted(signal);
|
|
1227
1608
|
let tokenMetadata = await fetchTransactionTokenMetadata(mintsToFetch, {
|
|
1228
1609
|
signal,
|
|
1229
|
-
cluster:
|
|
1610
|
+
cluster: chunkBZ2VBJCZ_js.getClusterType(currentCluster)
|
|
1230
1611
|
});
|
|
1231
1612
|
tokenMetadata.size > 0 && (newTransactions = newTransactions.map((tx) => {
|
|
1232
1613
|
let enrichedTx = { ...tx };
|
|
@@ -1270,15 +1651,15 @@ function useTransactions(options = {}) {
|
|
|
1270
1651
|
};
|
|
1271
1652
|
},
|
|
1272
1653
|
[rpcClient, address, limit, fetchDetails, detailsConcurrency, parseTransaction, imageProxy]
|
|
1273
|
-
), queryFn =
|
|
1654
|
+
), queryFn = React4.useCallback(
|
|
1274
1655
|
async (signal) => {
|
|
1275
|
-
if (!
|
|
1656
|
+
if (!isConnected2 || !address || !rpcClient || !cluster)
|
|
1276
1657
|
return [];
|
|
1277
1658
|
throwIfAborted(signal);
|
|
1278
1659
|
let result = await fetchAndEnrichTransactions(void 0, cluster, signal);
|
|
1279
1660
|
return throwIfAborted(signal), result.transactions;
|
|
1280
1661
|
},
|
|
1281
|
-
[
|
|
1662
|
+
[isConnected2, address, rpcClient, cluster, fetchAndEnrichTransactions]
|
|
1282
1663
|
), {
|
|
1283
1664
|
data: initialTransactions,
|
|
1284
1665
|
error,
|
|
@@ -1293,10 +1674,10 @@ function useTransactions(options = {}) {
|
|
|
1293
1674
|
refetchOnMount,
|
|
1294
1675
|
refetchIntervalMs: autoRefresh ? refreshInterval : false
|
|
1295
1676
|
});
|
|
1296
|
-
|
|
1677
|
+
React4.useEffect(() => {
|
|
1297
1678
|
initialTransactions && (beforeSignatureRef.current = initialTransactions.length ? initialTransactions[initialTransactions.length - 1].signature : void 0, setHasMore(initialTransactions.length === limit), setPaginatedTransactions((prev) => prev.length ? [] : prev));
|
|
1298
1679
|
}, [initialTransactions, limit]);
|
|
1299
|
-
let loadMoreFn =
|
|
1680
|
+
let loadMoreFn = React4.useCallback(async () => {
|
|
1300
1681
|
if (!(!hasMore || isPaginationLoading || !cluster)) {
|
|
1301
1682
|
setIsPaginationLoading(true);
|
|
1302
1683
|
try {
|
|
@@ -1308,13 +1689,13 @@ function useTransactions(options = {}) {
|
|
|
1308
1689
|
setIsPaginationLoading(false);
|
|
1309
1690
|
}
|
|
1310
1691
|
}
|
|
1311
|
-
}, [hasMore, isPaginationLoading, cluster, fetchAndEnrichTransactions]), refetch =
|
|
1692
|
+
}, [hasMore, isPaginationLoading, cluster, fetchAndEnrichTransactions]), refetch = React4.useCallback(
|
|
1312
1693
|
async (opts) => {
|
|
1313
1694
|
beforeSignatureRef.current = void 0, setPaginatedTransactions([]), setHasMore(true), await sharedRefetch(opts);
|
|
1314
1695
|
},
|
|
1315
1696
|
[sharedRefetch]
|
|
1316
|
-
), transactions =
|
|
1317
|
-
return
|
|
1697
|
+
), transactions = React4.useMemo(() => [...initialTransactions ?? [], ...paginatedTransactions], [initialTransactions, paginatedTransactions]), isLoading = isInitialLoading || isPaginationLoading, visibleError = updatedAt ? null : error;
|
|
1698
|
+
return React4.useMemo(
|
|
1318
1699
|
() => ({
|
|
1319
1700
|
transactions,
|
|
1320
1701
|
isLoading,
|
|
@@ -1333,10 +1714,10 @@ function getTokensQueryKey(rpcUrl, address) {
|
|
|
1333
1714
|
}
|
|
1334
1715
|
var CACHE_MAX_SIZE = 500, PRICE_CACHE_TTL = 6e4, STALE_CLEANUP_INTERVAL = 12e4, COINGECKO_DEFAULT_MAX_RETRIES = 3, COINGECKO_DEFAULT_BASE_DELAY = 1e3, COINGECKO_DEFAULT_MAX_TIMEOUT = 3e4, COINGECKO_API_BASE_URL = "https://api.coingecko.com/api/v3", LRUCache = class {
|
|
1335
1716
|
constructor(maxSize, options) {
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1717
|
+
chunkSITQ4JWM_js.__publicField(this, "cache", /* @__PURE__ */ new Map());
|
|
1718
|
+
chunkSITQ4JWM_js.__publicField(this, "maxSize");
|
|
1719
|
+
chunkSITQ4JWM_js.__publicField(this, "getTtl");
|
|
1720
|
+
chunkSITQ4JWM_js.__publicField(this, "getTimestamp");
|
|
1340
1721
|
this.maxSize = maxSize, this.getTtl = options?.getTtl, this.getTimestamp = options?.getTimestamp;
|
|
1341
1722
|
}
|
|
1342
1723
|
get(key) {
|
|
@@ -1506,12 +1887,12 @@ async function fetchTokenMetadataHybrid(mints, coingeckoConfig, options) {
|
|
|
1506
1887
|
return didUpdatePrices && options?.onUpdate?.(), didUpdate;
|
|
1507
1888
|
}
|
|
1508
1889
|
function formatBalance(amount, decimals) {
|
|
1509
|
-
return
|
|
1890
|
+
return chunkBZ2VBJCZ_js.formatBigIntBalance(amount, decimals, {
|
|
1510
1891
|
maxDecimals: Math.min(decimals, 6)
|
|
1511
1892
|
});
|
|
1512
1893
|
}
|
|
1513
1894
|
function formatUsd(amount, decimals, usdPrice) {
|
|
1514
|
-
return
|
|
1895
|
+
return chunkBZ2VBJCZ_js.formatBigIntUsd(amount, decimals, usdPrice);
|
|
1515
1896
|
}
|
|
1516
1897
|
function selectTokens(assets, address) {
|
|
1517
1898
|
return {
|
|
@@ -1539,7 +1920,7 @@ function useTokens(options = {}) {
|
|
|
1539
1920
|
// 5 minutes
|
|
1540
1921
|
refetchOnMount = "stale",
|
|
1541
1922
|
client: clientOverride
|
|
1542
|
-
} = options, {
|
|
1923
|
+
} = options, { account, isConnected: isConnected2 } = useWallet(), address = React4.useMemo(() => account ? String(account) : null, [account]), { type: clusterType } = useCluster(), connectorConfig = useConnectorClient()?.getConfig(), imageProxy = connectorConfig?.imageProxy, coingeckoConfig = connectorConfig?.coingecko, selectFn = React4.useCallback(
|
|
1543
1924
|
(assets) => selectTokens(assets, address ?? ""),
|
|
1544
1925
|
[address]
|
|
1545
1926
|
), {
|
|
@@ -1557,7 +1938,7 @@ function useTokens(options = {}) {
|
|
|
1557
1938
|
refetchIntervalMs: autoRefresh ? refreshInterval : false,
|
|
1558
1939
|
client: clientOverride,
|
|
1559
1940
|
select: selectFn
|
|
1560
|
-
}), lamports = selection?.lamports ?? 0n, tokenAccounts = selection?.tokenAccounts ?? [], walletAddress = selection?.address ?? "", baseTokens =
|
|
1941
|
+
}), lamports = selection?.lamports ?? 0n, tokenAccounts = selection?.tokenAccounts ?? [], walletAddress = selection?.address ?? "", baseTokens = React4.useMemo(() => {
|
|
1561
1942
|
let result = [];
|
|
1562
1943
|
includeNativeSol && walletAddress && (includeZeroBalance || lamports > 0n) && result.push({
|
|
1563
1944
|
mint: NATIVE_SOL_MINT,
|
|
@@ -1568,25 +1949,25 @@ function useTokens(options = {}) {
|
|
|
1568
1949
|
isFrozen: false,
|
|
1569
1950
|
owner: walletAddress
|
|
1570
1951
|
});
|
|
1571
|
-
for (let
|
|
1572
|
-
!includeZeroBalance &&
|
|
1573
|
-
mint:
|
|
1574
|
-
tokenAccount:
|
|
1575
|
-
amount:
|
|
1576
|
-
decimals:
|
|
1577
|
-
formatted: formatBalance(
|
|
1578
|
-
isFrozen:
|
|
1579
|
-
owner:
|
|
1580
|
-
programId:
|
|
1952
|
+
for (let account2 of tokenAccounts)
|
|
1953
|
+
!includeZeroBalance && account2.amount === 0n || result.push({
|
|
1954
|
+
mint: account2.mint,
|
|
1955
|
+
tokenAccount: account2.pubkey,
|
|
1956
|
+
amount: account2.amount,
|
|
1957
|
+
decimals: account2.decimals,
|
|
1958
|
+
formatted: formatBalance(account2.amount, account2.decimals),
|
|
1959
|
+
isFrozen: account2.isFrozen,
|
|
1960
|
+
owner: account2.owner,
|
|
1961
|
+
programId: account2.programId
|
|
1581
1962
|
});
|
|
1582
1963
|
return result;
|
|
1583
|
-
}, [lamports, tokenAccounts, walletAddress, includeNativeSol, includeZeroBalance]), mints =
|
|
1964
|
+
}, [lamports, tokenAccounts, walletAddress, includeNativeSol, includeZeroBalance]), mints = React4.useMemo(() => {
|
|
1584
1965
|
let unique = /* @__PURE__ */ new Set();
|
|
1585
1966
|
for (let token of baseTokens)
|
|
1586
1967
|
unique.add(token.mint);
|
|
1587
1968
|
return [...unique].sort();
|
|
1588
|
-
}, [baseTokens]), mintsKey =
|
|
1589
|
-
|
|
1969
|
+
}, [baseTokens]), mintsKey = React4.useMemo(() => mints.join(","), [mints]), [metadataVersion, setMetadataVersion] = React4.useState(0);
|
|
1970
|
+
React4.useEffect(() => {
|
|
1590
1971
|
if (!fetchMetadata || !mintsKey) return;
|
|
1591
1972
|
let isMounted = true;
|
|
1592
1973
|
return (async () => {
|
|
@@ -1605,7 +1986,7 @@ function useTokens(options = {}) {
|
|
|
1605
1986
|
isMounted = false;
|
|
1606
1987
|
};
|
|
1607
1988
|
}, [mintsKey, fetchMetadata, coingeckoConfig, clusterType]);
|
|
1608
|
-
let tokens =
|
|
1989
|
+
let tokens = React4.useMemo(() => fetchMetadata ? baseTokens.map((token) => {
|
|
1609
1990
|
let meta = metadataCache.get(token.mint);
|
|
1610
1991
|
if (!meta) return token;
|
|
1611
1992
|
let usdPrice = (meta.coingeckoId ? priceCache.get(meta.coingeckoId) : void 0)?.price ?? meta.usdPrice;
|
|
@@ -1618,18 +1999,18 @@ function useTokens(options = {}) {
|
|
|
1618
1999
|
formattedUsd: usdPrice ? formatUsd(token.amount, token.decimals, usdPrice) : void 0
|
|
1619
2000
|
};
|
|
1620
2001
|
}).sort(sortByValueDesc) : baseTokens.slice().sort(sortByValueDesc), [baseTokens, fetchMetadata, imageProxy, metadataVersion]), totalAccounts = tokenAccounts.length + (includeNativeSol ? 1 : 0);
|
|
1621
|
-
|
|
1622
|
-
let wasConnectedRef =
|
|
1623
|
-
|
|
1624
|
-
wasConnectedRef.current && !
|
|
1625
|
-
}, [
|
|
1626
|
-
let visibleError = updatedAt ? null : error, refetch =
|
|
2002
|
+
React4.useEffect(() => (startCacheCleanup(), () => stopCacheCleanup()), []);
|
|
2003
|
+
let wasConnectedRef = React4.useRef(isConnected2);
|
|
2004
|
+
React4.useEffect(() => {
|
|
2005
|
+
wasConnectedRef.current && !isConnected2 && clearTokenCaches(), wasConnectedRef.current = isConnected2;
|
|
2006
|
+
}, [isConnected2]);
|
|
2007
|
+
let visibleError = updatedAt ? null : error, refetch = React4.useCallback(
|
|
1627
2008
|
async (opts) => {
|
|
1628
2009
|
await sharedRefetch(opts);
|
|
1629
2010
|
},
|
|
1630
2011
|
[sharedRefetch]
|
|
1631
2012
|
);
|
|
1632
|
-
return
|
|
2013
|
+
return React4.useMemo(
|
|
1633
2014
|
() => ({
|
|
1634
2015
|
tokens,
|
|
1635
2016
|
isLoading: isFetching,
|
|
@@ -1651,17 +2032,12 @@ function DisconnectElement({
|
|
|
1651
2032
|
onDisconnect,
|
|
1652
2033
|
render
|
|
1653
2034
|
}) {
|
|
1654
|
-
let {
|
|
1655
|
-
|
|
1656
|
-
try {
|
|
1657
|
-
await disconnect(), onDisconnect?.();
|
|
1658
|
-
} finally {
|
|
1659
|
-
setDisconnecting(false);
|
|
1660
|
-
}
|
|
2035
|
+
let { isConnecting: isConnecting2 } = useWallet(), { disconnect, isDisconnecting } = useDisconnectWallet(), handleDisconnect = async () => {
|
|
2036
|
+
await disconnect(), onDisconnect?.();
|
|
1661
2037
|
};
|
|
1662
2038
|
if (render)
|
|
1663
|
-
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: render({ disconnect: handleDisconnect, disconnecting }) });
|
|
1664
|
-
let isDisabled =
|
|
2039
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: render({ disconnect: handleDisconnect, disconnecting: isDisconnecting }) });
|
|
2040
|
+
let isDisabled = isConnecting2 || isDisconnecting, content = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
1665
2041
|
showIcon && (icon || showIcon && !icon && /* @__PURE__ */ jsxRuntime.jsxs(
|
|
1666
2042
|
"svg",
|
|
1667
2043
|
{
|
|
@@ -1693,7 +2069,7 @@ function DisconnectElement({
|
|
|
1693
2069
|
disabled: isDisabled,
|
|
1694
2070
|
"data-slot": "disconnect-element",
|
|
1695
2071
|
"data-variant": "button",
|
|
1696
|
-
"data-disconnecting":
|
|
2072
|
+
"data-disconnecting": isDisconnecting,
|
|
1697
2073
|
children: content
|
|
1698
2074
|
}
|
|
1699
2075
|
) : variant === "link" ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -1705,7 +2081,7 @@ function DisconnectElement({
|
|
|
1705
2081
|
disabled: isDisabled,
|
|
1706
2082
|
"data-slot": "disconnect-element",
|
|
1707
2083
|
"data-variant": "link",
|
|
1708
|
-
"data-disconnecting":
|
|
2084
|
+
"data-disconnecting": isDisconnecting,
|
|
1709
2085
|
children: content
|
|
1710
2086
|
}
|
|
1711
2087
|
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -1718,7 +2094,7 @@ function DisconnectElement({
|
|
|
1718
2094
|
disabled: isDisabled,
|
|
1719
2095
|
"data-slot": "disconnect-element",
|
|
1720
2096
|
"data-variant": "menuitem",
|
|
1721
|
-
"data-disconnecting":
|
|
2097
|
+
"data-disconnecting": isDisconnecting,
|
|
1722
2098
|
children: content
|
|
1723
2099
|
}
|
|
1724
2100
|
);
|
|
@@ -1733,8 +2109,16 @@ function AccountElement({
|
|
|
1733
2109
|
variant = "compact",
|
|
1734
2110
|
render
|
|
1735
2111
|
}) {
|
|
1736
|
-
let { address, formatted,
|
|
1737
|
-
|
|
2112
|
+
let { account, connectorId } = useWallet(), connectors = useWalletConnectors(), address = React4__default.default.useMemo(() => account ? String(account) : null, [account]), formatted = React4__default.default.useMemo(() => address ? chunkBZ2VBJCZ_js.formatAddress(address) : "", [address]), connector = React4__default.default.useMemo(() => connectorId ? connectors.find((c) => c.id === connectorId) ?? null : null, [connectors, connectorId]), walletName = connector?.name ?? null, walletIcon = connector?.icon ? connector.icon : null, [copied, setCopied] = React4__default.default.useState(false), copyTimeoutRef = React4__default.default.useRef(void 0), copy = React4__default.default.useCallback(async () => address ? (copyTimeoutRef.current && clearTimeout(copyTimeoutRef.current), await chunkBZ2VBJCZ_js.copyAddressToClipboard(address, {
|
|
2113
|
+
onSuccess: () => {
|
|
2114
|
+
setCopied(true), copyTimeoutRef.current = setTimeout(() => setCopied(false), 2e3);
|
|
2115
|
+
}
|
|
2116
|
+
})) : {
|
|
2117
|
+
success: false
|
|
2118
|
+
}, [address]);
|
|
2119
|
+
if (React4__default.default.useEffect(() => () => {
|
|
2120
|
+
copyTimeoutRef.current && clearTimeout(copyTimeoutRef.current);
|
|
2121
|
+
}, []), render)
|
|
1738
2122
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: render({ address, formatted, walletName, walletIcon, copy, copied }) });
|
|
1739
2123
|
if (!address) return null;
|
|
1740
2124
|
let displayAddress = showFullAddress ? address : formatted, handleCopy = async (e) => {
|
|
@@ -1895,7 +2279,7 @@ function ClusterElement({
|
|
|
1895
2279
|
labels = {},
|
|
1896
2280
|
render
|
|
1897
2281
|
}) {
|
|
1898
|
-
let { cluster, clusters, setCluster, isMainnet, isDevnet, isTestnet, isLocal } = useCluster(), [isOpen, setIsOpen] =
|
|
2282
|
+
let { cluster, clusters, setCluster, isMainnet, isDevnet, isTestnet, isLocal } = useCluster(), [isOpen, setIsOpen] = React4__default.default.useState(false);
|
|
1899
2283
|
if (render)
|
|
1900
2284
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: render({ cluster, clusters, setCluster, isMainnet, isDevnet, isTestnet, isLocal }) });
|
|
1901
2285
|
if (!cluster) return null;
|
|
@@ -2102,14 +2486,41 @@ function WalletListElement({
|
|
|
2102
2486
|
variant = "list",
|
|
2103
2487
|
showStatus = true,
|
|
2104
2488
|
onSelect,
|
|
2489
|
+
onConnect,
|
|
2105
2490
|
render,
|
|
2106
2491
|
renderWallet
|
|
2107
2492
|
}) {
|
|
2108
|
-
let
|
|
2109
|
-
|
|
2493
|
+
let connectors = useWalletConnectors(), { isConnecting: isConnectingGlobal } = useWallet(), { connect, isConnecting: isConnectingLocal } = useConnectWallet(), connecting = isConnectingGlobal || isConnectingLocal, wallets = React4__default.default.useMemo(
|
|
2494
|
+
() => connectors.map((c) => ({
|
|
2495
|
+
name: c.name,
|
|
2496
|
+
connectorId: c.id,
|
|
2497
|
+
icon: c.icon || void 0,
|
|
2498
|
+
installed: c.ready,
|
|
2499
|
+
connectable: c.ready
|
|
2500
|
+
})),
|
|
2501
|
+
[connectors]
|
|
2502
|
+
), installedWallets = wallets.filter((w) => w.installed), displayWallets = installedOnly ? installedWallets : wallets, handleSelect = async (walletName) => {
|
|
2503
|
+
let wallet = wallets.find((w) => w.name === walletName);
|
|
2504
|
+
if (!wallet) {
|
|
2505
|
+
let availableWalletNames = wallets.map((w) => w.name);
|
|
2506
|
+
console.warn(
|
|
2507
|
+
`[WalletListElement] Wallet not found for walletName: ${walletName}. Available wallets (${availableWalletNames.length}):`,
|
|
2508
|
+
availableWalletNames
|
|
2509
|
+
);
|
|
2510
|
+
return;
|
|
2511
|
+
}
|
|
2512
|
+
await connect(wallet.connectorId), onSelect?.(walletName), onConnect?.(wallet.connectorId);
|
|
2513
|
+
}, handleConnectById = async (connectorId) => {
|
|
2514
|
+
await connect(connectorId), onConnect?.(connectorId);
|
|
2110
2515
|
};
|
|
2111
2516
|
if (render)
|
|
2112
|
-
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: render({
|
|
2517
|
+
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: render({
|
|
2518
|
+
wallets,
|
|
2519
|
+
installedWallets,
|
|
2520
|
+
select: handleSelect,
|
|
2521
|
+
connectById: handleConnectById,
|
|
2522
|
+
connecting
|
|
2523
|
+
}) });
|
|
2113
2524
|
if (displayWallets.length === 0)
|
|
2114
2525
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
2115
2526
|
"div",
|
|
@@ -2167,28 +2578,33 @@ function WalletListElement({
|
|
|
2167
2578
|
className: `ck-wallet-list-block ck-wallet-list-block--grid ${className || ""}`,
|
|
2168
2579
|
"data-slot": "wallet-list-element",
|
|
2169
2580
|
"data-variant": "grid",
|
|
2170
|
-
children: displayWallets.map((wallet) =>
|
|
2171
|
-
wallet
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2581
|
+
children: displayWallets.map((wallet) => {
|
|
2582
|
+
let handleWalletConnect = () => handleConnectById(wallet.connectorId);
|
|
2583
|
+
return renderWallet ? /* @__PURE__ */ jsxRuntime.jsx(React4__default.default.Fragment, { children: renderWallet({
|
|
2584
|
+
wallet,
|
|
2585
|
+
select: handleWalletConnect,
|
|
2586
|
+
connect: handleWalletConnect,
|
|
2587
|
+
connecting
|
|
2588
|
+
}) }, wallet.name) : /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2589
|
+
"button",
|
|
2590
|
+
{
|
|
2591
|
+
type: "button",
|
|
2592
|
+
className: "ck-wallet-list-item ck-wallet-list-item--grid",
|
|
2593
|
+
onClick: handleWalletConnect,
|
|
2594
|
+
disabled: connecting || !wallet.connectable,
|
|
2595
|
+
"data-slot": "wallet-list-item",
|
|
2596
|
+
"data-wallet": wallet.name,
|
|
2597
|
+
"data-connector-id": wallet.connectorId,
|
|
2598
|
+
"data-installed": wallet.installed,
|
|
2599
|
+
children: [
|
|
2600
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "ck-wallet-list-item-icon", "data-slot": "wallet-list-item-icon", children: wallet.icon ? /* @__PURE__ */ jsxRuntime.jsx("img", { src: wallet.icon, alt: wallet.name }) : walletIcon }),
|
|
2601
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "ck-wallet-list-item-name", "data-slot": "wallet-list-item-name", children: wallet.name }),
|
|
2602
|
+
showStatus && !wallet.installed && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "ck-wallet-list-item-status", "data-slot": "wallet-list-item-status", children: "Not installed" })
|
|
2603
|
+
]
|
|
2604
|
+
},
|
|
2605
|
+
wallet.name
|
|
2606
|
+
);
|
|
2607
|
+
})
|
|
2192
2608
|
}
|
|
2193
2609
|
) : variant === "compact" ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
2194
2610
|
"div",
|
|
@@ -2196,27 +2612,32 @@ function WalletListElement({
|
|
|
2196
2612
|
className: `ck-wallet-list-block ck-wallet-list-block--compact ${className || ""}`,
|
|
2197
2613
|
"data-slot": "wallet-list-element",
|
|
2198
2614
|
"data-variant": "compact",
|
|
2199
|
-
children: displayWallets.map((wallet) =>
|
|
2200
|
-
wallet
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
2217
|
-
|
|
2218
|
-
|
|
2219
|
-
|
|
2615
|
+
children: displayWallets.map((wallet) => {
|
|
2616
|
+
let handleWalletConnect = () => handleConnectById(wallet.connectorId);
|
|
2617
|
+
return renderWallet ? /* @__PURE__ */ jsxRuntime.jsx(React4__default.default.Fragment, { children: renderWallet({
|
|
2618
|
+
wallet,
|
|
2619
|
+
select: handleWalletConnect,
|
|
2620
|
+
connect: handleWalletConnect,
|
|
2621
|
+
connecting
|
|
2622
|
+
}) }, wallet.name) : /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2623
|
+
"button",
|
|
2624
|
+
{
|
|
2625
|
+
type: "button",
|
|
2626
|
+
className: "ck-wallet-list-item ck-wallet-list-item--compact",
|
|
2627
|
+
onClick: handleWalletConnect,
|
|
2628
|
+
disabled: connecting || !wallet.connectable,
|
|
2629
|
+
"data-slot": "wallet-list-item",
|
|
2630
|
+
"data-wallet": wallet.name,
|
|
2631
|
+
"data-connector-id": wallet.connectorId,
|
|
2632
|
+
"data-installed": wallet.installed,
|
|
2633
|
+
children: [
|
|
2634
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "ck-wallet-list-item-icon", "data-slot": "wallet-list-item-icon", children: wallet.icon ? /* @__PURE__ */ jsxRuntime.jsx("img", { src: wallet.icon, alt: wallet.name }) : walletIcon }),
|
|
2635
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "ck-wallet-list-item-name", "data-slot": "wallet-list-item-name", children: wallet.name })
|
|
2636
|
+
]
|
|
2637
|
+
},
|
|
2638
|
+
wallet.name
|
|
2639
|
+
);
|
|
2640
|
+
})
|
|
2220
2641
|
}
|
|
2221
2642
|
) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
2222
2643
|
"div",
|
|
@@ -2224,54 +2645,59 @@ function WalletListElement({
|
|
|
2224
2645
|
className: `ck-wallet-list-block ck-wallet-list-block--list ${className || ""}`,
|
|
2225
2646
|
"data-slot": "wallet-list-element",
|
|
2226
2647
|
"data-variant": "list",
|
|
2227
|
-
children: displayWallets.map((wallet) =>
|
|
2228
|
-
wallet
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
|
|
2246
|
-
|
|
2648
|
+
children: displayWallets.map((wallet) => {
|
|
2649
|
+
let handleWalletConnect = () => handleConnectById(wallet.connectorId);
|
|
2650
|
+
return renderWallet ? /* @__PURE__ */ jsxRuntime.jsx(React4__default.default.Fragment, { children: renderWallet({
|
|
2651
|
+
wallet,
|
|
2652
|
+
select: handleWalletConnect,
|
|
2653
|
+
connect: handleWalletConnect,
|
|
2654
|
+
connecting
|
|
2655
|
+
}) }, wallet.name) : /* @__PURE__ */ jsxRuntime.jsxs(
|
|
2656
|
+
"button",
|
|
2657
|
+
{
|
|
2658
|
+
type: "button",
|
|
2659
|
+
className: "ck-wallet-list-item ck-wallet-list-item--list",
|
|
2660
|
+
onClick: handleWalletConnect,
|
|
2661
|
+
disabled: connecting || !wallet.connectable,
|
|
2662
|
+
"data-slot": "wallet-list-item",
|
|
2663
|
+
"data-wallet": wallet.name,
|
|
2664
|
+
"data-connector-id": wallet.connectorId,
|
|
2665
|
+
"data-installed": wallet.installed,
|
|
2666
|
+
children: [
|
|
2667
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "ck-wallet-list-item-icon", "data-slot": "wallet-list-item-icon", children: wallet.icon ? /* @__PURE__ */ jsxRuntime.jsx("img", { src: wallet.icon, alt: wallet.name }) : walletIcon }),
|
|
2668
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "ck-wallet-list-item-info", "data-slot": "wallet-list-item-info", children: [
|
|
2669
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "ck-wallet-list-item-name", "data-slot": "wallet-list-item-name", children: wallet.name }),
|
|
2670
|
+
showStatus && /* @__PURE__ */ jsxRuntime.jsx(
|
|
2671
|
+
"span",
|
|
2672
|
+
{
|
|
2673
|
+
className: "ck-wallet-list-item-status",
|
|
2674
|
+
"data-slot": "wallet-list-item-status",
|
|
2675
|
+
"data-installed": wallet.installed,
|
|
2676
|
+
children: wallet.installed ? "Detected" : "Not installed"
|
|
2677
|
+
}
|
|
2678
|
+
)
|
|
2679
|
+
] }),
|
|
2680
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
2681
|
+
"svg",
|
|
2247
2682
|
{
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
"
|
|
2251
|
-
|
|
2683
|
+
width: "16",
|
|
2684
|
+
height: "16",
|
|
2685
|
+
viewBox: "0 0 24 24",
|
|
2686
|
+
fill: "none",
|
|
2687
|
+
stroke: "currentColor",
|
|
2688
|
+
strokeWidth: "2",
|
|
2689
|
+
strokeLinecap: "round",
|
|
2690
|
+
strokeLinejoin: "round",
|
|
2691
|
+
className: "ck-wallet-list-item-arrow",
|
|
2692
|
+
"data-slot": "wallet-list-item-arrow",
|
|
2693
|
+
children: /* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "9 18 15 12 9 6" })
|
|
2252
2694
|
}
|
|
2253
2695
|
)
|
|
2254
|
-
]
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
height: "16",
|
|
2260
|
-
viewBox: "0 0 24 24",
|
|
2261
|
-
fill: "none",
|
|
2262
|
-
stroke: "currentColor",
|
|
2263
|
-
strokeWidth: "2",
|
|
2264
|
-
strokeLinecap: "round",
|
|
2265
|
-
strokeLinejoin: "round",
|
|
2266
|
-
className: "ck-wallet-list-item-arrow",
|
|
2267
|
-
"data-slot": "wallet-list-item-arrow",
|
|
2268
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("polyline", { points: "9 18 15 12 9 6" })
|
|
2269
|
-
}
|
|
2270
|
-
)
|
|
2271
|
-
]
|
|
2272
|
-
},
|
|
2273
|
-
wallet.name
|
|
2274
|
-
))
|
|
2696
|
+
]
|
|
2697
|
+
},
|
|
2698
|
+
wallet.name
|
|
2699
|
+
);
|
|
2700
|
+
})
|
|
2275
2701
|
}
|
|
2276
2702
|
);
|
|
2277
2703
|
}
|
|
@@ -2308,7 +2734,7 @@ function injectStyles() {
|
|
|
2308
2734
|
}
|
|
2309
2735
|
}
|
|
2310
2736
|
function SkeletonShine() {
|
|
2311
|
-
return
|
|
2737
|
+
return React4__default.default.useEffect(() => {
|
|
2312
2738
|
injectStyles();
|
|
2313
2739
|
}, []), /* @__PURE__ */ jsxRuntime.jsx("div", { className: "ck-skeleton-shine", "data-slot": "skeleton-shine" });
|
|
2314
2740
|
}
|
|
@@ -2846,6 +3272,7 @@ exports.AccountElement = AccountElement;
|
|
|
2846
3272
|
exports.AppProvider = AppProvider;
|
|
2847
3273
|
exports.BalanceElement = BalanceElement;
|
|
2848
3274
|
exports.ClusterElement = ClusterElement;
|
|
3275
|
+
exports.ConnectorErrorBoundary = ConnectorErrorBoundary;
|
|
2849
3276
|
exports.ConnectorProvider = ConnectorProvider;
|
|
2850
3277
|
exports.DisconnectElement = DisconnectElement;
|
|
2851
3278
|
exports.SkeletonShine = SkeletonShine;
|
|
@@ -2864,8 +3291,10 @@ exports.invalidateSharedQuery = invalidateSharedQuery;
|
|
|
2864
3291
|
exports.useAccount = useAccount;
|
|
2865
3292
|
exports.useBalance = useBalance;
|
|
2866
3293
|
exports.useCluster = useCluster;
|
|
3294
|
+
exports.useConnectWallet = useConnectWallet;
|
|
2867
3295
|
exports.useConnector = useConnector;
|
|
2868
3296
|
exports.useConnectorClient = useConnectorClient;
|
|
3297
|
+
exports.useDisconnectWallet = useDisconnectWallet;
|
|
2869
3298
|
exports.useGillSolanaClient = useGillSolanaClient;
|
|
2870
3299
|
exports.useGillTransactionSigner = useGillTransactionSigner;
|
|
2871
3300
|
exports.useKitTransactionSigner = useKitTransactionSigner;
|
|
@@ -2874,7 +3303,10 @@ exports.useTokens = useTokens;
|
|
|
2874
3303
|
exports.useTransactionPreparer = useTransactionPreparer;
|
|
2875
3304
|
exports.useTransactionSigner = useTransactionSigner;
|
|
2876
3305
|
exports.useTransactions = useTransactions;
|
|
3306
|
+
exports.useWallet = useWallet;
|
|
2877
3307
|
exports.useWalletConnectUri = useWalletConnectUri;
|
|
3308
|
+
exports.useWalletConnectors = useWalletConnectors;
|
|
2878
3309
|
exports.useWalletInfo = useWalletInfo;
|
|
2879
|
-
|
|
2880
|
-
//# sourceMappingURL=chunk-
|
|
3310
|
+
exports.withErrorBoundary = withErrorBoundary;
|
|
3311
|
+
//# sourceMappingURL=chunk-4Z2F6ERB.js.map
|
|
3312
|
+
//# sourceMappingURL=chunk-4Z2F6ERB.js.map
|