@phantom/react-sdk 1.0.0-beta.22 → 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/README.md +73 -5
- package/dist/index.d.ts +14 -6
- package/dist/index.js +494 -199
- package/dist/index.mjs +482 -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,227 @@ 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.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"
|
|
345
540
|
}
|
|
346
541
|
),
|
|
347
|
-
allowedProviders.includes("
|
|
348
|
-
|
|
542
|
+
!isMobile && allowedProviders.includes("phantom") && isPhantomLoginAvailable2.isAvailable && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
543
|
+
import_wallet_sdk_ui2.LoginWithPhantomButton,
|
|
349
544
|
{
|
|
350
|
-
onClick: () => connectWithAuthProvider("
|
|
545
|
+
onClick: () => connectWithAuthProvider("phantom"),
|
|
351
546
|
disabled: isConnecting,
|
|
352
|
-
isLoading: isConnecting && providerType === "
|
|
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",
|
|
353
556
|
fullWidth: true,
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
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
|
+
] })
|
|
359
564
|
}
|
|
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,
|
|
565
|
+
),
|
|
566
|
+
allowedProviders.includes("apple") && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
567
|
+
import_wallet_sdk_ui2.Button,
|
|
370
568
|
{
|
|
371
|
-
onClick: () => connectWithAuthProvider("
|
|
569
|
+
onClick: () => connectWithAuthProvider("apple"),
|
|
372
570
|
disabled: isConnecting,
|
|
373
|
-
isLoading: isConnecting && providerType === "
|
|
571
|
+
isLoading: isConnecting && providerType === "apple",
|
|
374
572
|
fullWidth: true,
|
|
375
|
-
children: /* @__PURE__ */ (0,
|
|
376
|
-
/* @__PURE__ */ (0,
|
|
377
|
-
/* @__PURE__ */ (0,
|
|
378
|
-
/* @__PURE__ */ (0,
|
|
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" })
|
|
379
577
|
] }),
|
|
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
|
-
] })
|
|
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 }) })
|
|
384
579
|
] })
|
|
385
580
|
}
|
|
386
|
-
)
|
|
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" })
|
|
387
631
|
] })
|
|
388
632
|
] })
|
|
389
633
|
] });
|
|
390
634
|
}
|
|
391
635
|
|
|
392
636
|
// src/components/ConnectedModalContent.tsx
|
|
393
|
-
var
|
|
394
|
-
var
|
|
637
|
+
var import_react7 = require("react");
|
|
638
|
+
var import_wallet_sdk_ui3 = require("@phantom/wallet-sdk-ui");
|
|
395
639
|
|
|
396
640
|
// src/hooks/useDisconnect.ts
|
|
397
|
-
var
|
|
641
|
+
var import_react6 = require("react");
|
|
398
642
|
function useDisconnect() {
|
|
399
643
|
const { sdk } = usePhantom();
|
|
400
|
-
const [isDisconnecting, setIsDisconnecting] = (0,
|
|
401
|
-
const [error, setError] = (0,
|
|
402
|
-
const disconnect = (0,
|
|
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 () => {
|
|
403
647
|
if (!sdk) {
|
|
404
648
|
throw new Error("SDK not initialized");
|
|
405
649
|
}
|
|
@@ -423,14 +667,14 @@ function useDisconnect() {
|
|
|
423
667
|
}
|
|
424
668
|
|
|
425
669
|
// src/components/ConnectedModalContent.tsx
|
|
426
|
-
var
|
|
670
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
427
671
|
function ConnectedModalContent({ onClose }) {
|
|
428
|
-
const theme = (0,
|
|
672
|
+
const theme = (0, import_wallet_sdk_ui3.useTheme)();
|
|
429
673
|
const { addresses } = usePhantom();
|
|
430
674
|
const { disconnect } = useDisconnect();
|
|
431
|
-
const [isDisconnecting, setIsDisconnecting] = (0,
|
|
432
|
-
const [disconnectError, setDisconnectError] = (0,
|
|
433
|
-
(0,
|
|
675
|
+
const [isDisconnecting, setIsDisconnecting] = (0, import_react7.useState)(false);
|
|
676
|
+
const [disconnectError, setDisconnectError] = (0, import_react7.useState)(null);
|
|
677
|
+
(0, import_react7.useEffect)(() => {
|
|
434
678
|
setDisconnectError(null);
|
|
435
679
|
}, []);
|
|
436
680
|
const handleDisconnect = async () => {
|
|
@@ -450,48 +694,84 @@ function ConnectedModalContent({ onClose }) {
|
|
|
450
694
|
display: "flex",
|
|
451
695
|
flexDirection: "column",
|
|
452
696
|
gap: "16px",
|
|
453
|
-
width: "100%"
|
|
697
|
+
width: "100%",
|
|
698
|
+
minWidth: 0,
|
|
699
|
+
boxSizing: "border-box"
|
|
454
700
|
};
|
|
455
701
|
const accountItemStyle = {
|
|
456
702
|
display: "flex",
|
|
457
703
|
flexDirection: "column",
|
|
458
704
|
gap: "8px",
|
|
459
|
-
width: "100%"
|
|
705
|
+
width: "100%",
|
|
706
|
+
minWidth: 0,
|
|
707
|
+
boxSizing: "border-box"
|
|
460
708
|
};
|
|
461
709
|
const addressTextStyle = {
|
|
462
710
|
fontFamily: "monospace",
|
|
463
|
-
wordBreak: "break-all"
|
|
711
|
+
wordBreak: "break-all",
|
|
712
|
+
overflowWrap: "break-word",
|
|
713
|
+
minWidth: 0
|
|
464
714
|
};
|
|
465
715
|
const errorContainerStyle = {
|
|
466
716
|
padding: "12px",
|
|
467
717
|
backgroundColor: "rgba(220, 53, 69, 0.1)",
|
|
468
718
|
borderRadius: theme.borderRadius,
|
|
469
719
|
border: "1px solid rgba(220, 53, 69, 0.3)",
|
|
470
|
-
width: "100%"
|
|
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
|
|
471
748
|
};
|
|
472
|
-
return /* @__PURE__ */ (0,
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
/* @__PURE__ */ (0,
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
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" }) }) })
|
|
479
759
|
] });
|
|
480
760
|
}
|
|
481
761
|
|
|
482
762
|
// src/ModalProvider.tsx
|
|
483
|
-
var
|
|
763
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
484
764
|
function ModalProvider({ children, appIcon, appName }) {
|
|
485
765
|
const { isConnected } = usePhantom();
|
|
486
|
-
const [isModalOpen, setIsModalOpen] = (0,
|
|
487
|
-
const isMobile = (0,
|
|
488
|
-
const openModal = (0,
|
|
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)(() => {
|
|
489
769
|
setIsModalOpen(true);
|
|
490
770
|
}, []);
|
|
491
|
-
const closeModal = (0,
|
|
771
|
+
const closeModal = (0, import_react8.useCallback)(() => {
|
|
492
772
|
setIsModalOpen(false);
|
|
493
773
|
}, []);
|
|
494
|
-
const modalContextValue = (0,
|
|
774
|
+
const modalContextValue = (0, import_react8.useMemo)(
|
|
495
775
|
() => ({
|
|
496
776
|
isModalOpen,
|
|
497
777
|
openModal,
|
|
@@ -499,46 +779,35 @@ function ModalProvider({ children, appIcon, appName }) {
|
|
|
499
779
|
}),
|
|
500
780
|
[isModalOpen, openModal, closeModal]
|
|
501
781
|
);
|
|
502
|
-
return /* @__PURE__ */ (0,
|
|
782
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(ModalContext.Provider, { value: modalContextValue, children: [
|
|
503
783
|
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
|
-
)
|
|
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 }) })
|
|
516
785
|
] });
|
|
517
786
|
}
|
|
518
787
|
|
|
519
788
|
// src/PhantomProvider.tsx
|
|
520
|
-
var
|
|
789
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
521
790
|
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,
|
|
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)(() => {
|
|
533
802
|
setIsClient(true);
|
|
534
803
|
}, []);
|
|
535
|
-
(0,
|
|
804
|
+
(0, import_react9.useEffect)(() => {
|
|
536
805
|
if (!isClient)
|
|
537
806
|
return;
|
|
538
807
|
const sdkInstance = new import_browser_sdk5.BrowserSDK(memoizedConfig);
|
|
539
808
|
setSdk(sdkInstance);
|
|
540
809
|
}, [isClient, memoizedConfig]);
|
|
541
|
-
(0,
|
|
810
|
+
(0, import_react9.useEffect)(() => {
|
|
542
811
|
if (!sdk)
|
|
543
812
|
return;
|
|
544
813
|
const handleConnectStart = () => {
|
|
@@ -585,12 +854,12 @@ function PhantomProvider({ children, config, debugConfig, theme, appIcon, appNam
|
|
|
585
854
|
sdk.off("disconnect", handleDisconnect);
|
|
586
855
|
};
|
|
587
856
|
}, [sdk]);
|
|
588
|
-
(0,
|
|
857
|
+
(0, import_react9.useEffect)(() => {
|
|
589
858
|
if (!debugConfig || !sdk)
|
|
590
859
|
return;
|
|
591
860
|
sdk.configureDebug(debugConfig);
|
|
592
861
|
}, [sdk, debugConfig]);
|
|
593
|
-
(0,
|
|
862
|
+
(0, import_react9.useEffect)(() => {
|
|
594
863
|
if (!isClient || !sdk)
|
|
595
864
|
return;
|
|
596
865
|
const initialize = async () => {
|
|
@@ -603,7 +872,7 @@ function PhantomProvider({ children, config, debugConfig, theme, appIcon, appNam
|
|
|
603
872
|
};
|
|
604
873
|
initialize();
|
|
605
874
|
}, [sdk, isClient]);
|
|
606
|
-
const value = (0,
|
|
875
|
+
const value = (0, import_react9.useMemo)(
|
|
607
876
|
() => ({
|
|
608
877
|
sdk,
|
|
609
878
|
isConnected,
|
|
@@ -629,7 +898,7 @@ function PhantomProvider({ children, config, debugConfig, theme, appIcon, appNam
|
|
|
629
898
|
memoizedConfig.providers
|
|
630
899
|
]
|
|
631
900
|
);
|
|
632
|
-
return /* @__PURE__ */ (0,
|
|
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 }) }) });
|
|
633
902
|
}
|
|
634
903
|
|
|
635
904
|
// src/hooks/useAccounts.ts
|
|
@@ -639,15 +908,15 @@ function useAccounts() {
|
|
|
639
908
|
}
|
|
640
909
|
|
|
641
910
|
// src/hooks/useAutoConfirm.ts
|
|
642
|
-
var
|
|
911
|
+
var import_react10 = require("react");
|
|
643
912
|
function useAutoConfirm() {
|
|
644
913
|
const { sdk, user } = usePhantom();
|
|
645
|
-
const [status, setStatus] = (0,
|
|
646
|
-
const [supportedChains, setSupportedChains] = (0,
|
|
647
|
-
const [isLoading, setIsLoading] = (0,
|
|
648
|
-
const [error, setError] = (0,
|
|
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);
|
|
649
918
|
const isInjected = user?.authProvider === "injected";
|
|
650
|
-
const enable = (0,
|
|
919
|
+
const enable = (0, import_react10.useCallback)(
|
|
651
920
|
async (params) => {
|
|
652
921
|
if (!sdk) {
|
|
653
922
|
throw new Error("SDK not initialized");
|
|
@@ -671,7 +940,7 @@ function useAutoConfirm() {
|
|
|
671
940
|
},
|
|
672
941
|
[sdk, isInjected]
|
|
673
942
|
);
|
|
674
|
-
const disable = (0,
|
|
943
|
+
const disable = (0, import_react10.useCallback)(async () => {
|
|
675
944
|
if (!sdk) {
|
|
676
945
|
throw new Error("SDK not initialized");
|
|
677
946
|
}
|
|
@@ -692,7 +961,7 @@ function useAutoConfirm() {
|
|
|
692
961
|
setIsLoading(false);
|
|
693
962
|
}
|
|
694
963
|
}, [sdk, isInjected]);
|
|
695
|
-
const refetch = (0,
|
|
964
|
+
const refetch = (0, import_react10.useCallback)(async () => {
|
|
696
965
|
if (!sdk || !isInjected) {
|
|
697
966
|
return;
|
|
698
967
|
}
|
|
@@ -712,7 +981,7 @@ function useAutoConfirm() {
|
|
|
712
981
|
setIsLoading(false);
|
|
713
982
|
}
|
|
714
983
|
}, [sdk, isInjected]);
|
|
715
|
-
(0,
|
|
984
|
+
(0, import_react10.useEffect)(() => {
|
|
716
985
|
if (sdk && isInjected) {
|
|
717
986
|
refetch();
|
|
718
987
|
} else {
|
|
@@ -733,53 +1002,79 @@ function useAutoConfirm() {
|
|
|
733
1002
|
}
|
|
734
1003
|
|
|
735
1004
|
// src/hooks/useSolana.ts
|
|
1005
|
+
var import_browser_sdk6 = require("@phantom/browser-sdk");
|
|
736
1006
|
function useSolana() {
|
|
737
|
-
const { sdk,
|
|
738
|
-
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) {
|
|
739
1028
|
return {
|
|
740
1029
|
solana: {},
|
|
741
|
-
// This will be replaced when SDK is ready
|
|
742
1030
|
isAvailable: false
|
|
743
1031
|
};
|
|
744
1032
|
}
|
|
745
|
-
return {
|
|
746
|
-
// Chain instance with connection enforcement for signing methods
|
|
747
|
-
solana: sdk.solana,
|
|
748
|
-
// State
|
|
749
|
-
isAvailable: !!isConnected
|
|
750
|
-
};
|
|
751
1033
|
}
|
|
752
1034
|
|
|
753
1035
|
// src/hooks/useEthereum.ts
|
|
1036
|
+
var import_browser_sdk7 = require("@phantom/browser-sdk");
|
|
754
1037
|
function useEthereum() {
|
|
755
|
-
const { sdk,
|
|
756
|
-
if (!isClient || !sdk) {
|
|
1038
|
+
const { sdk, isClient, isLoading } = usePhantom();
|
|
1039
|
+
if (!isClient || !sdk || isLoading) {
|
|
1040
|
+
return {
|
|
1041
|
+
ethereum: {},
|
|
1042
|
+
isAvailable: false
|
|
1043
|
+
};
|
|
1044
|
+
}
|
|
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) {
|
|
757
1059
|
return {
|
|
758
1060
|
ethereum: {},
|
|
759
|
-
// This will be replaced when SDK is ready
|
|
760
1061
|
isAvailable: false
|
|
761
1062
|
};
|
|
762
1063
|
}
|
|
763
|
-
return {
|
|
764
|
-
// Chain instance with connection enforcement for signing methods
|
|
765
|
-
ethereum: sdk.ethereum,
|
|
766
|
-
// State
|
|
767
|
-
isAvailable: !!isConnected
|
|
768
|
-
};
|
|
769
1064
|
}
|
|
770
1065
|
|
|
771
1066
|
// src/hooks/index.ts
|
|
772
|
-
var
|
|
1067
|
+
var import_wallet_sdk_ui6 = require("@phantom/wallet-sdk-ui");
|
|
773
1068
|
|
|
774
1069
|
// src/components/ConnectButton.tsx
|
|
775
|
-
var
|
|
776
|
-
var
|
|
777
|
-
var
|
|
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");
|
|
778
1073
|
function ConnectButton({ addressType, fullWidth = false }) {
|
|
779
|
-
const theme = (0,
|
|
1074
|
+
const theme = (0, import_wallet_sdk_ui7.useTheme)();
|
|
780
1075
|
const { open } = useModal();
|
|
781
1076
|
const { isConnected, addresses } = usePhantom();
|
|
782
|
-
const displayAddress = (0,
|
|
1077
|
+
const displayAddress = (0, import_react11.useMemo)(() => {
|
|
783
1078
|
if (!addresses || addresses.length === 0)
|
|
784
1079
|
return null;
|
|
785
1080
|
if (addressType) {
|
|
@@ -787,7 +1082,7 @@ function ConnectButton({ addressType, fullWidth = false }) {
|
|
|
787
1082
|
}
|
|
788
1083
|
return addresses[0];
|
|
789
1084
|
}, [addresses, addressType]);
|
|
790
|
-
const truncatedAddress = (0,
|
|
1085
|
+
const truncatedAddress = (0, import_react11.useMemo)(() => {
|
|
791
1086
|
if (!displayAddress)
|
|
792
1087
|
return "";
|
|
793
1088
|
const addr = displayAddress.address;
|
|
@@ -821,11 +1116,11 @@ function ConnectButton({ addressType, fullWidth = false }) {
|
|
|
821
1116
|
cursor: "pointer"
|
|
822
1117
|
};
|
|
823
1118
|
if (isConnected && displayAddress) {
|
|
824
|
-
return /* @__PURE__ */ (0,
|
|
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 }) });
|
|
825
1120
|
}
|
|
826
|
-
return /* @__PURE__ */ (0,
|
|
1121
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("button", { style: buttonStyle, onClick: open, children: "Connect Wallet" });
|
|
827
1122
|
}
|
|
828
1123
|
|
|
829
1124
|
// src/index.ts
|
|
830
|
-
var
|
|
831
|
-
var
|
|
1125
|
+
var import_wallet_sdk_ui8 = require("@phantom/wallet-sdk-ui");
|
|
1126
|
+
var import_browser_sdk8 = require("@phantom/browser-sdk");
|