@phantom/react-sdk 1.0.0-beta.21 → 1.0.0-beta.24

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/index.js CHANGED
@@ -30,51 +30,784 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var src_exports = {};
32
32
  __export(src_exports, {
33
- AddressType: () => import_browser_sdk4.AddressType,
34
- DebugLevel: () => import_browser_sdk4.DebugLevel,
35
- NetworkId: () => import_browser_sdk4.NetworkId,
33
+ AddressType: () => import_browser_sdk8.AddressType,
34
+ ConnectButton: () => ConnectButton,
35
+ DebugLevel: () => import_browser_sdk8.DebugLevel,
36
+ NetworkId: () => import_browser_sdk8.NetworkId,
36
37
  PhantomProvider: () => PhantomProvider,
37
- debug: () => import_browser_sdk4.debug,
38
+ darkTheme: () => import_wallet_sdk_ui8.darkTheme,
39
+ debug: () => import_browser_sdk8.debug,
40
+ isMobileDevice: () => import_browser_sdk8.isMobileDevice,
41
+ lightTheme: () => import_wallet_sdk_ui8.lightTheme,
42
+ mergeTheme: () => import_wallet_sdk_ui8.mergeTheme,
38
43
  useAccounts: () => useAccounts,
39
44
  useAutoConfirm: () => useAutoConfirm,
40
45
  useConnect: () => useConnect,
41
46
  useDisconnect: () => useDisconnect,
47
+ useDiscoveredWallets: () => useDiscoveredWallets,
42
48
  useEthereum: () => useEthereum,
43
49
  useIsExtensionInstalled: () => useIsExtensionInstalled,
44
50
  useIsPhantomLoginAvailable: () => useIsPhantomLoginAvailable,
51
+ useModal: () => useModal,
45
52
  usePhantom: () => usePhantom,
46
- useSolana: () => useSolana
53
+ useSolana: () => useSolana,
54
+ useTheme: () => import_wallet_sdk_ui6.useTheme
47
55
  });
48
56
  module.exports = __toCommonJS(src_exports);
49
57
 
50
58
  // src/PhantomProvider.tsx
59
+ var import_react9 = require("react");
60
+ var import_browser_sdk5 = require("@phantom/browser-sdk");
61
+ var import_wallet_sdk_ui5 = require("@phantom/wallet-sdk-ui");
62
+
63
+ // src/PhantomContext.ts
51
64
  var import_react = require("react");
65
+ var PhantomContext = (0, import_react.createContext)(void 0);
66
+ function usePhantom() {
67
+ const context = (0, import_react.useContext)(PhantomContext);
68
+ if (!context) {
69
+ throw new Error("usePhantom must be used within a PhantomProvider");
70
+ }
71
+ return context;
72
+ }
73
+
74
+ // src/ModalProvider.tsx
75
+ var import_react8 = require("react");
76
+
77
+ // src/ModalContext.ts
78
+ var import_react2 = require("react");
79
+ var ModalContext = (0, import_react2.createContext)(void 0);
80
+ function useModal() {
81
+ const context = (0, import_react2.useContext)(ModalContext);
82
+ if (!context) {
83
+ throw new Error("useModal must be used within a ModalProvider");
84
+ }
85
+ return {
86
+ open: context.openModal,
87
+ close: context.closeModal,
88
+ isOpened: context.isModalOpen
89
+ };
90
+ }
91
+
92
+ // src/ModalProvider.tsx
93
+ var import_browser_sdk4 = require("@phantom/browser-sdk");
94
+ var import_wallet_sdk_ui4 = require("@phantom/wallet-sdk-ui");
95
+
96
+ // src/components/ConnectModalContent.tsx
97
+ var import_react5 = require("react");
98
+ var import_browser_sdk3 = require("@phantom/browser-sdk");
99
+ var import_wallet_sdk_ui2 = require("@phantom/wallet-sdk-ui");
100
+ var import_constants = require("@phantom/constants");
101
+
102
+ // src/hooks/useIsExtensionInstalled.ts
103
+ var React = __toESM(require("react"));
52
104
  var import_browser_sdk = require("@phantom/browser-sdk");
