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