solariskit 1.3.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{WalletButton-B-bj9FNL.d.ts → ChainSelectButton-COIW5SBO.d.ts} +9 -134
- package/dist/RainbowKitProvider-CKy7nmFG.js +271 -0
- package/dist/WalletButton-B3e-uEwx.d.ts +126 -0
- package/dist/components/index.d.ts +3 -2
- package/dist/components/index.js +3 -2
- package/dist/index.css +47 -47
- package/dist/index.d.ts +9 -4
- package/dist/index.js +4 -3
- package/dist/{injectedWallet-Bq0gF2WF.js → injectedWallet-CnP8-uv5.js} +19 -1
- package/dist/solana/index.d.ts +156 -0
- package/dist/solana/index.js +601 -0
- package/dist/{WalletButton-DpDL4qfh.js → useFingerprint-BoVxC_1f.js} +4199 -4184
- package/dist/{walletConnectors-C02JPPxf.js → walletConnectors-DwPMzHor.js} +1 -1
- package/dist/wallets/walletConnectors/index.js +1 -1
- package/package.json +30 -15
|
@@ -0,0 +1,601 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { t as injectedWallet_default } from "../injectedWallet-CnP8-uv5.js";
|
|
3
|
+
import { At as useHydrated, C as ConnectModalShellView, Dt as useIsMounted, F as setStorageItem, G as AppContext, H as defaultAvatar, K as defaultAppInfo, L as NetworkModalView, M as createWalletIdStorage, N as getStorageItem, Ot as ShowBalanceProvider, P as removeStorageItem, Q as DialogContent, S as WalletListView, Tt as getChainIconUrl, V as AvatarContext, W as Text, X as formatAddress, Z as abbreviateETHBalance, a as NetworkSelectButtonView, at as WalletButtonProvider, c as defaultConnectButtonProps, ct as ThemeRootStyle, ft as Box, h as useModalStateValue, i as WalletButtonView, kt as useShowBalance, l as resolveShowBalance, lt as useThemeRoot, n as lightTheme, nt as ModalSizeOptions, o as defaultNetworkSelectChainStatus, ot as Dialog, pt as isMobile, q as t, rt as ModalSizeProvider, s as ConnectButtonView, st as ThemeIdProvider, t as useFingerprint, tt as ModalSizeContext, v as MobileWalletItemView, w as ConnectModalIntro, y as MobileWalletListView, z as ProfileDetailsView } from "../useFingerprint-BoVxC_1f.js";
|
|
4
|
+
import React, { createContext, useCallback, useContext, useEffect, useMemo, useRef, useState } from "react";
|
|
5
|
+
import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
import { AppProvider, useBalance, useCluster, useConnectWallet, useDisconnectWallet, useKitTransactionSigner, useSolanaClient as useSolanaClient$1, useWallet, useWalletConnectors } from "@solana/connector/react";
|
|
7
|
+
import { getDefaultConfig, getDefaultMobileConfig } from "@solana/connector/headless";
|
|
8
|
+
|
|
9
|
+
//#region src/solana/wallets/recentSolanaWalletIds.ts
|
|
10
|
+
const reconnectDisabledStorageKey = "rk-solana-reconnect-disabled";
|
|
11
|
+
const storage = createWalletIdStorage({
|
|
12
|
+
latest: "rk-solana-latest-id",
|
|
13
|
+
recent: "rk-solana-recent"
|
|
14
|
+
});
|
|
15
|
+
function getRecentSolanaWalletIds() {
|
|
16
|
+
return storage.getRecent();
|
|
17
|
+
}
|
|
18
|
+
function addRecentSolanaWalletId(walletId) {
|
|
19
|
+
storage.addRecent(walletId);
|
|
20
|
+
}
|
|
21
|
+
function getLatestSolanaWalletId() {
|
|
22
|
+
return storage.getLatest();
|
|
23
|
+
}
|
|
24
|
+
function getLastConnectedSolanaWalletId() {
|
|
25
|
+
if (getStorageItem(reconnectDisabledStorageKey) === "true") return "";
|
|
26
|
+
return getLatestSolanaWalletId() || getRecentSolanaWalletIds()[0] || "";
|
|
27
|
+
}
|
|
28
|
+
function addLatestSolanaWalletId(walletId) {
|
|
29
|
+
removeStorageItem(reconnectDisabledStorageKey);
|
|
30
|
+
storage.addLatest(walletId);
|
|
31
|
+
}
|
|
32
|
+
function clearLatestSolanaWalletId() {
|
|
33
|
+
storage.clearLatest();
|
|
34
|
+
}
|
|
35
|
+
function disableSolanaAutoReconnect() {
|
|
36
|
+
setStorageItem(reconnectDisabledStorageKey, "true");
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
//#endregion
|
|
40
|
+
//#region src/solana/hooks.ts
|
|
41
|
+
function useSolanaWallet() {
|
|
42
|
+
const wallet = useWallet();
|
|
43
|
+
return useMemo(() => ({
|
|
44
|
+
account: wallet.account ? String(wallet.account) : null,
|
|
45
|
+
accounts: wallet.accounts.map((account) => ({
|
|
46
|
+
address: String(account.address),
|
|
47
|
+
label: account.label
|
|
48
|
+
})),
|
|
49
|
+
connectorId: wallet.connectorId ? String(wallet.connectorId) : null,
|
|
50
|
+
error: wallet.error,
|
|
51
|
+
isConnected: wallet.isConnected,
|
|
52
|
+
isConnecting: wallet.isConnecting,
|
|
53
|
+
isError: wallet.isError,
|
|
54
|
+
status: wallet.status
|
|
55
|
+
}), [wallet]);
|
|
56
|
+
}
|
|
57
|
+
function useSolanaWalletConnectors() {
|
|
58
|
+
const connectors = useWalletConnectors();
|
|
59
|
+
return useMemo(() => connectors.map((connector) => ({
|
|
60
|
+
chains: connector.chains,
|
|
61
|
+
features: connector.features,
|
|
62
|
+
icon: connector.icon,
|
|
63
|
+
id: String(connector.id),
|
|
64
|
+
name: connector.name,
|
|
65
|
+
ready: connector.ready
|
|
66
|
+
})), [connectors]);
|
|
67
|
+
}
|
|
68
|
+
function useSolanaConnectWallet() {
|
|
69
|
+
const { connect, error, isConnecting, resetError } = useConnectWallet();
|
|
70
|
+
const connectById = useCallback((connectorId, options) => connect(connectorId, options), [connect]);
|
|
71
|
+
return useMemo(() => ({
|
|
72
|
+
connect: connectById,
|
|
73
|
+
error,
|
|
74
|
+
isConnecting,
|
|
75
|
+
resetError
|
|
76
|
+
}), [
|
|
77
|
+
connectById,
|
|
78
|
+
error,
|
|
79
|
+
isConnecting,
|
|
80
|
+
resetError
|
|
81
|
+
]);
|
|
82
|
+
}
|
|
83
|
+
function useSolanaDisconnectWallet() {
|
|
84
|
+
const { disconnect, isDisconnecting } = useDisconnectWallet();
|
|
85
|
+
return useMemo(() => ({
|
|
86
|
+
disconnect: async () => {
|
|
87
|
+
await disconnect();
|
|
88
|
+
clearLatestSolanaWalletId();
|
|
89
|
+
disableSolanaAutoReconnect();
|
|
90
|
+
},
|
|
91
|
+
isDisconnecting
|
|
92
|
+
}), [disconnect, isDisconnecting]);
|
|
93
|
+
}
|
|
94
|
+
function useSolanaCluster() {
|
|
95
|
+
return useCluster();
|
|
96
|
+
}
|
|
97
|
+
function useSolanaBalance(options) {
|
|
98
|
+
return useBalance(options);
|
|
99
|
+
}
|
|
100
|
+
function useSolanaClient() {
|
|
101
|
+
return useSolanaClient$1();
|
|
102
|
+
}
|
|
103
|
+
function useSolanaKitTransactionSigner() {
|
|
104
|
+
return useKitTransactionSigner();
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/solana/components/SolanaAccountModal/SolanaAccountModal.tsx
|
|
109
|
+
function SolanaAccountModal({ onClose, open }) {
|
|
110
|
+
const wallet = useSolanaWallet();
|
|
111
|
+
const { disconnect } = useSolanaDisconnectWallet();
|
|
112
|
+
const { lastUpdated, solBalance } = useSolanaBalance({ enabled: open && wallet.isConnected });
|
|
113
|
+
const titleId = `rk_account_modal_title_${React.useId()}`;
|
|
114
|
+
if (!wallet.account) return null;
|
|
115
|
+
return /* @__PURE__ */ jsx(Dialog, {
|
|
116
|
+
onClose,
|
|
117
|
+
open,
|
|
118
|
+
titleId,
|
|
119
|
+
children: /* @__PURE__ */ jsx(DialogContent, {
|
|
120
|
+
bottomSheetOnMobile: true,
|
|
121
|
+
padding: "0",
|
|
122
|
+
children: /* @__PURE__ */ jsx(ProfileDetailsView, {
|
|
123
|
+
accountName: formatAddress(wallet.account),
|
|
124
|
+
address: wallet.account,
|
|
125
|
+
balanceLabel: lastUpdated ? `${abbreviateETHBalance(solBalance)} SOL` : void 0,
|
|
126
|
+
onClose,
|
|
127
|
+
onDisconnect: () => {
|
|
128
|
+
disconnect().catch(() => {});
|
|
129
|
+
},
|
|
130
|
+
titleId
|
|
131
|
+
})
|
|
132
|
+
})
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/solana/components/SolanaChainModal/SolanaChainModal.tsx
|
|
138
|
+
const solanaIconUrl$1 = getChainIconUrl("solana");
|
|
139
|
+
function SolanaChainModal({ onClose, open }) {
|
|
140
|
+
const { cluster, clusters, setCluster } = useSolanaCluster();
|
|
141
|
+
const [pendingClusterId, setPendingClusterId] = useState(null);
|
|
142
|
+
const onSelectNetwork = (networkId) => {
|
|
143
|
+
const clusterId = String(networkId);
|
|
144
|
+
setPendingClusterId(clusterId);
|
|
145
|
+
setCluster(clusterId).catch(() => {}).finally(() => {
|
|
146
|
+
setPendingClusterId(null);
|
|
147
|
+
onClose();
|
|
148
|
+
});
|
|
149
|
+
};
|
|
150
|
+
return /* @__PURE__ */ jsx(NetworkModalView, {
|
|
151
|
+
currentNetworkId: cluster?.id,
|
|
152
|
+
networks: clusters.map((cluster) => ({
|
|
153
|
+
iconUrl: solanaIconUrl$1,
|
|
154
|
+
id: cluster.id,
|
|
155
|
+
name: cluster.label
|
|
156
|
+
})),
|
|
157
|
+
onClose,
|
|
158
|
+
onSelectNetwork,
|
|
159
|
+
open,
|
|
160
|
+
pendingNetworkId: pendingClusterId,
|
|
161
|
+
searchThreshold: 5
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
//#endregion
|
|
166
|
+
//#region src/solana/components/SolanaConnectModal/SolanaConnectModal.tsx
|
|
167
|
+
const SOLANA_GET_WALLET_URL = "https://solana.com/ecosystem/explore?categories=wallet";
|
|
168
|
+
function SolanaConnectModal({ onClose, open }) {
|
|
169
|
+
const titleId = `rk_connect_title_${React.useId()}`;
|
|
170
|
+
const connectors = useSolanaWalletConnectors();
|
|
171
|
+
const walletState = useSolanaWallet();
|
|
172
|
+
const { connect, error, isConnecting, resetError } = useSolanaConnectWallet();
|
|
173
|
+
const [selectedWalletId, setSelectedWalletId] = useState();
|
|
174
|
+
const [walletStep, setWalletStep] = useState("LIST");
|
|
175
|
+
const compactModeEnabled = React.useContext(ModalSizeContext) === ModalSizeOptions.COMPACT;
|
|
176
|
+
useEffect(() => {
|
|
177
|
+
if (!open) {
|
|
178
|
+
setSelectedWalletId(void 0);
|
|
179
|
+
setWalletStep("LIST");
|
|
180
|
+
resetError();
|
|
181
|
+
}
|
|
182
|
+
}, [open, resetError]);
|
|
183
|
+
const wallets = useMemo(() => {
|
|
184
|
+
const recentIds = new Set(getRecentSolanaWalletIds());
|
|
185
|
+
return connectors.map((connector) => ({
|
|
186
|
+
groupName: connector.ready ? "Installed" : "Other",
|
|
187
|
+
iconUrl: connector.icon || injectedWallet_default,
|
|
188
|
+
id: connector.id,
|
|
189
|
+
isRainbowKitConnector: false,
|
|
190
|
+
name: connector.name,
|
|
191
|
+
ready: connector.ready,
|
|
192
|
+
recent: recentIds.has(connector.id)
|
|
193
|
+
})).sort((a, b) => Number(b.recent) - Number(a.recent) || a.name.localeCompare(b.name));
|
|
194
|
+
}, [connectors]);
|
|
195
|
+
const groupedWallets = useMemo(() => {
|
|
196
|
+
const installed = wallets.filter((wallet) => wallet.ready);
|
|
197
|
+
const other = wallets.filter((wallet) => !wallet.ready);
|
|
198
|
+
return {
|
|
199
|
+
...installed.length ? { Installed: installed } : {},
|
|
200
|
+
...other.length ? { Other: other } : {}
|
|
201
|
+
};
|
|
202
|
+
}, [wallets]);
|
|
203
|
+
const selectWallet = async (wallet) => {
|
|
204
|
+
if (isConnecting || walletState.isConnecting) return;
|
|
205
|
+
if (!wallet.ready) {
|
|
206
|
+
window.open(SOLANA_GET_WALLET_URL, "_blank", "noopener,noreferrer");
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
resetError();
|
|
210
|
+
setSelectedWalletId(wallet.id);
|
|
211
|
+
try {
|
|
212
|
+
await connect(wallet.id);
|
|
213
|
+
addLatestSolanaWalletId(wallet.id);
|
|
214
|
+
addRecentSolanaWalletId(wallet.id);
|
|
215
|
+
} catch {}
|
|
216
|
+
};
|
|
217
|
+
const mobile = isMobile();
|
|
218
|
+
const walletList = /* @__PURE__ */ jsxs(Fragment$1, { children: [/* @__PURE__ */ jsx(WalletListView, {
|
|
219
|
+
groupedWallets,
|
|
220
|
+
onSelectWallet: selectWallet,
|
|
221
|
+
selectedWalletId
|
|
222
|
+
}), error ? /* @__PURE__ */ jsx(Box, {
|
|
223
|
+
marginTop: "12",
|
|
224
|
+
marginX: "6",
|
|
225
|
+
children: /* @__PURE__ */ jsx(Text, {
|
|
226
|
+
color: "error",
|
|
227
|
+
size: "14",
|
|
228
|
+
weight: "medium",
|
|
229
|
+
children: error.message
|
|
230
|
+
})
|
|
231
|
+
}) : null] });
|
|
232
|
+
return /* @__PURE__ */ jsx(Dialog, {
|
|
233
|
+
onClose,
|
|
234
|
+
open,
|
|
235
|
+
titleId,
|
|
236
|
+
children: /* @__PURE__ */ jsx(DialogContent, {
|
|
237
|
+
bottomSheetOnMobile: true,
|
|
238
|
+
padding: "0",
|
|
239
|
+
wide: !compactModeEnabled,
|
|
240
|
+
children: mobile ? /* @__PURE__ */ jsx(MobileWalletListView, {
|
|
241
|
+
getWalletUrl: SOLANA_GET_WALLET_URL,
|
|
242
|
+
onClose,
|
|
243
|
+
titleId,
|
|
244
|
+
walletItems: wallets.filter((wallet) => wallet.ready).map((wallet) => /* @__PURE__ */ jsx(Box, {
|
|
245
|
+
width: "60",
|
|
246
|
+
children: /* @__PURE__ */ jsx(MobileWalletItemView, {
|
|
247
|
+
connecting: isConnecting && selectedWalletId === wallet.id,
|
|
248
|
+
iconUrl: wallet.iconUrl,
|
|
249
|
+
id: wallet.id,
|
|
250
|
+
name: wallet.name,
|
|
251
|
+
onClick: () => selectWallet(wallet),
|
|
252
|
+
ready: wallet.ready,
|
|
253
|
+
recent: wallet.recent
|
|
254
|
+
})
|
|
255
|
+
}, wallet.id))
|
|
256
|
+
}) : /* @__PURE__ */ jsx(ConnectModalShellView, {
|
|
257
|
+
compactModeEnabled,
|
|
258
|
+
onClose,
|
|
259
|
+
onCompactInfoClick: () => setWalletStep("LEARN_COMPACT"),
|
|
260
|
+
onRightPaneBack: compactModeEnabled ? () => setWalletStep("LIST") : void 0,
|
|
261
|
+
rightPaneContent: /* @__PURE__ */ jsx(ConnectModalIntro, {
|
|
262
|
+
compactModeEnabled,
|
|
263
|
+
getWallet: () => window.open(SOLANA_GET_WALLET_URL, "_blank", "noopener,noreferrer")
|
|
264
|
+
}),
|
|
265
|
+
rightPaneHeaderLabel: compactModeEnabled ? t("intro.title") : null,
|
|
266
|
+
showRightPane: compactModeEnabled ? walletStep !== "LIST" : true,
|
|
267
|
+
showSidebar: compactModeEnabled ? walletStep === "LIST" : true,
|
|
268
|
+
titleId,
|
|
269
|
+
walletList
|
|
270
|
+
})
|
|
271
|
+
})
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
//#endregion
|
|
276
|
+
//#region src/solana/components/SolanaKitProvider/SolanaModalContext.tsx
|
|
277
|
+
const SolanaModalContext = createContext({
|
|
278
|
+
accountModalOpen: false,
|
|
279
|
+
chainModalOpen: false,
|
|
280
|
+
connectModalOpen: false
|
|
281
|
+
});
|
|
282
|
+
function SolanaModalProvider({ children }) {
|
|
283
|
+
const { closeModal: closeConnectModal, isModalOpen: connectModalOpen, openModal: openConnectModal } = useModalStateValue();
|
|
284
|
+
const { closeModal: closeAccountModal, isModalOpen: accountModalOpen, openModal: openAccountModal } = useModalStateValue();
|
|
285
|
+
const { closeModal: closeChainModal, isModalOpen: chainModalOpen, openModal: openChainModal } = useModalStateValue();
|
|
286
|
+
const wallet = useSolanaWallet();
|
|
287
|
+
const { clusters } = useSolanaCluster();
|
|
288
|
+
const closeModals = useCallback(() => {
|
|
289
|
+
closeConnectModal();
|
|
290
|
+
closeAccountModal();
|
|
291
|
+
closeChainModal();
|
|
292
|
+
}, [
|
|
293
|
+
closeAccountModal,
|
|
294
|
+
closeChainModal,
|
|
295
|
+
closeConnectModal
|
|
296
|
+
]);
|
|
297
|
+
useEffect(() => {
|
|
298
|
+
if (wallet.isConnected) {
|
|
299
|
+
closeModals();
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
closeAccountModal();
|
|
303
|
+
}, [
|
|
304
|
+
closeAccountModal,
|
|
305
|
+
closeModals,
|
|
306
|
+
wallet.isConnected
|
|
307
|
+
]);
|
|
308
|
+
useEffect(() => {
|
|
309
|
+
if (wallet.status === "disconnected") closeModals();
|
|
310
|
+
}, [closeModals, wallet.status]);
|
|
311
|
+
return /* @__PURE__ */ jsxs(SolanaModalContext.Provider, {
|
|
312
|
+
value: useMemo(() => ({
|
|
313
|
+
accountModalOpen,
|
|
314
|
+
chainModalOpen,
|
|
315
|
+
connectModalOpen,
|
|
316
|
+
openAccountModal: wallet.isConnected ? openAccountModal : void 0,
|
|
317
|
+
openChainModal: clusters.length > 1 ? openChainModal : void 0,
|
|
318
|
+
openConnectModal: !wallet.isConnected ? openConnectModal : void 0
|
|
319
|
+
}), [
|
|
320
|
+
accountModalOpen,
|
|
321
|
+
chainModalOpen,
|
|
322
|
+
clusters.length,
|
|
323
|
+
connectModalOpen,
|
|
324
|
+
openAccountModal,
|
|
325
|
+
openChainModal,
|
|
326
|
+
openConnectModal,
|
|
327
|
+
wallet.isConnected
|
|
328
|
+
]),
|
|
329
|
+
children: [
|
|
330
|
+
children,
|
|
331
|
+
/* @__PURE__ */ jsx(SolanaConnectModal, {
|
|
332
|
+
onClose: closeConnectModal,
|
|
333
|
+
open: connectModalOpen
|
|
334
|
+
}),
|
|
335
|
+
/* @__PURE__ */ jsx(SolanaAccountModal, {
|
|
336
|
+
onClose: closeAccountModal,
|
|
337
|
+
open: accountModalOpen
|
|
338
|
+
}),
|
|
339
|
+
/* @__PURE__ */ jsx(SolanaChainModal, {
|
|
340
|
+
onClose: closeChainModal,
|
|
341
|
+
open: chainModalOpen
|
|
342
|
+
})
|
|
343
|
+
]
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
function useSolanaAccountModal() {
|
|
347
|
+
const { accountModalOpen, openAccountModal } = useContext(SolanaModalContext);
|
|
348
|
+
return {
|
|
349
|
+
accountModalOpen,
|
|
350
|
+
openAccountModal
|
|
351
|
+
};
|
|
352
|
+
}
|
|
353
|
+
function useSolanaChainModal() {
|
|
354
|
+
const { chainModalOpen, openChainModal } = useContext(SolanaModalContext);
|
|
355
|
+
return {
|
|
356
|
+
chainModalOpen,
|
|
357
|
+
openChainModal
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
function useSolanaConnectModal() {
|
|
361
|
+
const { connectModalOpen, openConnectModal } = useContext(SolanaModalContext);
|
|
362
|
+
return {
|
|
363
|
+
connectModalOpen,
|
|
364
|
+
openConnectModal
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
//#endregion
|
|
369
|
+
//#region src/solana/components/SolanaKitProvider/SolanaKitProvider.tsx
|
|
370
|
+
const defaultTheme = lightTheme();
|
|
371
|
+
const solanaDefaultLearnMoreUrl = "https://solana.com/learn";
|
|
372
|
+
const reconnectDelayMs = 250;
|
|
373
|
+
function splitConnectorKitConfig(config) {
|
|
374
|
+
if (!config) return { connectorConfig: { autoConnect: true } };
|
|
375
|
+
const { autoConnect = true, mobile, ...connectorConfig } = config;
|
|
376
|
+
return {
|
|
377
|
+
connectorConfig: {
|
|
378
|
+
...connectorConfig,
|
|
379
|
+
autoConnect
|
|
380
|
+
},
|
|
381
|
+
mobile
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
function SolanaAutoConnect() {
|
|
385
|
+
const attemptedReconnect = useRef(false);
|
|
386
|
+
const connectRef = useRef(null);
|
|
387
|
+
const wallet = useSolanaWallet();
|
|
388
|
+
const walletRef = useRef(wallet);
|
|
389
|
+
const connectors = useSolanaWalletConnectors();
|
|
390
|
+
const { connect } = useSolanaConnectWallet();
|
|
391
|
+
useEffect(() => {
|
|
392
|
+
connectRef.current = connect;
|
|
393
|
+
}, [connect]);
|
|
394
|
+
useEffect(() => {
|
|
395
|
+
walletRef.current = wallet;
|
|
396
|
+
}, [wallet]);
|
|
397
|
+
useEffect(() => {
|
|
398
|
+
if (attemptedReconnect.current || wallet.isConnected || wallet.isConnecting) return;
|
|
399
|
+
const walletId = getLastConnectedSolanaWalletId();
|
|
400
|
+
const connector = connectors.find((connector) => connector.id === walletId);
|
|
401
|
+
if (!walletId || !connector?.ready) return;
|
|
402
|
+
const timer = window.setTimeout(() => {
|
|
403
|
+
if (attemptedReconnect.current) return;
|
|
404
|
+
attemptedReconnect.current = true;
|
|
405
|
+
if (walletRef.current.isConnected || walletRef.current.isConnecting) return;
|
|
406
|
+
connectRef.current?.(walletId, {
|
|
407
|
+
allowInteractiveFallback: false,
|
|
408
|
+
silent: true
|
|
409
|
+
}).then(() => addLatestSolanaWalletId(walletId)).catch(() => {});
|
|
410
|
+
}, reconnectDelayMs);
|
|
411
|
+
return () => window.clearTimeout(timer);
|
|
412
|
+
}, [
|
|
413
|
+
connectors,
|
|
414
|
+
wallet.isConnected,
|
|
415
|
+
wallet.isConnecting
|
|
416
|
+
]);
|
|
417
|
+
return null;
|
|
418
|
+
}
|
|
419
|
+
function SolanaKitProvider({ appInfo, avatar, children, config, id, modalSize = ModalSizeOptions.WIDE, theme = defaultTheme }) {
|
|
420
|
+
useFingerprint();
|
|
421
|
+
const { themeCss, themeId } = useThemeRoot(id, theme);
|
|
422
|
+
const appContext = useMemo(() => ({
|
|
423
|
+
...defaultAppInfo,
|
|
424
|
+
learnMoreUrl: solanaDefaultLearnMoreUrl,
|
|
425
|
+
...appInfo
|
|
426
|
+
}), [appInfo]);
|
|
427
|
+
const avatarContext = avatar ?? defaultAvatar;
|
|
428
|
+
const { connectorConfig, mobile } = useMemo(() => splitConnectorKitConfig(config), [config]);
|
|
429
|
+
return /* @__PURE__ */ jsxs(AppProvider, {
|
|
430
|
+
connectorConfig,
|
|
431
|
+
mobile,
|
|
432
|
+
children: [config?.autoConnect !== false && /* @__PURE__ */ jsx(SolanaAutoConnect, {}), /* @__PURE__ */ jsx(WalletButtonProvider, { children: /* @__PURE__ */ jsx(ModalSizeProvider, {
|
|
433
|
+
modalSize,
|
|
434
|
+
children: /* @__PURE__ */ jsx(AvatarContext.Provider, {
|
|
435
|
+
value: avatarContext,
|
|
436
|
+
children: /* @__PURE__ */ jsx(AppContext.Provider, {
|
|
437
|
+
value: appContext,
|
|
438
|
+
children: /* @__PURE__ */ jsx(ThemeIdProvider, {
|
|
439
|
+
id: themeId,
|
|
440
|
+
children: /* @__PURE__ */ jsx(ShowBalanceProvider, { children: /* @__PURE__ */ jsx(SolanaModalProvider, { children: /* @__PURE__ */ jsx(ThemeRootStyle, {
|
|
441
|
+
themeCss,
|
|
442
|
+
themeId,
|
|
443
|
+
children
|
|
444
|
+
}) }) })
|
|
445
|
+
})
|
|
446
|
+
})
|
|
447
|
+
})
|
|
448
|
+
}) })]
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
//#endregion
|
|
453
|
+
//#region src/solana/components/SolanaConnectButton/SolanaConnectButton.tsx
|
|
454
|
+
const noop = () => {};
|
|
455
|
+
function SolanaConnectButton({ accountStatus = defaultConnectButtonProps.accountStatus, label = defaultConnectButtonProps.label, showBalance = defaultConnectButtonProps.showBalance }) {
|
|
456
|
+
const wallet = useSolanaWallet();
|
|
457
|
+
const { openAccountModal } = useSolanaAccountModal();
|
|
458
|
+
const { openConnectModal } = useSolanaConnectModal();
|
|
459
|
+
const { setShowBalance } = useShowBalance();
|
|
460
|
+
const hydrated = useHydrated();
|
|
461
|
+
useEffect(() => {
|
|
462
|
+
setShowBalance(showBalance);
|
|
463
|
+
}, [setShowBalance, showBalance]);
|
|
464
|
+
const shouldShowBalance = resolveShowBalance(showBalance);
|
|
465
|
+
const { lastUpdated, solBalance } = useSolanaBalance({ enabled: wallet.isConnected && shouldShowBalance });
|
|
466
|
+
if (!hydrated) return null;
|
|
467
|
+
return /* @__PURE__ */ jsx(ConnectButtonView, {
|
|
468
|
+
account: wallet.account ? {
|
|
469
|
+
address: wallet.account,
|
|
470
|
+
displayBalance: shouldShowBalance && lastUpdated ? `${abbreviateETHBalance(solBalance)} SOL` : void 0,
|
|
471
|
+
displayName: formatAddress(wallet.account),
|
|
472
|
+
hasPendingTransactions: false
|
|
473
|
+
} : void 0,
|
|
474
|
+
accountStatus,
|
|
475
|
+
buttonReady: hydrated,
|
|
476
|
+
isConnected: wallet.isConnected,
|
|
477
|
+
label,
|
|
478
|
+
mounted: hydrated,
|
|
479
|
+
onOpenAccountModal: openAccountModal ?? noop,
|
|
480
|
+
onOpenConnectModal: openConnectModal ?? noop,
|
|
481
|
+
showBalance,
|
|
482
|
+
testIdPrefix: "solana-"
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
//#endregion
|
|
487
|
+
//#region src/solana/components/SolanaChainSelectButton/SolanaChainSelectButton.tsx
|
|
488
|
+
const solanaIconUrl = getChainIconUrl("solana");
|
|
489
|
+
function SolanaChainSelectButton({ chainStatus = defaultNetworkSelectChainStatus }) {
|
|
490
|
+
const { cluster, clusters } = useSolanaCluster();
|
|
491
|
+
const { openChainModal } = useSolanaChainModal();
|
|
492
|
+
const hydrated = useHydrated();
|
|
493
|
+
if (!hydrated) return null;
|
|
494
|
+
return /* @__PURE__ */ jsx(NetworkSelectButtonView, {
|
|
495
|
+
buttonReady: hydrated,
|
|
496
|
+
chainStatus,
|
|
497
|
+
network: cluster ? {
|
|
498
|
+
hasIcon: true,
|
|
499
|
+
iconUrl: solanaIconUrl,
|
|
500
|
+
id: cluster.id,
|
|
501
|
+
name: cluster.label,
|
|
502
|
+
unsupported: false
|
|
503
|
+
} : void 0,
|
|
504
|
+
networkCount: clusters.length,
|
|
505
|
+
onOpenNetworkModal: openChainModal,
|
|
506
|
+
testIdPrefix: "solana-"
|
|
507
|
+
});
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
//#endregion
|
|
511
|
+
//#region src/solana/components/SolanaWalletButton/SolanaWalletButton.tsx
|
|
512
|
+
function SolanaWalletButtonRenderer({ children, connectorId }) {
|
|
513
|
+
const connectors = useSolanaWalletConnectors();
|
|
514
|
+
const wallet = useSolanaWallet();
|
|
515
|
+
const { connect } = useSolanaConnectWallet();
|
|
516
|
+
const { openConnectModal } = useSolanaConnectModal();
|
|
517
|
+
const isMounted = useIsMounted();
|
|
518
|
+
const [loading, setLoading] = useState(false);
|
|
519
|
+
const [isError, setIsError] = useState(false);
|
|
520
|
+
const connector = useMemo(() => connectorId ? connectors.find((connector) => connector.id === connectorId) : connectors.find((connector) => connector.ready) ?? connectors[0], [connectorId, connectors]);
|
|
521
|
+
if (!connector) return /* @__PURE__ */ jsx(Fragment$1, { children: children({
|
|
522
|
+
connected: false,
|
|
523
|
+
connector: {
|
|
524
|
+
iconUrl: injectedWallet_default,
|
|
525
|
+
id: connectorId ?? "unknown",
|
|
526
|
+
name: connectorId ?? "Wallet",
|
|
527
|
+
ready: false
|
|
528
|
+
},
|
|
529
|
+
connect: async () => openConnectModal?.(),
|
|
530
|
+
error: isError,
|
|
531
|
+
loading: false,
|
|
532
|
+
mounted: isMounted(),
|
|
533
|
+
ready: false
|
|
534
|
+
}) });
|
|
535
|
+
const connectWallet = async () => {
|
|
536
|
+
if (!connector.ready) {
|
|
537
|
+
openConnectModal?.();
|
|
538
|
+
return;
|
|
539
|
+
}
|
|
540
|
+
try {
|
|
541
|
+
setLoading(true);
|
|
542
|
+
if (isError) setIsError(false);
|
|
543
|
+
await connect(connector.id);
|
|
544
|
+
addLatestSolanaWalletId(connector.id);
|
|
545
|
+
addRecentSolanaWalletId(connector.id);
|
|
546
|
+
} catch {
|
|
547
|
+
setIsError(true);
|
|
548
|
+
} finally {
|
|
549
|
+
setLoading(false);
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
return /* @__PURE__ */ jsx(Fragment$1, { children: children({
|
|
553
|
+
connected: wallet.isConnected && wallet.connectorId === connector.id,
|
|
554
|
+
connector: {
|
|
555
|
+
iconUrl: connector.icon || injectedWallet_default,
|
|
556
|
+
id: connector.id,
|
|
557
|
+
name: connector.name,
|
|
558
|
+
ready: connector.ready
|
|
559
|
+
},
|
|
560
|
+
connect: connectWallet,
|
|
561
|
+
error: isError,
|
|
562
|
+
loading,
|
|
563
|
+
mounted: isMounted(),
|
|
564
|
+
ready: !wallet.isConnecting && !!openConnectModal
|
|
565
|
+
}) });
|
|
566
|
+
}
|
|
567
|
+
const SolanaWalletButton = ({ connectorId }) => /* @__PURE__ */ jsx(SolanaWalletButtonRenderer, {
|
|
568
|
+
connectorId,
|
|
569
|
+
children: ({ connected, connector, connect, loading, mounted, ready }) => /* @__PURE__ */ jsx(WalletButtonView, {
|
|
570
|
+
connected,
|
|
571
|
+
connector,
|
|
572
|
+
loading,
|
|
573
|
+
mounted,
|
|
574
|
+
onConnect: connect,
|
|
575
|
+
ready
|
|
576
|
+
})
|
|
577
|
+
});
|
|
578
|
+
SolanaWalletButton.Custom = SolanaWalletButtonRenderer;
|
|
579
|
+
|
|
580
|
+
//#endregion
|
|
581
|
+
//#region src/solana/config/getDefaultSolanaConfig.ts
|
|
582
|
+
function getDefaultMobileNetwork(network) {
|
|
583
|
+
return network === "localnet" ? void 0 : network;
|
|
584
|
+
}
|
|
585
|
+
function getDefaultSolanaConfig(options) {
|
|
586
|
+
const { walletConnect: _walletConnect, ...connectorOptions } = options;
|
|
587
|
+
const { walletConnect: _connectorWalletConnect, ...connectorConfig } = getDefaultConfig(connectorOptions);
|
|
588
|
+
const mobileNetwork = getDefaultMobileNetwork(options.network);
|
|
589
|
+
const mobile = options.enableMobile === false || !mobileNetwork ? void 0 : getDefaultMobileConfig({
|
|
590
|
+
appName: options.appName,
|
|
591
|
+
appUrl: options.appUrl,
|
|
592
|
+
network: mobileNetwork
|
|
593
|
+
});
|
|
594
|
+
return mobile ? {
|
|
595
|
+
...connectorConfig,
|
|
596
|
+
mobile
|
|
597
|
+
} : connectorConfig;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
//#endregion
|
|
601
|
+
export { SolanaChainSelectButton, SolanaConnectButton, SolanaKitProvider, SolanaWalletButton, getDefaultSolanaConfig, useSolanaAccountModal, useSolanaBalance, useSolanaChainModal, useSolanaClient, useSolanaCluster, useSolanaConnectModal, useSolanaConnectWallet, useSolanaDisconnectWallet, useSolanaKitTransactionSigner, useSolanaWallet, useSolanaWalletConnectors };
|