105
+ function useIsExtensionInstalled() {
106
+ const [isLoading, setIsLoading] = React.useState(true);
107
+ const [isInstalled, setIsInstalled] = React.useState(false);
108
+ React.useEffect(() => {
109
+ let isMounted = true;
110
+ const checkExtension = async () => {
111
+ try {
112
+ setIsLoading(true);
113
+ const result = await (0, import_browser_sdk.waitForPhantomExtension)(3e3);
114
+ if (isMounted) {
115
+ setIsInstalled(result);
116
+ }
117
+ } catch (error) {
118
+ if (isMounted) {
119
+ setIsInstalled(false);
120
+ }
121
+ } finally {
122
+ if (isMounted) {
123
+ setIsLoading(false);
124
+ }
125
+ }
126
+ };
127
+ checkExtension();
128
+ return () => {
129
+ isMounted = false;
130
+ };
131
+ }, []);
132
+ return { isLoading, isInstalled };
133
+ }
134
+
135
+ // src/hooks/useIsPhantomLoginAvailable.ts
136
+ var React2 = __toESM(require("react"));
137
+ var import_browser_sdk2 = require("@phantom/browser-sdk");
138
+ function useIsPhantomLoginAvailable() {
139
+ const [isLoading, setIsLoading] = React2.useState(true);
140
+ const [isAvailable, setIsAvailable] = React2.useState(false);
141
+ React2.useEffect(() => {
142
+ let isMounted = true;
143
+ const checkPhantomLogin = async () => {
144
+ try {
145
+ setIsLoading(true);
146
+ const result = await (0, import_browser_sdk2.isPhantomLoginAvailable)(3e3);
147
+ if (isMounted) {
148
+ setIsAvailable(result);
149
+ }
150
+ } catch (error) {
151
+ if (isMounted) {
152
+ setIsAvailable(false);
153
+ }
154
+ } finally {
155
+ if (isMounted) {
156
+ setIsLoading(false);
157
+ }
158
+ }
159
+ };
160
+ checkPhantomLogin();
161
+ return () => {
162
+ isMounted = false;
163
+ };
164
+ }, []);
165
+ return { isLoading, isAvailable };
166
+ }
167
+
168
+ // src/hooks/useConnect.ts
169
+ var import_react3 = require("react");
170
+ function useConnect() {
171
+ const { sdk, isConnecting, isLoading, connectError } = usePhantom();
172
+ const connect = (0, import_react3.useCallback)(
173
+ async (options) => {
174
+ if (!sdk) {
175
+ throw new Error("SDK not initialized");
176
+ }
177
+ try {
178
+ const result = await sdk.connect(options);
179
+ return result;
180
+ } catch (err) {
181
+ console.error("Error connecting to Phantom:", err);
182
+ throw err;
183
+ }
184
+ },
185
+ [sdk]
186
+ );
187
+ return {
188
+ connect,
189
+ isConnecting,
190
+ isLoading,
191
+ error: connectError
192
+ };
193
+ }
194
+
195
+ // src/hooks/useDiscoveredWallets.ts
196
+ var import_react4 = require("react");
197
+ function useDiscoveredWallets() {
198
+ const { sdk } = usePhantom();
199
+ const [wallets, setWallets] = (0, import_react4.useState)([]);
200
+ const [isLoading, setIsLoading] = (0, import_react4.useState)(true);
201
+ const [error, setError] = (0, import_react4.useState)(null);
202
+ const refetch = (0, import_react4.useCallback)(async () => {
203
+ if (!sdk) {
204
+ setWallets([]);
205
+ setError(null);
206
+ setIsLoading(false);
207
+ return;
208
+ }
209
+ try {
210
+ setIsLoading(true);
211
+ setError(null);
212
+ const initialWallets = sdk.getDiscoveredWallets();
213
+ if (initialWallets.length > 0) {
214
+ setWallets(initialWallets);
215
+ setIsLoading(false);
216
+ } else {
217
+ await sdk.discoverWallets();
218
+ const discoveredWallets = sdk.getDiscoveredWallets();
219
+ setWallets(discoveredWallets);
220
+ setIsLoading(false);
221
+ }
222
+ } catch (err) {
223
+ const error2 = err instanceof Error ? err : new Error("Failed to fetch discovered wallets");
224
+ setError(error2);
225
+ setWallets([]);
226
+ setIsLoading(false);
227
+ }
228
+ }, [sdk]);
229
+ (0, import_react4.useEffect)(() => {
230
+ refetch();
231
+ }, [refetch]);
232
+ return {
233
+ wallets,
234
+ isLoading,
235
+ error,
236
+ refetch
237
+ };
238
+ }
239
+
240
+ // src/components/ChainIcon.tsx
241
+ var import_wallet_sdk_ui = require("@phantom/wallet-sdk-ui");
53
242
  var import_jsx_runtime = require("react/jsx-runtime");
