@phantom/react-sdk 1.0.0-beta.8 → 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 -179
- package/dist/index.mjs +975 -176
- package/package.json +13 -6
package/dist/index.js
CHANGED
|
@@ -30,69 +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
|
-
return () => {
|
|
76
|
-
sdkInstance.disconnect().catch(() => {
|
|
77
|
-
});
|
|
78
|
-
};
|
|
79
830
|
}, [isClient, memoizedConfig]);
|
|
80
|
-
(0,
|
|
831
|
+
(0, import_react9.useEffect)(() => {
|
|
81
832
|
if (!sdk)
|
|
82
833
|
return;
|
|
83
834
|
const handleConnectStart = () => {
|
|
84
835
|
setIsConnecting(true);
|
|
85
|
-
|
|
836
|
+
setErrors((prev) => ({ ...prev, connect: void 0 }));
|
|
86
837
|
};
|
|
87
|
-
const handleConnect = async () => {
|
|
838
|
+
const handleConnect = async (data) => {
|
|
88
839
|
try {
|
|
89
840
|
setIsConnected(true);
|
|
90
841
|
setIsConnecting(false);
|
|
91
|
-
|
|
92
|
-
setCurrentProviderType(providerInfo?.type || null);
|
|
842
|
+
setUser(data);
|
|
93
843
|
const addrs = await sdk.getAddresses();
|
|
94
844
|
setAddresses(addrs);
|
|
95
|
-
setWalletId(sdk.getWalletId());
|
|
96
845
|
} catch (err) {
|
|
97
846
|
console.error("Error connecting:", err);
|
|
98
847
|
try {
|
|
@@ -105,127 +854,91 @@ function PhantomProvider({ children, config, debugConfig }) {
|
|
|
105
854
|
const handleConnectError = (errorData) => {
|
|
106
855
|
setIsConnecting(false);
|
|
107
856
|
setIsConnected(false);
|
|
108
|
-
|
|
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([]);
|
|
109
864
|
};
|
|
110
865
|
const handleDisconnect = () => {
|
|
111
866
|
setIsConnected(false);
|
|
112
867
|
setIsConnecting(false);
|
|
113
|
-
|
|
868
|
+
setErrors({});
|
|
114
869
|
setAddresses([]);
|
|
115
|
-
|
|
870
|
+
setUser(null);
|
|
871
|
+
};
|
|
872
|
+
const handleSpendingLimitReached = () => {
|
|
873
|
+
setErrors((prev) => ({ ...prev, spendingLimit: true }));
|
|
116
874
|
};
|
|
117
875
|
sdk.on("connect_start", handleConnectStart);
|
|
118
876
|
sdk.on("connect", handleConnect);
|
|
119
877
|
sdk.on("connect_error", handleConnectError);
|
|
120
878
|
sdk.on("disconnect", handleDisconnect);
|
|
879
|
+
sdk.on("spending_limit_reached", handleSpendingLimitReached);
|
|
121
880
|
return () => {
|
|
122
881
|
sdk.off("connect_start", handleConnectStart);
|
|
123
882
|
sdk.off("connect", handleConnect);
|
|
124
883
|
sdk.off("connect_error", handleConnectError);
|
|
125
884
|
sdk.off("disconnect", handleDisconnect);
|
|
885
|
+
sdk.off("spending_limit_reached", handleSpendingLimitReached);
|
|
126
886
|
};
|
|
127
887
|
}, [sdk]);
|
|
128
|
-
(0,
|
|
888
|
+
(0, import_react9.useEffect)(() => {
|
|
129
889
|
if (!debugConfig || !sdk)
|
|
130
890
|
return;
|
|
131
891
|
sdk.configureDebug(debugConfig);
|
|
132
892
|
}, [sdk, debugConfig]);
|
|
133
|
-
(0,
|
|
893
|
+
(0, import_react9.useEffect)(() => {
|
|
134
894
|
if (!isClient || !sdk)
|
|
135
895
|
return;
|
|
136
896
|
const initialize = async () => {
|
|
137
897
|
try {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
console.error("Error checking Phantom extension:", err);
|
|
142
|
-
setIsPhantomAvailable(false);
|
|
143
|
-
}
|
|
144
|
-
if (memoizedConfig.autoConnect !== false) {
|
|
145
|
-
sdk.autoConnect().catch(() => {
|
|
146
|
-
});
|
|
898
|
+
await sdk.autoConnect();
|
|
899
|
+
} catch (error) {
|
|
900
|
+
console.error("Auto-connect error:", error);
|
|
147
901
|
}
|
|
902
|
+
setIsLoading(false);
|
|
148
903
|
};
|
|
149
904
|
initialize();
|
|
150
|
-
}, [sdk,
|
|
151
|
-
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)(
|
|
152
914
|
() => ({
|
|
153
915
|
sdk,
|
|
154
916
|
isConnected,
|
|
155
917
|
isConnecting,
|
|
156
|
-
|
|
918
|
+
isLoading,
|
|
919
|
+
errors,
|
|
157
920
|
addresses,
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
921
|
+
isClient,
|
|
922
|
+
user,
|
|
923
|
+
theme: resolvedTheme,
|
|
924
|
+
allowedProviders: memoizedConfig.providers,
|
|
925
|
+
clearError
|
|
162
926
|
}),
|
|
163
|
-
[
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
var import_react2 = require("react");
|
|
177
|
-
function useConnect() {
|
|
178
|
-
const { sdk, isConnecting, connectError, currentProviderType, isPhantomAvailable } = usePhantom();
|
|
179
|
-
const connect = (0, import_react2.useCallback)(
|
|
180
|
-
async (options) => {
|
|
181
|
-
if (!sdk) {
|
|
182
|
-
throw new Error("SDK not initialized");
|
|
183
|
-
}
|
|
184
|
-
try {
|
|
185
|
-
const result = await sdk.connect(options);
|
|
186
|
-
return result;
|
|
187
|
-
} catch (err) {
|
|
188
|
-
console.error("Error connecting to Phantom:", err);
|
|
189
|
-
throw err;
|
|
190
|
-
}
|
|
191
|
-
},
|
|
192
|
-
[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
|
+
]
|
|
193
940
|
);
|
|
194
|
-
return {
|
|
195
|
-
connect,
|
|
196
|
-
isConnecting,
|
|
197
|
-
error: connectError,
|
|
198
|
-
currentProviderType,
|
|
199
|
-
isPhantomAvailable
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// src/hooks/useDisconnect.ts
|
|
204
|
-
var import_react3 = require("react");
|
|
205
|
-
function useDisconnect() {
|
|
206
|
-
const { sdk } = usePhantom();
|
|
207
|
-
const [isDisconnecting, setIsDisconnecting] = (0, import_react3.useState)(false);
|
|
208
|
-
const [error, setError] = (0, import_react3.useState)(null);
|
|
209
|
-
const disconnect = (0, import_react3.useCallback)(async () => {
|
|
210
|
-
if (!sdk) {
|
|
211
|
-
throw new Error("SDK not initialized");
|
|
212
|
-
}
|
|
213
|
-
setIsDisconnecting(true);
|
|
214
|
-
setError(null);
|
|
215
|
-
try {
|
|
216
|
-
await sdk.disconnect();
|
|
217
|
-
} catch (err) {
|
|
218
|
-
setError(err);
|
|
219
|
-
throw err;
|
|
220
|
-
} finally {
|
|
221
|
-
setIsDisconnecting(false);
|
|
222
|
-
}
|
|
223
|
-
}, [sdk]);
|
|
224
|
-
return {
|
|
225
|
-
disconnect,
|
|
226
|
-
isDisconnecting,
|
|
227
|
-
error
|
|
228
|
-
};
|
|
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 }) }) });
|
|
229
942
|
}
|
|
230
943
|
|
|
231
944
|
// src/hooks/useAccounts.ts
|
|
@@ -234,49 +947,16 @@ function useAccounts() {
|
|
|
234
947
|
return isConnected ? addresses : null;
|
|
235
948
|
}
|
|
236
949
|
|
|
237
|
-
// src/hooks/useIsExtensionInstalled.ts
|
|
238
|
-
var React = __toESM(require("react"));
|
|
239
|
-
var import_browser_sdk2 = require("@phantom/browser-sdk");
|
|
240
|
-
function useIsExtensionInstalled() {
|
|
241
|
-
const [isLoading, setIsLoading] = React.useState(true);
|
|
242
|
-
const [isInstalled, setIsInstalled] = React.useState(false);
|
|
243
|
-
React.useEffect(() => {
|
|
244
|
-
let isMounted = true;
|
|
245
|
-
const checkExtension = async () => {
|
|
246
|
-
try {
|
|
247
|
-
setIsLoading(true);
|
|
248
|
-
const result = await (0, import_browser_sdk2.waitForPhantomExtension)(3e3);
|
|
249
|
-
if (isMounted) {
|
|
250
|
-
setIsInstalled(result);
|
|
251
|
-
}
|
|
252
|
-
} catch (error) {
|
|
253
|
-
if (isMounted) {
|
|
254
|
-
setIsInstalled(false);
|
|
255
|
-
}
|
|
256
|
-
} finally {
|
|
257
|
-
if (isMounted) {
|
|
258
|
-
setIsLoading(false);
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
};
|
|
262
|
-
checkExtension();
|
|
263
|
-
return () => {
|
|
264
|
-
isMounted = false;
|
|
265
|
-
};
|
|
266
|
-
}, []);
|
|
267
|
-
return { isLoading, isInstalled };
|
|
268
|
-
}
|
|
269
|
-
|
|
270
950
|
// src/hooks/useAutoConfirm.ts
|
|
271
|
-
var
|
|
951
|
+
var import_react10 = require("react");
|
|
272
952
|
function useAutoConfirm() {
|
|
273
|
-
const { sdk,
|
|
274
|
-
const [status, setStatus] = (0,
|
|
275
|
-
const [supportedChains, setSupportedChains] = (0,
|
|
276
|
-
const [isLoading, setIsLoading] = (0,
|
|
277
|
-
const [error, setError] = (0,
|
|
278
|
-
const isInjected =
|
|
279
|
-
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)(
|
|
280
960
|
async (params) => {
|
|
281
961
|
if (!sdk) {
|
|
282
962
|
throw new Error("SDK not initialized");
|
|
@@ -300,7 +980,7 @@ function useAutoConfirm() {
|
|
|
300
980
|
},
|
|
301
981
|
[sdk, isInjected]
|
|
302
982
|
);
|
|
303
|
-
const disable = (0,
|
|
983
|
+
const disable = (0, import_react10.useCallback)(async () => {
|
|
304
984
|
if (!sdk) {
|
|
305
985
|
throw new Error("SDK not initialized");
|
|
306
986
|
}
|
|
@@ -321,7 +1001,7 @@ function useAutoConfirm() {
|
|
|
321
1001
|
setIsLoading(false);
|
|
322
1002
|
}
|
|
323
1003
|
}, [sdk, isInjected]);
|
|
324
|
-
const refetch = (0,
|
|
1004
|
+
const refetch = (0, import_react10.useCallback)(async () => {
|
|
325
1005
|
if (!sdk || !isInjected) {
|
|
326
1006
|
return;
|
|
327
1007
|
}
|
|
@@ -341,7 +1021,7 @@ function useAutoConfirm() {
|
|
|
341
1021
|
setIsLoading(false);
|
|
342
1022
|
}
|
|
343
1023
|
}, [sdk, isInjected]);
|
|
344
|
-
(0,
|
|
1024
|
+
(0, import_react10.useEffect)(() => {
|
|
345
1025
|
if (sdk && isInjected) {
|
|
346
1026
|
refetch();
|
|
347
1027
|
} else {
|
|
@@ -362,40 +1042,150 @@ function useAutoConfirm() {
|
|
|
362
1042
|
}
|
|
363
1043
|
|
|
364
1044
|
// src/hooks/useSolana.ts
|
|
1045
|
+
var import_browser_sdk6 = require("@phantom/browser-sdk");
|
|
365
1046
|
function useSolana() {
|
|
366
|
-
const { sdk,
|
|
367
|
-
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) {
|
|
368
1068
|
return {
|
|
369
1069
|
solana: {},
|
|
370
|
-
// This will be replaced when SDK is ready
|
|
371
1070
|
isAvailable: false
|
|
372
1071
|
};
|
|
373
1072
|
}
|
|
374
|
-
return {
|
|
375
|
-
// Chain instance with connection enforcement for signing methods
|
|
376
|
-
solana: sdk.solana,
|
|
377
|
-
// State
|
|
378
|
-
isAvailable: !!isConnected
|
|
379
|
-
};
|
|
380
1073
|
}
|
|
381
1074
|
|
|
382
1075
|
// src/hooks/useEthereum.ts
|
|
1076
|
+
var import_browser_sdk7 = require("@phantom/browser-sdk");
|
|
383
1077
|
function useEthereum() {
|
|
384
|
-
const { sdk,
|
|
385
|
-
if (!isClient || !sdk) {
|
|
1078
|
+
const { sdk, isClient, isLoading } = usePhantom();
|
|
1079
|
+
if (!isClient || !sdk || isLoading) {
|
|
386
1080
|
return {
|
|
387
1081
|
ethereum: {},
|
|
388
|
-
// This will be replaced when SDK is ready
|
|
389
1082
|
isAvailable: false
|
|
390
1083
|
};
|
|
391
1084
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
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
|
|
397
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 }) });
|
|
398
1187
|
}
|
|
399
1188
|
|
|
400
1189
|
// src/index.ts
|
|
401
|
-
var
|
|
1190
|
+
var import_wallet_sdk_ui10 = require("@phantom/wallet-sdk-ui");
|
|
1191
|
+
var import_browser_sdk8 = require("@phantom/browser-sdk");
|