@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,10 +1,284 @@
|
|
|
1
|
-
import { installPolyfills,
|
|
2
|
-
import { createLogger, __publicField, createSolanaClient, NetworkError, prepareTransaction } from './chunk-
|
|
3
|
-
import
|
|
4
|
-
import { jsx,
|
|
1
|
+
import { installPolyfills, isMainnetCluster, isDevnetCluster, isTestnetCluster, isLocalCluster, getClusterExplorerUrl, getClusterType, formatAddress, copyAddressToClipboard, createConnectorId, createTransactionSigner, createKitTransactionSigner, formatLamportsToSolSafe, getTransactionUrl, ConnectorClient, formatBigIntBalance, formatBigIntUsd } from './chunk-IDTUFDNB.mjs';
|
|
2
|
+
import { createLogger, __publicField, WalletErrorType, createSolanaClient, NetworkError, prepareTransaction, isConnectorError } from './chunk-ZZTY3O4N.mjs';
|
|
3
|
+
import React4, { createContext, Component, useTransition, useState, useCallback, useMemo, useRef, useEffect, useContext, useSyncExternalStore } from 'react';
|
|
4
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
5
5
|
import { address } from '@solana/addresses';
|
|
6
6
|
import { signature } from '@solana/keys';
|
|
7
7
|
|
|
8
|
+
var logger = createLogger("ErrorBoundary");
|
|
9
|
+
var ErrorLogger = class {
|
|
10
|
+
static log(error, errorInfo, context) {
|
|
11
|
+
if (process.env.NODE_ENV === "development" && logger.error(error.message, {
|
|
12
|
+
error,
|
|
13
|
+
errorInfo,
|
|
14
|
+
context
|
|
15
|
+
}), process.env.NODE_ENV === "production" && typeof window < "u")
|
|
16
|
+
try {
|
|
17
|
+
let gtag = window.gtag;
|
|
18
|
+
typeof gtag == "function" && gtag("event", "exception", {
|
|
19
|
+
description: error.message,
|
|
20
|
+
fatal: false,
|
|
21
|
+
custom_map: { error_type: "wallet_error", ...context }
|
|
22
|
+
});
|
|
23
|
+
} catch {
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
function classifyError(error) {
|
|
28
|
+
if (isConnectorError(error)) {
|
|
29
|
+
let typeMapping = {
|
|
30
|
+
WALLET_NOT_CONNECTED: WalletErrorType.CONNECTION_FAILED,
|
|
31
|
+
WALLET_NOT_FOUND: WalletErrorType.WALLET_NOT_FOUND,
|
|
32
|
+
CONNECTION_FAILED: WalletErrorType.CONNECTION_FAILED,
|
|
33
|
+
USER_REJECTED: WalletErrorType.USER_REJECTED,
|
|
34
|
+
RPC_ERROR: WalletErrorType.NETWORK_ERROR,
|
|
35
|
+
NETWORK_TIMEOUT: WalletErrorType.NETWORK_ERROR,
|
|
36
|
+
SIGNING_FAILED: WalletErrorType.TRANSACTION_FAILED,
|
|
37
|
+
SEND_FAILED: WalletErrorType.TRANSACTION_FAILED
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
...error,
|
|
41
|
+
type: typeMapping[error.code] || WalletErrorType.UNKNOWN_ERROR,
|
|
42
|
+
recoverable: error.recoverable,
|
|
43
|
+
context: error.context
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
let walletError = error;
|
|
47
|
+
if (walletError.type) return walletError;
|
|
48
|
+
let type = WalletErrorType.UNKNOWN_ERROR, recoverable = false;
|
|
49
|
+
return error.message.includes("User rejected") || error.message.includes("User denied") ? (type = WalletErrorType.USER_REJECTED, recoverable = true) : error.message.includes("Insufficient funds") ? (type = WalletErrorType.INSUFFICIENT_FUNDS, recoverable = false) : error.message.includes("Network") || error.message.includes("fetch") ? (type = WalletErrorType.NETWORK_ERROR, recoverable = true) : error.message.includes("Wallet not found") || error.message.includes("not installed") ? (type = WalletErrorType.WALLET_NOT_FOUND, recoverable = true) : (error.message.includes("Failed to connect") || error.message.includes("Connection")) && (type = WalletErrorType.CONNECTION_FAILED, recoverable = true), {
|
|
50
|
+
...error,
|
|
51
|
+
type,
|
|
52
|
+
recoverable,
|
|
53
|
+
context: { originalMessage: error.message }
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
var ConnectorErrorBoundary = class extends Component {
|
|
57
|
+
constructor(props) {
|
|
58
|
+
super(props);
|
|
59
|
+
__publicField(this, "retryTimeouts", /* @__PURE__ */ new Set());
|
|
60
|
+
__publicField(this, "retry", () => {
|
|
61
|
+
let { maxRetries = 3 } = this.props;
|
|
62
|
+
this.state.retryCount >= maxRetries || this.setState((prevState) => ({
|
|
63
|
+
hasError: false,
|
|
64
|
+
error: null,
|
|
65
|
+
errorInfo: null,
|
|
66
|
+
retryCount: prevState.retryCount + 1
|
|
67
|
+
}));
|
|
68
|
+
});
|
|
69
|
+
this.state = {
|
|
70
|
+
hasError: false,
|
|
71
|
+
error: null,
|
|
72
|
+
errorInfo: null,
|
|
73
|
+
errorId: "",
|
|
74
|
+
retryCount: 0
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
static getDerivedStateFromError(error) {
|
|
78
|
+
return {
|
|
79
|
+
hasError: true,
|
|
80
|
+
error,
|
|
81
|
+
errorId: `error_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
componentDidCatch(error, errorInfo) {
|
|
85
|
+
this.setState({ errorInfo }), ErrorLogger.log(error, errorInfo, {
|
|
86
|
+
retryCount: this.state.retryCount,
|
|
87
|
+
errorId: this.state.errorId,
|
|
88
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
89
|
+
}), this.props.onError?.(error, errorInfo);
|
|
90
|
+
}
|
|
91
|
+
componentWillUnmount() {
|
|
92
|
+
this.retryTimeouts.forEach((timeout) => clearTimeout(timeout));
|
|
93
|
+
}
|
|
94
|
+
render() {
|
|
95
|
+
if (this.state.hasError && this.state.error) {
|
|
96
|
+
let walletError = classifyError(this.state.error);
|
|
97
|
+
return this.props.fallback ? this.props.fallback(walletError, this.retry) : /* @__PURE__ */ jsx(DefaultErrorFallback, { error: walletError, onRetry: this.retry });
|
|
98
|
+
}
|
|
99
|
+
return this.props.children;
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
function DefaultErrorFallback({ error, onRetry }) {
|
|
103
|
+
let [isPending, startTransition] = useTransition(), [isRetrying, setIsRetrying] = useState(false), handleRetry = useCallback(() => {
|
|
104
|
+
setIsRetrying(true), startTransition(() => {
|
|
105
|
+
setTimeout(() => {
|
|
106
|
+
onRetry(), setIsRetrying(false);
|
|
107
|
+
}, 500);
|
|
108
|
+
});
|
|
109
|
+
}, [onRetry]), { title, message, actionText, showRetry } = useMemo(() => {
|
|
110
|
+
switch (error.type) {
|
|
111
|
+
case WalletErrorType.USER_REJECTED:
|
|
112
|
+
return {
|
|
113
|
+
title: "Transaction Cancelled",
|
|
114
|
+
message: "You cancelled the transaction. No problem!",
|
|
115
|
+
actionText: "Try Again",
|
|
116
|
+
showRetry: true
|
|
117
|
+
};
|
|
118
|
+
case WalletErrorType.WALLET_NOT_FOUND:
|
|
119
|
+
return {
|
|
120
|
+
title: "Wallet Not Found",
|
|
121
|
+
message: "Please install a supported Solana wallet to continue.",
|
|
122
|
+
actionText: "Check Wallets",
|
|
123
|
+
showRetry: true
|
|
124
|
+
};
|
|
125
|
+
case WalletErrorType.NETWORK_ERROR:
|
|
126
|
+
return {
|
|
127
|
+
title: "Network Error",
|
|
128
|
+
message: "Having trouble connecting. Please check your internet connection.",
|
|
129
|
+
actionText: "Retry",
|
|
130
|
+
showRetry: true
|
|
131
|
+
};
|
|
132
|
+
case WalletErrorType.INSUFFICIENT_FUNDS:
|
|
133
|
+
return {
|
|
134
|
+
title: "Insufficient Funds",
|
|
135
|
+
message: "You don't have enough SOL for this transaction.",
|
|
136
|
+
actionText: "Add Funds",
|
|
137
|
+
showRetry: false
|
|
138
|
+
};
|
|
139
|
+
default:
|
|
140
|
+
return {
|
|
141
|
+
title: "Something went wrong",
|
|
142
|
+
message: "An unexpected error occurred. Please try again.",
|
|
143
|
+
actionText: "Retry",
|
|
144
|
+
showRetry: error.recoverable
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}, [error.type, error.recoverable]);
|
|
148
|
+
return /* @__PURE__ */ jsxs(
|
|
149
|
+
"div",
|
|
150
|
+
{
|
|
151
|
+
style: {
|
|
152
|
+
display: "flex",
|
|
153
|
+
flexDirection: "column",
|
|
154
|
+
alignItems: "center",
|
|
155
|
+
justifyContent: "center",
|
|
156
|
+
padding: "2rem",
|
|
157
|
+
textAlign: "center",
|
|
158
|
+
borderRadius: "12px",
|
|
159
|
+
border: "1px solid #e5e7eb",
|
|
160
|
+
backgroundColor: "#fafafa",
|
|
161
|
+
maxWidth: "400px",
|
|
162
|
+
margin: "0 auto"
|
|
163
|
+
},
|
|
164
|
+
children: [
|
|
165
|
+
/* @__PURE__ */ jsx(
|
|
166
|
+
"div",
|
|
167
|
+
{
|
|
168
|
+
style: {
|
|
169
|
+
width: "48px",
|
|
170
|
+
height: "48px",
|
|
171
|
+
borderRadius: "50%",
|
|
172
|
+
backgroundColor: "#fee2e2",
|
|
173
|
+
display: "flex",
|
|
174
|
+
alignItems: "center",
|
|
175
|
+
justifyContent: "center",
|
|
176
|
+
marginBottom: "1rem"
|
|
177
|
+
},
|
|
178
|
+
children: /* @__PURE__ */ jsx("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "#dc2626", children: /* @__PURE__ */ 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" }) })
|
|
179
|
+
}
|
|
180
|
+
),
|
|
181
|
+
/* @__PURE__ */ jsx(
|
|
182
|
+
"h3",
|
|
183
|
+
{
|
|
184
|
+
style: {
|
|
185
|
+
margin: "0 0 0.5rem 0",
|
|
186
|
+
fontSize: "1.125rem",
|
|
187
|
+
fontWeight: "600",
|
|
188
|
+
color: "#111827"
|
|
189
|
+
},
|
|
190
|
+
children: title
|
|
191
|
+
}
|
|
192
|
+
),
|
|
193
|
+
/* @__PURE__ */ jsx(
|
|
194
|
+
"p",
|
|
195
|
+
{
|
|
196
|
+
style: {
|
|
197
|
+
margin: "0 0 1.5rem 0",
|
|
198
|
+
fontSize: "0.875rem",
|
|
199
|
+
color: "#6b7280",
|
|
200
|
+
lineHeight: "1.5"
|
|
201
|
+
},
|
|
202
|
+
children: message
|
|
203
|
+
}
|
|
204
|
+
),
|
|
205
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: "0.75rem", flexWrap: "wrap" }, children: [
|
|
206
|
+
showRetry && /* @__PURE__ */ jsx(
|
|
207
|
+
"button",
|
|
208
|
+
{
|
|
209
|
+
onClick: handleRetry,
|
|
210
|
+
disabled: isPending || isRetrying,
|
|
211
|
+
style: {
|
|
212
|
+
padding: "0.5rem 1rem",
|
|
213
|
+
backgroundColor: "#3b82f6",
|
|
214
|
+
color: "white",
|
|
215
|
+
border: "none",
|
|
216
|
+
borderRadius: "6px",
|
|
217
|
+
fontSize: "0.875rem",
|
|
218
|
+
fontWeight: "500",
|
|
219
|
+
cursor: isPending || isRetrying ? "wait" : "pointer",
|
|
220
|
+
opacity: isPending || isRetrying ? 0.7 : 1,
|
|
221
|
+
transition: "all 0.2s"
|
|
222
|
+
},
|
|
223
|
+
children: isRetrying ? "Retrying..." : actionText
|
|
224
|
+
}
|
|
225
|
+
),
|
|
226
|
+
/* @__PURE__ */ jsx(
|
|
227
|
+
"button",
|
|
228
|
+
{
|
|
229
|
+
onClick: () => window.location.reload(),
|
|
230
|
+
style: {
|
|
231
|
+
padding: "0.5rem 1rem",
|
|
232
|
+
backgroundColor: "transparent",
|
|
233
|
+
color: "#6b7280",
|
|
234
|
+
border: "1px solid #d1d5db",
|
|
235
|
+
borderRadius: "6px",
|
|
236
|
+
fontSize: "0.875rem",
|
|
237
|
+
fontWeight: "500",
|
|
238
|
+
cursor: "pointer",
|
|
239
|
+
transition: "all 0.2s"
|
|
240
|
+
},
|
|
241
|
+
children: "Refresh Page"
|
|
242
|
+
}
|
|
243
|
+
)
|
|
244
|
+
] }),
|
|
245
|
+
process.env.NODE_ENV === "development" && /* @__PURE__ */ jsxs(
|
|
246
|
+
"details",
|
|
247
|
+
{
|
|
248
|
+
style: {
|
|
249
|
+
marginTop: "1rem",
|
|
250
|
+
fontSize: "0.75rem",
|
|
251
|
+
color: "#6b7280",
|
|
252
|
+
width: "100%"
|
|
253
|
+
},
|
|
254
|
+
children: [
|
|
255
|
+
/* @__PURE__ */ jsx("summary", { style: { cursor: "pointer", marginBottom: "0.5rem" }, children: "Error Details" }),
|
|
256
|
+
/* @__PURE__ */ jsx(
|
|
257
|
+
"pre",
|
|
258
|
+
{
|
|
259
|
+
style: {
|
|
260
|
+
whiteSpace: "pre-wrap",
|
|
261
|
+
wordBreak: "break-all",
|
|
262
|
+
backgroundColor: "#f3f4f6",
|
|
263
|
+
padding: "0.5rem",
|
|
264
|
+
borderRadius: "4px",
|
|
265
|
+
overflow: "auto",
|
|
266
|
+
maxHeight: "200px"
|
|
267
|
+
},
|
|
268
|
+
children: error.message
|
|
269
|
+
}
|
|
270
|
+
)
|
|
271
|
+
]
|
|
272
|
+
}
|
|
273
|
+
)
|
|
274
|
+
]
|
|
275
|
+
}
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
function withErrorBoundary(Component2, errorBoundaryProps) {
|
|
279
|
+
let WrappedComponent = (props) => /* @__PURE__ */ jsx(ConnectorErrorBoundary, { ...errorBoundaryProps, children: /* @__PURE__ */ jsx(Component2, { ...props }) });
|
|
280
|
+
return WrappedComponent.displayName = `withErrorBoundary(${Component2.displayName || Component2.name})`, WrappedComponent;
|
|
281
|
+
}
|
|
8
282
|
var WalletConnectContext = createContext(null);
|
|
9
283
|
function WalletConnectProvider({ children }) {
|
|
10
284
|
let [uri, setUriState] = useState(null), isMountedRef = useRef(false), pendingUriRef = useRef(null);
|
|
@@ -32,7 +306,7 @@ function useWalletConnectUri() {
|
|
|
32
306
|
}
|
|
33
307
|
};
|
|
34
308
|
}
|
|
35
|
-
var
|
|
309
|
+
var logger2 = createLogger("ConnectorProvider");
|
|
36
310
|
installPolyfills();
|
|
37
311
|
var ConnectorContext = createContext(null);
|
|
38
312
|
ConnectorContext.displayName = "ConnectorContext";
|
|
@@ -41,13 +315,13 @@ function ConnectorProviderInternal({
|
|
|
41
315
|
config,
|
|
42
316
|
mobile
|
|
43
317
|
}) {
|
|
44
|
-
let clientRef = useRef(null), client =
|
|
318
|
+
let clientRef = useRef(null), client = React4.useCallback(() => {
|
|
45
319
|
if (!clientRef.current)
|
|
46
320
|
try {
|
|
47
|
-
clientRef.current = new ConnectorClient(config), typeof window < "u" && (window.__connectorClient = clientRef.current), config?.debug &&
|
|
321
|
+
clientRef.current = new ConnectorClient(config), typeof window < "u" && (window.__connectorClient = clientRef.current), config?.debug && logger2.info("Client initialized successfully");
|
|
48
322
|
} catch (error) {
|
|
49
323
|
let err = error;
|
|
50
|
-
|
|
324
|
+
logger2.error("Failed to initialize client", { error: err });
|
|
51
325
|
let extendedConfig = config;
|
|
52
326
|
return extendedConfig?.errorBoundary?.onError && extendedConfig.errorBoundary.onError(err, {
|
|
53
327
|
componentStack: "client-initialization",
|
|
@@ -56,7 +330,7 @@ function ConnectorProviderInternal({
|
|
|
56
330
|
}
|
|
57
331
|
return clientRef.current;
|
|
58
332
|
}, [config])();
|
|
59
|
-
return
|
|
333
|
+
return React4.useEffect(() => {
|
|
60
334
|
let currentClient = clientRef.current;
|
|
61
335
|
if (currentClient) {
|
|
62
336
|
let privateClient = currentClient;
|
|
@@ -65,7 +339,7 @@ function ConnectorProviderInternal({
|
|
|
65
339
|
return () => {
|
|
66
340
|
typeof window < "u" && (window.__connectorClient = void 0), currentClient && typeof currentClient.destroy == "function" && currentClient.destroy();
|
|
67
341
|
};
|
|
68
|
-
}, []),
|
|
342
|
+
}, []), React4.useEffect(() => {
|
|
69
343
|
if (!mobile) return;
|
|
70
344
|
let cancelled = false;
|
|
71
345
|
return (async () => {
|
|
@@ -120,25 +394,45 @@ function useConnector() {
|
|
|
120
394
|
"useConnector must be used within ConnectorProvider. Wrap your app with <ConnectorProvider> or <UnifiedProvider> to use connector hooks."
|
|
121
395
|
);
|
|
122
396
|
let { uri: walletConnectUri, clearUri: clearWalletConnectUri } = useWalletConnectUri(), state = useSyncExternalStore(
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
397
|
+
React4.useCallback((cb) => client.subscribe(cb), [client]),
|
|
398
|
+
React4.useCallback(() => client.getSnapshot(), [client]),
|
|
399
|
+
React4.useCallback(() => client.getSnapshot(), [client])
|
|
126
400
|
), methods = useMemo(
|
|
127
401
|
() => ({
|
|
402
|
+
// Legacy (kept for backwards compatibility)
|
|
128
403
|
select: client.select.bind(client),
|
|
129
404
|
disconnect: client.disconnect.bind(client),
|
|
130
|
-
selectAccount: client.selectAccount.bind(client)
|
|
405
|
+
selectAccount: client.selectAccount.bind(client),
|
|
406
|
+
// vNext
|
|
407
|
+
connectWallet: client.connectWallet.bind(client),
|
|
408
|
+
disconnectWallet: client.disconnectWallet.bind(client)
|
|
131
409
|
}),
|
|
132
410
|
[client]
|
|
133
|
-
)
|
|
411
|
+
), vNextFields = useMemo(() => {
|
|
412
|
+
let walletStatus = state.wallet, isConnected2 = walletStatus.status === "connected", isConnecting2 = walletStatus.status === "connecting", isError = walletStatus.status === "error", connectorId = null, account = null, sessionAccounts = [], walletError = null;
|
|
413
|
+
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);
|
|
414
|
+
let connector = connectorId ? state.connectors.find((c) => c.id === connectorId) ?? null : null;
|
|
415
|
+
return {
|
|
416
|
+
walletStatus,
|
|
417
|
+
isConnected: isConnected2,
|
|
418
|
+
isConnecting: isConnecting2,
|
|
419
|
+
isError,
|
|
420
|
+
walletError,
|
|
421
|
+
account,
|
|
422
|
+
sessionAccounts,
|
|
423
|
+
connectorId,
|
|
424
|
+
connector
|
|
425
|
+
};
|
|
426
|
+
}, [state.wallet, state.connectors]);
|
|
134
427
|
return useMemo(
|
|
135
428
|
() => ({
|
|
136
429
|
...state,
|
|
137
430
|
...methods,
|
|
431
|
+
...vNextFields,
|
|
138
432
|
walletConnectUri,
|
|
139
433
|
clearWalletConnectUri
|
|
140
434
|
}),
|
|
141
|
-
[state, methods, walletConnectUri, clearWalletConnectUri]
|
|
435
|
+
[state, methods, vNextFields, walletConnectUri, clearWalletConnectUri]
|
|
142
436
|
);
|
|
143
437
|
}
|
|
144
438
|
function useConnectorClient() {
|
|
@@ -170,6 +464,92 @@ function AppProvider(props) {
|
|
|
170
464
|
return props.connectorConfig?.walletConnect?.enabled ? /* @__PURE__ */ jsx(WalletConnectProvider, { children: /* @__PURE__ */ jsx(AppProviderInner, { ...props }) }) : /* @__PURE__ */ jsx(AppProviderInner, { ...props });
|
|
171
465
|
}
|
|
172
466
|
var UnifiedProvider = AppProvider;
|
|
467
|
+
function useWallet() {
|
|
468
|
+
let client = useContext(ConnectorContext);
|
|
469
|
+
if (!client)
|
|
470
|
+
throw new Error(
|
|
471
|
+
"useWallet must be used within ConnectorProvider. Wrap your app with <ConnectorProvider> or <UnifiedProvider> to use wallet hooks."
|
|
472
|
+
);
|
|
473
|
+
let walletStatus = useSyncExternalStore(
|
|
474
|
+
useCallback((cb) => client.subscribe(cb), [client]),
|
|
475
|
+
useCallback(() => client.getSnapshot().wallet, [client]),
|
|
476
|
+
useCallback(() => client.getSnapshot().wallet, [client])
|
|
477
|
+
);
|
|
478
|
+
return useMemo(() => {
|
|
479
|
+
let status = walletStatus.status, isConnected2 = status === "connected", isConnecting2 = status === "connecting", isError = status === "error", connectorId = null, account = null, accounts = [], session = null, error = null;
|
|
480
|
+
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), {
|
|
481
|
+
status,
|
|
482
|
+
walletStatus,
|
|
483
|
+
isConnected: isConnected2,
|
|
484
|
+
isConnecting: isConnecting2,
|
|
485
|
+
isError,
|
|
486
|
+
error,
|
|
487
|
+
connectorId,
|
|
488
|
+
account,
|
|
489
|
+
accounts,
|
|
490
|
+
session
|
|
491
|
+
};
|
|
492
|
+
}, [walletStatus]);
|
|
493
|
+
}
|
|
494
|
+
function useWalletConnectors() {
|
|
495
|
+
let client = useContext(ConnectorContext);
|
|
496
|
+
if (!client)
|
|
497
|
+
throw new Error(
|
|
498
|
+
"useWalletConnectors must be used within ConnectorProvider. Wrap your app with <ConnectorProvider> or <UnifiedProvider> to use wallet hooks."
|
|
499
|
+
);
|
|
500
|
+
return useSyncExternalStore(
|
|
501
|
+
useCallback((cb) => client.subscribe(cb), [client]),
|
|
502
|
+
useCallback(() => client.getSnapshot().connectors, [client]),
|
|
503
|
+
useCallback(() => client.getSnapshot().connectors, [client])
|
|
504
|
+
);
|
|
505
|
+
}
|
|
506
|
+
function useConnectWallet() {
|
|
507
|
+
let client = useContext(ConnectorContext), [isConnecting2, setIsConnecting] = useState(false), [error, setError] = useState(null);
|
|
508
|
+
if (!client)
|
|
509
|
+
throw new Error(
|
|
510
|
+
"useConnectWallet must be used within ConnectorProvider. Wrap your app with <ConnectorProvider> or <UnifiedProvider> to use wallet hooks."
|
|
511
|
+
);
|
|
512
|
+
let connect = useCallback(
|
|
513
|
+
async (connectorId, options) => {
|
|
514
|
+
setIsConnecting(true), setError(null);
|
|
515
|
+
try {
|
|
516
|
+
await client.connectWallet(connectorId, options);
|
|
517
|
+
} catch (e) {
|
|
518
|
+
let connectError = e instanceof Error ? e : new Error(String(e));
|
|
519
|
+
throw setError(connectError), connectError;
|
|
520
|
+
} finally {
|
|
521
|
+
setIsConnecting(false);
|
|
522
|
+
}
|
|
523
|
+
},
|
|
524
|
+
[client]
|
|
525
|
+
), resetError = useCallback(() => {
|
|
526
|
+
setError(null);
|
|
527
|
+
}, []);
|
|
528
|
+
return {
|
|
529
|
+
connect,
|
|
530
|
+
isConnecting: isConnecting2,
|
|
531
|
+
error,
|
|
532
|
+
resetError
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
function useDisconnectWallet() {
|
|
536
|
+
let client = useContext(ConnectorContext), [isDisconnecting, setIsDisconnecting] = useState(false);
|
|
537
|
+
if (!client)
|
|
538
|
+
throw new Error(
|
|
539
|
+
"useDisconnectWallet must be used within ConnectorProvider. Wrap your app with <ConnectorProvider> or <UnifiedProvider> to use wallet hooks."
|
|
540
|
+
);
|
|
541
|
+
return {
|
|
542
|
+
disconnect: useCallback(async () => {
|
|
543
|
+
setIsDisconnecting(true);
|
|
544
|
+
try {
|
|
545
|
+
await client.disconnectWallet();
|
|
546
|
+
} finally {
|
|
547
|
+
setIsDisconnecting(false);
|
|
548
|
+
}
|
|
549
|
+
}, [client]),
|
|
550
|
+
isDisconnecting
|
|
551
|
+
};
|
|
552
|
+
}
|
|
173
553
|
function useCluster() {
|
|
174
554
|
let { cluster, clusters } = useConnector(), client = useConnectorClient();
|
|
175
555
|
if (!client)
|
|
@@ -196,7 +576,7 @@ function useCluster() {
|
|
|
196
576
|
}, [cluster, clusters, setCluster]);
|
|
197
577
|
}
|
|
198
578
|
function useAccount() {
|
|
199
|
-
let { selectedAccount, accounts, connected, selectAccount } = useConnector(), [copied, setCopied] = useState(false), copyTimeoutRef =
|
|
579
|
+
let { selectedAccount, accounts, connected, selectAccount } = useConnector(), [copied, setCopied] = useState(false), copyTimeoutRef = React4.useRef(void 0), account = useMemo(
|
|
200
580
|
() => accounts.find((a) => a.address === selectedAccount) ?? null,
|
|
201
581
|
[accounts, selectedAccount]
|
|
202
582
|
), formatted = useMemo(() => selectedAccount ? formatAddress(selectedAccount) : "", [selectedAccount]), copy = useCallback(async () => selectedAccount ? (copyTimeoutRef.current && clearTimeout(copyTimeoutRef.current), await copyAddressToClipboard(selectedAccount, {
|
|
@@ -208,7 +588,7 @@ function useAccount() {
|
|
|
208
588
|
error: "empty_value" /* EMPTY_VALUE */,
|
|
209
589
|
errorMessage: "No account selected"
|
|
210
590
|
}, [selectedAccount]);
|
|
211
|
-
return
|
|
591
|
+
return React4.useEffect(() => () => {
|
|
212
592
|
copyTimeoutRef.current && clearTimeout(copyTimeoutRef.current);
|
|
213
593
|
}, []), useMemo(
|
|
214
594
|
() => ({
|
|
@@ -229,6 +609,7 @@ function useWalletInfo() {
|
|
|
229
609
|
() => wallets.map(
|
|
230
610
|
(walletInfo) => ({
|
|
231
611
|
name: walletInfo.wallet.name,
|
|
612
|
+
connectorId: createConnectorId(walletInfo.wallet.name),
|
|
232
613
|
icon: walletInfo.wallet.icon,
|
|
233
614
|
installed: walletInfo.installed,
|
|
234
615
|
connectable: walletInfo.connectable
|
|
@@ -298,7 +679,7 @@ function useKitTransactionSigner() {
|
|
|
298
679
|
};
|
|
299
680
|
}
|
|
300
681
|
var useGillTransactionSigner = useKitTransactionSigner;
|
|
301
|
-
var
|
|
682
|
+
var logger3 = createLogger("useSolanaClient");
|
|
302
683
|
function useSolanaClient() {
|
|
303
684
|
let { type } = useCluster(), connectorClient = useConnectorClient(), client = useMemo(() => {
|
|
304
685
|
if (!type || !connectorClient) return null;
|
|
@@ -310,7 +691,7 @@ function useSolanaClient() {
|
|
|
310
691
|
urlOrMoniker: type
|
|
311
692
|
}) : null;
|
|
312
693
|
} catch (error) {
|
|
313
|
-
return
|
|
694
|
+
return logger3.error("Failed to create Solana client", { error }), null;
|
|
314
695
|
}
|
|
315
696
|
}, [type, connectorClient]);
|
|
316
697
|
return useMemo(
|
|
@@ -610,13 +991,13 @@ function useWalletAssets(options = {}) {
|
|
|
610
991
|
refetchIntervalMs = false,
|
|
611
992
|
client: clientOverride,
|
|
612
993
|
select
|
|
613
|
-
} = options, {
|
|
614
|
-
if (!enabled || !
|
|
994
|
+
} = options, { account, isConnected: isConnected2 } = useWallet(), address$1 = account ? String(account) : null, { client: providerClient } = useSolanaClient(), rpcClient = clientOverride ?? providerClient, key = useMemo(() => {
|
|
995
|
+
if (!enabled || !isConnected2 || !address$1 || !rpcClient) return null;
|
|
615
996
|
let rpcUrl = rpcClient.urlOrMoniker instanceof URL ? rpcClient.urlOrMoniker.toString() : String(rpcClient.urlOrMoniker);
|
|
616
997
|
return getWalletAssetsQueryKey(rpcUrl, address$1);
|
|
617
|
-
}, [enabled,
|
|
998
|
+
}, [enabled, isConnected2, address$1, rpcClient]), queryFn = useCallback(
|
|
618
999
|
async (signal) => {
|
|
619
|
-
if (!
|
|
1000
|
+
if (!isConnected2 || !address$1 || !rpcClient)
|
|
620
1001
|
return { lamports: 0n, tokenAccounts: [] };
|
|
621
1002
|
if (signal.aborted)
|
|
622
1003
|
throw new DOMException("Query aborted", "AbortError");
|
|
@@ -632,12 +1013,12 @@ function useWalletAssets(options = {}) {
|
|
|
632
1013
|
if (signal.aborted)
|
|
633
1014
|
throw new DOMException("Query aborted", "AbortError");
|
|
634
1015
|
let tokenAccounts = [];
|
|
635
|
-
for (let
|
|
636
|
-
let parsed = parseTokenAccount(
|
|
1016
|
+
for (let account2 of tokenAccountsResult.value) {
|
|
1017
|
+
let parsed = parseTokenAccount(account2, "token");
|
|
637
1018
|
parsed && tokenAccounts.push(parsed);
|
|
638
1019
|
}
|
|
639
|
-
for (let
|
|
640
|
-
let parsed = parseTokenAccount(
|
|
1020
|
+
for (let account2 of token2022AccountsResult.value) {
|
|
1021
|
+
let parsed = parseTokenAccount(account2, "token-2022");
|
|
641
1022
|
parsed && tokenAccounts.push(parsed);
|
|
642
1023
|
}
|
|
643
1024
|
return {
|
|
@@ -645,7 +1026,7 @@ function useWalletAssets(options = {}) {
|
|
|
645
1026
|
tokenAccounts
|
|
646
1027
|
};
|
|
647
1028
|
},
|
|
648
|
-
[
|
|
1029
|
+
[isConnected2, address$1, rpcClient]
|
|
649
1030
|
), { data, error, status, updatedAt, isFetching, refetch, abort } = useSharedQuery(
|
|
650
1031
|
key,
|
|
651
1032
|
queryFn,
|
|
@@ -1103,7 +1484,7 @@ function useTransactions(options = {}) {
|
|
|
1103
1484
|
// 5 minutes
|
|
1104
1485
|
refetchOnMount = "stale",
|
|
1105
1486
|
client: clientOverride
|
|
1106
|
-
} = options, {
|
|
1487
|
+
} = options, { account, isConnected: isConnected2 } = useWallet(), address$1 = useMemo(() => account ? String(account) : null, [account]), { cluster } = useCluster(), { client: providerClient } = useSolanaClient(), connectorClient = useConnectorClient(), [paginatedTransactions, setPaginatedTransactions] = useState([]), [isPaginationLoading, setIsPaginationLoading] = useState(false), [hasMore, setHasMore] = useState(true), beforeSignatureRef = useRef(void 0), rpcClient = clientOverride ?? providerClient, connectorConfig = connectorClient?.getConfig(), imageProxy = connectorConfig?.imageProxy, programLabels = connectorConfig?.programLabels, parseTransaction = useCallback(
|
|
1107
1488
|
(tx, walletAddress, sig, blockTime, slot, err, explorerUrl) => {
|
|
1108
1489
|
let { date, time } = formatDate(blockTime), baseInfo = {
|
|
1109
1490
|
signature: sig,
|
|
@@ -1155,10 +1536,10 @@ function useTransactions(options = {}) {
|
|
|
1155
1536
|
},
|
|
1156
1537
|
[programLabels]
|
|
1157
1538
|
), key = useMemo(() => {
|
|
1158
|
-
if (!enabled || !
|
|
1539
|
+
if (!enabled || !isConnected2 || !address$1 || !rpcClient || !cluster) return null;
|
|
1159
1540
|
let rpcUrl = rpcClient.urlOrMoniker instanceof URL ? rpcClient.urlOrMoniker.toString() : String(rpcClient.urlOrMoniker);
|
|
1160
1541
|
return getTransactionsQueryKey({ rpcUrl, address: address$1, clusterId: cluster.id, limit, fetchDetails });
|
|
1161
|
-
}, [enabled,
|
|
1542
|
+
}, [enabled, isConnected2, address$1, rpcClient, cluster, limit, fetchDetails]);
|
|
1162
1543
|
useEffect(() => {
|
|
1163
1544
|
beforeSignatureRef.current = void 0, setPaginatedTransactions([]), setIsPaginationLoading(false), setHasMore(true);
|
|
1164
1545
|
}, [key]);
|
|
@@ -1266,13 +1647,13 @@ function useTransactions(options = {}) {
|
|
|
1266
1647
|
[rpcClient, address$1, limit, fetchDetails, detailsConcurrency, parseTransaction, imageProxy]
|
|
1267
1648
|
), queryFn = useCallback(
|
|
1268
1649
|
async (signal) => {
|
|
1269
|
-
if (!
|
|
1650
|
+
if (!isConnected2 || !address$1 || !rpcClient || !cluster)
|
|
1270
1651
|
return [];
|
|
1271
1652
|
throwIfAborted(signal);
|
|
1272
1653
|
let result = await fetchAndEnrichTransactions(void 0, cluster, signal);
|
|
1273
1654
|
return throwIfAborted(signal), result.transactions;
|
|
1274
1655
|
},
|
|
1275
|
-
[
|
|
1656
|
+
[isConnected2, address$1, rpcClient, cluster, fetchAndEnrichTransactions]
|
|
1276
1657
|
), {
|
|
1277
1658
|
data: initialTransactions,
|
|
1278
1659
|
error,
|
|
@@ -1533,7 +1914,7 @@ function useTokens(options = {}) {
|
|
|
1533
1914
|
// 5 minutes
|
|
1534
1915
|
refetchOnMount = "stale",
|
|
1535
1916
|
client: clientOverride
|
|
1536
|
-
} = options, {
|
|
1917
|
+
} = options, { account, isConnected: isConnected2 } = useWallet(), address = useMemo(() => account ? String(account) : null, [account]), { type: clusterType } = useCluster(), connectorConfig = useConnectorClient()?.getConfig(), imageProxy = connectorConfig?.imageProxy, coingeckoConfig = connectorConfig?.coingecko, selectFn = useCallback(
|
|
1537
1918
|
(assets) => selectTokens(assets, address ?? ""),
|
|
1538
1919
|
[address]
|
|
1539
1920
|
), {
|
|
@@ -1562,16 +1943,16 @@ function useTokens(options = {}) {
|
|
|
1562
1943
|
isFrozen: false,
|
|
1563
1944
|
owner: walletAddress
|
|
1564
1945
|
});
|
|
1565
|
-
for (let
|
|
1566
|
-
!includeZeroBalance &&
|
|
1567
|
-
mint:
|
|
1568
|
-
tokenAccount:
|
|
1569
|
-
amount:
|
|
1570
|
-
decimals:
|
|
1571
|
-
formatted: formatBalance(
|
|
1572
|
-
isFrozen:
|
|
1573
|
-
owner:
|
|
1574
|
-
programId:
|
|
1946
|
+
for (let account2 of tokenAccounts)
|
|
1947
|
+
!includeZeroBalance && account2.amount === 0n || result.push({
|
|
1948
|
+
mint: account2.mint,
|
|
1949
|
+
tokenAccount: account2.pubkey,
|
|
1950
|
+
amount: account2.amount,
|
|
1951
|
+
decimals: account2.decimals,
|
|
1952
|
+
formatted: formatBalance(account2.amount, account2.decimals),
|
|
1953
|
+
isFrozen: account2.isFrozen,
|
|
1954
|
+
owner: account2.owner,
|
|
1955
|
+
programId: account2.programId
|
|
1575
1956
|
});
|
|
1576
1957
|
return result;
|
|
1577
1958
|
}, [lamports, tokenAccounts, walletAddress, includeNativeSol, includeZeroBalance]), mints = useMemo(() => {
|
|
@@ -1613,10 +1994,10 @@ function useTokens(options = {}) {
|
|
|
1613
1994
|
};
|
|
1614
1995
|
}).sort(sortByValueDesc) : baseTokens.slice().sort(sortByValueDesc), [baseTokens, fetchMetadata, imageProxy, metadataVersion]), totalAccounts = tokenAccounts.length + (includeNativeSol ? 1 : 0);
|
|
1615
1996
|
useEffect(() => (startCacheCleanup(), () => stopCacheCleanup()), []);
|
|
1616
|
-
let wasConnectedRef = useRef(
|
|
1997
|
+
let wasConnectedRef = useRef(isConnected2);
|
|
1617
1998
|
useEffect(() => {
|
|
1618
|
-
wasConnectedRef.current && !
|
|
1619
|
-
}, [
|
|
1999
|
+
wasConnectedRef.current && !isConnected2 && clearTokenCaches(), wasConnectedRef.current = isConnected2;
|
|
2000
|
+
}, [isConnected2]);
|
|
1620
2001
|
let visibleError = updatedAt ? null : error, refetch = useCallback(
|
|
1621
2002
|
async (opts) => {
|
|
1622
2003
|
await sharedRefetch(opts);
|
|
@@ -1645,17 +2026,12 @@ function DisconnectElement({
|
|
|
1645
2026
|
onDisconnect,
|
|
1646
2027
|
render
|
|
1647
2028
|
}) {
|
|
1648
|
-
let {
|
|
1649
|
-
|
|
1650
|
-
try {
|
|
1651
|
-
await disconnect(), onDisconnect?.();
|
|
1652
|
-
} finally {
|
|
1653
|
-
setDisconnecting(false);
|
|
1654
|
-
}
|
|
2029
|
+
let { isConnecting: isConnecting2 } = useWallet(), { disconnect, isDisconnecting } = useDisconnectWallet(), handleDisconnect = async () => {
|
|
2030
|
+
await disconnect(), onDisconnect?.();
|
|
1655
2031
|
};
|
|
1656
2032
|
if (render)
|
|
1657
|
-
return /* @__PURE__ */ jsx(Fragment, { children: render({ disconnect: handleDisconnect, disconnecting }) });
|
|
1658
|
-
let isDisabled =
|
|
2033
|
+
return /* @__PURE__ */ jsx(Fragment, { children: render({ disconnect: handleDisconnect, disconnecting: isDisconnecting }) });
|
|
2034
|
+
let isDisabled = isConnecting2 || isDisconnecting, content = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1659
2035
|
showIcon && (icon || showIcon && !icon && /* @__PURE__ */ jsxs(
|
|
1660
2036
|
"svg",
|
|
1661
2037
|
{
|
|
@@ -1687,7 +2063,7 @@ function DisconnectElement({
|
|
|
1687
2063
|
disabled: isDisabled,
|
|
1688
2064
|
"data-slot": "disconnect-element",
|
|
1689
2065
|
"data-variant": "button",
|
|
1690
|
-
"data-disconnecting":
|
|
2066
|
+
"data-disconnecting": isDisconnecting,
|
|
1691
2067
|
children: content
|
|
1692
2068
|
}
|
|
1693
2069
|
) : variant === "link" ? /* @__PURE__ */ jsx(
|
|
@@ -1699,7 +2075,7 @@ function DisconnectElement({
|
|
|
1699
2075
|
disabled: isDisabled,
|
|
1700
2076
|
"data-slot": "disconnect-element",
|
|
1701
2077
|
"data-variant": "link",
|
|
1702
|
-
"data-disconnecting":
|
|
2078
|
+
"data-disconnecting": isDisconnecting,
|
|
1703
2079
|
children: content
|
|
1704
2080
|
}
|
|
1705
2081
|
) : /* @__PURE__ */ jsx(
|
|
@@ -1712,7 +2088,7 @@ function DisconnectElement({
|
|
|
1712
2088
|
disabled: isDisabled,
|
|
1713
2089
|
"data-slot": "disconnect-element",
|
|
1714
2090
|
"data-variant": "menuitem",
|
|
1715
|
-
"data-disconnecting":
|
|
2091
|
+
"data-disconnecting": isDisconnecting,
|
|
1716
2092
|
children: content
|
|
1717
2093
|
}
|
|
1718
2094
|
);
|
|
@@ -1727,8 +2103,16 @@ function AccountElement({
|
|
|
1727
2103
|
variant = "compact",
|
|
1728
2104
|
render
|
|
1729
2105
|
}) {
|
|
1730
|
-
let { address, formatted,
|
|
1731
|
-
|
|
2106
|
+
let { account, connectorId } = useWallet(), connectors = useWalletConnectors(), address = React4.useMemo(() => account ? String(account) : null, [account]), formatted = React4.useMemo(() => address ? formatAddress(address) : "", [address]), connector = React4.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.useState(false), copyTimeoutRef = React4.useRef(void 0), copy = React4.useCallback(async () => address ? (copyTimeoutRef.current && clearTimeout(copyTimeoutRef.current), await copyAddressToClipboard(address, {
|
|
2107
|
+
onSuccess: () => {
|
|
2108
|
+
setCopied(true), copyTimeoutRef.current = setTimeout(() => setCopied(false), 2e3);
|
|
2109
|
+
}
|
|
2110
|
+
})) : {
|
|
2111
|
+
success: false
|
|
2112
|
+
}, [address]);
|
|
2113
|
+
if (React4.useEffect(() => () => {
|
|
2114
|
+
copyTimeoutRef.current && clearTimeout(copyTimeoutRef.current);
|
|
2115
|
+
}, []), render)
|
|
1732
2116
|
return /* @__PURE__ */ jsx(Fragment, { children: render({ address, formatted, walletName, walletIcon, copy, copied }) });
|
|
1733
2117
|
if (!address) return null;
|
|
1734
2118
|
let displayAddress = showFullAddress ? address : formatted, handleCopy = async (e) => {
|
|
@@ -1889,7 +2273,7 @@ function ClusterElement({
|
|
|
1889
2273
|
labels = {},
|
|
1890
2274
|
render
|
|
1891
2275
|
}) {
|
|
1892
|
-
let { cluster, clusters, setCluster, isMainnet, isDevnet, isTestnet, isLocal } = useCluster(), [isOpen, setIsOpen] =
|
|
2276
|
+
let { cluster, clusters, setCluster, isMainnet, isDevnet, isTestnet, isLocal } = useCluster(), [isOpen, setIsOpen] = React4.useState(false);
|
|
1893
2277
|
if (render)
|
|
1894
2278
|
return /* @__PURE__ */ jsx(Fragment, { children: render({ cluster, clusters, setCluster, isMainnet, isDevnet, isTestnet, isLocal }) });
|
|
1895
2279
|
if (!cluster) return null;
|
|
@@ -2096,14 +2480,41 @@ function WalletListElement({
|
|
|
2096
2480
|
variant = "list",
|
|
2097
2481
|
showStatus = true,
|
|
2098
2482
|
onSelect,
|
|
2483
|
+
onConnect,
|
|
2099
2484
|
render,
|
|
2100
2485
|
renderWallet
|
|
2101
2486
|
}) {
|
|
2102
|
-
let
|
|
2103
|
-
|
|
2487
|
+
let connectors = useWalletConnectors(), { isConnecting: isConnectingGlobal } = useWallet(), { connect, isConnecting: isConnectingLocal } = useConnectWallet(), connecting = isConnectingGlobal || isConnectingLocal, wallets = React4.useMemo(
|
|
2488
|
+
() => connectors.map((c) => ({
|
|
2489
|
+
name: c.name,
|
|
2490
|
+
connectorId: c.id,
|
|
2491
|
+
icon: c.icon || void 0,
|
|
2492
|
+
installed: c.ready,
|
|
2493
|
+
connectable: c.ready
|
|
2494
|
+
})),
|
|
2495
|
+
[connectors]
|
|
2496
|
+
), installedWallets = wallets.filter((w) => w.installed), displayWallets = installedOnly ? installedWallets : wallets, handleSelect = async (walletName) => {
|
|
2497
|
+
let wallet = wallets.find((w) => w.name === walletName);
|
|
2498
|
+
if (!wallet) {
|
|
2499
|
+
let availableWalletNames = wallets.map((w) => w.name);
|
|
2500
|
+
console.warn(
|
|
2501
|
+
`[WalletListElement] Wallet not found for walletName: ${walletName}. Available wallets (${availableWalletNames.length}):`,
|
|
2502
|
+
availableWalletNames
|
|
2503
|
+
);
|
|
2504
|
+
return;
|
|
2505
|
+
}
|
|
2506
|
+
await connect(wallet.connectorId), onSelect?.(walletName), onConnect?.(wallet.connectorId);
|
|
2507
|
+
}, handleConnectById = async (connectorId) => {
|
|
2508
|
+
await connect(connectorId), onConnect?.(connectorId);
|
|
2104
2509
|
};
|
|
2105
2510
|
if (render)
|
|
2106
|
-
return /* @__PURE__ */ jsx(Fragment, { children: render({
|
|
2511
|
+
return /* @__PURE__ */ jsx(Fragment, { children: render({
|
|
2512
|
+
wallets,
|
|
2513
|
+
installedWallets,
|
|
2514
|
+
select: handleSelect,
|
|
2515
|
+
connectById: handleConnectById,
|
|
2516
|
+
connecting
|
|
2517
|
+
}) });
|
|
2107
2518
|
if (displayWallets.length === 0)
|
|
2108
2519
|
return /* @__PURE__ */ jsx(
|
|
2109
2520
|
"div",
|
|
@@ -2161,28 +2572,33 @@ function WalletListElement({
|
|
|
2161
2572
|
className: `ck-wallet-list-block ck-wallet-list-block--grid ${className || ""}`,
|
|
2162
2573
|
"data-slot": "wallet-list-element",
|
|
2163
2574
|
"data-variant": "grid",
|
|
2164
|
-
children: displayWallets.map((wallet) =>
|
|
2165
|
-
wallet
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
|
|
2177
|
-
|
|
2178
|
-
|
|
2179
|
-
|
|
2180
|
-
|
|
2181
|
-
|
|
2182
|
-
|
|
2183
|
-
|
|
2184
|
-
|
|
2185
|
-
|
|
2575
|
+
children: displayWallets.map((wallet) => {
|
|
2576
|
+
let handleWalletConnect = () => handleConnectById(wallet.connectorId);
|
|
2577
|
+
return renderWallet ? /* @__PURE__ */ jsx(React4.Fragment, { children: renderWallet({
|
|
2578
|
+
wallet,
|
|
2579
|
+
select: handleWalletConnect,
|
|
2580
|
+
connect: handleWalletConnect,
|
|
2581
|
+
connecting
|
|
2582
|
+
}) }, wallet.name) : /* @__PURE__ */ jsxs(
|
|
2583
|
+
"button",
|
|
2584
|
+
{
|
|
2585
|
+
type: "button",
|
|
2586
|
+
className: "ck-wallet-list-item ck-wallet-list-item--grid",
|
|
2587
|
+
onClick: handleWalletConnect,
|
|
2588
|
+
disabled: connecting || !wallet.connectable,
|
|
2589
|
+
"data-slot": "wallet-list-item",
|
|
2590
|
+
"data-wallet": wallet.name,
|
|
2591
|
+
"data-connector-id": wallet.connectorId,
|
|
2592
|
+
"data-installed": wallet.installed,
|
|
2593
|
+
children: [
|
|
2594
|
+
/* @__PURE__ */ jsx("div", { className: "ck-wallet-list-item-icon", "data-slot": "wallet-list-item-icon", children: wallet.icon ? /* @__PURE__ */ jsx("img", { src: wallet.icon, alt: wallet.name }) : walletIcon }),
|
|
2595
|
+
/* @__PURE__ */ jsx("span", { className: "ck-wallet-list-item-name", "data-slot": "wallet-list-item-name", children: wallet.name }),
|
|
2596
|
+
showStatus && !wallet.installed && /* @__PURE__ */ jsx("span", { className: "ck-wallet-list-item-status", "data-slot": "wallet-list-item-status", children: "Not installed" })
|
|
2597
|
+
]
|
|
2598
|
+
},
|
|
2599
|
+
wallet.name
|
|
2600
|
+
);
|
|
2601
|
+
})
|
|
2186
2602
|
}
|
|
2187
2603
|
) : variant === "compact" ? /* @__PURE__ */ jsx(
|
|
2188
2604
|
"div",
|
|
@@ -2190,27 +2606,32 @@ function WalletListElement({
|
|
|
2190
2606
|
className: `ck-wallet-list-block ck-wallet-list-block--compact ${className || ""}`,
|
|
2191
2607
|
"data-slot": "wallet-list-element",
|
|
2192
2608
|
"data-variant": "compact",
|
|
2193
|
-
children: displayWallets.map((wallet) =>
|
|
2194
|
-
wallet
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
|
|
2202
|
-
|
|
2203
|
-
|
|
2204
|
-
|
|
2205
|
-
|
|
2206
|
-
|
|
2207
|
-
|
|
2208
|
-
|
|
2209
|
-
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
2609
|
+
children: displayWallets.map((wallet) => {
|
|
2610
|
+
let handleWalletConnect = () => handleConnectById(wallet.connectorId);
|
|
2611
|
+
return renderWallet ? /* @__PURE__ */ jsx(React4.Fragment, { children: renderWallet({
|
|
2612
|
+
wallet,
|
|
2613
|
+
select: handleWalletConnect,
|
|
2614
|
+
connect: handleWalletConnect,
|
|
2615
|
+
connecting
|
|
2616
|
+
}) }, wallet.name) : /* @__PURE__ */ jsxs(
|
|
2617
|
+
"button",
|
|
2618
|
+
{
|
|
2619
|
+
type: "button",
|
|
2620
|
+
className: "ck-wallet-list-item ck-wallet-list-item--compact",
|
|
2621
|
+
onClick: handleWalletConnect,
|
|
2622
|
+
disabled: connecting || !wallet.connectable,
|
|
2623
|
+
"data-slot": "wallet-list-item",
|
|
2624
|
+
"data-wallet": wallet.name,
|
|
2625
|
+
"data-connector-id": wallet.connectorId,
|
|
2626
|
+
"data-installed": wallet.installed,
|
|
2627
|
+
children: [
|
|
2628
|
+
/* @__PURE__ */ jsx("div", { className: "ck-wallet-list-item-icon", "data-slot": "wallet-list-item-icon", children: wallet.icon ? /* @__PURE__ */ jsx("img", { src: wallet.icon, alt: wallet.name }) : walletIcon }),
|
|
2629
|
+
/* @__PURE__ */ jsx("span", { className: "ck-wallet-list-item-name", "data-slot": "wallet-list-item-name", children: wallet.name })
|
|
2630
|
+
]
|
|
2631
|
+
},
|
|
2632
|
+
wallet.name
|
|
2633
|
+
);
|
|
2634
|
+
})
|
|
2214
2635
|
}
|
|
2215
2636
|
) : /* @__PURE__ */ jsx(
|
|
2216
2637
|
"div",
|
|
@@ -2218,54 +2639,59 @@ function WalletListElement({
|
|
|
2218
2639
|
className: `ck-wallet-list-block ck-wallet-list-block--list ${className || ""}`,
|
|
2219
2640
|
"data-slot": "wallet-list-element",
|
|
2220
2641
|
"data-variant": "list",
|
|
2221
|
-
children: displayWallets.map((wallet) =>
|
|
2222
|
-
wallet
|
|
2223
|
-
|
|
2224
|
-
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2228
|
-
|
|
2229
|
-
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2235
|
-
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2642
|
+
children: displayWallets.map((wallet) => {
|
|
2643
|
+
let handleWalletConnect = () => handleConnectById(wallet.connectorId);
|
|
2644
|
+
return renderWallet ? /* @__PURE__ */ jsx(React4.Fragment, { children: renderWallet({
|
|
2645
|
+
wallet,
|
|
2646
|
+
select: handleWalletConnect,
|
|
2647
|
+
connect: handleWalletConnect,
|
|
2648
|
+
connecting
|
|
2649
|
+
}) }, wallet.name) : /* @__PURE__ */ jsxs(
|
|
2650
|
+
"button",
|
|
2651
|
+
{
|
|
2652
|
+
type: "button",
|
|
2653
|
+
className: "ck-wallet-list-item ck-wallet-list-item--list",
|
|
2654
|
+
onClick: handleWalletConnect,
|
|
2655
|
+
disabled: connecting || !wallet.connectable,
|
|
2656
|
+
"data-slot": "wallet-list-item",
|
|
2657
|
+
"data-wallet": wallet.name,
|
|
2658
|
+
"data-connector-id": wallet.connectorId,
|
|
2659
|
+
"data-installed": wallet.installed,
|
|
2660
|
+
children: [
|
|
2661
|
+
/* @__PURE__ */ jsx("div", { className: "ck-wallet-list-item-icon", "data-slot": "wallet-list-item-icon", children: wallet.icon ? /* @__PURE__ */ jsx("img", { src: wallet.icon, alt: wallet.name }) : walletIcon }),
|
|
2662
|
+
/* @__PURE__ */ jsxs("div", { className: "ck-wallet-list-item-info", "data-slot": "wallet-list-item-info", children: [
|
|
2663
|
+
/* @__PURE__ */ jsx("span", { className: "ck-wallet-list-item-name", "data-slot": "wallet-list-item-name", children: wallet.name }),
|
|
2664
|
+
showStatus && /* @__PURE__ */ jsx(
|
|
2665
|
+
"span",
|
|
2666
|
+
{
|
|
2667
|
+
className: "ck-wallet-list-item-status",
|
|
2668
|
+
"data-slot": "wallet-list-item-status",
|
|
2669
|
+
"data-installed": wallet.installed,
|
|
2670
|
+
children: wallet.installed ? "Detected" : "Not installed"
|
|
2671
|
+
}
|
|
2672
|
+
)
|
|
2673
|
+
] }),
|
|
2674
|
+
/* @__PURE__ */ jsx(
|
|
2675
|
+
"svg",
|
|
2241
2676
|
{
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
"
|
|
2245
|
-
|
|
2677
|
+
width: "16",
|
|
2678
|
+
height: "16",
|
|
2679
|
+
viewBox: "0 0 24 24",
|
|
2680
|
+
fill: "none",
|
|
2681
|
+
stroke: "currentColor",
|
|
2682
|
+
strokeWidth: "2",
|
|
2683
|
+
strokeLinecap: "round",
|
|
2684
|
+
strokeLinejoin: "round",
|
|
2685
|
+
className: "ck-wallet-list-item-arrow",
|
|
2686
|
+
"data-slot": "wallet-list-item-arrow",
|
|
2687
|
+
children: /* @__PURE__ */ jsx("polyline", { points: "9 18 15 12 9 6" })
|
|
2246
2688
|
}
|
|
2247
2689
|
)
|
|
2248
|
-
]
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
2252
|
-
|
|
2253
|
-
height: "16",
|
|
2254
|
-
viewBox: "0 0 24 24",
|
|
2255
|
-
fill: "none",
|
|
2256
|
-
stroke: "currentColor",
|
|
2257
|
-
strokeWidth: "2",
|
|
2258
|
-
strokeLinecap: "round",
|
|
2259
|
-
strokeLinejoin: "round",
|
|
2260
|
-
className: "ck-wallet-list-item-arrow",
|
|
2261
|
-
"data-slot": "wallet-list-item-arrow",
|
|
2262
|
-
children: /* @__PURE__ */ jsx("polyline", { points: "9 18 15 12 9 6" })
|
|
2263
|
-
}
|
|
2264
|
-
)
|
|
2265
|
-
]
|
|
2266
|
-
},
|
|
2267
|
-
wallet.name
|
|
2268
|
-
))
|
|
2690
|
+
]
|
|
2691
|
+
},
|
|
2692
|
+
wallet.name
|
|
2693
|
+
);
|
|
2694
|
+
})
|
|
2269
2695
|
}
|
|
2270
2696
|
);
|
|
2271
2697
|
}
|
|
@@ -2302,7 +2728,7 @@ function injectStyles() {
|
|
|
2302
2728
|
}
|
|
2303
2729
|
}
|
|
2304
2730
|
function SkeletonShine() {
|
|
2305
|
-
return
|
|
2731
|
+
return React4.useEffect(() => {
|
|
2306
2732
|
injectStyles();
|
|
2307
2733
|
}, []), /* @__PURE__ */ jsx("div", { className: "ck-skeleton-shine", "data-slot": "skeleton-shine" });
|
|
2308
2734
|
}
|
|
@@ -2836,6 +3262,6 @@ function TokenListElement({
|
|
|
2836
3262
|
}
|
|
2837
3263
|
TokenListElement.displayName = "TokenListElement";
|
|
2838
3264
|
|
|
2839
|
-
export { AccountElement, AppProvider, BalanceElement, ClusterElement, ConnectorProvider, DisconnectElement, SkeletonShine, TokenListElement, TransactionHistoryElement, UnifiedProvider, WalletConnectProvider, WalletListElement, clearSharedQueryCache, clearTokenCaches, getBalanceQueryKey, getTokensQueryKey, getTransactionsQueryKey, getWalletAssetsQueryKey, invalidateSharedQuery, useAccount, useBalance, useCluster, useConnector, useConnectorClient, useGillSolanaClient, useGillTransactionSigner, useKitTransactionSigner, useSolanaClient, useTokens, useTransactionPreparer, useTransactionSigner, useTransactions, useWalletConnectUri, useWalletInfo };
|
|
2840
|
-
//# sourceMappingURL=chunk-
|
|
2841
|
-
//# sourceMappingURL=chunk-
|
|
3265
|
+
export { AccountElement, AppProvider, BalanceElement, ClusterElement, ConnectorErrorBoundary, ConnectorProvider, DisconnectElement, SkeletonShine, TokenListElement, TransactionHistoryElement, UnifiedProvider, WalletConnectProvider, WalletListElement, clearSharedQueryCache, clearTokenCaches, getBalanceQueryKey, getTokensQueryKey, getTransactionsQueryKey, getWalletAssetsQueryKey, invalidateSharedQuery, useAccount, useBalance, useCluster, useConnectWallet, useConnector, useConnectorClient, useDisconnectWallet, useGillSolanaClient, useGillTransactionSigner, useKitTransactionSigner, useSolanaClient, useTokens, useTransactionPreparer, useTransactionSigner, useTransactions, useWallet, useWalletConnectUri, useWalletConnectors, useWalletInfo, withErrorBoundary };
|
|
3266
|
+
//# sourceMappingURL=chunk-MDR4Y37Z.mjs.map
|
|
3267
|
+
//# sourceMappingURL=chunk-MDR4Y37Z.mjs.map
|