54
- var PhantomContext = (0, import_react.createContext)(void 0);
55
- function PhantomProvider({ children, config, debugConfig }) {
56
- const memoizedConfig = (0, import_react.useMemo)(() => config, [config]);
57
- const [sdk, setSdk] = (0, import_react.useState)(null);
58
- const [isClient, setIsClient] = (0, import_react.useState)(false);
59
- const [isConnected, setIsConnected] = (0, import_react.useState)(false);
60
- const [isConnecting, setIsConnecting] = (0, import_react.useState)(false);
61
- const [connectError, setConnectError] = (0, import_react.useState)(null);
62
- const [addresses, setAddresses] = (0, import_react.useState)([]);
63
- const [currentProviderType, setCurrentProviderType] = (0, import_react.useState)(
64
- memoizedConfig.providerType || null
243
+ var IconWrapper = ({ children }) => {
244
+ const theme = (0, import_wallet_sdk_ui.useTheme)();
245
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
246
+ "span",
247
+ {
248
+ style: {
249
+ display: "inline-flex",
250
+ alignItems: "center",
251
+ justifyContent: "center",
252
+ borderRadius: "4px",
253
+ backgroundColor: theme.aux,
254
+ color: theme.text,
255
+ padding: "2px"
256
+ },
257
+ children
258
+ }
259
+ );
260
+ };
261
+ function ChainIcon({ addressType, size = 8 }) {
262
+ const theme = (0, import_wallet_sdk_ui.useTheme)();
263
+ const type = addressType.toLowerCase();
264
+ if (type.includes("solana")) {
265
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IconWrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_wallet_sdk_ui.Icon, { type: "solana", size, color: theme.text }) });
266
+ }
267
+ if (type.includes("ethereum") || type.includes("evm")) {
268
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IconWrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_wallet_sdk_ui.Icon, { type: "ethereum", size, color: theme.text }) });
269
+ }
270
+ if (type.includes("bitcoin")) {
271
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IconWrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_wallet_sdk_ui.Icon, { type: "bitcoin", size, color: theme.text }) });
272
+ }
273
+ if (type.includes("sui")) {
274
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(IconWrapper, { children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_wallet_sdk_ui.Icon, { type: "sui", size, color: theme.text }) });
275
+ }
276
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
277
+ "span",
278
+ {
279
+ style: {
280
+ display: "inline-flex",
281
+ alignItems: "center",
282
+ justifyContent: "center",
283
+ borderRadius: "4px",
284
+ backgroundColor: theme.aux,
285
+ color: theme.text,
286
+ fontSize: "6px",
287
+ fontWeight: "bold",
288
+ lineHeight: "1",
289
+ padding: "2px"
290
+ },
291
+ title: addressType,
292
+ children: addressType.charAt(0).toUpperCase()
293
+ }
294
+ );
295
+ }
296
+
297
+ // src/components/ConnectModalContent.tsx
298
+ var import_jsx_runtime2 = require("react/jsx-runtime");
299
+ function ConnectModalContent({ appIcon, appName = "App Name", onClose }) {
300
+ const theme = (0, import_wallet_sdk_ui2.useTheme)();
301
+ const { isLoading, allowedProviders } = usePhantom();
302
+ const baseConnect = useConnect();
303
+ const isExtensionInstalled = useIsExtensionInstalled();
304
+ const isPhantomLoginAvailable2 = useIsPhantomLoginAvailable();
305
+ const isMobile = (0, import_react5.useMemo)(() => (0, import_browser_sdk3.isMobileDevice)(), []);
306
+ const { wallets: discoveredWallets } = useDiscoveredWallets();
307
+ const [isConnecting, setIsConnecting] = (0, import_react5.useState)(false);
308
+ const [error, setError] = (0, import_react5.useState)(null);
309
+ const [providerType, setProviderType] = (0, import_react5.useState)(null);
310
+ const [showOtherWallets, setShowOtherWallets] = (0, import_react5.useState)(false);
311
+ const [selectedWalletId, setSelectedWalletId] = (0, import_react5.useState)(null);
312
+ const showDivider = !(allowedProviders.length === 1 && allowedProviders.includes("injected"));
313
+ const shouldShowOtherWalletsButton = discoveredWallets.length > 2;
314
+ const walletsToShowInline = shouldShowOtherWalletsButton ? [] : discoveredWallets;
315
+ const connectWithAuthProvider = (0, import_react5.useCallback)(
316
+ async (provider, walletId) => {
317
+ try {
318
+ setIsConnecting(true);
319
+ setError(null);
320
+ setProviderType(provider);
321
+ setSelectedWalletId(walletId || null);
322
+ await baseConnect.connect({ provider, walletId });
323
+ onClose();
324
+ } catch {
325
+ const wallet = discoveredWallets.find((w) => w.id === walletId);
326
+ const providerName = wallet?.name || (0, import_constants.getProviderName)(provider);
327
+ setError(`Failed to connect to ${providerName}`);
328
+ } finally {
329
+ setIsConnecting(false);
330
+ setProviderType(null);
331
+ setSelectedWalletId(null);
332
+ }
333
+ },
334
+ [baseConnect, discoveredWallets, onClose]
335
+ );
336
+ const connectWithWallet = (0, import_react5.useCallback)(
337
+ async (wallet) => {
338
+ await connectWithAuthProvider("injected", wallet.id);
339
+ },
340
+ [connectWithAuthProvider]
341
+ );
342
+ const connectWithDeeplink = (0, import_react5.useCallback)(() => {
343
+ try {
344
+ setIsConnecting(true);
345
+ setError(null);
346
+ setProviderType("deeplink");
347
+ const deeplinkUrl = (0, import_browser_sdk3.getDeeplinkToPhantom)();
348
+ window.location.href = deeplinkUrl;
349
+ onClose();
350
+ } catch {
351
+ setError("Failed to open deeplink");
352
+ } finally {
353
+ setIsConnecting(false);
354
+ setProviderType(null);
355
+ }
356
+ }, [onClose]);
357
+ const appIconStyle = {
358
+ width: "56px",
359
+ height: "56px",
360
+ borderRadius: "50%",
361
+ display: "block",
362
+ objectFit: "cover",
363
+ marginBottom: "12px"
364
+ };
365
+ const connectContentContainerStyle = {
366
+ transition: "opacity 0.15s ease-in-out, transform 0.15s ease-in-out",
367
+ display: "flex",
368
+ flexDirection: "column",
369
+ alignItems: "center",
370
+ gap: "12px",
371
+ padding: "0 32px"
372
+ };
373
+ const otherWalletsContainerStyle = {
374
+ display: "flex",
375
+ flexDirection: "column",
376
+ alignItems: "center",
377
+ gap: "12px",
378
+ maxHeight: "480px",
379
+ overflowY: "auto",
380
+ padding: "0 32px 32px 32px",
381
+ transition: "opacity 0.15s ease-in-out, transform 0.15s ease-in-out"
382
+ };
383
+ const dividerStyle = {
384
+ display: "flex",
385
+ alignItems: "center",
386
+ width: "100%",
387
+ margin: "12px 0",
388
+ ...theme.typography.caption,
389
+ color: theme.secondary,
390
+ textTransform: "uppercase"
391
+ };
392
+ const dividerLineStyle = {
393
+ flex: 1,
394
+ height: "1px",
395
+ backgroundColor: (0, import_wallet_sdk_ui2.hexToRgba)(theme.secondary, 0.1)
396
+ };
397
+ const dividerTextStyle = {
398
+ padding: "0 12px"
399
+ };
400
+ const errorStyle = {
401
+ backgroundColor: "rgba(220, 53, 69, 0.1)",
402
+ color: "#ff6b6b",
403
+ border: "1px solid rgba(220, 53, 69, 0.3)",
404
+ borderRadius: theme.borderRadius,
405
+ boxSizing: "border-box",
406
+ padding: "12px",
407
+ width: "100%",
408
+ fontSize: "14px"
409
+ };
410
+ const loadingContainerStyle = {
411
+ display: "flex",
412
+ flexDirection: "column",
413
+ alignItems: "center",
414
+ justifyContent: "center",
415
+ padding: "24px",
416
+ gap: "12px"
417
+ };
418
+ const spinnerStyle = {
419
+ width: "40px",
420
+ height: "40px",
421
+ border: `3px solid ${theme.secondary}`,
422
+ borderTop: `3px solid ${theme.brand}`,
423
+ borderRadius: "50%",
424
+ animation: "spin 1s linear infinite"
425
+ };
426
+ const walletIconStyle = {
427
+ width: "32px",
428
+ height: "32px",
429
+ borderRadius: "8px",
430
+ objectFit: "cover"
431
+ };
432
+ const walletButtonContentStyle = {
433
+ display: "flex",
434
+ alignItems: "center",
435
+ justifyContent: "space-between",
436
+ gap: "8px",
437
+ width: "100%"
438
+ };
439
+ const walletButtonLeftStyle = {
440
+ display: "flex",
441
+ alignItems: "center",
442
+ gap: "8px",
443
+ flex: 1
444
+ };
445
+ const walletNameContainerStyle = {
446
+ display: "flex",
447
+ flexDirection: "column",
448
+ gap: "4px",
449
+ alignItems: "flex-start"
450
+ };
451
+ const chainIndicatorsStyle = {
452
+ display: "flex",
453
+ alignItems: "center",
454
+ gap: "4px"
455
+ };
456
+ const walletButtonRightStyle = {
457
+ display: "flex",
458
+ alignItems: "center",
459
+ gap: "8px",
460
+ color: theme.secondary
461
+ };
462
+ const footerStyle = {
463
+ display: "flex",
464
+ padding: "16px",
465
+ justifyContent: "center",
466
+ alignItems: "center",
467
+ gap: "4px",
468
+ borderTop: "1px solid rgba(152, 151, 156, 0.10)",
469
+ ...theme.typography.caption,
470
+ color: theme.secondary
471
+ };
472
+ const contentWrapperStyle = {
473
+ display: "flex",
474
+ flexDirection: "column",
475
+ justifyContent: "space-between",
476
+ gap: "24px"
477
+ };
478
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: contentWrapperStyle, children: [
479
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("style", { children: `
480
+ @keyframes spin {
481
+ 0% { transform: rotate(0deg); }
482
+ 100% { transform: rotate(360deg); }
483
+ }
484
+ ` }),
485
+ isLoading ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: loadingContainerStyle, children: [
486
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: spinnerStyle }),
487
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Text, { variant: "label", color: theme.secondary, children: "Loading..." })
488
+ ] }) : showOtherWallets ? /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
489
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
490
+ import_wallet_sdk_ui2.ModalHeader,
491
+ {
492
+ goBack: true,
493
+ onGoBack: () => {
494
+ setError(null);
495
+ setShowOtherWallets(false);
496
+ },
497
+ title: "Other Wallets",
498
+ onClose
499
+ }
500
+ ),
501
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: otherWalletsContainerStyle, children: [
502
+ error && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: errorStyle, children: error }),
503
+ discoveredWallets.map((wallet) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
504
+ import_wallet_sdk_ui2.Button,
505
+ {
506
+ onClick: () => connectWithWallet(wallet),
507
+ disabled: isConnecting,
508
+ isLoading: isConnecting && providerType === "injected" && selectedWalletId === wallet.id,
509
+ fullWidth: true,
510
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: walletButtonContentStyle, children: [
511
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: walletButtonLeftStyle, children: [
512
+ wallet.icon ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("img", { src: wallet.icon, alt: wallet.name, style: walletIconStyle }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.BoundedIcon, { type: "wallet", size: 20, background: theme.aux, color: theme.text }),
513
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: walletNameContainerStyle, children: [
514
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Text, { variant: "captionBold", children: wallet.name }),
515
+ wallet.addressTypes && wallet.addressTypes.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: chainIndicatorsStyle, children: wallet.addressTypes.map((addressType) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChainIcon, { addressType, size: 8 }, `${wallet.id}-chain-${addressType}`)) })
516
+ ] })
517
+ ] }),
518
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: walletButtonRightStyle, children: [
519
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Text, { variant: "label", color: theme.secondary, children: "Detected" }),
520
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Icon, { type: "chevron-right", size: 16, color: theme.secondary })
521
+ ] })
522
+ ] })
523
+ },
524
+ wallet.id
525
+ ))
526
+ ] })
527
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
528
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.ModalHeader, { title: "Login or Sign Up", onClose }),
529
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: connectContentContainerStyle, children: [
530
+ appIcon && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("img", { src: appIcon, alt: appName, style: appIconStyle }),
531
+ error && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: errorStyle, children: error }),
532
+ isMobile && !isExtensionInstalled.isInstalled && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
533
+ import_wallet_sdk_ui2.Button,
534
+ {
535
+ onClick: connectWithDeeplink,
536
+ disabled: isConnecting,
537
+ isLoading: isConnecting && providerType === "deeplink",
538
+ fullWidth: true,
539
+ children: isConnecting && providerType === "deeplink" ? "Opening Phantom..." : "Open in Phantom App"
540
+ }
541
+ ),
542
+ !isMobile && allowedProviders.includes("phantom") && isPhantomLoginAvailable2.isAvailable && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
543
+ import_wallet_sdk_ui2.LoginWithPhantomButton,
544
+ {
545
+ onClick: () => connectWithAuthProvider("phantom"),
546
+ disabled: isConnecting,
547
+ isLoading: isConnecting && providerType === "phantom"
548
+ }
549
+ ),
550
+ allowedProviders.includes("google") && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
551
+ import_wallet_sdk_ui2.Button,
552
+ {
553
+ onClick: () => connectWithAuthProvider("google"),
554
+ disabled: isConnecting,
555
+ isLoading: isConnecting && providerType === "google",
556
+ fullWidth: true,
557
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: walletButtonContentStyle, children: [
558
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: walletButtonLeftStyle, children: [
559
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Icon, { type: "google", size: 20 }),
560
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Text, { variant: "captionBold", children: "Continue with Google" })
561
+ ] }),
562
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: walletButtonRightStyle, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Icon, { type: "chevron-right", size: 16, color: theme.secondary }) })
563
+ ] })
564
+ }
565
+ ),
566
+ allowedProviders.includes("apple") && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
567
+ import_wallet_sdk_ui2.Button,
568
+ {
569
+ onClick: () => connectWithAuthProvider("apple"),
570
+ disabled: isConnecting,
571
+ isLoading: isConnecting && providerType === "apple",
572
+ fullWidth: true,
573
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: walletButtonContentStyle, children: [
574
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: walletButtonLeftStyle, children: [
575
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Icon, { type: "apple", size: 20 }),
576
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Text, { variant: "captionBold", children: "Continue with Apple" })
577
+ ] }),
578
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: walletButtonRightStyle, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Icon, { type: "chevron-right", size: 16, color: theme.secondary }) })
579
+ ] })
580
+ }
581
+ ),
582
+ !isMobile && allowedProviders.includes("injected") && isExtensionInstalled.isInstalled && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
583
+ showDivider && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: dividerStyle, children: [
584
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: dividerLineStyle }),
585
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: dividerTextStyle, children: "OR" }),
586
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: dividerLineStyle })
587
+ ] }),
588
+ walletsToShowInline.map((wallet) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
589
+ import_wallet_sdk_ui2.Button,
590
+ {
591
+ onClick: () => connectWithWallet(wallet),
592
+ disabled: isConnecting,
593
+ isLoading: isConnecting && providerType === "injected" && selectedWalletId === wallet.id,
594
+ fullWidth: true,
595
+ children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: walletButtonContentStyle, children: [
596
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: walletButtonLeftStyle, children: [
597
+ wallet.icon ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("img", { src: wallet.icon, alt: wallet.name, style: walletIconStyle }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.BoundedIcon, { type: "wallet", size: 10, background: theme.aux, color: theme.text }),
598
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: walletNameContainerStyle, children: [
599
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Text, { variant: "captionBold", children: wallet.name }),
600
+ wallet.addressTypes && wallet.addressTypes.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: chainIndicatorsStyle, children: wallet.addressTypes.map((addressType) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
601
+ ChainIcon,
602
+ {
603
+ addressType,
604
+ size: 8
605
+ },
606
+ `${wallet.id}-chain-${addressType}`
607
+ )) })
608
+ ] })
609
+ ] }),
610
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: walletButtonRightStyle, children: [
611
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Text, { variant: "label", color: theme.secondary, children: "Detected" }),
612
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Icon, { type: "chevron-right", size: 16, color: theme.secondary })
613
+ ] })
614
+ ] })
615
+ },
616
+ wallet.id
617
+ )),
618
+ shouldShowOtherWalletsButton && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Button, { onClick: () => setShowOtherWallets(true), disabled: isConnecting, fullWidth: true, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: walletButtonContentStyle, children: [
619
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: walletButtonLeftStyle, children: [
620
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.BoundedIcon, { type: "wallet", size: 20, background: theme.aux, color: theme.text }),
621
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Text, { variant: "captionBold", children: "Other Wallets" })
622
+ ] }),
623
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: walletButtonRightStyle, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Icon, { type: "chevron-right", size: 16, color: theme.secondary }) })
624
+ ] }) })
625
+ ] })
626
+ ] }),
627
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: footerStyle, children: [
628
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Text, { variant: "label", color: theme.secondary, children: "Powered by" }),
629
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Icon, { type: "phantom", size: 16 }),
630
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Text, { variant: "label", color: theme.secondary, children: "Phantom" })
631
+ ] })
632
+ ] })
633
+ ] });
634
+ }
635
+
636
+ // src/components/ConnectedModalContent.tsx
637
+ var import_react7 = require("react");
638
+ var import_wallet_sdk_ui3 = require("@phantom/wallet-sdk-ui");
639
+
640
+ // src/hooks/useDisconnect.ts
641
+ var import_react6 = require("react");
642
+ function useDisconnect() {
643
+ const { sdk } = usePhantom();
644
+ const [isDisconnecting, setIsDisconnecting] = (0, import_react6.useState)(false);
645
+ const [error, setError] = (0, import_react6.useState)(null);
646
+ const disconnect = (0, import_react6.useCallback)(async () => {
647
+ if (!sdk) {
648
+ throw new Error("SDK not initialized");
649
+ }
650
+ setIsDisconnecting(true);
651
+ setError(null);
652
+ try {
653
+ await sdk.disconnect();
654
+ } catch (err) {
655
+ const error2 = err instanceof Error ? err : new Error(String(err));
656
+ setError(error2);
657
+ throw err;
658
+ } finally {
659
+ setIsDisconnecting(false);
660
+ }
661
+ }, [sdk]);
662
+ return {
663
+ disconnect,
664
+ isDisconnecting,
665
+ error
666
+ };
667
+ }
668
+
669
+ // src/components/ConnectedModalContent.tsx
670
+ var import_jsx_runtime3 = require("react/jsx-runtime");
671
+ function ConnectedModalContent({ onClose }) {
672
+ const theme = (0, import_wallet_sdk_ui3.useTheme)();
673
+ const { addresses } = usePhantom();
674
+ const { disconnect } = useDisconnect();
675
+ const [isDisconnecting, setIsDisconnecting] = (0, import_react7.useState)(false);
676
+ const [disconnectError, setDisconnectError] = (0, import_react7.useState)(null);
677
+ (0, import_react7.useEffect)(() => {
678
+ setDisconnectError(null);
679
+ }, []);
680
+ const handleDisconnect = async () => {
681
+ try {
682
+ setIsDisconnecting(true);
683
+ setDisconnectError(null);
684
+ await disconnect();
685
+ onClose();
686
+ } catch (err) {
687
+ const error = err instanceof Error ? err : new Error(String(err));
688
+ setDisconnectError(error);
689
+ } finally {
690
+ setIsDisconnecting(false);
691
+ }
692
+ };
693
+ const accountListStyle = {
694
+ display: "flex",
695
+ flexDirection: "column",
696
+ gap: "16px",
697
+ width: "100%",
698
+ minWidth: 0,
699
+ boxSizing: "border-box"
700
+ };
701
+ const accountItemStyle = {
702
+ display: "flex",
703
+ flexDirection: "column",
704
+ gap: "8px",
705
+ width: "100%",
706
+ minWidth: 0,
707
+ boxSizing: "border-box"
708
+ };
709
+ const addressTextStyle = {
710
+ fontFamily: "monospace",
711
+ wordBreak: "break-all",
712
+ overflowWrap: "break-word",
713
+ minWidth: 0
714
+ };
715
+ const errorContainerStyle = {
716
+ padding: "12px",
717
+ backgroundColor: "rgba(220, 53, 69, 0.1)",
718
+ borderRadius: theme.borderRadius,
719
+ border: "1px solid rgba(220, 53, 69, 0.3)",
720
+ width: "100%",
721
+ boxSizing: "border-box",
722
+ minWidth: 0
723
+ };
724
+ const contentWrapperStyle = {
725
+ display: "flex",
726
+ flexDirection: "column",
727
+ gap: "24px"
728
+ };
729
+ const accountListContainerStyle = {
730
+ display: "flex",
731
+ flexDirection: "column",
732
+ alignItems: "center",
733
+ gap: "12px",
734
+ padding: "0 32px 24px 32px",
735
+ boxSizing: "border-box",
736
+ width: "100%",
737
+ minWidth: 0
738
+ };
739
+ const disconnectButtonContainerStyle = {
740
+ display: "flex",
741
+ flexDirection: "column",
742
+ alignItems: "center",
743
+ gap: "12px",
744
+ padding: "0 32px 24px 32px",
745
+ boxSizing: "border-box",
746
+ width: "100%",
747
+ minWidth: 0
748
+ };
749
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: contentWrapperStyle, children: [
750
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_wallet_sdk_ui3.ModalHeader, { title: "Wallet", onClose }),
751
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: accountListContainerStyle, children: [
752
+ disconnectError && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: errorContainerStyle, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_wallet_sdk_ui3.Text, { variant: "caption", color: theme.error, children: "Failed to disconnect" }) }),
753
+ addresses && addresses.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: accountListStyle, children: addresses.map((account, index) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: accountItemStyle, children: [
754
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_wallet_sdk_ui3.Text, { variant: "label", color: theme.secondary, style: { textTransform: "uppercase" }, children: account.addressType }),
755
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: addressTextStyle, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_wallet_sdk_ui3.Text, { variant: "caption", children: account.address }) })
756
+ ] }, index)) })
757
+ ] }),
758
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: disconnectButtonContainerStyle, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_wallet_sdk_ui3.Button, { onClick: handleDisconnect, disabled: isDisconnecting, isLoading: isDisconnecting, fullWidth: true, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_wallet_sdk_ui3.Text, { variant: "captionBold", children: isDisconnecting ? "Disconnecting..." : "Disconnect" }) }) })
759
+ ] });
760
+ }
761
+
762
+ // src/ModalProvider.tsx
763
+ var import_jsx_runtime4 = require("react/jsx-runtime");
764
+ function ModalProvider({ children, appIcon, appName }) {
765
+ const { isConnected } = usePhantom();
766
+ const [isModalOpen, setIsModalOpen] = (0, import_react8.useState)(false);
767
+ const isMobile = (0, import_react8.useMemo)(() => (0, import_browser_sdk4.isMobileDevice)(), []);
768
+ const openModal = (0, import_react8.useCallback)(() => {
769
+ setIsModalOpen(true);
770
+ }, []);
771
+ const closeModal = (0, import_react8.useCallback)(() => {
772
+ setIsModalOpen(false);
773
+ }, []);
774
+ const modalContextValue = (0, import_react8.useMemo)(
775
+ () => ({
776
+ isModalOpen,
777
+ openModal,
778
+ closeModal
779
+ }),
780
+ [isModalOpen, openModal, closeModal]
65
781
  );
66
- const [isPhantomAvailable, setIsPhantomAvailable] = (0, import_react.useState)(false);
67
- const [user, setUser] = (0, import_react.useState)(null);
68
- (0, import_react.useEffect)(() => {
782
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(ModalContext.Provider, { value: modalContextValue, children: [
783
+ children,
784
+ /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_wallet_sdk_ui4.Modal, { isVisible: isModalOpen, onClose: closeModal, appIcon, appName, isMobile, children: isConnected ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ConnectedModalContent, { onClose: closeModal }) : /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(ConnectModalContent, { appIcon, appName, onClose: closeModal }) })
785
+ ] });
786
+ }
787
+
788
+ // src/PhantomProvider.tsx
789
+ var import_jsx_runtime5 = require("react/jsx-runtime");
790
+ function PhantomProvider({ children, config, debugConfig, theme, appIcon, appName }) {
791
+ const memoizedConfig = (0, import_react9.useMemo)(() => config, [config]);
792
+ const resolvedTheme = (0, import_react9.useMemo)(() => (0, import_wallet_sdk_ui5.mergeTheme)(theme || import_wallet_sdk_ui5.darkTheme), [theme]);
793
+ const [sdk, setSdk] = (0, import_react9.useState)(null);
794
+ const [isClient, setIsClient] = (0, import_react9.useState)(false);
795
+ const [isConnected, setIsConnected] = (0, import_react9.useState)(false);
796
+ const [isConnecting, setIsConnecting] = (0, import_react9.useState)(false);
797
+ const [isLoading, setIsLoading] = (0, import_react9.useState)(true);
798
+ const [connectError, setConnectError] = (0, import_react9.useState)(null);
799
+ const [addresses, setAddresses] = (0, import_react9.useState)([]);
800
+ const [user, setUser] = (0, import_react9.useState)(null);
801
+ (0, import_react9.useEffect)(() => {
69
802
  setIsClient(true);
70
803
  }, []);
71
- (0, import_react.useEffect)(() => {
804
+ (0, import_react9.useEffect)(() => {
72
805
  if (!isClient)
73
806
  return;
74
- const sdkInstance = new import_browser_sdk.BrowserSDK(memoizedConfig);
807
+ const sdkInstance = new import_browser_sdk5.BrowserSDK(memoizedConfig);
75
808
  setSdk(sdkInstance);
76
809
  }, [isClient, memoizedConfig]);
77
- (0, import_react.useEffect)(() => {
810
+ (0, import_react9.useEffect)(() => {
78
811
  if (!sdk)
79
812
  return;
80
813
  const handleConnectStart = () => {
@@ -86,7 +819,6 @@ function PhantomProvider({ children, config, debugConfig }) {
86
819
  setIsConnected(true);
87
820
  setIsConnecting(false);
88
821
  setUser(data);
89
- setCurrentProviderType(data.providerType || null);
90
822
  const addrs = await sdk.getAddresses();
91
823
  setAddresses(addrs);
92
824
  } catch (err) {
@@ -122,107 +854,51 @@ function PhantomProvider({ children, config, debugConfig }) {
122
854
  sdk.off("disconnect", handleDisconnect);
123
855
  };
124
856
  }, [sdk]);
125
- (0, import_react.useEffect)(() => {
857
+ (0, import_react9.useEffect)(() => {
126
858
  if (!debugConfig || !sdk)
127
859
  return;
128
860
  sdk.configureDebug(debugConfig);
129
861
  }, [sdk, debugConfig]);
130
- (0, import_react.useEffect)(() => {
862
+ (0, import_react9.useEffect)(() => {
131
863
  if (!isClient || !sdk)
132
864
  return;
133
865
  const initialize = async () => {
134
866
  try {
135
- const available = await import_browser_sdk.BrowserSDK.isPhantomInstalled();
136
- setIsPhantomAvailable(available);
137
- } catch (err) {
138
- console.error("Error checking Phantom extension:", err);
139
- setIsPhantomAvailable(false);
140
- }
141
- if (memoizedConfig.autoConnect !== false) {
142
- sdk.autoConnect().catch(() => {
143
- });
867
+ await sdk.autoConnect();
868
+ } catch (error) {
869
+ console.error("Auto-connect error:", error);
144
870
  }
871
+ setIsLoading(false);
145
872
  };
146
873
  initialize();
147
- }, [sdk, memoizedConfig.autoConnect, isClient]);
148
- const value = (0, import_react.useMemo)(
874
+ }, [sdk, isClient]);
875
+ const value = (0, import_react9.useMemo)(
149
876
  () => ({
150
877
  sdk,
151
878
  isConnected,
152
879
  isConnecting,
880
+ isLoading,
153
881
  connectError,
154
882
  addresses,
155
- currentProviderType,
156
- isPhantomAvailable,
157
883
  isClient,
158
- user
884
+ user,
885
+ theme: resolvedTheme,
886
+ allowedProviders: memoizedConfig.providers
159
887
  }),
160
- [sdk, isConnected, isConnecting, connectError, addresses, currentProviderType, isPhantomAvailable, isClient, user]
161
- );
162
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PhantomContext.Provider, { value, children });
163
- }
164
- function usePhantom() {
165
- const context = (0, import_react.useContext)(PhantomContext);
166
- if (!context) {
167
- throw new Error("usePhantom must be used within a PhantomProvider");
168
- }
169
- return context;
170
- }
171
-
172
- // src/hooks/useConnect.ts
173
- var import_react2 = require("react");
174
- function useConnect() {
175
- const { sdk, isConnecting, connectError, currentProviderType, isPhantomAvailable } = usePhantom();
176
- const connect = (0, import_react2.useCallback)(
177
- async (options) => {
178
- if (!sdk) {
179
- throw new Error("SDK not initialized");
180
- }
181
- try {
182
- const result = await sdk.connect(options);
183
- return result;
184
- } catch (err) {
185
- console.error("Error connecting to Phantom:", err);
186
- throw err;
187
- }
188
- },
189
- [sdk]
888
+ [
889
+ sdk,
890
+ isConnected,
891
+ isConnecting,
892
+ isLoading,
893
+ connectError,
894
+ addresses,
895
+ isClient,
896
+ user,
897
+ resolvedTheme,
898
+ memoizedConfig.providers
899
+ ]
190
900
  );
191
- return {
192
- connect,
193
- isConnecting,
194
- error: connectError,
195
- currentProviderType,
196
- isPhantomAvailable
197
- };
198
- }
199
-
200
- // src/hooks/useDisconnect.ts
201
- var import_react3 = require("react");
202
- function useDisconnect() {
203
- const { sdk } = usePhantom();
204
- const [isDisconnecting, setIsDisconnecting] = (0, import_react3.useState)(false);
205
- const [error, setError] = (0, import_react3.useState)(null);
206
- const disconnect = (0, import_react3.useCallback)(async () => {
207
- if (!sdk) {
208
- throw new Error("SDK not initialized");
209
- }
210
- setIsDisconnecting(true);
211
- setError(null);
212
- try {
213
- await sdk.disconnect();
214
- } catch (err) {
215
- setError(err);
216
- throw err;
217
- } finally {
218
- setIsDisconnecting(false);
219
- }
220
- }, [sdk]);
221
- return {
222
- disconnect,
223
- isDisconnecting,
224
- error
225
- };
901
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_wallet_sdk_ui5.ThemeProvider, { theme: resolvedTheme, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(PhantomContext.Provider, { value, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ModalProvider, { appIcon, appName, children }) }) });
226
902
  }
227
903
 
228
904
  // src/hooks/useAccounts.ts
@@ -231,82 +907,16 @@ function useAccounts() {
231
907
  return isConnected ? addresses : null;
232
908
  }
233
909
 
234
- // src/hooks/useIsExtensionInstalled.ts
235
- var React = __toESM(require("react"));
236
- var import_browser_sdk2 = require("@phantom/browser-sdk");
237
- function useIsExtensionInstalled() {
238
- const [isLoading, setIsLoading] = React.useState(true);
239
- const [isInstalled, setIsInstalled] = React.useState(false);
240
- React.useEffect(() => {
241
- let isMounted = true;
242
- const checkExtension = async () => {
243
- try {
244
- setIsLoading(true);
245
- const result = await (0, import_browser_sdk2.waitForPhantomExtension)(3e3);
246
- if (isMounted) {
247
- setIsInstalled(result);
248
- }
249
- } catch (error) {
250
- if (isMounted) {
251
- setIsInstalled(false);
252
- }
253
- } finally {
254
- if (isMounted) {
255
- setIsLoading(false);
256
- }
257
- }
258
- };
259
- checkExtension();
260
- return () => {
261
- isMounted = false;
262
- };
263
- }, []);
264
- return { isLoading, isInstalled };
265
- }
266
-
267
- // src/hooks/useIsPhantomLoginAvailable.ts
268
- var React2 = __toESM(require("react"));
269
- var import_browser_sdk3 = require("@phantom/browser-sdk");
270
- function useIsPhantomLoginAvailable() {
271
- const [isLoading, setIsLoading] = React2.useState(true);
272
- const [isAvailable, setIsAvailable] = React2.useState(false);
273
- React2.useEffect(() => {
274
- let isMounted = true;
275
- const checkPhantomLogin = async () => {
276
- try {
277
- setIsLoading(true);
278
- const result = await (0, import_browser_sdk3.isPhantomLoginAvailable)(3e3);
279
- if (isMounted) {
280
- setIsAvailable(result);
281
- }
282
- } catch (error) {
283
- if (isMounted) {
284
- setIsAvailable(false);
285
- }
286
- } finally {
287
- if (isMounted) {
288
- setIsLoading(false);
289
- }
290
- }
291
- };
292
- checkPhantomLogin();
293
- return () => {
294
- isMounted = false;
295
- };
296
- }, []);
297
- return { isLoading, isAvailable };
298
- }
299
-
300
910
  // src/hooks/useAutoConfirm.ts
301
- var import_react4 = require("react");
911
+ var import_react10 = require("react");
302
912
  function useAutoConfirm() {
303
- const { sdk, currentProviderType } = usePhantom();
304
- const [status, setStatus] = (0, import_react4.useState)(null);
305
- const [supportedChains, setSupportedChains] = (0, import_react4.useState)(null);
306
- const [isLoading, setIsLoading] = (0, import_react4.useState)(false);
307
- const [error, setError] = (0, import_react4.useState)(null);
308
- const isInjected = currentProviderType === "injected";
309
- const enable = (0, import_react4.useCallback)(
913
+ const { sdk, user } = usePhantom();
914
+ const [status, setStatus] = (0, import_react10.useState)(null);
915
+ const [supportedChains, setSupportedChains] = (0, import_react10.useState)(null);
916
+ const [isLoading, setIsLoading] = (0, import_react10.useState)(false);
917
+ const [error, setError] = (0, import_react10.useState)(null);
918
+ const isInjected = user?.authProvider === "injected";
919
+ const enable = (0, import_react10.useCallback)(
310
920
  async (params) => {
311
921
  if (!sdk) {
312
922
  throw new Error("SDK not initialized");
@@ -330,7 +940,7 @@ function useAutoConfirm() {
330
940
  },
331
941
  [sdk, isInjected]
332
942
  );
333
- const disable = (0, import_react4.useCallback)(async () => {
943
+ const disable = (0, import_react10.useCallback)(async () => {
334
944
  if (!sdk) {
335
945
  throw new Error("SDK not initialized");
336
946
  }
@@ -351,7 +961,7 @@ function useAutoConfirm() {
351
961
  setIsLoading(false);
352
962
  }
353
963
  }, [sdk, isInjected]);
354
- const refetch = (0, import_react4.useCallback)(async () => {
964
+ const refetch = (0, import_react10.useCallback)(async () => {
355
965
  if (!sdk || !isInjected) {
356
966
  return;
357
967
  }
@@ -371,7 +981,7 @@ function useAutoConfirm() {
371
981
  setIsLoading(false);
372
982
  }
373
983
  }, [sdk, isInjected]);
374
- (0, import_react4.useEffect)(() => {
984
+ (0, import_react10.useEffect)(() => {
375
985
  if (sdk && isInjected) {
376
986
  refetch();
377
987
  } else {
@@ -392,40 +1002,125 @@ function useAutoConfirm() {
392
1002
  }
393
1003
 
394
1004
  // src/hooks/useSolana.ts
1005
+ var import_browser_sdk6 = require("@phantom/browser-sdk");
395
1006
  function useSolana() {
396
- const { sdk, isConnected, isClient } = usePhantom();
397
- if (!isClient || !sdk) {
1007
+ const { sdk, isClient, isLoading } = usePhantom();
1008
+ if (!isClient || !sdk || isLoading) {
1009
+ return {
1010
+ solana: {},
1011
+ isAvailable: false
1012
+ };
1013
+ }
1014
+ const enabledAddressTypes = sdk.getEnabledAddressTypes();
1015
+ const isAvailable = enabledAddressTypes.includes(import_browser_sdk6.AddressType.solana);
1016
+ if (!isAvailable) {
1017
+ return {
1018
+ solana: {},
1019
+ isAvailable: false
1020
+ };
1021
+ }
1022
+ try {
1023
+ return {
1024
+ solana: sdk.solana,
1025
+ isAvailable: true
1026
+ };
1027
+ } catch (error) {
398
1028
  return {
399
1029
  solana: {},
400
- // This will be replaced when SDK is ready
401
1030
  isAvailable: false
402
1031
  };
403
1032
  }
404
- return {
405
- // Chain instance with connection enforcement for signing methods
406
- solana: sdk.solana,
407
- // State
408
- isAvailable: !!isConnected
409
- };
410
1033
  }
411
1034
 
412
1035
  // src/hooks/useEthereum.ts
1036
+ var import_browser_sdk7 = require("@phantom/browser-sdk");
413
1037
  function useEthereum() {
414
- const { sdk, isConnected, isClient } = usePhantom();
415
- if (!isClient || !sdk) {
1038
+ const { sdk, isClient, isLoading } = usePhantom();
1039
+ if (!isClient || !sdk || isLoading) {
416
1040
  return {
417
1041
  ethereum: {},
418
- // This will be replaced when SDK is ready
419
1042
  isAvailable: false
420
1043
  };
421
1044
  }
422
- return {
423
- // Chain instance with connection enforcement for signing methods
424
- ethereum: sdk.ethereum,
425
- // State
426
- isAvailable: !!isConnected
1045
+ const enabledAddressTypes = sdk.getEnabledAddressTypes();
1046
+ const isAvailable = enabledAddressTypes.includes(import_browser_sdk7.AddressType.ethereum);
1047
+ if (!isAvailable) {
1048
+ return {
1049
+ ethereum: {},
1050
+ isAvailable: false
1051
+ };
1052
+ }
1053
+ try {
1054
+ return {
1055
+ ethereum: sdk.ethereum,
1056
+ isAvailable: true
1057
+ };
1058
+ } catch (error) {
1059
+ return {
1060
+ ethereum: {},
1061
+ isAvailable: false
1062
+ };
1063
+ }
1064
+ }
1065
+
1066
+ // src/hooks/index.ts
1067
+ var import_wallet_sdk_ui6 = require("@phantom/wallet-sdk-ui");
1068
+
1069
+ // src/components/ConnectButton.tsx
1070
+ var import_react11 = require("react");
1071
+ var import_wallet_sdk_ui7 = require("@phantom/wallet-sdk-ui");
1072
+ var import_jsx_runtime6 = require("react/jsx-runtime");
1073
+ function ConnectButton({ addressType, fullWidth = false }) {
1074
+ const theme = (0, import_wallet_sdk_ui7.useTheme)();
1075
+ const { open } = useModal();
1076
+ const { isConnected, addresses } = usePhantom();
1077
+ const displayAddress = (0, import_react11.useMemo)(() => {
1078
+ if (!addresses || addresses.length === 0)
1079
+ return null;
1080
+ if (addressType) {
1081
+ return addresses.find((addr) => addr.addressType === addressType);
1082
+ }
1083
+ return addresses[0];
1084
+ }, [addresses, addressType]);
1085
+ const truncatedAddress = (0, import_react11.useMemo)(() => {
1086
+ if (!displayAddress)
1087
+ return "";
1088
+ const addr = displayAddress.address;
1089
+ if (addr.length <= 12)
1090
+ return addr;
1091
+ return `${addr.slice(0, 6)}...${addr.slice(-4)}`;
1092
+ }, [displayAddress]);
1093
+ const buttonStyle = {
1094
+ width: fullWidth ? "100%" : "auto",
1095
+ padding: "12px 16px",
1096
+ border: "none",
1097
+ borderRadius: theme.borderRadius,
1098
+ fontFamily: theme.typography.captionBold.fontFamily,
1099
+ fontSize: theme.typography.captionBold.fontSize,
1100
+ fontStyle: theme.typography.captionBold.fontStyle,
1101
+ fontWeight: theme.typography.captionBold.fontWeight,
1102
+ lineHeight: theme.typography.captionBold.lineHeight,
1103
+ letterSpacing: theme.typography.captionBold.letterSpacing,
1104
+ cursor: "pointer",
1105
+ transition: "background-color 0.2s",
1106
+ display: "flex",
1107
+ alignItems: "center",
1108
+ justifyContent: "center",
1109
+ gap: "8px",
1110
+ background: theme.aux,
1111
+ color: theme.text
427
1112
  };
1113
+ const connectedButtonStyle = {
1114
+ ...buttonStyle,
1115
+ background: theme.aux,
1116
+ cursor: "pointer"
1117
+ };
1118
+ if (isConnected && displayAddress) {
1119
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { style: connectedButtonStyle, onClick: open, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { style: { fontFamily: "monospace" }, children: truncatedAddress }) });
1120
+ }
1121
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { style: buttonStyle, onClick: open, children: "Connect Wallet" });
428
1122
  }
429
1123
 
430
1124
  // src/index.ts
431
- var import_browser_sdk4 = require("@phantom/browser-sdk");
1125
+ var import_wallet_sdk_ui8 = require("@phantom/wallet-sdk-ui");
1126
+ var import_browser_sdk8 = require("@phantom/browser-sdk");