@phantom/react-sdk 1.0.0-beta.22 → 1.0.0-beta.25
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 +73 -5
- package/dist/index.d.ts +14 -6
- package/dist/index.js +481 -199
- package/dist/index.mjs +469 -175
- package/package.json +13 -7
package/dist/index.js
CHANGED
|
@@ -30,34 +30,35 @@ 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: () =>
|
|
33
|
+
AddressType: () => import_browser_sdk8.AddressType,
|
|
34
34
|
ConnectButton: () => ConnectButton,
|
|
35
|
-
DebugLevel: () =>
|
|
36
|
-
NetworkId: () =>
|
|
35
|
+
DebugLevel: () => import_browser_sdk8.DebugLevel,
|
|
36
|
+
NetworkId: () => import_browser_sdk8.NetworkId,
|
|
37
37
|
PhantomProvider: () => PhantomProvider,
|
|
38
|
-
darkTheme: () =>
|
|
39
|
-
debug: () =>
|
|
40
|
-
isMobileDevice: () =>
|
|
41
|
-
lightTheme: () =>
|
|
42
|
-
mergeTheme: () =>
|
|
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,
|
|
43
43
|
useAccounts: () => useAccounts,
|
|
44
44
|
useAutoConfirm: () => useAutoConfirm,
|
|
45
45
|
useConnect: () => useConnect,
|
|
46
46
|
useDisconnect: () => useDisconnect,
|
|
47
|
+
useDiscoveredWallets: () => useDiscoveredWallets,
|
|
47
48
|
useEthereum: () => useEthereum,
|
|
48
49
|
useIsExtensionInstalled: () => useIsExtensionInstalled,
|
|
49
50
|
useIsPhantomLoginAvailable: () => useIsPhantomLoginAvailable,
|
|
50
51
|
useModal: () => useModal,
|
|
51
52
|
usePhantom: () => usePhantom,
|
|
52
53
|
useSolana: () => useSolana,
|
|
53
|
-
useTheme: () =>
|
|
54
|
+
useTheme: () => import_wallet_sdk_ui6.useTheme
|
|
54
55
|
});
|
|
55
56
|
module.exports = __toCommonJS(src_exports);
|
|
56
57
|
|
|
57
58
|
// src/PhantomProvider.tsx
|
|
58
|
-
var
|
|
59
|
+
var import_react9 = require("react");
|
|
59
60
|
var import_browser_sdk5 = require("@phantom/browser-sdk");
|
|
60
|
-
var
|
|
61
|
+
var import_wallet_sdk_ui5 = require("@phantom/wallet-sdk-ui");
|
|
61
62
|
|
|
62
63
|
// src/PhantomContext.ts
|
|
63
64
|
var import_react = require("react");
|
|
@@ -71,7 +72,7 @@ function usePhantom() {
|
|
|
71
72
|
}
|
|
72
73
|
|
|
73
74
|
// src/ModalProvider.tsx
|
|
74
|
-
var
|
|
75
|
+
var import_react8 = require("react");
|
|
75
76
|
|
|
76
77
|
// src/ModalContext.ts
|
|
77
78
|
var import_react2 = require("react");
|
|
@@ -90,12 +91,13 @@ function useModal() {
|
|
|
90
91
|
|
|
91
92
|
// src/ModalProvider.tsx
|
|
92
93
|
var import_browser_sdk4 = require("@phantom/browser-sdk");
|
|
93
|
-
var
|
|
94
|
+
var import_wallet_sdk_ui4 = require("@phantom/wallet-sdk-ui");
|
|
94
95
|
|
|
95
96
|
// src/components/ConnectModalContent.tsx
|
|
96
|
-
var
|
|
97
|
+
var import_react5 = require("react");
|
|
97
98
|
var import_browser_sdk3 = require("@phantom/browser-sdk");
|
|
98
|
-
var
|
|
99
|
+
var import_wallet_sdk_ui2 = require("@phantom/wallet-sdk-ui");
|
|
100
|
+
var import_constants = require("@phantom/constants");
|
|
99
101
|
|
|
100
102
|
// src/hooks/useIsExtensionInstalled.ts
|
|
101
103
|
var React = __toESM(require("react"));
|
|
@@ -190,38 +192,154 @@ function useConnect() {
|
|
|
190
192
|
};
|
|
191
193
|
}
|
|
192
194
|
|
|
193
|
-
// src/
|
|
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");
|
|
194
242
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
195
|
-
|
|
243
|
+
var IconWrapper = ({ children }) => {
|
|
196
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)();
|
|
197
301
|
const { isLoading, allowedProviders } = usePhantom();
|
|
198
302
|
const baseConnect = useConnect();
|
|
199
303
|
const isExtensionInstalled = useIsExtensionInstalled();
|
|
200
304
|
const isPhantomLoginAvailable2 = useIsPhantomLoginAvailable();
|
|
201
|
-
const isMobile = (0,
|
|
202
|
-
const
|
|
203
|
-
const [
|
|
204
|
-
const [
|
|
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);
|
|
205
312
|
const showDivider = !(allowedProviders.length === 1 && allowedProviders.includes("injected"));
|
|
206
|
-
const
|
|
207
|
-
|
|
313
|
+
const shouldShowOtherWalletsButton = discoveredWallets.length > 2;
|
|
314
|
+
const walletsToShowInline = shouldShowOtherWalletsButton ? [] : discoveredWallets;
|
|
315
|
+
const connectWithAuthProvider = (0, import_react5.useCallback)(
|
|
316
|
+
async (provider, walletId) => {
|
|
208
317
|
try {
|
|
209
318
|
setIsConnecting(true);
|
|
210
319
|
setError(null);
|
|
211
320
|
setProviderType(provider);
|
|
212
|
-
|
|
321
|
+
setSelectedWalletId(walletId || null);
|
|
322
|
+
await baseConnect.connect({ provider, walletId });
|
|
213
323
|
onClose();
|
|
214
|
-
} catch
|
|
215
|
-
const
|
|
216
|
-
|
|
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}`);
|
|
217
328
|
} finally {
|
|
218
329
|
setIsConnecting(false);
|
|
219
330
|
setProviderType(null);
|
|
331
|
+
setSelectedWalletId(null);
|
|
220
332
|
}
|
|
221
333
|
},
|
|
222
|
-
[baseConnect, onClose]
|
|
334
|
+
[baseConnect, discoveredWallets, onClose]
|
|
223
335
|
);
|
|
224
|
-
const
|
|
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)(() => {
|
|
225
343
|
try {
|
|
226
344
|
setIsConnecting(true);
|
|
227
345
|
setError(null);
|
|
@@ -229,9 +347,8 @@ function ConnectModalContent({ appIcon, appName = "App Name", onClose }) {
|
|
|
229
347
|
const deeplinkUrl = (0, import_browser_sdk3.getDeeplinkToPhantom)();
|
|
230
348
|
window.location.href = deeplinkUrl;
|
|
231
349
|
onClose();
|
|
232
|
-
} catch
|
|
233
|
-
|
|
234
|
-
setError(error2);
|
|
350
|
+
} catch {
|
|
351
|
+
setError("Failed to open deeplink");
|
|
235
352
|
} finally {
|
|
236
353
|
setIsConnecting(false);
|
|
237
354
|
setProviderType(null);
|
|
@@ -242,25 +359,32 @@ function ConnectModalContent({ appIcon, appName = "App Name", onClose }) {
|
|
|
242
359
|
height: "56px",
|
|
243
360
|
borderRadius: "50%",
|
|
244
361
|
display: "block",
|
|
245
|
-
objectFit: "cover"
|
|
362
|
+
objectFit: "cover",
|
|
363
|
+
marginBottom: "12px"
|
|
246
364
|
};
|
|
247
|
-
const
|
|
365
|
+
const connectContentContainerStyle = {
|
|
366
|
+
transition: "opacity 0.15s ease-in-out, transform 0.15s ease-in-out",
|
|
248
367
|
display: "flex",
|
|
249
368
|
flexDirection: "column",
|
|
250
369
|
alignItems: "center",
|
|
251
370
|
gap: "12px",
|
|
252
|
-
|
|
371
|
+
padding: "0 32px"
|
|
253
372
|
};
|
|
254
|
-
const
|
|
373
|
+
const otherWalletsContainerStyle = {
|
|
255
374
|
display: "flex",
|
|
375
|
+
flexDirection: "column",
|
|
376
|
+
alignItems: "center",
|
|
256
377
|
gap: "12px",
|
|
257
|
-
|
|
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"
|
|
258
382
|
};
|
|
259
383
|
const dividerStyle = {
|
|
260
384
|
display: "flex",
|
|
261
385
|
alignItems: "center",
|
|
262
386
|
width: "100%",
|
|
263
|
-
margin: "
|
|
387
|
+
margin: "12px 0",
|
|
264
388
|
...theme.typography.caption,
|
|
265
389
|
color: theme.secondary,
|
|
266
390
|
textTransform: "uppercase"
|
|
@@ -268,7 +392,7 @@ function ConnectModalContent({ appIcon, appName = "App Name", onClose }) {
|
|
|
268
392
|
const dividerLineStyle = {
|
|
269
393
|
flex: 1,
|
|
270
394
|
height: "1px",
|
|
271
|
-
backgroundColor: (0,
|
|
395
|
+
backgroundColor: (0, import_wallet_sdk_ui2.hexToRgba)(theme.secondary, 0.1)
|
|
272
396
|
};
|
|
273
397
|
const dividerTextStyle = {
|
|
274
398
|
padding: "0 12px"
|
|
@@ -278,6 +402,7 @@ function ConnectModalContent({ appIcon, appName = "App Name", onClose }) {
|
|
|
278
402
|
color: "#ff6b6b",
|
|
279
403
|
border: "1px solid rgba(220, 53, 69, 0.3)",
|
|
280
404
|
borderRadius: theme.borderRadius,
|
|
405
|
+
boxSizing: "border-box",
|
|
281
406
|
padding: "12px",
|
|
282
407
|
width: "100%",
|
|
283
408
|
fontSize: "14px"
|
|
@@ -298,108 +423,214 @@ function ConnectModalContent({ appIcon, appName = "App Name", onClose }) {
|
|
|
298
423
|
borderRadius: "50%",
|
|
299
424
|
animation: "spin 1s linear infinite"
|
|
300
425
|
};
|
|
301
|
-
|
|
302
|
-
|
|
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: `
|
|
303
480
|
@keyframes spin {
|
|
304
481
|
0% { transform: rotate(0deg); }
|
|
305
482
|
100% { transform: rotate(360deg); }
|
|
306
483
|
}
|
|
307
484
|
` }),
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
/* @__PURE__ */ (0,
|
|
313
|
-
|
|
314
|
-
isMobile && !isExtensionInstalled.isInstalled && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
315
|
-
import_wallet_sdk_ui.Button,
|
|
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,
|
|
316
491
|
{
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
492
|
+
goBack: true,
|
|
493
|
+
onGoBack: () => {
|
|
494
|
+
setError(null);
|
|
495
|
+
setShowOtherWallets(false);
|
|
496
|
+
},
|
|
497
|
+
title: "Other Wallets",
|
|
498
|
+
onClose
|
|
322
499
|
}
|
|
323
500
|
),
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
disabled: isConnecting,
|
|
329
|
-
isLoading: isConnecting && providerType === "phantom"
|
|
330
|
-
}
|
|
331
|
-
),
|
|
332
|
-
(allowedProviders.includes("google") || allowedProviders.includes("apple")) && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: socialButtonRowStyle, children: [
|
|
333
|
-
allowedProviders.includes("google") && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
334
|
-
import_wallet_sdk_ui.Button,
|
|
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,
|
|
335
505
|
{
|
|
336
|
-
onClick: () =>
|
|
506
|
+
onClick: () => connectWithWallet(wallet),
|
|
337
507
|
disabled: isConnecting,
|
|
338
|
-
isLoading: isConnecting && providerType === "
|
|
508
|
+
isLoading: isConnecting && providerType === "injected" && selectedWalletId === wallet.id,
|
|
339
509
|
fullWidth: true,
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
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.id === "phantom" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.BoundedIcon, { type: "phantom", size: 20, background: "#aba0f2", color: "white" }) : 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.jsx)("span", { style: walletNameContainerStyle, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Text, { variant: "captionBold", children: wallet.name }) })
|
|
514
|
+
] }),
|
|
515
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: walletButtonRightStyle, children: [
|
|
516
|
+
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)("span", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChainIcon, { addressType, size: 8 }) }, `${wallet.id}-chain-${addressType}`)) }),
|
|
517
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Icon, { type: "chevron-right", size: 16, color: theme.secondary })
|
|
518
|
+
] })
|
|
519
|
+
] })
|
|
520
|
+
},
|
|
521
|
+
wallet.id
|
|
522
|
+
))
|
|
523
|
+
] })
|
|
524
|
+
] }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
525
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.ModalHeader, { title: "Login or Sign Up", onClose }),
|
|
526
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: connectContentContainerStyle, children: [
|
|
527
|
+
appIcon && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("img", { src: appIcon, alt: appName, style: appIconStyle }),
|
|
528
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: errorStyle, children: error }),
|
|
529
|
+
isMobile && !isExtensionInstalled.isInstalled && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
530
|
+
import_wallet_sdk_ui2.Button,
|
|
531
|
+
{
|
|
532
|
+
onClick: connectWithDeeplink,
|
|
533
|
+
disabled: isConnecting,
|
|
534
|
+
isLoading: isConnecting && providerType === "deeplink",
|
|
535
|
+
fullWidth: true,
|
|
536
|
+
children: isConnecting && providerType === "deeplink" ? "Opening Phantom..." : "Open in Phantom App"
|
|
345
537
|
}
|
|
346
538
|
),
|
|
347
|
-
allowedProviders.includes("
|
|
348
|
-
|
|
539
|
+
!isMobile && allowedProviders.includes("phantom") && isPhantomLoginAvailable2.isAvailable && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
540
|
+
import_wallet_sdk_ui2.LoginWithPhantomButton,
|
|
349
541
|
{
|
|
350
|
-
onClick: () => connectWithAuthProvider("
|
|
542
|
+
onClick: () => connectWithAuthProvider("phantom"),
|
|
351
543
|
disabled: isConnecting,
|
|
352
|
-
isLoading: isConnecting && providerType === "
|
|
544
|
+
isLoading: isConnecting && providerType === "phantom"
|
|
545
|
+
}
|
|
546
|
+
),
|
|
547
|
+
allowedProviders.includes("google") && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
548
|
+
import_wallet_sdk_ui2.Button,
|
|
549
|
+
{
|
|
550
|
+
onClick: () => connectWithAuthProvider("google"),
|
|
551
|
+
disabled: isConnecting,
|
|
552
|
+
isLoading: isConnecting && providerType === "google",
|
|
353
553
|
fullWidth: true,
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
554
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: walletButtonContentStyle, children: [
|
|
555
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: walletButtonLeftStyle, children: [
|
|
556
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Icon, { type: "google", size: 20 }),
|
|
557
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Text, { variant: "captionBold", children: "Continue with Google" })
|
|
558
|
+
] }),
|
|
559
|
+
/* @__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 }) })
|
|
560
|
+
] })
|
|
359
561
|
}
|
|
360
|
-
)
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
showDivider && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: dividerStyle, children: [
|
|
364
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: dividerLineStyle }),
|
|
365
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: dividerTextStyle, children: "OR" }),
|
|
366
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { style: dividerLineStyle })
|
|
367
|
-
] }),
|
|
368
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
369
|
-
import_wallet_sdk_ui.Button,
|
|
562
|
+
),
|
|
563
|
+
allowedProviders.includes("apple") && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
564
|
+
import_wallet_sdk_ui2.Button,
|
|
370
565
|
{
|
|
371
|
-
onClick: () => connectWithAuthProvider("
|
|
566
|
+
onClick: () => connectWithAuthProvider("apple"),
|
|
372
567
|
disabled: isConnecting,
|
|
373
|
-
isLoading: isConnecting && providerType === "
|
|
568
|
+
isLoading: isConnecting && providerType === "apple",
|
|
374
569
|
fullWidth: true,
|
|
375
|
-
children: /* @__PURE__ */ (0,
|
|
376
|
-
/* @__PURE__ */ (0,
|
|
377
|
-
/* @__PURE__ */ (0,
|
|
378
|
-
/* @__PURE__ */ (0,
|
|
570
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: walletButtonContentStyle, children: [
|
|
571
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: walletButtonLeftStyle, children: [
|
|
572
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Icon, { type: "apple", size: 20 }),
|
|
573
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Text, { variant: "captionBold", children: "Continue with Apple" })
|
|
379
574
|
] }),
|
|
380
|
-
/* @__PURE__ */ (0,
|
|
381
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_wallet_sdk_ui.Text, { variant: "label", color: theme.secondary, children: "Detected" }),
|
|
382
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_wallet_sdk_ui.Icon, { type: "chevron-right", size: 16 })
|
|
383
|
-
] })
|
|
575
|
+
/* @__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 }) })
|
|
384
576
|
] })
|
|
385
577
|
}
|
|
386
|
-
)
|
|
578
|
+
),
|
|
579
|
+
!isMobile && allowedProviders.includes("injected") && isExtensionInstalled.isInstalled && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
|
|
580
|
+
showDivider && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: dividerStyle, children: [
|
|
581
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: dividerLineStyle }),
|
|
582
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: dividerTextStyle, children: "OR" }),
|
|
583
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { style: dividerLineStyle })
|
|
584
|
+
] }),
|
|
585
|
+
walletsToShowInline.map((wallet) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
586
|
+
import_wallet_sdk_ui2.Button,
|
|
587
|
+
{
|
|
588
|
+
onClick: () => connectWithWallet(wallet),
|
|
589
|
+
disabled: isConnecting,
|
|
590
|
+
isLoading: isConnecting && providerType === "injected" && selectedWalletId === wallet.id,
|
|
591
|
+
fullWidth: true,
|
|
592
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: walletButtonContentStyle, children: [
|
|
593
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: walletButtonLeftStyle, children: [
|
|
594
|
+
wallet.id === "phantom" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.BoundedIcon, { type: "phantom", size: 20, background: "#aba0f2", color: "white" }) : 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 }),
|
|
595
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { style: walletNameContainerStyle, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Text, { variant: "captionBold", children: wallet.name }) })
|
|
596
|
+
] }),
|
|
597
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: walletButtonRightStyle, children: [
|
|
598
|
+
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)("span", { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChainIcon, { addressType, size: 8 }) }, `${wallet.id}-chain-${addressType}`)) }),
|
|
599
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Icon, { type: "chevron-right", size: 16, color: theme.secondary })
|
|
600
|
+
] })
|
|
601
|
+
] })
|
|
602
|
+
},
|
|
603
|
+
wallet.id
|
|
604
|
+
)),
|
|
605
|
+
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: [
|
|
606
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("span", { style: walletButtonLeftStyle, children: [
|
|
607
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.BoundedIcon, { type: "wallet", size: 20, background: theme.aux, color: theme.text }),
|
|
608
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Text, { variant: "captionBold", children: "Other Wallets" })
|
|
609
|
+
] }),
|
|
610
|
+
/* @__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 }) })
|
|
611
|
+
] }) })
|
|
612
|
+
] })
|
|
613
|
+
] }),
|
|
614
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: footerStyle, children: [
|
|
615
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Text, { variant: "label", color: theme.secondary, children: "Powered by" }),
|
|
616
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Icon, { type: "phantom", size: 16 }),
|
|
617
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_wallet_sdk_ui2.Text, { variant: "label", color: theme.secondary, children: "Phantom" })
|
|
387
618
|
] })
|
|
388
619
|
] })
|
|
389
620
|
] });
|
|
390
621
|
}
|
|
391
622
|
|
|
392
623
|
// src/components/ConnectedModalContent.tsx
|
|
393
|
-
var
|
|
394
|
-
var
|
|
624
|
+
var import_react7 = require("react");
|
|
625
|
+
var import_wallet_sdk_ui3 = require("@phantom/wallet-sdk-ui");
|
|
395
626
|
|
|
396
627
|
// src/hooks/useDisconnect.ts
|
|
397
|
-
var
|
|
628
|
+
var import_react6 = require("react");
|
|
398
629
|
function useDisconnect() {
|
|
399
630
|
const { sdk } = usePhantom();
|
|
400
|
-
const [isDisconnecting, setIsDisconnecting] = (0,
|
|
401
|
-
const [error, setError] = (0,
|
|
402
|
-
const disconnect = (0,
|
|
631
|
+
const [isDisconnecting, setIsDisconnecting] = (0, import_react6.useState)(false);
|
|
632
|
+
const [error, setError] = (0, import_react6.useState)(null);
|
|
633
|
+
const disconnect = (0, import_react6.useCallback)(async () => {
|
|
403
634
|
if (!sdk) {
|
|
404
635
|
throw new Error("SDK not initialized");
|
|
405
636
|
}
|
|
@@ -423,14 +654,14 @@ function useDisconnect() {
|
|
|
423
654
|
}
|
|
424
655
|
|
|
425
656
|
// src/components/ConnectedModalContent.tsx
|
|
426
|
-
var
|
|
657
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
427
658
|
function ConnectedModalContent({ onClose }) {
|
|
428
|
-
const theme = (0,
|
|
659
|
+
const theme = (0, import_wallet_sdk_ui3.useTheme)();
|
|
429
660
|
const { addresses } = usePhantom();
|
|
430
661
|
const { disconnect } = useDisconnect();
|
|
431
|
-
const [isDisconnecting, setIsDisconnecting] = (0,
|
|
432
|
-
const [disconnectError, setDisconnectError] = (0,
|
|
433
|
-
(0,
|
|
662
|
+
const [isDisconnecting, setIsDisconnecting] = (0, import_react7.useState)(false);
|
|
663
|
+
const [disconnectError, setDisconnectError] = (0, import_react7.useState)(null);
|
|
664
|
+
(0, import_react7.useEffect)(() => {
|
|
434
665
|
setDisconnectError(null);
|
|
435
666
|
}, []);
|
|
436
667
|
const handleDisconnect = async () => {
|
|
@@ -450,48 +681,84 @@ function ConnectedModalContent({ onClose }) {
|
|
|
450
681
|
display: "flex",
|
|
451
682
|
flexDirection: "column",
|
|
452
683
|
gap: "16px",
|
|
453
|
-
width: "100%"
|
|
684
|
+
width: "100%",
|
|
685
|
+
minWidth: 0,
|
|
686
|
+
boxSizing: "border-box"
|
|
454
687
|
};
|
|
455
688
|
const accountItemStyle = {
|
|
456
689
|
display: "flex",
|
|
457
690
|
flexDirection: "column",
|
|
458
691
|
gap: "8px",
|
|
459
|
-
width: "100%"
|
|
692
|
+
width: "100%",
|
|
693
|
+
minWidth: 0,
|
|
694
|
+
boxSizing: "border-box"
|
|
460
695
|
};
|
|
461
696
|
const addressTextStyle = {
|
|
462
697
|
fontFamily: "monospace",
|
|
463
|
-
wordBreak: "break-all"
|
|
698
|
+
wordBreak: "break-all",
|
|
699
|
+
overflowWrap: "break-word",
|
|
700
|
+
minWidth: 0
|
|
464
701
|
};
|
|
465
702
|
const errorContainerStyle = {
|
|
466
703
|
padding: "12px",
|
|
467
704
|
backgroundColor: "rgba(220, 53, 69, 0.1)",
|
|
468
705
|
borderRadius: theme.borderRadius,
|
|
469
706
|
border: "1px solid rgba(220, 53, 69, 0.3)",
|
|
470
|
-
width: "100%"
|
|
707
|
+
width: "100%",
|
|
708
|
+
boxSizing: "border-box",
|
|
709
|
+
minWidth: 0
|
|
710
|
+
};
|
|
711
|
+
const contentWrapperStyle = {
|
|
712
|
+
display: "flex",
|
|
713
|
+
flexDirection: "column",
|
|
714
|
+
gap: "24px"
|
|
715
|
+
};
|
|
716
|
+
const accountListContainerStyle = {
|
|
717
|
+
display: "flex",
|
|
718
|
+
flexDirection: "column",
|
|
719
|
+
alignItems: "center",
|
|
720
|
+
gap: "12px",
|
|
721
|
+
padding: "0 32px 24px 32px",
|
|
722
|
+
boxSizing: "border-box",
|
|
723
|
+
width: "100%",
|
|
724
|
+
minWidth: 0
|
|
725
|
+
};
|
|
726
|
+
const disconnectButtonContainerStyle = {
|
|
727
|
+
display: "flex",
|
|
728
|
+
flexDirection: "column",
|
|
729
|
+
alignItems: "center",
|
|
730
|
+
gap: "12px",
|
|
731
|
+
padding: "0 32px 24px 32px",
|
|
732
|
+
boxSizing: "border-box",
|
|
733
|
+
width: "100%",
|
|
734
|
+
minWidth: 0
|
|
471
735
|
};
|
|
472
|
-
return /* @__PURE__ */ (0,
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
/* @__PURE__ */ (0,
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
736
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: contentWrapperStyle, children: [
|
|
737
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_wallet_sdk_ui3.ModalHeader, { title: "Wallet", onClose }),
|
|
738
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: accountListContainerStyle, children: [
|
|
739
|
+
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" }) }),
|
|
740
|
+
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: [
|
|
741
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_wallet_sdk_ui3.Text, { variant: "label", color: theme.secondary, style: { textTransform: "uppercase" }, children: account.addressType }),
|
|
742
|
+
/* @__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 }) })
|
|
743
|
+
] }, index)) })
|
|
744
|
+
] }),
|
|
745
|
+
/* @__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" }) }) })
|
|
479
746
|
] });
|
|
480
747
|
}
|
|
481
748
|
|
|
482
749
|
// src/ModalProvider.tsx
|
|
483
|
-
var
|
|
750
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
484
751
|
function ModalProvider({ children, appIcon, appName }) {
|
|
485
752
|
const { isConnected } = usePhantom();
|
|
486
|
-
const [isModalOpen, setIsModalOpen] = (0,
|
|
487
|
-
const isMobile = (0,
|
|
488
|
-
const openModal = (0,
|
|
753
|
+
const [isModalOpen, setIsModalOpen] = (0, import_react8.useState)(false);
|
|
754
|
+
const isMobile = (0, import_react8.useMemo)(() => (0, import_browser_sdk4.isMobileDevice)(), []);
|
|
755
|
+
const openModal = (0, import_react8.useCallback)(() => {
|
|
489
756
|
setIsModalOpen(true);
|
|
490
757
|
}, []);
|
|
491
|
-
const closeModal = (0,
|
|
758
|
+
const closeModal = (0, import_react8.useCallback)(() => {
|
|
492
759
|
setIsModalOpen(false);
|
|
493
760
|
}, []);
|
|
494
|
-
const modalContextValue = (0,
|
|
761
|
+
const modalContextValue = (0, import_react8.useMemo)(
|
|
495
762
|
() => ({
|
|
496
763
|
isModalOpen,
|
|
497
764
|
openModal,
|
|
@@ -499,46 +766,35 @@ function ModalProvider({ children, appIcon, appName }) {
|
|
|
499
766
|
}),
|
|
500
767
|
[isModalOpen, openModal, closeModal]
|
|
501
768
|
);
|
|
502
|
-
return /* @__PURE__ */ (0,
|
|
769
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(ModalContext.Provider, { value: modalContextValue, children: [
|
|
503
770
|
children,
|
|
504
|
-
/* @__PURE__ */ (0,
|
|
505
|
-
import_wallet_sdk_ui3.Modal,
|
|
506
|
-
{
|
|
507
|
-
isVisible: isModalOpen,
|
|
508
|
-
onClose: closeModal,
|
|
509
|
-
appIcon,
|
|
510
|
-
appName,
|
|
511
|
-
isConnected,
|
|
512
|
-
isMobile,
|
|
513
|
-
children: isConnected ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ConnectedModalContent, { onClose: closeModal }) : /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ConnectModalContent, { appIcon, appName, onClose: closeModal })
|
|
514
|
-
}
|
|
515
|
-
)
|
|
771
|
+
/* @__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 }) })
|
|
516
772
|
] });
|
|
517
773
|
}
|
|
518
774
|
|
|
519
775
|
// src/PhantomProvider.tsx
|
|
520
|
-
var
|
|
776
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
521
777
|
function PhantomProvider({ children, config, debugConfig, theme, appIcon, appName }) {
|
|
522
|
-
const memoizedConfig = (0,
|
|
523
|
-
const resolvedTheme = (0,
|
|
524
|
-
const [sdk, setSdk] = (0,
|
|
525
|
-
const [isClient, setIsClient] = (0,
|
|
526
|
-
const [isConnected, setIsConnected] = (0,
|
|
527
|
-
const [isConnecting, setIsConnecting] = (0,
|
|
528
|
-
const [isLoading, setIsLoading] = (0,
|
|
529
|
-
const [connectError, setConnectError] = (0,
|
|
530
|
-
const [addresses, setAddresses] = (0,
|
|
531
|
-
const [user, setUser] = (0,
|
|
532
|
-
(0,
|
|
778
|
+
const memoizedConfig = (0, import_react9.useMemo)(() => config, [config]);
|
|
779
|
+
const resolvedTheme = (0, import_react9.useMemo)(() => (0, import_wallet_sdk_ui5.mergeTheme)(theme || import_wallet_sdk_ui5.darkTheme), [theme]);
|
|
780
|
+
const [sdk, setSdk] = (0, import_react9.useState)(null);
|
|
781
|
+
const [isClient, setIsClient] = (0, import_react9.useState)(false);
|
|
782
|
+
const [isConnected, setIsConnected] = (0, import_react9.useState)(false);
|
|
783
|
+
const [isConnecting, setIsConnecting] = (0, import_react9.useState)(false);
|
|
784
|
+
const [isLoading, setIsLoading] = (0, import_react9.useState)(true);
|
|
785
|
+
const [connectError, setConnectError] = (0, import_react9.useState)(null);
|
|
786
|
+
const [addresses, setAddresses] = (0, import_react9.useState)([]);
|
|
787
|
+
const [user, setUser] = (0, import_react9.useState)(null);
|
|
788
|
+
(0, import_react9.useEffect)(() => {
|
|
533
789
|
setIsClient(true);
|
|
534
790
|
}, []);
|
|
535
|
-
(0,
|
|
791
|
+
(0, import_react9.useEffect)(() => {
|
|
536
792
|
if (!isClient)
|
|
537
793
|
return;
|
|
538
794
|
const sdkInstance = new import_browser_sdk5.BrowserSDK(memoizedConfig);
|
|
539
795
|
setSdk(sdkInstance);
|
|
540
796
|
}, [isClient, memoizedConfig]);
|
|
541
|
-
(0,
|
|
797
|
+
(0, import_react9.useEffect)(() => {
|
|
542
798
|
if (!sdk)
|
|
543
799
|
return;
|
|
544
800
|
const handleConnectStart = () => {
|
|
@@ -585,12 +841,12 @@ function PhantomProvider({ children, config, debugConfig, theme, appIcon, appNam
|
|
|
585
841
|
sdk.off("disconnect", handleDisconnect);
|
|
586
842
|
};
|
|
587
843
|
}, [sdk]);
|
|
588
|
-
(0,
|
|
844
|
+
(0, import_react9.useEffect)(() => {
|
|
589
845
|
if (!debugConfig || !sdk)
|
|
590
846
|
return;
|
|
591
847
|
sdk.configureDebug(debugConfig);
|
|
592
848
|
}, [sdk, debugConfig]);
|
|
593
|
-
(0,
|
|
849
|
+
(0, import_react9.useEffect)(() => {
|
|
594
850
|
if (!isClient || !sdk)
|
|
595
851
|
return;
|
|
596
852
|
const initialize = async () => {
|
|
@@ -603,7 +859,7 @@ function PhantomProvider({ children, config, debugConfig, theme, appIcon, appNam
|
|
|
603
859
|
};
|
|
604
860
|
initialize();
|
|
605
861
|
}, [sdk, isClient]);
|
|
606
|
-
const value = (0,
|
|
862
|
+
const value = (0, import_react9.useMemo)(
|
|
607
863
|
() => ({
|
|
608
864
|
sdk,
|
|
609
865
|
isConnected,
|
|
@@ -629,7 +885,7 @@ function PhantomProvider({ children, config, debugConfig, theme, appIcon, appNam
|
|
|
629
885
|
memoizedConfig.providers
|
|
630
886
|
]
|
|
631
887
|
);
|
|
632
|
-
return /* @__PURE__ */ (0,
|
|
888
|
+
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 }) }) });
|
|
633
889
|
}
|
|
634
890
|
|
|
635
891
|
// src/hooks/useAccounts.ts
|
|
@@ -639,15 +895,15 @@ function useAccounts() {
|
|
|
639
895
|
}
|
|
640
896
|
|
|
641
897
|
// src/hooks/useAutoConfirm.ts
|
|
642
|
-
var
|
|
898
|
+
var import_react10 = require("react");
|
|
643
899
|
function useAutoConfirm() {
|
|
644
900
|
const { sdk, user } = usePhantom();
|
|
645
|
-
const [status, setStatus] = (0,
|
|
646
|
-
const [supportedChains, setSupportedChains] = (0,
|
|
647
|
-
const [isLoading, setIsLoading] = (0,
|
|
648
|
-
const [error, setError] = (0,
|
|
901
|
+
const [status, setStatus] = (0, import_react10.useState)(null);
|
|
902
|
+
const [supportedChains, setSupportedChains] = (0, import_react10.useState)(null);
|
|
903
|
+
const [isLoading, setIsLoading] = (0, import_react10.useState)(false);
|
|
904
|
+
const [error, setError] = (0, import_react10.useState)(null);
|
|
649
905
|
const isInjected = user?.authProvider === "injected";
|
|
650
|
-
const enable = (0,
|
|
906
|
+
const enable = (0, import_react10.useCallback)(
|
|
651
907
|
async (params) => {
|
|
652
908
|
if (!sdk) {
|
|
653
909
|
throw new Error("SDK not initialized");
|
|
@@ -671,7 +927,7 @@ function useAutoConfirm() {
|
|
|
671
927
|
},
|
|
672
928
|
[sdk, isInjected]
|
|
673
929
|
);
|
|
674
|
-
const disable = (0,
|
|
930
|
+
const disable = (0, import_react10.useCallback)(async () => {
|
|
675
931
|
if (!sdk) {
|
|
676
932
|
throw new Error("SDK not initialized");
|
|
677
933
|
}
|
|
@@ -692,7 +948,7 @@ function useAutoConfirm() {
|
|
|
692
948
|
setIsLoading(false);
|
|
693
949
|
}
|
|
694
950
|
}, [sdk, isInjected]);
|
|
695
|
-
const refetch = (0,
|
|
951
|
+
const refetch = (0, import_react10.useCallback)(async () => {
|
|
696
952
|
if (!sdk || !isInjected) {
|
|
697
953
|
return;
|
|
698
954
|
}
|
|
@@ -712,7 +968,7 @@ function useAutoConfirm() {
|
|
|
712
968
|
setIsLoading(false);
|
|
713
969
|
}
|
|
714
970
|
}, [sdk, isInjected]);
|
|
715
|
-
(0,
|
|
971
|
+
(0, import_react10.useEffect)(() => {
|
|
716
972
|
if (sdk && isInjected) {
|
|
717
973
|
refetch();
|
|
718
974
|
} else {
|
|
@@ -733,53 +989,79 @@ function useAutoConfirm() {
|
|
|
733
989
|
}
|
|
734
990
|
|
|
735
991
|
// src/hooks/useSolana.ts
|
|
992
|
+
var import_browser_sdk6 = require("@phantom/browser-sdk");
|
|
736
993
|
function useSolana() {
|
|
737
|
-
const { sdk,
|
|
738
|
-
if (!isClient || !sdk) {
|
|
994
|
+
const { sdk, isClient, isLoading } = usePhantom();
|
|
995
|
+
if (!isClient || !sdk || isLoading) {
|
|
996
|
+
return {
|
|
997
|
+
solana: {},
|
|
998
|
+
isAvailable: false
|
|
999
|
+
};
|
|
1000
|
+
}
|
|
1001
|
+
const enabledAddressTypes = sdk.getEnabledAddressTypes();
|
|
1002
|
+
const isAvailable = enabledAddressTypes.includes(import_browser_sdk6.AddressType.solana);
|
|
1003
|
+
if (!isAvailable) {
|
|
1004
|
+
return {
|
|
1005
|
+
solana: {},
|
|
1006
|
+
isAvailable: false
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
1009
|
+
try {
|
|
1010
|
+
return {
|
|
1011
|
+
solana: sdk.solana,
|
|
1012
|
+
isAvailable: true
|
|
1013
|
+
};
|
|
1014
|
+
} catch (error) {
|
|
739
1015
|
return {
|
|
740
1016
|
solana: {},
|
|
741
|
-
// This will be replaced when SDK is ready
|
|
742
1017
|
isAvailable: false
|
|
743
1018
|
};
|
|
744
1019
|
}
|
|
745
|
-
return {
|
|
746
|
-
// Chain instance with connection enforcement for signing methods
|
|
747
|
-
solana: sdk.solana,
|
|
748
|
-
// State
|
|
749
|
-
isAvailable: !!isConnected
|
|
750
|
-
};
|
|
751
1020
|
}
|
|
752
1021
|
|
|
753
1022
|
// src/hooks/useEthereum.ts
|
|
1023
|
+
var import_browser_sdk7 = require("@phantom/browser-sdk");
|
|
754
1024
|
function useEthereum() {
|
|
755
|
-
const { sdk,
|
|
756
|
-
if (!isClient || !sdk) {
|
|
1025
|
+
const { sdk, isClient, isLoading } = usePhantom();
|
|
1026
|
+
if (!isClient || !sdk || isLoading) {
|
|
1027
|
+
return {
|
|
1028
|
+
ethereum: {},
|
|
1029
|
+
isAvailable: false
|
|
1030
|
+
};
|
|
1031
|
+
}
|
|
1032
|
+
const enabledAddressTypes = sdk.getEnabledAddressTypes();
|
|
1033
|
+
const isAvailable = enabledAddressTypes.includes(import_browser_sdk7.AddressType.ethereum);
|
|
1034
|
+
if (!isAvailable) {
|
|
1035
|
+
return {
|
|
1036
|
+
ethereum: {},
|
|
1037
|
+
isAvailable: false
|
|
1038
|
+
};
|
|
1039
|
+
}
|
|
1040
|
+
try {
|
|
1041
|
+
return {
|
|
1042
|
+
ethereum: sdk.ethereum,
|
|
1043
|
+
isAvailable: true
|
|
1044
|
+
};
|
|
1045
|
+
} catch (error) {
|
|
757
1046
|
return {
|
|
758
1047
|
ethereum: {},
|
|
759
|
-
// This will be replaced when SDK is ready
|
|
760
1048
|
isAvailable: false
|
|
761
1049
|
};
|
|
762
1050
|
}
|
|
763
|
-
return {
|
|
764
|
-
// Chain instance with connection enforcement for signing methods
|
|
765
|
-
ethereum: sdk.ethereum,
|
|
766
|
-
// State
|
|
767
|
-
isAvailable: !!isConnected
|
|
768
|
-
};
|
|
769
1051
|
}
|
|
770
1052
|
|
|
771
1053
|
// src/hooks/index.ts
|
|
772
|
-
var
|
|
1054
|
+
var import_wallet_sdk_ui6 = require("@phantom/wallet-sdk-ui");
|
|
773
1055
|
|
|
774
1056
|
// src/components/ConnectButton.tsx
|
|
775
|
-
var
|
|
776
|
-
var
|
|
777
|
-
var
|
|
1057
|
+
var import_react11 = require("react");
|
|
1058
|
+
var import_wallet_sdk_ui7 = require("@phantom/wallet-sdk-ui");
|
|
1059
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
778
1060
|
function ConnectButton({ addressType, fullWidth = false }) {
|
|
779
|
-
const theme = (0,
|
|
1061
|
+
const theme = (0, import_wallet_sdk_ui7.useTheme)();
|
|
780
1062
|
const { open } = useModal();
|
|
781
1063
|
const { isConnected, addresses } = usePhantom();
|
|
782
|
-
const displayAddress = (0,
|
|
1064
|
+
const displayAddress = (0, import_react11.useMemo)(() => {
|
|
783
1065
|
if (!addresses || addresses.length === 0)
|
|
784
1066
|
return null;
|
|
785
1067
|
if (addressType) {
|
|
@@ -787,7 +1069,7 @@ function ConnectButton({ addressType, fullWidth = false }) {
|
|
|
787
1069
|
}
|
|
788
1070
|
return addresses[0];
|
|
789
1071
|
}, [addresses, addressType]);
|
|
790
|
-
const truncatedAddress = (0,
|
|
1072
|
+
const truncatedAddress = (0, import_react11.useMemo)(() => {
|
|
791
1073
|
if (!displayAddress)
|
|
792
1074
|
return "";
|
|
793
1075
|
const addr = displayAddress.address;
|
|
@@ -821,11 +1103,11 @@ function ConnectButton({ addressType, fullWidth = false }) {
|
|
|
821
1103
|
cursor: "pointer"
|
|
822
1104
|
};
|
|
823
1105
|
if (isConnected && displayAddress) {
|
|
824
|
-
return /* @__PURE__ */ (0,
|
|
1106
|
+
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 }) });
|
|
825
1107
|
}
|
|
826
|
-
return /* @__PURE__ */ (0,
|
|
1108
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { style: buttonStyle, onClick: open, children: "Connect Wallet" });
|
|
827
1109
|
}
|
|
828
1110
|
|
|
829
1111
|
// src/index.ts
|
|
830
|
-
var
|
|
831
|
-
var
|
|
1112
|
+
var import_wallet_sdk_ui8 = require("@phantom/wallet-sdk-ui");
|
|
1113
|
+
var import_browser_sdk8 = require("@phantom/browser-sdk");
|