@moneymq/react 0.5.0 → 0.9.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/dist/index.cjs +51083 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{index.d.mts → index.d.cts} +41 -27
- package/dist/index.d.ts +41 -27
- package/dist/index.js +50489 -1189
- package/dist/index.js.map +1 -1
- package/package.json +12 -11
- package/dist/index.mjs +0 -1739
- package/dist/index.mjs.map +0 -1
package/dist/index.mjs
DELETED
|
@@ -1,1739 +0,0 @@
|
|
|
1
|
-
// src/provider.tsx
|
|
2
|
-
import { createContext as createContext2, useContext as useContext2, useEffect as useEffect2, useMemo as useMemo3, useState as useState3 } from "react";
|
|
3
|
-
import { ConnectionProvider, WalletProvider } from "@solana/wallet-adapter-react";
|
|
4
|
-
import { PhantomWalletAdapter, SolflareWalletAdapter } from "@solana/wallet-adapter-wallets";
|
|
5
|
-
|
|
6
|
-
// src/wallet-modal-provider.tsx
|
|
7
|
-
import { createContext, useContext, useState as useState2, useCallback as useCallback2, useMemo as useMemo2 } from "react";
|
|
8
|
-
|
|
9
|
-
// src/wallet-modal.tsx
|
|
10
|
-
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
11
|
-
import { useWallet } from "@solana/wallet-adapter-react";
|
|
12
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
13
|
-
var overlayStyle = {
|
|
14
|
-
position: "fixed",
|
|
15
|
-
inset: 0,
|
|
16
|
-
backgroundColor: "rgba(0, 0, 0, 0.6)",
|
|
17
|
-
backdropFilter: "blur(4px)",
|
|
18
|
-
display: "flex",
|
|
19
|
-
alignItems: "center",
|
|
20
|
-
justifyContent: "center",
|
|
21
|
-
zIndex: 9999,
|
|
22
|
-
animation: "fadeIn 150ms ease-out"
|
|
23
|
-
};
|
|
24
|
-
var modalStyle = {
|
|
25
|
-
backgroundColor: "#18181b",
|
|
26
|
-
borderRadius: "1rem",
|
|
27
|
-
padding: "1.5rem",
|
|
28
|
-
width: "100%",
|
|
29
|
-
maxWidth: "400px",
|
|
30
|
-
maxHeight: "90vh",
|
|
31
|
-
overflow: "auto",
|
|
32
|
-
border: "1px solid #27272a",
|
|
33
|
-
boxShadow: "0 25px 50px -12px rgba(0, 0, 0, 0.5)",
|
|
34
|
-
animation: "slideUp 150ms ease-out"
|
|
35
|
-
};
|
|
36
|
-
var headerStyle = {
|
|
37
|
-
display: "flex",
|
|
38
|
-
alignItems: "center",
|
|
39
|
-
gap: "0.75rem",
|
|
40
|
-
marginBottom: "0.5rem"
|
|
41
|
-
};
|
|
42
|
-
var logoStyle = {
|
|
43
|
-
width: "2.5rem",
|
|
44
|
-
height: "2.5rem",
|
|
45
|
-
borderRadius: "0.5rem",
|
|
46
|
-
objectFit: "contain"
|
|
47
|
-
};
|
|
48
|
-
var titleStyle = {
|
|
49
|
-
fontSize: "1.25rem",
|
|
50
|
-
fontWeight: 600,
|
|
51
|
-
color: "#fafafa",
|
|
52
|
-
margin: 0
|
|
53
|
-
};
|
|
54
|
-
var descriptionStyle = {
|
|
55
|
-
fontSize: "0.875rem",
|
|
56
|
-
color: "#a1a1aa",
|
|
57
|
-
marginBottom: "1.5rem"
|
|
58
|
-
};
|
|
59
|
-
var walletListStyle = {
|
|
60
|
-
display: "flex",
|
|
61
|
-
flexDirection: "column",
|
|
62
|
-
gap: "0.5rem"
|
|
63
|
-
};
|
|
64
|
-
var walletButtonStyle = {
|
|
65
|
-
display: "flex",
|
|
66
|
-
alignItems: "center",
|
|
67
|
-
gap: "0.75rem",
|
|
68
|
-
width: "100%",
|
|
69
|
-
padding: "0.875rem 1rem",
|
|
70
|
-
backgroundColor: "#27272a",
|
|
71
|
-
border: "1px solid #3f3f46",
|
|
72
|
-
borderRadius: "0.75rem",
|
|
73
|
-
cursor: "pointer",
|
|
74
|
-
transition: "all 150ms",
|
|
75
|
-
textAlign: "left"
|
|
76
|
-
};
|
|
77
|
-
var walletIconStyle = {
|
|
78
|
-
width: "2rem",
|
|
79
|
-
height: "2rem",
|
|
80
|
-
borderRadius: "0.375rem"
|
|
81
|
-
};
|
|
82
|
-
var walletNameStyle = {
|
|
83
|
-
flex: 1,
|
|
84
|
-
fontSize: "0.9375rem",
|
|
85
|
-
fontWeight: 500,
|
|
86
|
-
color: "#fafafa"
|
|
87
|
-
};
|
|
88
|
-
var walletTagStyle = {
|
|
89
|
-
fontSize: "0.75rem",
|
|
90
|
-
padding: "0.25rem 0.5rem",
|
|
91
|
-
borderRadius: "9999px",
|
|
92
|
-
backgroundColor: "#3f3f46",
|
|
93
|
-
color: "#a1a1aa"
|
|
94
|
-
};
|
|
95
|
-
var closeButtonStyle = {
|
|
96
|
-
position: "absolute",
|
|
97
|
-
top: "1rem",
|
|
98
|
-
right: "1rem",
|
|
99
|
-
padding: "0.5rem",
|
|
100
|
-
backgroundColor: "transparent",
|
|
101
|
-
border: "none",
|
|
102
|
-
borderRadius: "0.375rem",
|
|
103
|
-
cursor: "pointer",
|
|
104
|
-
color: "#71717a",
|
|
105
|
-
transition: "color 150ms"
|
|
106
|
-
};
|
|
107
|
-
var noWalletsStyle = {
|
|
108
|
-
textAlign: "center",
|
|
109
|
-
padding: "2rem 1rem",
|
|
110
|
-
color: "#a1a1aa",
|
|
111
|
-
fontSize: "0.875rem"
|
|
112
|
-
};
|
|
113
|
-
function WalletModal({ visible, onClose, branding }) {
|
|
114
|
-
const { wallets, select, connecting } = useWallet();
|
|
115
|
-
const [hoveredWallet, setHoveredWallet] = useState(null);
|
|
116
|
-
const accentColor = branding?.accentColor || "#ec4899";
|
|
117
|
-
const sortedWallets = useMemo(() => {
|
|
118
|
-
const installed = [];
|
|
119
|
-
const notInstalled = [];
|
|
120
|
-
for (const wallet of wallets) {
|
|
121
|
-
if (wallet.readyState === "Installed") {
|
|
122
|
-
installed.push(wallet);
|
|
123
|
-
} else if (wallet.readyState === "Loadable" || wallet.readyState === "NotDetected") {
|
|
124
|
-
notInstalled.push(wallet);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return [...installed, ...notInstalled];
|
|
128
|
-
}, [wallets]);
|
|
129
|
-
const handleSelect = useCallback((wallet) => {
|
|
130
|
-
select(wallet.adapter.name);
|
|
131
|
-
onClose();
|
|
132
|
-
}, [select, onClose]);
|
|
133
|
-
useEffect(() => {
|
|
134
|
-
const handleEscape = (e) => {
|
|
135
|
-
if (e.key === "Escape") onClose();
|
|
136
|
-
};
|
|
137
|
-
if (visible) {
|
|
138
|
-
document.addEventListener("keydown", handleEscape);
|
|
139
|
-
document.body.style.overflow = "hidden";
|
|
140
|
-
}
|
|
141
|
-
return () => {
|
|
142
|
-
document.removeEventListener("keydown", handleEscape);
|
|
143
|
-
document.body.style.overflow = "";
|
|
144
|
-
};
|
|
145
|
-
}, [visible, onClose]);
|
|
146
|
-
if (!visible) return null;
|
|
147
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
148
|
-
/* @__PURE__ */ jsx("style", { children: `
|
|
149
|
-
@keyframes fadeIn {
|
|
150
|
-
from { opacity: 0; }
|
|
151
|
-
to { opacity: 1; }
|
|
152
|
-
}
|
|
153
|
-
@keyframes slideUp {
|
|
154
|
-
from { opacity: 0; transform: translateY(10px); }
|
|
155
|
-
to { opacity: 1; transform: translateY(0); }
|
|
156
|
-
}
|
|
157
|
-
` }),
|
|
158
|
-
/* @__PURE__ */ jsx("div", { style: overlayStyle, onClick: onClose, children: /* @__PURE__ */ jsxs(
|
|
159
|
-
"div",
|
|
160
|
-
{
|
|
161
|
-
style: { ...modalStyle, position: "relative" },
|
|
162
|
-
onClick: (e) => e.stopPropagation(),
|
|
163
|
-
children: [
|
|
164
|
-
/* @__PURE__ */ jsx(
|
|
165
|
-
"button",
|
|
166
|
-
{
|
|
167
|
-
style: closeButtonStyle,
|
|
168
|
-
onClick: onClose,
|
|
169
|
-
onMouseEnter: (e) => e.currentTarget.style.color = "#fafafa",
|
|
170
|
-
onMouseLeave: (e) => e.currentTarget.style.color = "#71717a",
|
|
171
|
-
children: /* @__PURE__ */ jsx("svg", { width: "20", height: "20", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: /* @__PURE__ */ jsx("path", { d: "M18 6L6 18M6 6l12 12" }) })
|
|
172
|
-
}
|
|
173
|
-
),
|
|
174
|
-
/* @__PURE__ */ jsxs("div", { style: headerStyle, children: [
|
|
175
|
-
branding?.logo && /* @__PURE__ */ jsx("img", { src: branding.logo, alt: "", style: logoStyle }),
|
|
176
|
-
/* @__PURE__ */ jsx("h2", { style: titleStyle, children: branding?.title || "Connect Wallet" })
|
|
177
|
-
] }),
|
|
178
|
-
/* @__PURE__ */ jsx("p", { style: descriptionStyle, children: branding?.description || "Select a wallet to connect and pay securely." }),
|
|
179
|
-
/* @__PURE__ */ jsx("div", { style: walletListStyle, children: sortedWallets.length === 0 ? /* @__PURE__ */ jsx("div", { style: noWalletsStyle, children: "No wallets found. Please install a Solana wallet extension." }) : sortedWallets.map((wallet) => {
|
|
180
|
-
const isInstalled = wallet.readyState === "Installed";
|
|
181
|
-
const isHovered = hoveredWallet === wallet.adapter.name;
|
|
182
|
-
return /* @__PURE__ */ jsxs(
|
|
183
|
-
"button",
|
|
184
|
-
{
|
|
185
|
-
style: {
|
|
186
|
-
...walletButtonStyle,
|
|
187
|
-
backgroundColor: isHovered ? "#3f3f46" : "#27272a",
|
|
188
|
-
borderColor: isHovered ? accentColor : "#3f3f46"
|
|
189
|
-
},
|
|
190
|
-
onClick: () => handleSelect(wallet),
|
|
191
|
-
onMouseEnter: () => setHoveredWallet(wallet.adapter.name),
|
|
192
|
-
onMouseLeave: () => setHoveredWallet(null),
|
|
193
|
-
disabled: connecting,
|
|
194
|
-
children: [
|
|
195
|
-
/* @__PURE__ */ jsx(
|
|
196
|
-
"img",
|
|
197
|
-
{
|
|
198
|
-
src: wallet.adapter.icon,
|
|
199
|
-
alt: wallet.adapter.name,
|
|
200
|
-
style: walletIconStyle
|
|
201
|
-
}
|
|
202
|
-
),
|
|
203
|
-
/* @__PURE__ */ jsx("span", { style: walletNameStyle, children: wallet.adapter.name }),
|
|
204
|
-
isInstalled ? /* @__PURE__ */ jsx("span", { style: { ...walletTagStyle, backgroundColor: accentColor + "20", color: accentColor }, children: "Detected" }) : /* @__PURE__ */ jsx("span", { style: walletTagStyle, children: "Install" })
|
|
205
|
-
]
|
|
206
|
-
},
|
|
207
|
-
wallet.adapter.name
|
|
208
|
-
);
|
|
209
|
-
}) })
|
|
210
|
-
]
|
|
211
|
-
}
|
|
212
|
-
) })
|
|
213
|
-
] });
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
// src/wallet-modal-provider.tsx
|
|
217
|
-
import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
218
|
-
var WalletModalContext = createContext({
|
|
219
|
-
visible: false,
|
|
220
|
-
setVisible: () => {
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
var BrandingContext = createContext(void 0);
|
|
224
|
-
function useWalletModal() {
|
|
225
|
-
return useContext(WalletModalContext);
|
|
226
|
-
}
|
|
227
|
-
function useBranding() {
|
|
228
|
-
return useContext(BrandingContext);
|
|
229
|
-
}
|
|
230
|
-
function CustomWalletModalProvider({ children, branding }) {
|
|
231
|
-
const [visible, setVisible] = useState2(false);
|
|
232
|
-
const handleClose = useCallback2(() => setVisible(false), []);
|
|
233
|
-
const contextValue = useMemo2(
|
|
234
|
-
() => ({ visible, setVisible }),
|
|
235
|
-
[visible]
|
|
236
|
-
);
|
|
237
|
-
return /* @__PURE__ */ jsx2(BrandingContext.Provider, { value: branding, children: /* @__PURE__ */ jsxs2(WalletModalContext.Provider, { value: contextValue, children: [
|
|
238
|
-
children,
|
|
239
|
-
/* @__PURE__ */ jsx2(WalletModal, { visible, onClose: handleClose, branding })
|
|
240
|
-
] }) });
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// src/provider.tsx
|
|
244
|
-
import { jsx as jsx3 } from "react/jsx-runtime";
|
|
245
|
-
var MoneyMQContext = createContext2(null);
|
|
246
|
-
var SandboxContext = createContext2({
|
|
247
|
-
isSandboxMode: false,
|
|
248
|
-
sandboxAccounts: []
|
|
249
|
-
});
|
|
250
|
-
var DEFAULT_RPC_URL = "https://api.devnet.solana.com";
|
|
251
|
-
var SANDBOX_HASH_PREFIX = "SURFNETxSAFEHASH";
|
|
252
|
-
function normalizeRpcUrl(url) {
|
|
253
|
-
return url.replace("0.0.0.0", "localhost").replace("127.0.0.1", "localhost");
|
|
254
|
-
}
|
|
255
|
-
async function getRpcUrl(apiUrl) {
|
|
256
|
-
try {
|
|
257
|
-
console.log("[MoneyMQ] Fetching config from:", `${apiUrl}/config`);
|
|
258
|
-
const response = await fetch(`${apiUrl}/config`);
|
|
259
|
-
const config = await response.json();
|
|
260
|
-
const rawRpcUrl = config.x402?.validator?.rpcUrl || DEFAULT_RPC_URL;
|
|
261
|
-
console.log("[MoneyMQ] Raw RPC URL from config:", rawRpcUrl);
|
|
262
|
-
const normalizedUrl = normalizeRpcUrl(rawRpcUrl);
|
|
263
|
-
console.log("[MoneyMQ] Normalized RPC URL:", normalizedUrl);
|
|
264
|
-
return normalizedUrl;
|
|
265
|
-
} catch (err) {
|
|
266
|
-
console.error("[MoneyMQ] Error fetching config:", err);
|
|
267
|
-
return DEFAULT_RPC_URL;
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
async function checkSandboxMode(rpcUrl) {
|
|
271
|
-
try {
|
|
272
|
-
console.log("[MoneyMQ] Checking sandbox mode with RPC:", rpcUrl);
|
|
273
|
-
const response = await fetch(rpcUrl, {
|
|
274
|
-
method: "POST",
|
|
275
|
-
headers: { "Content-Type": "application/json" },
|
|
276
|
-
body: JSON.stringify({
|
|
277
|
-
jsonrpc: "2.0",
|
|
278
|
-
id: 1,
|
|
279
|
-
method: "getLatestBlockhash",
|
|
280
|
-
params: [{ commitment: "finalized" }]
|
|
281
|
-
})
|
|
282
|
-
});
|
|
283
|
-
const data = await response.json();
|
|
284
|
-
const blockhash = data?.result?.value?.blockhash || "";
|
|
285
|
-
const isSandbox = blockhash.startsWith(SANDBOX_HASH_PREFIX);
|
|
286
|
-
console.log("[MoneyMQ] Blockhash:", blockhash, "| Sandbox:", isSandbox);
|
|
287
|
-
return isSandbox;
|
|
288
|
-
} catch (err) {
|
|
289
|
-
console.error("[MoneyMQ] Error checking sandbox mode:", err);
|
|
290
|
-
return false;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
async function fetchTokenBalance(rpcUrl, tokenAccountAddress) {
|
|
294
|
-
try {
|
|
295
|
-
const response = await fetch(rpcUrl, {
|
|
296
|
-
method: "POST",
|
|
297
|
-
headers: { "Content-Type": "application/json" },
|
|
298
|
-
body: JSON.stringify({
|
|
299
|
-
jsonrpc: "2.0",
|
|
300
|
-
id: 1,
|
|
301
|
-
method: "getAccountInfo",
|
|
302
|
-
params: [tokenAccountAddress, { encoding: "jsonParsed" }]
|
|
303
|
-
})
|
|
304
|
-
});
|
|
305
|
-
const data = await response.json();
|
|
306
|
-
if (data.result?.value?.data?.parsed?.info?.tokenAmount) {
|
|
307
|
-
return parseFloat(data.result.value.data.parsed.info.tokenAmount.uiAmountString || "0");
|
|
308
|
-
}
|
|
309
|
-
return 0;
|
|
310
|
-
} catch {
|
|
311
|
-
return 0;
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
async function fetchSandboxAccounts(apiUrl, rpcUrl) {
|
|
315
|
-
try {
|
|
316
|
-
console.log("[MoneyMQ] Fetching sandbox accounts from:", `${apiUrl}/sandbox/accounts`);
|
|
317
|
-
const response = await fetch(`${apiUrl}/sandbox/accounts`);
|
|
318
|
-
if (!response.ok) {
|
|
319
|
-
console.log("[MoneyMQ] Sandbox accounts fetch failed:", response.status);
|
|
320
|
-
return [];
|
|
321
|
-
}
|
|
322
|
-
const data = await response.json();
|
|
323
|
-
if (data.solana?.userAccounts) {
|
|
324
|
-
const accounts = await Promise.all(
|
|
325
|
-
data.solana.userAccounts.map(async (acc) => {
|
|
326
|
-
let usdcBalance = 0;
|
|
327
|
-
if (acc.stablecoins?.usdc) {
|
|
328
|
-
usdcBalance = await fetchTokenBalance(rpcUrl, acc.stablecoins.usdc);
|
|
329
|
-
}
|
|
330
|
-
return {
|
|
331
|
-
id: acc.address,
|
|
332
|
-
name: acc.label,
|
|
333
|
-
address: acc.address,
|
|
334
|
-
secretKeyHex: acc.secretKeyHex,
|
|
335
|
-
stablecoins: acc.stablecoins,
|
|
336
|
-
usdcBalance
|
|
337
|
-
};
|
|
338
|
-
})
|
|
339
|
-
);
|
|
340
|
-
console.log("[MoneyMQ] Sandbox accounts loaded:", accounts.length);
|
|
341
|
-
return accounts;
|
|
342
|
-
}
|
|
343
|
-
return [];
|
|
344
|
-
} catch (err) {
|
|
345
|
-
console.error("[MoneyMQ] Error fetching sandbox accounts:", err);
|
|
346
|
-
return [];
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
function useMoneyMQ() {
|
|
350
|
-
const client = useContext2(MoneyMQContext);
|
|
351
|
-
if (!client) {
|
|
352
|
-
throw new Error("useMoneyMQ must be used within a MoneyMQProvider");
|
|
353
|
-
}
|
|
354
|
-
return client;
|
|
355
|
-
}
|
|
356
|
-
function useSandbox() {
|
|
357
|
-
return useContext2(SandboxContext);
|
|
358
|
-
}
|
|
359
|
-
function MoneyMQProvider({
|
|
360
|
-
children,
|
|
361
|
-
client,
|
|
362
|
-
branding
|
|
363
|
-
}) {
|
|
364
|
-
const [rpcEndpoint, setRpcEndpoint] = useState3(null);
|
|
365
|
-
const [isSandboxMode, setIsSandboxMode] = useState3(false);
|
|
366
|
-
const [sandboxAccounts, setSandboxAccounts] = useState3([]);
|
|
367
|
-
useEffect2(() => {
|
|
368
|
-
async function initialize() {
|
|
369
|
-
const rpcUrl = await getRpcUrl(client.config.endpoint);
|
|
370
|
-
setRpcEndpoint(rpcUrl);
|
|
371
|
-
const isSandbox = await checkSandboxMode(rpcUrl);
|
|
372
|
-
setIsSandboxMode(isSandbox);
|
|
373
|
-
if (isSandbox) {
|
|
374
|
-
const accounts = await fetchSandboxAccounts(client.config.endpoint, rpcUrl);
|
|
375
|
-
setSandboxAccounts(accounts);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
initialize();
|
|
379
|
-
}, [client.config.endpoint]);
|
|
380
|
-
const wallets = useMemo3(
|
|
381
|
-
() => [
|
|
382
|
-
new PhantomWalletAdapter(),
|
|
383
|
-
new SolflareWalletAdapter()
|
|
384
|
-
],
|
|
385
|
-
[]
|
|
386
|
-
);
|
|
387
|
-
const sandboxContextValue = useMemo3(
|
|
388
|
-
() => ({ isSandboxMode, sandboxAccounts }),
|
|
389
|
-
[isSandboxMode, sandboxAccounts]
|
|
390
|
-
);
|
|
391
|
-
if (!rpcEndpoint) {
|
|
392
|
-
return null;
|
|
393
|
-
}
|
|
394
|
-
return /* @__PURE__ */ jsx3(MoneyMQContext.Provider, { value: client, children: /* @__PURE__ */ jsx3(SandboxContext.Provider, { value: sandboxContextValue, children: /* @__PURE__ */ jsx3(ConnectionProvider, { endpoint: rpcEndpoint, children: /* @__PURE__ */ jsx3(WalletProvider, { wallets, autoConnect: true, children: /* @__PURE__ */ jsx3(CustomWalletModalProvider, { branding, children }) }) }) }) });
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
// src/checkout-button.tsx
|
|
398
|
-
import React5, { forwardRef, useEffect as useEffect4, useState as useState5 } from "react";
|
|
399
|
-
|
|
400
|
-
// src/checkout-modal.tsx
|
|
401
|
-
import React4, { useCallback as useCallback3, useState as useState4, useEffect as useEffect3, useRef } from "react";
|
|
402
|
-
import { useWallet as useWallet2 } from "@solana/wallet-adapter-react";
|
|
403
|
-
import { Menu, MenuButton, MenuItem, MenuItems } from "@headlessui/react";
|
|
404
|
-
import Lottie from "lottie-react";
|
|
405
|
-
|
|
406
|
-
// src/assets/logo-animation.json
|
|
407
|
-
var logo_animation_default = { assets: [{ id: "4", layers: [{ ind: 3, ty: 4, ks: {}, ip: 0, op: 58, st: 0, shapes: [{ ty: "rc", p: { a: 0, k: [40, 40] }, r: { a: 0, k: 0 }, s: { a: 0, k: [80, 80] } }, { ty: "fl", c: { a: 0, k: [0, 0, 0, 0] }, o: { a: 0, k: 0 } }] }, { ind: 0, ty: 4, ks: { s: { a: 0, k: [133.33, 133.33] } }, ip: 0, op: 58, st: 0, shapes: [{ ty: "gr", it: [{ ty: "gr", it: [{ ty: "sh", ks: { a: 0, k: { c: true, i: [[0, 0], [0, 20.55], [20.55, 0], [0, -20.55], [-20.55, 0]], o: [[20.55, 0], [0, -20.55], [-20.55, 0], [0, 20.55], [0, 0]], v: [[39.65, 76.85], [76.85, 39.65], [39.65, 2.43], [2.44, 39.65], [39.65, 76.85]] } } }, { ty: "st", c: { a: 0, k: [0, 0, 0, 1] }, lc: 1, lj: 1, ml: 10, o: { a: 0, k: 100 }, w: { a: 0, k: 4.87 } }, { ty: "fl", c: { a: 0, k: [1, 1, 1, 1] }, o: { a: 0, k: 100 } }, { ty: "tr", o: { a: 0, k: 100 }, s: { a: 0, k: [75, 75] } }] }, { ty: "tr", o: { a: 0, k: 100 } }] }] }] }, { id: "7", layers: [{ ind: 6, ty: 0, ks: {}, w: 80, h: 80, ip: 0, op: 58, st: 0, refId: "4" }] }, { id: "12", layers: [{ ind: 11, ty: 4, ks: {}, ip: 0, op: 58, st: 0, shapes: [{ ty: "rc", p: { a: 0, k: [40, 40] }, r: { a: 0, k: 0 }, s: { a: 0, k: [80, 80] } }, { ty: "fl", c: { a: 0, k: [0, 0, 0, 0] }, o: { a: 0, k: 0 } }] }, { ind: 0, ty: 4, ks: { s: { a: 0, k: [133.33, 133.33] } }, ip: 0, op: 58, st: 0, shapes: [{ ty: "gr", it: [{ ty: "gr", it: [{ ty: "sh", ks: { a: 0, k: { c: true, i: [[0, 0], [0, 20.55], [20.55, 0], [0, -20.55], [-20.55, 0]], o: [[20.55, 0], [0, -20.55], [-20.55, 0], [0, 20.55], [0, 0]], v: [[39.65, 76.85], [76.85, 39.65], [39.65, 2.43], [2.44, 39.65], [39.65, 76.85]] } } }, { ty: "st", c: { a: 0, k: [0, 0, 0, 1] }, lc: 1, lj: 1, ml: 10, o: { a: 0, k: 100 }, w: { a: 0, k: 4.87 } }, { ty: "fl", c: { a: 0, k: [1, 1, 1, 1] }, o: { a: 0, k: 100 } }, { ty: "tr", o: { a: 0, k: 100 }, s: { a: 0, k: [75, 75] } }] }, { ty: "tr", o: { a: 0, k: 100 } }] }] }] }, { id: "17", layers: [{ ind: 16, ty: 4, ks: {}, ip: 0, op: 58, st: 0, shapes: [{ ty: "rc", p: { a: 0, k: [40, 40] }, r: { a: 0, k: 0 }, s: { a: 0, k: [80, 80] } }, { ty: "fl", c: { a: 0, k: [0, 0, 0, 0] }, o: { a: 0, k: 0 } }] }, { ind: 0, ty: 4, ks: { s: { a: 0, k: [133.33, 133.33] } }, ip: 0, op: 58, st: 0, shapes: [{ ty: "gr", it: [{ ty: "gr", it: [{ ty: "sh", ks: { a: 0, k: { c: true, i: [[0, 0], [0, 20.55], [20.55, 0], [0, -20.55], [-20.55, 0]], o: [[20.55, 0], [0, -20.55], [-20.55, 0], [0, 20.55], [0, 0]], v: [[39.65, 76.85], [76.85, 39.65], [39.65, 2.43], [2.44, 39.65], [39.65, 76.85]] } } }, { ty: "st", c: { a: 0, k: [0, 0, 0, 1] }, lc: 1, lj: 1, ml: 10, o: { a: 0, k: 100 }, w: { a: 0, k: 4.87 } }, { ty: "fl", c: { a: 0, k: [1, 1, 1, 1] }, o: { a: 0, k: 100 } }, { ty: "tr", o: { a: 0, k: 100 }, s: { a: 0, k: [75, 75] } }] }, { ty: "tr", o: { a: 0, k: 100 } }] }] }] }, { id: "22", layers: [{ ind: 21, ty: 4, ks: {}, ip: 0, op: 58, st: 0, shapes: [{ ty: "rc", p: { a: 0, k: [40, 40] }, r: { a: 0, k: 0 }, s: { a: 0, k: [80, 80] } }, { ty: "fl", c: { a: 0, k: [0, 0, 0, 0] }, o: { a: 0, k: 0 } }] }, { ind: 0, ty: 4, ks: { s: { a: 0, k: [133.33, 133.33] } }, ip: 0, op: 58, st: 0, shapes: [{ ty: "gr", it: [{ ty: "gr", it: [{ ty: "sh", ks: { a: 0, k: { c: true, i: [[0, 0], [0, 20.55], [20.55, 0], [0, -20.55], [-20.55, 0]], o: [[20.55, 0], [0, -20.55], [-20.55, 0], [0, 20.55], [0, 0]], v: [[39.65, 76.85], [76.85, 39.65], [39.65, 2.43], [2.44, 39.65], [39.65, 76.85]] } } }, { ty: "st", c: { a: 0, k: [0, 0, 0, 1] }, lc: 1, lj: 1, ml: 10, o: { a: 0, k: 100 }, w: { a: 0, k: 4.87 } }, { ty: "fl", c: { a: 0, k: [1, 1, 1, 1] }, o: { a: 0, k: 100 } }, { ty: "tr", o: { a: 0, k: 100 }, s: { a: 0, k: [75, 75] } }] }, { ty: "tr", o: { a: 0, k: 100 } }] }] }] }], fr: 60, h: 200, ip: 0, layers: [{ ind: 9, ty: 0, parent: 2, ks: { a: { a: 0, k: [40, 40] }, o: { a: 1, k: [{ t: 0, s: [100], h: 1 }, { t: 7.2, s: [100], h: 1 }, { t: 7.2, s: [0], h: 1 }, { t: 57, s: [0], h: 1 }] }, p: { a: 1, k: [{ t: 0, s: [119, 40], i: { x: [0, 1], y: [1, 1] }, o: { x: [0.384, 0], y: [0, 0] } }, { t: 48, s: [219, 40], i: { x: [1, 1], y: [1, 1] }, o: { x: [0, 0], y: [0, 0] } }, { t: 57, s: [219, 40], h: 1 }] }, s: { a: 1, k: [{ t: 0, s: [100, 100], i: { x: [1, 1], y: [1, 1] }, o: { x: [0, 0], y: [0, 0] } }, { t: 5.4, s: [100, 100], i: { x: [0, 0], y: [1, 1] }, o: { x: [0.5, 0.5], y: [0, 0] } }, { t: 7.2, s: [103, 103], i: { x: [1, 1], y: [1, 1] }, o: { x: [0, 0], y: [0, 0] } }, { t: 57, s: [103, 103], h: 1 }] } }, w: 80, h: 80, ip: 0, op: 58, st: 0, refId: "7" }, { ind: 14, ty: 0, parent: 10, ks: {}, w: 80, h: 80, ip: 0, op: 58, st: 0, refId: "12" }, { ind: 10, ty: 3, parent: 2, ks: { p: { a: 1, k: [{ t: 0, s: [39, 0], i: { x: [0, 1], y: [1, 1] }, o: { x: [0.384, 0], y: [0, 0] } }, { t: 48, s: [79, 0], i: { x: [1, 1], y: [1, 1] }, o: { x: [0, 0], y: [0, 0] } }, { t: 57, s: [79, 0], h: 1 }] } }, ip: 0, op: 58, st: 0 }, { ind: 19, ty: 0, parent: 15, ks: {}, w: 80, h: 80, ip: 0, op: 58, st: 0, refId: "17" }, { ind: 15, ty: 3, parent: 2, ks: { p: { a: 1, k: [{ t: 0, s: [0, 0], i: { x: [1, 1], y: [1, 1] }, o: { x: [0, 0], y: [0, 0] } }, { t: 7.2, s: [0, 0], i: { x: [0, 1], y: [1, 1] }, o: { x: [0.384, 0], y: [0, 0] } }, { t: 55.2, s: [39, 0], i: { x: [1, 1], y: [1, 1] }, o: { x: [0, 0], y: [0, 0] } }, { t: 57, s: [39, 0], h: 1 }] } }, ip: 0, op: 58, st: 0 }, { ind: 24, ty: 0, parent: 20, ks: {}, w: 80, h: 80, ip: 0, op: 58, st: 0, refId: "22" }, { ind: 20, ty: 3, parent: 2, ks: { a: { a: 0, k: [40, 40] }, p: { a: 0, k: [40, 40] }, s: { a: 1, k: [{ t: 0, s: [70, 70], i: { x: [1, 1], y: [1, 1] }, o: { x: [0, 0], y: [0, 0] } }, { t: 13.8, s: [70, 70], i: { x: [0, 0], y: [1, 1] }, o: { x: [0.5, 0.5], y: [0, 0] } }, { t: 37.2, s: [100, 100], i: { x: [1, 1], y: [1, 1] }, o: { x: [0, 0], y: [0, 0] } }, { t: 57, s: [100, 100], h: 1 }] } }, ip: 0, op: 58, st: 0 }, { ind: 2, ty: 3, parent: 1, ks: { p: { a: 0, k: [21, 61] } }, ip: 0, op: 58, st: 0 }, { ind: 1, ty: 3, parent: 0, ks: {}, ip: 0, op: 58, st: 0 }, { ind: 0, ty: 3, ks: {}, ip: 0, op: 58, st: 0 }], meta: { g: "https://jitter.video" }, op: 57, v: "5.7.4", w: 200 };
|
|
408
|
-
|
|
409
|
-
// src/checkout-modal.tsx
|
|
410
|
-
import { Fragment as Fragment2, jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
411
|
-
function encodeFormData(data) {
|
|
412
|
-
const params = new URLSearchParams();
|
|
413
|
-
const addParams = (obj, prefix = "") => {
|
|
414
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
415
|
-
const paramKey = prefix ? `${prefix}[${key}]` : key;
|
|
416
|
-
if (value === null || value === void 0) {
|
|
417
|
-
continue;
|
|
418
|
-
} else if (typeof value === "object" && !Array.isArray(value)) {
|
|
419
|
-
addParams(value, paramKey);
|
|
420
|
-
} else {
|
|
421
|
-
params.append(paramKey, String(value));
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
};
|
|
425
|
-
addParams(data);
|
|
426
|
-
return params.toString();
|
|
427
|
-
}
|
|
428
|
-
function normalizeRpcUrl2(url) {
|
|
429
|
-
return url.replace("0.0.0.0", "localhost").replace("127.0.0.1", "localhost");
|
|
430
|
-
}
|
|
431
|
-
async function makeRequestWith402Handling(url, method, body, secretKeyHex, rpcUrl, headers = {}, useJson = false) {
|
|
432
|
-
console.log(`[MoneyMQ] Making ${method} request to ${url}`);
|
|
433
|
-
const contentType = useJson ? "application/json" : "application/x-www-form-urlencoded";
|
|
434
|
-
const requestBody = body ? useJson ? JSON.stringify(body) : encodeFormData(body) : void 0;
|
|
435
|
-
let response = await fetch(url, {
|
|
436
|
-
method,
|
|
437
|
-
headers: {
|
|
438
|
-
"Content-Type": contentType,
|
|
439
|
-
...headers
|
|
440
|
-
},
|
|
441
|
-
body: requestBody
|
|
442
|
-
});
|
|
443
|
-
let data = await response.json();
|
|
444
|
-
console.log(`[MoneyMQ] Response status: ${response.status}`, data);
|
|
445
|
-
if (response.status === 402) {
|
|
446
|
-
console.log("[MoneyMQ] \u{1F4B3} 402 Payment Required - processing payment...");
|
|
447
|
-
const paymentRequirements = data?.accepts || data?.payment_requirements || data?.error?.payment_requirements || [];
|
|
448
|
-
if (paymentRequirements.length === 0) {
|
|
449
|
-
console.warn("[MoneyMQ] \u26A0\uFE0F No payment requirements found in 402 response");
|
|
450
|
-
throw new Error("Payment required but no payment requirements provided");
|
|
451
|
-
}
|
|
452
|
-
console.log("[MoneyMQ] Payment requirements:", paymentRequirements);
|
|
453
|
-
const { createPaymentHeader, selectPaymentRequirements } = await import("x402/client");
|
|
454
|
-
const { createSigner } = await import("x402-fetch");
|
|
455
|
-
const signer = await createSigner("solana", secretKeyHex, {
|
|
456
|
-
svmConfig: rpcUrl
|
|
457
|
-
});
|
|
458
|
-
const selectedPaymentRequirement = selectPaymentRequirements(paymentRequirements, "solana", "exact");
|
|
459
|
-
console.log(`[MoneyMQ] \u{1F4B0} Creating payment for ${selectedPaymentRequirement.network}...`);
|
|
460
|
-
const paymentHeaderValue = await createPaymentHeader(
|
|
461
|
-
signer,
|
|
462
|
-
1,
|
|
463
|
-
// x402Version
|
|
464
|
-
selectedPaymentRequirement,
|
|
465
|
-
{
|
|
466
|
-
svmConfig: {
|
|
467
|
-
rpcUrl
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
);
|
|
471
|
-
console.log("[MoneyMQ] \u2705 Payment header created, retrying request...");
|
|
472
|
-
response = await fetch(url, {
|
|
473
|
-
method,
|
|
474
|
-
headers: {
|
|
475
|
-
"Content-Type": contentType,
|
|
476
|
-
"X-Payment": paymentHeaderValue,
|
|
477
|
-
...headers
|
|
478
|
-
},
|
|
479
|
-
body: requestBody
|
|
480
|
-
});
|
|
481
|
-
data = await response.json();
|
|
482
|
-
console.log(`[MoneyMQ] Retry response status: ${response.status}`, data);
|
|
483
|
-
if (!response.ok) {
|
|
484
|
-
throw new Error(data.error?.message || "Request failed after payment");
|
|
485
|
-
}
|
|
486
|
-
} else if (!response.ok) {
|
|
487
|
-
throw new Error(data.error?.message || "Request failed");
|
|
488
|
-
}
|
|
489
|
-
return data;
|
|
490
|
-
}
|
|
491
|
-
async function createSandboxPayment(apiUrl, rpcUrl, amount, currency, recipient, senderAddress, secretKeyHex, lineItems) {
|
|
492
|
-
console.log("[MoneyMQ] Creating checkout session...", { amount, currency, recipient, senderAddress });
|
|
493
|
-
const checkoutLineItems = lineItems?.map((item) => ({
|
|
494
|
-
price_data: {
|
|
495
|
-
currency: item.price.currency.toLowerCase(),
|
|
496
|
-
unit_amount: item.price.unit_amount,
|
|
497
|
-
product_data: {
|
|
498
|
-
name: item.product.name,
|
|
499
|
-
description: item.product.description || void 0,
|
|
500
|
-
metadata: {
|
|
501
|
-
product_id: item.product.id
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
},
|
|
505
|
-
quantity: item.quantity
|
|
506
|
-
})) || [];
|
|
507
|
-
const checkoutSession = await makeRequestWith402Handling(
|
|
508
|
-
`${apiUrl}/catalog/v1/checkout/sessions`,
|
|
509
|
-
"POST",
|
|
510
|
-
{
|
|
511
|
-
line_items: checkoutLineItems,
|
|
512
|
-
customer: senderAddress,
|
|
513
|
-
metadata: {
|
|
514
|
-
sender_address: senderAddress,
|
|
515
|
-
recipient_address: recipient
|
|
516
|
-
},
|
|
517
|
-
mode: "payment"
|
|
518
|
-
},
|
|
519
|
-
secretKeyHex,
|
|
520
|
-
rpcUrl,
|
|
521
|
-
{},
|
|
522
|
-
true
|
|
523
|
-
// useJson
|
|
524
|
-
);
|
|
525
|
-
console.log("[MoneyMQ] Checkout session created:", checkoutSession);
|
|
526
|
-
const paymentIntentId = checkoutSession.payment_intent;
|
|
527
|
-
console.log("[MoneyMQ] Confirming payment intent:", paymentIntentId);
|
|
528
|
-
const confirmedIntent = await makeRequestWith402Handling(
|
|
529
|
-
`${apiUrl}/catalog/v1/payment_intents/${paymentIntentId}/confirm`,
|
|
530
|
-
"POST",
|
|
531
|
-
{},
|
|
532
|
-
secretKeyHex,
|
|
533
|
-
rpcUrl
|
|
534
|
-
);
|
|
535
|
-
console.log("[MoneyMQ] Payment intent confirmed:", confirmedIntent);
|
|
536
|
-
return confirmedIntent.id;
|
|
537
|
-
}
|
|
538
|
-
var truncateAddress = (address) => {
|
|
539
|
-
if (address.length <= 12) return address;
|
|
540
|
-
return `${address.slice(0, 4)}...${address.slice(-4)}`;
|
|
541
|
-
};
|
|
542
|
-
function CheckoutModal({
|
|
543
|
-
visible,
|
|
544
|
-
onClose,
|
|
545
|
-
amount,
|
|
546
|
-
currency,
|
|
547
|
-
recipient,
|
|
548
|
-
lineItems,
|
|
549
|
-
onSuccess,
|
|
550
|
-
onError,
|
|
551
|
-
accentColor = "#ec4899",
|
|
552
|
-
debug = false
|
|
553
|
-
}) {
|
|
554
|
-
const [isSending, setIsSending] = useState4(false);
|
|
555
|
-
const [copiedSender, setCopiedSender] = useState4(false);
|
|
556
|
-
const [copiedRecipient, setCopiedRecipient] = useState4(false);
|
|
557
|
-
const [showDetails, setShowDetails] = useState4(false);
|
|
558
|
-
const [showDebug, setShowDebug] = useState4(false);
|
|
559
|
-
const [accountBalance, setAccountBalance] = useState4(null);
|
|
560
|
-
const [selectedWallet, setSelectedWallet] = useState4(null);
|
|
561
|
-
const [selectedPaymentMethod, setSelectedPaymentMethod] = useState4(null);
|
|
562
|
-
const { publicKey, connected, disconnect, wallets, select, wallet: connectedWallet } = useWallet2();
|
|
563
|
-
const branding = useBranding();
|
|
564
|
-
const { isSandboxMode, sandboxAccounts } = useSandbox();
|
|
565
|
-
const client = useMoneyMQ();
|
|
566
|
-
const lottieRef = useRef(null);
|
|
567
|
-
const [shouldRender, setShouldRender] = useState4(false);
|
|
568
|
-
const [animationPhase, setAnimationPhase] = useState4("closed");
|
|
569
|
-
useEffect3(() => {
|
|
570
|
-
if (visible && !shouldRender) {
|
|
571
|
-
setShouldRender(true);
|
|
572
|
-
requestAnimationFrame(() => {
|
|
573
|
-
setAnimationPhase("backdrop");
|
|
574
|
-
setTimeout(() => {
|
|
575
|
-
setAnimationPhase("open");
|
|
576
|
-
}, 150);
|
|
577
|
-
});
|
|
578
|
-
} else if (!visible && shouldRender && animationPhase !== "closing") {
|
|
579
|
-
setAnimationPhase("closing");
|
|
580
|
-
setTimeout(() => {
|
|
581
|
-
setShouldRender(false);
|
|
582
|
-
setAnimationPhase("closed");
|
|
583
|
-
}, 300);
|
|
584
|
-
}
|
|
585
|
-
}, [visible, shouldRender, animationPhase]);
|
|
586
|
-
const handleAnimatedClose = useCallback3(() => {
|
|
587
|
-
if (animationPhase === "closing") return;
|
|
588
|
-
setAnimationPhase("closing");
|
|
589
|
-
setTimeout(() => {
|
|
590
|
-
setShouldRender(false);
|
|
591
|
-
setAnimationPhase("closed");
|
|
592
|
-
onClose();
|
|
593
|
-
}, 300);
|
|
594
|
-
}, [onClose, animationPhase]);
|
|
595
|
-
const copyToClipboard = (text, type) => {
|
|
596
|
-
navigator.clipboard.writeText(text);
|
|
597
|
-
if (type === "sender") {
|
|
598
|
-
setCopiedSender(true);
|
|
599
|
-
setTimeout(() => setCopiedSender(false), 2e3);
|
|
600
|
-
} else {
|
|
601
|
-
setCopiedRecipient(true);
|
|
602
|
-
setTimeout(() => setCopiedRecipient(false), 2e3);
|
|
603
|
-
}
|
|
604
|
-
};
|
|
605
|
-
const handleSelectWallet = (wallet) => {
|
|
606
|
-
setSelectedWallet(wallet);
|
|
607
|
-
setSelectedPaymentMethod({ type: "browser_extension", wallet });
|
|
608
|
-
select(wallet.adapter.name);
|
|
609
|
-
};
|
|
610
|
-
const handleSelectSandboxAccount = (account) => {
|
|
611
|
-
setSelectedPaymentMethod({ type: "sandbox_account", sandboxAccount: account });
|
|
612
|
-
setSelectedWallet(null);
|
|
613
|
-
};
|
|
614
|
-
const handleDisconnect = async () => {
|
|
615
|
-
await disconnect();
|
|
616
|
-
setSelectedWallet(null);
|
|
617
|
-
setSelectedPaymentMethod(null);
|
|
618
|
-
};
|
|
619
|
-
const availableWallets = wallets.filter(
|
|
620
|
-
(wallet) => wallet.readyState === "Installed" || wallet.readyState === "Loadable"
|
|
621
|
-
);
|
|
622
|
-
const displayedSandboxAccounts = sandboxAccounts.slice(0, 3);
|
|
623
|
-
const currentWalletIcon = connectedWallet?.adapter.icon || selectedWallet?.adapter.icon;
|
|
624
|
-
const currentWalletName = connectedWallet?.adapter.name || selectedWallet?.adapter.name;
|
|
625
|
-
const getCurrentSelectionDisplay = () => {
|
|
626
|
-
if (connected && publicKey) {
|
|
627
|
-
return {
|
|
628
|
-
icon: currentWalletIcon,
|
|
629
|
-
name: currentWalletName,
|
|
630
|
-
address: publicKey.toBase58(),
|
|
631
|
-
type: "browser_extension"
|
|
632
|
-
};
|
|
633
|
-
}
|
|
634
|
-
if (selectedPaymentMethod?.type === "sandbox_account" && selectedPaymentMethod.sandboxAccount) {
|
|
635
|
-
const name = selectedPaymentMethod.sandboxAccount.name;
|
|
636
|
-
return {
|
|
637
|
-
icon: null,
|
|
638
|
-
name: name.charAt(0).toUpperCase() + name.slice(1),
|
|
639
|
-
address: selectedPaymentMethod.sandboxAccount.address,
|
|
640
|
-
type: "sandbox_account"
|
|
641
|
-
};
|
|
642
|
-
}
|
|
643
|
-
return null;
|
|
644
|
-
};
|
|
645
|
-
const currentSelection = getCurrentSelectionDisplay();
|
|
646
|
-
React4.useEffect(() => {
|
|
647
|
-
if (!debug || !currentSelection) {
|
|
648
|
-
setAccountBalance(null);
|
|
649
|
-
return;
|
|
650
|
-
}
|
|
651
|
-
async function fetchBalance() {
|
|
652
|
-
try {
|
|
653
|
-
if (currentSelection?.type === "sandbox_account" && selectedPaymentMethod?.sandboxAccount) {
|
|
654
|
-
setAccountBalance(selectedPaymentMethod.sandboxAccount.usdcBalance ?? null);
|
|
655
|
-
return;
|
|
656
|
-
}
|
|
657
|
-
if (currentSelection?.type === "browser_extension" && publicKey) {
|
|
658
|
-
const apiUrl = normalizeRpcUrl2(client.config.endpoint);
|
|
659
|
-
try {
|
|
660
|
-
const configResponse = await fetch(`${apiUrl}/config`);
|
|
661
|
-
const config = await configResponse.json();
|
|
662
|
-
const rpcUrl = normalizeRpcUrl2(config.x402?.validator?.rpcUrl || "http://localhost:8899");
|
|
663
|
-
const response = await fetch(rpcUrl, {
|
|
664
|
-
method: "POST",
|
|
665
|
-
headers: { "Content-Type": "application/json" },
|
|
666
|
-
body: JSON.stringify({
|
|
667
|
-
jsonrpc: "2.0",
|
|
668
|
-
id: 1,
|
|
669
|
-
method: "getTokenAccountsByOwner",
|
|
670
|
-
params: [
|
|
671
|
-
publicKey.toBase58(),
|
|
672
|
-
{ programId: "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA" },
|
|
673
|
-
{ encoding: "jsonParsed" }
|
|
674
|
-
]
|
|
675
|
-
})
|
|
676
|
-
});
|
|
677
|
-
const data = await response.json();
|
|
678
|
-
const usdcAccount = data.result?.value?.find(
|
|
679
|
-
(acc) => acc.account.data.parsed.info.mint === "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v"
|
|
680
|
-
// USDC mint
|
|
681
|
-
);
|
|
682
|
-
if (usdcAccount) {
|
|
683
|
-
setAccountBalance(usdcAccount.account.data.parsed.info.tokenAmount.uiAmount);
|
|
684
|
-
} else {
|
|
685
|
-
setAccountBalance(0);
|
|
686
|
-
}
|
|
687
|
-
} catch {
|
|
688
|
-
console.log("[MoneyMQ] Could not fetch balance");
|
|
689
|
-
setAccountBalance(null);
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
} catch {
|
|
693
|
-
setAccountBalance(null);
|
|
694
|
-
}
|
|
695
|
-
}
|
|
696
|
-
fetchBalance();
|
|
697
|
-
}, [debug, currentSelection, selectedPaymentMethod, publicKey, client.config.endpoint]);
|
|
698
|
-
const handlePay = useCallback3(async () => {
|
|
699
|
-
if (!recipient) return;
|
|
700
|
-
let senderAddress;
|
|
701
|
-
let secretKeyHex;
|
|
702
|
-
if (selectedPaymentMethod?.type === "sandbox_account" && selectedPaymentMethod.sandboxAccount) {
|
|
703
|
-
senderAddress = selectedPaymentMethod.sandboxAccount.address;
|
|
704
|
-
secretKeyHex = selectedPaymentMethod.sandboxAccount.secretKeyHex;
|
|
705
|
-
} else if (publicKey) {
|
|
706
|
-
senderAddress = publicKey.toBase58();
|
|
707
|
-
} else {
|
|
708
|
-
return;
|
|
709
|
-
}
|
|
710
|
-
setIsSending(true);
|
|
711
|
-
try {
|
|
712
|
-
if (selectedPaymentMethod?.type === "sandbox_account" && secretKeyHex) {
|
|
713
|
-
const apiUrl = normalizeRpcUrl2(client.config.endpoint);
|
|
714
|
-
let rpcUrl = "http://localhost:8899";
|
|
715
|
-
try {
|
|
716
|
-
const configResponse = await fetch(`${apiUrl}/config`);
|
|
717
|
-
const config = await configResponse.json();
|
|
718
|
-
rpcUrl = normalizeRpcUrl2(config.x402?.validator?.rpcUrl || rpcUrl);
|
|
719
|
-
} catch {
|
|
720
|
-
console.log("[MoneyMQ] Using default RPC URL");
|
|
721
|
-
}
|
|
722
|
-
const paymentId = await createSandboxPayment(
|
|
723
|
-
apiUrl,
|
|
724
|
-
rpcUrl,
|
|
725
|
-
amount,
|
|
726
|
-
currency,
|
|
727
|
-
recipient,
|
|
728
|
-
senderAddress,
|
|
729
|
-
secretKeyHex,
|
|
730
|
-
lineItems
|
|
731
|
-
);
|
|
732
|
-
setIsSending(false);
|
|
733
|
-
onSuccess?.(paymentId);
|
|
734
|
-
onClose();
|
|
735
|
-
return;
|
|
736
|
-
}
|
|
737
|
-
const event = new CustomEvent("moneymq:payment-initiated", {
|
|
738
|
-
detail: {
|
|
739
|
-
amount,
|
|
740
|
-
currency,
|
|
741
|
-
recipient,
|
|
742
|
-
sender: senderAddress,
|
|
743
|
-
paymentMethod: selectedPaymentMethod?.type || "browser_extension"
|
|
744
|
-
},
|
|
745
|
-
bubbles: true
|
|
746
|
-
});
|
|
747
|
-
window.dispatchEvent(event);
|
|
748
|
-
const signature = await new Promise((resolve, reject) => {
|
|
749
|
-
const handleSuccess = (e) => {
|
|
750
|
-
const customEvent = e;
|
|
751
|
-
cleanup();
|
|
752
|
-
resolve(customEvent.detail.signature);
|
|
753
|
-
};
|
|
754
|
-
const handleError = (e) => {
|
|
755
|
-
const customEvent = e;
|
|
756
|
-
cleanup();
|
|
757
|
-
reject(customEvent.detail);
|
|
758
|
-
};
|
|
759
|
-
const cleanup = () => {
|
|
760
|
-
window.removeEventListener("moneymq:payment-success", handleSuccess);
|
|
761
|
-
window.removeEventListener("moneymq:payment-error", handleError);
|
|
762
|
-
};
|
|
763
|
-
window.addEventListener("moneymq:payment-success", handleSuccess);
|
|
764
|
-
window.addEventListener("moneymq:payment-error", handleError);
|
|
765
|
-
setTimeout(() => {
|
|
766
|
-
cleanup();
|
|
767
|
-
reject(new Error("Payment timeout"));
|
|
768
|
-
}, 6e4);
|
|
769
|
-
});
|
|
770
|
-
setIsSending(false);
|
|
771
|
-
onSuccess?.(signature);
|
|
772
|
-
onClose();
|
|
773
|
-
} catch (err) {
|
|
774
|
-
console.error("Payment failed:", err);
|
|
775
|
-
setIsSending(false);
|
|
776
|
-
onError?.(err instanceof Error ? err : new Error(String(err)));
|
|
777
|
-
}
|
|
778
|
-
}, [publicKey, recipient, amount, currency, onSuccess, onError, onClose, selectedPaymentMethod, client.config.endpoint, lineItems]);
|
|
779
|
-
const canPay = (connected && publicKey || selectedPaymentMethod?.type === "sandbox_account") && recipient && !isSending;
|
|
780
|
-
useEffect3(() => {
|
|
781
|
-
if (!canPay || !visible) return;
|
|
782
|
-
lottieRef.current?.goToAndPlay(0, true);
|
|
783
|
-
const interval = setInterval(() => {
|
|
784
|
-
lottieRef.current?.goToAndPlay(0, true);
|
|
785
|
-
}, 3e3);
|
|
786
|
-
return () => clearInterval(interval);
|
|
787
|
-
}, [canPay, visible]);
|
|
788
|
-
if (!shouldRender) return null;
|
|
789
|
-
const WalletIcon = () => /* @__PURE__ */ jsxs3("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", children: [
|
|
790
|
-
/* @__PURE__ */ jsx4("path", { d: "M21 12V7a2 2 0 00-2-2H5a2 2 0 00-2 2v10a2 2 0 002 2h14a2 2 0 002-2v-5z" }),
|
|
791
|
-
/* @__PURE__ */ jsx4("path", { d: "M16 12h.01", strokeWidth: "2", strokeLinecap: "round" })
|
|
792
|
-
] });
|
|
793
|
-
const SandboxIcon = () => /* @__PURE__ */ jsx4("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", children: /* @__PURE__ */ jsx4("path", { d: "M9.75 3.104v5.714a2.25 2.25 0 0 1-.659 1.591L5 14.5M9.75 3.104c-.251.023-.501.05-.75.082m.75-.082a24.301 24.301 0 0 1 4.5 0m0 0v5.714c0 .597.237 1.17.659 1.591L19.8 15.3M14.25 3.104c.251.023.501.05.75.082M19.8 15.3l-1.57.393A9.065 9.065 0 0 1 12 15a9.065 9.065 0 0 1-6.23.693L5 15.5m14.8-.2a2.25 2.25 0 0 1 .775 2.646l-.972 2.916a2.25 2.25 0 0 1-2.134 1.538H6.532a2.25 2.25 0 0 1-2.135-1.538l-.971-2.916A2.25 2.25 0 0 1 4.2 15.3", strokeLinecap: "round", strokeLinejoin: "round" }) });
|
|
794
|
-
const WrenchIcon = () => /* @__PURE__ */ jsx4("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.5", children: /* @__PURE__ */ jsx4("path", { d: "M11.42 15.17L17.25 21A2.652 2.652 0 0 0 21 17.25l-5.877-5.877M11.42 15.17l2.496-3.03c.317-.384.74-.626 1.208-.766M11.42 15.17l-4.655 5.653a2.548 2.548 0 1 1-3.586-3.586l6.837-5.63m5.108-.233c.55-.164 1.163-.188 1.743-.14a4.5 4.5 0 0 0 4.486-6.336l-3.276 3.277a3.004 3.004 0 0 1-2.25-2.25l3.276-3.276a4.5 4.5 0 0 0-6.336 4.486c.091 1.076-.071 2.264-.904 2.95l-.102.085m-1.745 1.437L5.909 7.5H4.5L2.25 3.75l1.5-1.5L7.5 4.5v1.409l4.26 4.26m-1.745 1.437 1.745-1.437m6.615 8.206L15.75 15.75M4.867 19.125h.008v.008h-.008v-.008Z", strokeLinecap: "round", strokeLinejoin: "round" }) });
|
|
795
|
-
const MoneyMQLogo = () => /* @__PURE__ */ jsxs3("svg", { width: "80", height: "17", viewBox: "0 0 471 99", fill: "none", children: [
|
|
796
|
-
/* @__PURE__ */ jsxs3("g", { clipPath: "url(#clip0_524_7)", children: [
|
|
797
|
-
/* @__PURE__ */ jsx4("path", { d: "M12.8892 77.1417H0V0.637573H14.3415L40.0291 60.1104L65.8075 0.637573H80.149V77.1417H67.169V25.5014L44.9306 77.2327H35.0368L12.8892 25.5014V77.2327V77.1417Z", fill: "white" }),
|
|
798
|
-
/* @__PURE__ */ jsx4("path", { d: "M113.28 77.9614C108.015 77.9614 103.295 76.7774 99.2104 74.5005C95.1257 72.2235 91.8581 68.9448 89.5888 64.7553C87.2289 60.5658 86.1396 55.6476 86.1396 49.9098C86.1396 44.172 87.3196 39.1628 89.7704 34.9733C92.2211 30.7838 95.4888 27.5051 99.6642 25.2281C103.84 22.9512 108.56 21.7673 113.733 21.7673C118.907 21.7673 123.627 22.9512 127.803 25.2281C131.978 27.5051 135.336 30.7838 137.787 34.9733C140.238 39.1628 141.509 44.081 141.509 49.8188C141.509 55.5566 140.238 60.5658 137.787 64.7553C135.246 68.9448 131.887 72.2235 127.621 74.5005C123.355 76.7774 118.635 77.9614 113.37 77.9614H113.28ZM113.189 66.9411C115.73 66.9411 118.181 66.3036 120.45 65.1196C122.72 63.8445 124.626 62.023 126.078 59.4729C127.53 56.9227 128.257 53.735 128.257 49.8188C128.257 45.9025 127.53 42.897 126.169 40.3468C124.807 37.7967 122.992 35.9752 120.723 34.7001C118.453 33.425 116.003 32.8786 113.461 32.8786C110.92 32.8786 108.56 33.5161 106.381 34.7001C104.203 35.9752 102.478 37.7967 101.207 40.3468C99.9365 42.897 99.3011 46.0846 99.3011 50.0009C99.3011 53.9172 99.9365 56.9227 101.117 59.4729C102.387 62.023 104.021 63.8445 106.2 65.1196C108.378 66.3947 110.647 66.9411 113.189 66.9411Z", fill: "white" }),
|
|
799
|
-
/* @__PURE__ */ jsx4("path", { d: "M146.41 22.4959H157.484L158.392 27.8694C160.207 25.9568 162.386 24.4995 164.927 23.4066C167.469 22.3137 170.192 21.7673 173.096 21.7673C177.272 21.7673 180.993 22.678 184.079 24.4085C187.166 26.23 189.526 28.7801 191.25 32.241C192.884 35.7019 193.792 39.9825 193.792 45.1739V77.0506H181.356V46.9043C181.356 42.2594 180.449 38.7075 178.633 36.4305C176.818 34.1536 174.095 32.9696 170.373 32.9696C166.652 32.9696 163.747 34.1536 161.75 36.5216C159.753 38.8896 158.846 42.4416 158.846 47.0865V77.1417H146.501V22.4959H146.41Z", fill: "white" }),
|
|
800
|
-
/* @__PURE__ */ jsx4("path", { d: "M225.107 77.9614C219.661 77.9614 214.85 76.7774 210.765 74.3183C206.681 71.8592 203.504 68.5805 201.144 64.2999C198.875 60.0193 197.695 55.0101 197.695 49.4545C197.695 44.172 198.784 39.4361 201.053 35.2466C203.322 31.057 206.409 27.7783 210.402 25.4103C214.396 23.0423 218.935 21.7673 223.927 21.7673C228.919 21.7673 233.73 22.8602 237.633 25.1371C241.536 27.414 244.622 30.5106 246.892 34.609C249.161 38.6164 250.25 43.3523 250.25 48.6348C250.25 49.5455 250.25 50.4563 250.068 51.4581C249.978 52.46 249.796 53.4618 249.705 54.5547H211.038C211.31 57.1959 212.127 59.3818 213.398 61.2033C214.669 63.0248 216.302 64.4821 218.209 65.4839C220.205 66.4857 222.475 67.0322 225.107 67.0322C228.102 67.0322 230.825 66.3947 233.185 65.1196C235.636 63.8445 237.27 62.2051 238.268 60.2925L249.07 63.9356C246.892 68.3073 243.715 71.7682 239.448 74.2272C235.182 76.6863 230.372 77.9614 225.016 77.9614H225.107ZM236.816 44.5363C236.816 42.2594 236.272 40.2557 235.092 38.4342C233.912 36.6127 232.368 35.1555 230.553 34.1536C228.647 33.0607 226.559 32.6053 224.199 32.6053C222.112 32.6053 220.115 33.1518 218.39 34.1536C216.575 35.1555 215.122 36.6127 213.852 38.3431C212.581 40.1647 211.764 42.2594 211.31 44.6274H236.816V44.5363Z", fill: "white" }),
|
|
801
|
-
/* @__PURE__ */ jsx4("path", { d: "M291.368 22.4958H304.439L272.398 99H260.235L270.038 75.5022L248.707 22.4958H262.413L276.754 61.2033L291.368 22.4958Z", fill: "white" }),
|
|
802
|
-
/* @__PURE__ */ jsx4("path", { d: "M320.687 77.1417H307.797V0.637573H322.139L347.827 60.1104L373.605 0.637573H387.946V77.1417H374.966V25.5014L352.728 77.2327H342.834L320.596 25.5014V77.2327L320.687 77.1417Z", fill: "white" }),
|
|
803
|
-
/* @__PURE__ */ jsx4("path", { d: "M432.332 77.9614C426.977 77.9614 421.894 77.0506 417.174 75.138C412.454 73.2254 408.369 70.5842 404.829 67.1233C401.289 63.6624 398.566 59.5639 396.569 54.7369C394.573 50.0009 393.574 44.7185 393.574 38.9807C393.574 33.2429 394.573 28.0515 396.569 23.3155C398.566 18.5796 401.289 14.3901 404.829 10.9292C408.369 7.46826 412.454 4.73597 417.174 2.82337C421.894 0.910764 426.886 0 432.332 0C437.779 0 442.771 0.910764 447.4 2.82337C452.029 4.73597 456.205 7.37719 459.745 10.9292C463.285 14.3901 466.008 18.5796 468.005 23.3155C470.002 28.0515 471 33.3339 471 38.9807C471 44.6274 470.002 50.0009 468.095 54.7369C466.098 59.4729 463.375 63.6624 459.835 67.1233C456.295 70.5842 452.12 73.2254 447.491 75.138C442.862 77.0506 437.779 77.9614 432.423 77.9614H432.332ZM432.242 66.9411C437.143 66.9411 441.591 65.7571 445.403 63.4802C449.215 61.2033 452.302 57.9246 454.571 53.735C456.84 49.5455 457.929 44.6274 457.929 38.8896C457.929 33.1518 456.84 28.1426 454.571 24.0442C452.302 19.9457 449.306 16.667 445.403 14.3901C441.591 12.1132 437.143 10.9292 432.242 10.9292C427.34 10.9292 422.892 12.1132 419.08 14.3901C415.268 16.667 412.182 19.9457 410.003 24.0442C407.825 28.1426 406.736 33.1518 406.736 38.8896C406.736 44.6274 407.825 49.5455 410.094 53.735C412.273 57.9246 415.359 61.2033 419.171 63.4802C422.983 65.7571 427.34 66.9411 432.332 66.9411H432.242ZM426.251 55.0101H438.868V87.9798H426.251V55.0101Z", fill: "white" })
|
|
804
|
-
] }),
|
|
805
|
-
/* @__PURE__ */ jsx4("defs", { children: /* @__PURE__ */ jsx4("clipPath", { id: "clip0_524_7", children: /* @__PURE__ */ jsx4("rect", { width: "471", height: "99", fill: "white" }) }) })
|
|
806
|
-
] });
|
|
807
|
-
const isBackdropVisible = animationPhase === "backdrop" || animationPhase === "open";
|
|
808
|
-
const isModalVisible = animationPhase === "open";
|
|
809
|
-
const isClosing = animationPhase === "closing";
|
|
810
|
-
return /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
811
|
-
/* @__PURE__ */ jsx4("style", { children: `
|
|
812
|
-
@keyframes spin {
|
|
813
|
-
from { transform: rotate(0deg); }
|
|
814
|
-
to { transform: rotate(360deg); }
|
|
815
|
-
}
|
|
816
|
-
` }),
|
|
817
|
-
/* @__PURE__ */ jsx4(
|
|
818
|
-
"div",
|
|
819
|
-
{
|
|
820
|
-
style: {
|
|
821
|
-
position: "fixed",
|
|
822
|
-
inset: 0,
|
|
823
|
-
zIndex: 9998,
|
|
824
|
-
backgroundColor: isBackdropVisible && !isClosing ? "rgba(0, 0, 0, 0.6)" : "rgba(0, 0, 0, 0)",
|
|
825
|
-
backdropFilter: isBackdropVisible && !isClosing ? "blur(8px)" : "blur(0px)",
|
|
826
|
-
transition: "background-color 250ms cubic-bezier(0.4, 0, 0.2, 1), backdrop-filter 250ms cubic-bezier(0.4, 0, 0.2, 1)"
|
|
827
|
-
},
|
|
828
|
-
onClick: handleAnimatedClose
|
|
829
|
-
}
|
|
830
|
-
),
|
|
831
|
-
/* @__PURE__ */ jsx4(
|
|
832
|
-
"div",
|
|
833
|
-
{
|
|
834
|
-
style: {
|
|
835
|
-
position: "fixed",
|
|
836
|
-
inset: 0,
|
|
837
|
-
zIndex: 9999,
|
|
838
|
-
display: "flex",
|
|
839
|
-
alignItems: "center",
|
|
840
|
-
justifyContent: "center",
|
|
841
|
-
padding: "1rem",
|
|
842
|
-
pointerEvents: isClosing ? "none" : "auto"
|
|
843
|
-
},
|
|
844
|
-
onClick: handleAnimatedClose,
|
|
845
|
-
children: /* @__PURE__ */ jsxs3(
|
|
846
|
-
"div",
|
|
847
|
-
{
|
|
848
|
-
style: {
|
|
849
|
-
width: "100%",
|
|
850
|
-
maxWidth: "380px",
|
|
851
|
-
backgroundColor: "#2c2c2e",
|
|
852
|
-
borderRadius: "1rem",
|
|
853
|
-
overflow: "hidden",
|
|
854
|
-
boxShadow: "0 25px 50px -12px rgba(0, 0, 0, 0.5)",
|
|
855
|
-
opacity: isModalVisible && !isClosing ? 1 : 0,
|
|
856
|
-
transform: isModalVisible && !isClosing ? "translateY(0) scale(1)" : "translateY(-20px) scale(0.98)",
|
|
857
|
-
transition: "opacity 200ms cubic-bezier(0.4, 0, 0.2, 1), transform 250ms cubic-bezier(0.4, 0, 0.2, 1)"
|
|
858
|
-
},
|
|
859
|
-
onClick: (e) => e.stopPropagation(),
|
|
860
|
-
children: [
|
|
861
|
-
/* @__PURE__ */ jsxs3(
|
|
862
|
-
"div",
|
|
863
|
-
{
|
|
864
|
-
style: {
|
|
865
|
-
display: "flex",
|
|
866
|
-
alignItems: "center",
|
|
867
|
-
justifyContent: "space-between",
|
|
868
|
-
padding: "1rem 1.25rem",
|
|
869
|
-
borderBottom: "1px solid #3a3a3c"
|
|
870
|
-
},
|
|
871
|
-
children: [
|
|
872
|
-
/* @__PURE__ */ jsxs3("div", { style: { display: "flex", alignItems: "center", gap: "0.5rem" }, children: [
|
|
873
|
-
branding?.logo ? /* @__PURE__ */ jsx4(
|
|
874
|
-
"img",
|
|
875
|
-
{
|
|
876
|
-
src: branding.logo,
|
|
877
|
-
alt: "Logo",
|
|
878
|
-
style: { height: "24px", width: "auto", filter: "invert(1)" }
|
|
879
|
-
}
|
|
880
|
-
) : /* @__PURE__ */ jsx4(MoneyMQLogo, {}),
|
|
881
|
-
isSandboxMode && /* @__PURE__ */ jsx4("span", { style: { fontSize: "0.75rem", fontWeight: 600, color: "#ff9f0a", position: "relative", top: "-1px" }, children: "{ sandbox }" })
|
|
882
|
-
] }),
|
|
883
|
-
/* @__PURE__ */ jsxs3("div", { style: { display: "flex", alignItems: "center", gap: "0.5rem" }, children: [
|
|
884
|
-
debug && /* @__PURE__ */ jsx4(
|
|
885
|
-
"button",
|
|
886
|
-
{
|
|
887
|
-
onClick: () => setShowDebug(!showDebug),
|
|
888
|
-
style: {
|
|
889
|
-
width: "28px",
|
|
890
|
-
height: "28px",
|
|
891
|
-
borderRadius: "9999px",
|
|
892
|
-
border: "none",
|
|
893
|
-
backgroundColor: showDebug ? "rgba(255, 159, 10, 0.2)" : "#3a3a3c",
|
|
894
|
-
color: showDebug ? "#ff9f0a" : "#8e8e93",
|
|
895
|
-
cursor: "pointer",
|
|
896
|
-
display: "flex",
|
|
897
|
-
alignItems: "center",
|
|
898
|
-
justifyContent: "center",
|
|
899
|
-
padding: 0,
|
|
900
|
-
transition: "all 150ms"
|
|
901
|
-
},
|
|
902
|
-
title: "Debug info",
|
|
903
|
-
children: /* @__PURE__ */ jsx4(WrenchIcon, {})
|
|
904
|
-
}
|
|
905
|
-
),
|
|
906
|
-
/* @__PURE__ */ jsx4(
|
|
907
|
-
"button",
|
|
908
|
-
{
|
|
909
|
-
onClick: handleAnimatedClose,
|
|
910
|
-
style: {
|
|
911
|
-
padding: "0.375rem 0.75rem",
|
|
912
|
-
fontSize: "0.8125rem",
|
|
913
|
-
fontWeight: 500,
|
|
914
|
-
color: "#8e8e93",
|
|
915
|
-
backgroundColor: "#3a3a3c",
|
|
916
|
-
borderRadius: "9999px",
|
|
917
|
-
border: "none",
|
|
918
|
-
cursor: "pointer"
|
|
919
|
-
},
|
|
920
|
-
children: "cancel"
|
|
921
|
-
}
|
|
922
|
-
)
|
|
923
|
-
] })
|
|
924
|
-
]
|
|
925
|
-
}
|
|
926
|
-
),
|
|
927
|
-
/* @__PURE__ */ jsx4("div", { style: { padding: "0.75rem" }, children: currentSelection ? /* @__PURE__ */ jsx4(
|
|
928
|
-
"div",
|
|
929
|
-
{
|
|
930
|
-
style: {
|
|
931
|
-
backgroundColor: "#3a3a3c",
|
|
932
|
-
borderRadius: "0.75rem",
|
|
933
|
-
padding: "0.875rem 1rem",
|
|
934
|
-
marginBottom: "0.5rem"
|
|
935
|
-
},
|
|
936
|
-
children: /* @__PURE__ */ jsxs3("div", { style: { display: "flex", alignItems: "center", gap: "0.75rem" }, children: [
|
|
937
|
-
/* @__PURE__ */ jsx4(
|
|
938
|
-
"div",
|
|
939
|
-
{
|
|
940
|
-
style: {
|
|
941
|
-
width: "40px",
|
|
942
|
-
height: "40px",
|
|
943
|
-
borderRadius: "0.5rem",
|
|
944
|
-
backgroundColor: currentSelection.icon ? "transparent" : "#636366",
|
|
945
|
-
display: "flex",
|
|
946
|
-
alignItems: "center",
|
|
947
|
-
justifyContent: "center",
|
|
948
|
-
color: "#fff",
|
|
949
|
-
overflow: "hidden"
|
|
950
|
-
},
|
|
951
|
-
children: currentSelection.icon ? /* @__PURE__ */ jsx4(
|
|
952
|
-
"img",
|
|
953
|
-
{
|
|
954
|
-
src: currentSelection.icon,
|
|
955
|
-
alt: currentSelection.name || "Wallet",
|
|
956
|
-
style: { width: "40px", height: "40px", borderRadius: "0.5rem" }
|
|
957
|
-
}
|
|
958
|
-
) : currentSelection.type === "sandbox_account" ? /* @__PURE__ */ jsx4(SandboxIcon, {}) : /* @__PURE__ */ jsx4(WalletIcon, {})
|
|
959
|
-
}
|
|
960
|
-
),
|
|
961
|
-
/* @__PURE__ */ jsxs3("div", { style: { flex: 1, minWidth: 0 }, children: [
|
|
962
|
-
/* @__PURE__ */ jsxs3("div", { style: { display: "flex", alignItems: "center", gap: "0.375rem", marginBottom: "0.125rem" }, children: [
|
|
963
|
-
/* @__PURE__ */ jsxs3("span", { style: { fontSize: "0.75rem", color: "#8e8e93" }, children: [
|
|
964
|
-
"From ",
|
|
965
|
-
truncateAddress(currentSelection.address)
|
|
966
|
-
] }),
|
|
967
|
-
/* @__PURE__ */ jsx4(
|
|
968
|
-
"button",
|
|
969
|
-
{
|
|
970
|
-
onClick: () => copyToClipboard(currentSelection.address, "sender"),
|
|
971
|
-
style: {
|
|
972
|
-
padding: 0,
|
|
973
|
-
background: "none",
|
|
974
|
-
border: "none",
|
|
975
|
-
cursor: "pointer",
|
|
976
|
-
color: copiedSender ? "#30d158" : "#8e8e93",
|
|
977
|
-
display: "flex",
|
|
978
|
-
alignItems: "center"
|
|
979
|
-
},
|
|
980
|
-
children: /* @__PURE__ */ jsxs3("svg", { width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
981
|
-
/* @__PURE__ */ jsx4("rect", { x: "9", y: "9", width: "13", height: "13", rx: "2", ry: "2" }),
|
|
982
|
-
/* @__PURE__ */ jsx4("path", { d: "M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1" })
|
|
983
|
-
] })
|
|
984
|
-
}
|
|
985
|
-
)
|
|
986
|
-
] }),
|
|
987
|
-
/* @__PURE__ */ jsx4(
|
|
988
|
-
"span",
|
|
989
|
-
{
|
|
990
|
-
style: {
|
|
991
|
-
fontSize: "0.9375rem",
|
|
992
|
-
fontWeight: 500,
|
|
993
|
-
color: "#fff"
|
|
994
|
-
},
|
|
995
|
-
children: currentSelection.name
|
|
996
|
-
}
|
|
997
|
-
)
|
|
998
|
-
] }),
|
|
999
|
-
/* @__PURE__ */ jsx4(
|
|
1000
|
-
"button",
|
|
1001
|
-
{
|
|
1002
|
-
onClick: handleDisconnect,
|
|
1003
|
-
style: {
|
|
1004
|
-
fontSize: "0.75rem",
|
|
1005
|
-
fontWeight: 500,
|
|
1006
|
-
color: "#ff453a",
|
|
1007
|
-
backgroundColor: "rgba(255, 69, 58, 0.15)",
|
|
1008
|
-
borderRadius: "9999px",
|
|
1009
|
-
border: "none",
|
|
1010
|
-
cursor: "pointer",
|
|
1011
|
-
padding: "0.25rem 0.625rem"
|
|
1012
|
-
},
|
|
1013
|
-
children: "unlink"
|
|
1014
|
-
}
|
|
1015
|
-
)
|
|
1016
|
-
] })
|
|
1017
|
-
}
|
|
1018
|
-
) : /* @__PURE__ */ jsxs3(Menu, { as: "div", style: { position: "relative", marginBottom: "0.5rem" }, children: [
|
|
1019
|
-
/* @__PURE__ */ jsxs3(
|
|
1020
|
-
MenuButton,
|
|
1021
|
-
{
|
|
1022
|
-
style: {
|
|
1023
|
-
width: "100%",
|
|
1024
|
-
backgroundColor: "#3a3a3c",
|
|
1025
|
-
borderRadius: "0.75rem",
|
|
1026
|
-
padding: "0.875rem 1rem",
|
|
1027
|
-
border: "none",
|
|
1028
|
-
cursor: "pointer",
|
|
1029
|
-
display: "flex",
|
|
1030
|
-
alignItems: "center",
|
|
1031
|
-
gap: "0.75rem",
|
|
1032
|
-
textAlign: "left"
|
|
1033
|
-
},
|
|
1034
|
-
children: [
|
|
1035
|
-
/* @__PURE__ */ jsx4(
|
|
1036
|
-
"div",
|
|
1037
|
-
{
|
|
1038
|
-
style: {
|
|
1039
|
-
width: "40px",
|
|
1040
|
-
height: "40px",
|
|
1041
|
-
borderRadius: "0.5rem",
|
|
1042
|
-
backgroundColor: currentWalletIcon ? "transparent" : "#636366",
|
|
1043
|
-
display: "flex",
|
|
1044
|
-
alignItems: "center",
|
|
1045
|
-
justifyContent: "center",
|
|
1046
|
-
color: "#fff",
|
|
1047
|
-
overflow: "hidden",
|
|
1048
|
-
flexShrink: 0
|
|
1049
|
-
},
|
|
1050
|
-
children: currentWalletIcon ? /* @__PURE__ */ jsx4(
|
|
1051
|
-
"img",
|
|
1052
|
-
{
|
|
1053
|
-
src: currentWalletIcon,
|
|
1054
|
-
alt: currentWalletName || "Wallet",
|
|
1055
|
-
style: { width: "40px", height: "40px", borderRadius: "0.5rem" }
|
|
1056
|
-
}
|
|
1057
|
-
) : /* @__PURE__ */ jsx4(WalletIcon, {})
|
|
1058
|
-
}
|
|
1059
|
-
),
|
|
1060
|
-
/* @__PURE__ */ jsxs3("div", { style: { flex: 1, minWidth: 0 }, children: [
|
|
1061
|
-
/* @__PURE__ */ jsx4("div", { style: { fontSize: "0.75rem", color: "#8e8e93", marginBottom: "0.125rem" }, children: "From" }),
|
|
1062
|
-
/* @__PURE__ */ jsx4(
|
|
1063
|
-
"span",
|
|
1064
|
-
{
|
|
1065
|
-
style: {
|
|
1066
|
-
fontSize: "0.9375rem",
|
|
1067
|
-
fontWeight: 500,
|
|
1068
|
-
color: "#0a84ff"
|
|
1069
|
-
},
|
|
1070
|
-
children: selectedWallet ? selectedWallet.adapter.name : "Connect Wallet"
|
|
1071
|
-
}
|
|
1072
|
-
)
|
|
1073
|
-
] }),
|
|
1074
|
-
/* @__PURE__ */ jsx4(
|
|
1075
|
-
"svg",
|
|
1076
|
-
{
|
|
1077
|
-
width: "16",
|
|
1078
|
-
height: "16",
|
|
1079
|
-
viewBox: "0 0 16 16",
|
|
1080
|
-
fill: "#8e8e93",
|
|
1081
|
-
style: { flexShrink: 0 },
|
|
1082
|
-
children: /* @__PURE__ */ jsx4("path", { fillRule: "evenodd", d: "M5.22 10.22a.75.75 0 0 1 1.06 0L8 11.94l1.72-1.72a.75.75 0 1 1 1.06 1.06l-2.25 2.25a.75.75 0 0 1-1.06 0l-2.25-2.25a.75.75 0 0 1 0-1.06ZM10.78 5.78a.75.75 0 0 1-1.06 0L8 4.06 6.28 5.78a.75.75 0 0 1-1.06-1.06l2.25-2.25a.75.75 0 0 1 1.06 0l2.25 2.25a.75.75 0 0 1 0 1.06Z", clipRule: "evenodd" })
|
|
1083
|
-
}
|
|
1084
|
-
)
|
|
1085
|
-
]
|
|
1086
|
-
}
|
|
1087
|
-
),
|
|
1088
|
-
/* @__PURE__ */ jsxs3(
|
|
1089
|
-
MenuItems,
|
|
1090
|
-
{
|
|
1091
|
-
anchor: "bottom start",
|
|
1092
|
-
style: {
|
|
1093
|
-
backgroundColor: "#2c2c2e",
|
|
1094
|
-
borderRadius: "0.75rem",
|
|
1095
|
-
padding: "0.25rem",
|
|
1096
|
-
boxShadow: "0 10px 25px rgba(0, 0, 0, 0.4)",
|
|
1097
|
-
zIndex: 1e4,
|
|
1098
|
-
outline: "none",
|
|
1099
|
-
border: "1px solid #48484a",
|
|
1100
|
-
maxHeight: "300px",
|
|
1101
|
-
overflowY: "auto",
|
|
1102
|
-
width: "var(--button-width)",
|
|
1103
|
-
marginTop: "0.25rem"
|
|
1104
|
-
},
|
|
1105
|
-
children: [
|
|
1106
|
-
isSandboxMode && displayedSandboxAccounts.length > 0 && /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
1107
|
-
displayedSandboxAccounts.map((account) => /* @__PURE__ */ jsx4(MenuItem, { children: ({ focus }) => /* @__PURE__ */ jsxs3(
|
|
1108
|
-
"button",
|
|
1109
|
-
{
|
|
1110
|
-
onClick: () => handleSelectSandboxAccount(account),
|
|
1111
|
-
style: {
|
|
1112
|
-
display: "flex",
|
|
1113
|
-
alignItems: "center",
|
|
1114
|
-
gap: "0.75rem",
|
|
1115
|
-
padding: "0.875rem 1rem",
|
|
1116
|
-
backgroundColor: focus ? "#3a3a3c" : "transparent",
|
|
1117
|
-
borderRadius: "0.5rem",
|
|
1118
|
-
border: "none",
|
|
1119
|
-
cursor: "pointer",
|
|
1120
|
-
width: "100%",
|
|
1121
|
-
textAlign: "left",
|
|
1122
|
-
transition: "background-color 150ms"
|
|
1123
|
-
},
|
|
1124
|
-
children: [
|
|
1125
|
-
/* @__PURE__ */ jsx4(
|
|
1126
|
-
"div",
|
|
1127
|
-
{
|
|
1128
|
-
style: {
|
|
1129
|
-
width: "40px",
|
|
1130
|
-
height: "40px",
|
|
1131
|
-
borderRadius: "0.5rem",
|
|
1132
|
-
backgroundColor: "#636366",
|
|
1133
|
-
display: "flex",
|
|
1134
|
-
alignItems: "center",
|
|
1135
|
-
justifyContent: "center",
|
|
1136
|
-
overflow: "hidden",
|
|
1137
|
-
flexShrink: 0,
|
|
1138
|
-
color: "#fff"
|
|
1139
|
-
},
|
|
1140
|
-
children: /* @__PURE__ */ jsx4(SandboxIcon, {})
|
|
1141
|
-
}
|
|
1142
|
-
),
|
|
1143
|
-
/* @__PURE__ */ jsxs3("div", { style: { flex: 1, minWidth: 0 }, children: [
|
|
1144
|
-
/* @__PURE__ */ jsxs3("div", { style: { display: "flex", alignItems: "center", gap: "0.375rem", marginBottom: "0.125rem" }, children: [
|
|
1145
|
-
/* @__PURE__ */ jsxs3("span", { style: { fontSize: "0.75rem", color: "#8e8e93" }, children: [
|
|
1146
|
-
"From ",
|
|
1147
|
-
truncateAddress(account.address)
|
|
1148
|
-
] }),
|
|
1149
|
-
/* @__PURE__ */ jsx4(
|
|
1150
|
-
"span",
|
|
1151
|
-
{
|
|
1152
|
-
role: "button",
|
|
1153
|
-
tabIndex: 0,
|
|
1154
|
-
onClick: (e) => {
|
|
1155
|
-
e.stopPropagation();
|
|
1156
|
-
navigator.clipboard.writeText(account.address);
|
|
1157
|
-
},
|
|
1158
|
-
onKeyDown: (e) => {
|
|
1159
|
-
if (e.key === "Enter" || e.key === " ") {
|
|
1160
|
-
e.stopPropagation();
|
|
1161
|
-
navigator.clipboard.writeText(account.address);
|
|
1162
|
-
}
|
|
1163
|
-
},
|
|
1164
|
-
style: {
|
|
1165
|
-
padding: 0,
|
|
1166
|
-
background: "none",
|
|
1167
|
-
border: "none",
|
|
1168
|
-
cursor: "pointer",
|
|
1169
|
-
color: "#8e8e93",
|
|
1170
|
-
display: "flex",
|
|
1171
|
-
alignItems: "center"
|
|
1172
|
-
},
|
|
1173
|
-
children: /* @__PURE__ */ jsxs3("svg", { width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
1174
|
-
/* @__PURE__ */ jsx4("rect", { x: "9", y: "9", width: "13", height: "13", rx: "2", ry: "2" }),
|
|
1175
|
-
/* @__PURE__ */ jsx4("path", { d: "M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1" })
|
|
1176
|
-
] })
|
|
1177
|
-
}
|
|
1178
|
-
)
|
|
1179
|
-
] }),
|
|
1180
|
-
/* @__PURE__ */ jsx4(
|
|
1181
|
-
"span",
|
|
1182
|
-
{
|
|
1183
|
-
style: {
|
|
1184
|
-
fontSize: "0.9375rem",
|
|
1185
|
-
fontWeight: 500,
|
|
1186
|
-
color: "#fff"
|
|
1187
|
-
},
|
|
1188
|
-
children: account.name.charAt(0).toUpperCase() + account.name.slice(1)
|
|
1189
|
-
}
|
|
1190
|
-
)
|
|
1191
|
-
] }),
|
|
1192
|
-
account.usdcBalance !== void 0 && /* @__PURE__ */ jsxs3(
|
|
1193
|
-
"span",
|
|
1194
|
-
{
|
|
1195
|
-
style: {
|
|
1196
|
-
fontSize: "0.6875rem",
|
|
1197
|
-
color: "#ff9f0a",
|
|
1198
|
-
backgroundColor: "rgba(255, 159, 10, 0.15)",
|
|
1199
|
-
padding: "0.25rem 0.5rem",
|
|
1200
|
-
borderRadius: "0.25rem",
|
|
1201
|
-
flexShrink: 0
|
|
1202
|
-
},
|
|
1203
|
-
children: [
|
|
1204
|
-
account.usdcBalance.toLocaleString(),
|
|
1205
|
-
" USDC"
|
|
1206
|
-
]
|
|
1207
|
-
}
|
|
1208
|
-
)
|
|
1209
|
-
]
|
|
1210
|
-
}
|
|
1211
|
-
) }, account.id)),
|
|
1212
|
-
availableWallets.length > 0 && /* @__PURE__ */ jsx4("div", { style: { height: "1px", backgroundColor: "#48484a", margin: "0.25rem 0" } })
|
|
1213
|
-
] }),
|
|
1214
|
-
availableWallets.length > 0 ? availableWallets.map((wallet) => /* @__PURE__ */ jsx4(MenuItem, { children: ({ focus }) => /* @__PURE__ */ jsxs3(
|
|
1215
|
-
"button",
|
|
1216
|
-
{
|
|
1217
|
-
onClick: () => handleSelectWallet(wallet),
|
|
1218
|
-
style: {
|
|
1219
|
-
display: "flex",
|
|
1220
|
-
alignItems: "center",
|
|
1221
|
-
gap: "0.75rem",
|
|
1222
|
-
padding: "0.875rem 1rem",
|
|
1223
|
-
backgroundColor: focus ? "#3a3a3c" : "transparent",
|
|
1224
|
-
borderRadius: "0.5rem",
|
|
1225
|
-
border: "none",
|
|
1226
|
-
cursor: "pointer",
|
|
1227
|
-
width: "100%",
|
|
1228
|
-
textAlign: "left",
|
|
1229
|
-
transition: "background-color 150ms"
|
|
1230
|
-
},
|
|
1231
|
-
children: [
|
|
1232
|
-
/* @__PURE__ */ jsx4(
|
|
1233
|
-
"div",
|
|
1234
|
-
{
|
|
1235
|
-
style: {
|
|
1236
|
-
width: "40px",
|
|
1237
|
-
height: "40px",
|
|
1238
|
-
borderRadius: "0.5rem",
|
|
1239
|
-
backgroundColor: "#636366",
|
|
1240
|
-
display: "flex",
|
|
1241
|
-
alignItems: "center",
|
|
1242
|
-
justifyContent: "center",
|
|
1243
|
-
overflow: "hidden",
|
|
1244
|
-
flexShrink: 0
|
|
1245
|
-
},
|
|
1246
|
-
children: wallet.adapter.icon ? /* @__PURE__ */ jsx4(
|
|
1247
|
-
"img",
|
|
1248
|
-
{
|
|
1249
|
-
src: wallet.adapter.icon,
|
|
1250
|
-
alt: wallet.adapter.name,
|
|
1251
|
-
style: {
|
|
1252
|
-
width: "40px",
|
|
1253
|
-
height: "40px",
|
|
1254
|
-
borderRadius: "0.5rem"
|
|
1255
|
-
}
|
|
1256
|
-
}
|
|
1257
|
-
) : /* @__PURE__ */ jsx4(WalletIcon, {})
|
|
1258
|
-
}
|
|
1259
|
-
),
|
|
1260
|
-
/* @__PURE__ */ jsxs3("div", { style: { flex: 1, minWidth: 0 }, children: [
|
|
1261
|
-
/* @__PURE__ */ jsx4("div", { style: { fontSize: "0.75rem", color: "#8e8e93", marginBottom: "0.125rem" }, children: "Browser Extension" }),
|
|
1262
|
-
/* @__PURE__ */ jsx4(
|
|
1263
|
-
"span",
|
|
1264
|
-
{
|
|
1265
|
-
style: {
|
|
1266
|
-
fontSize: "0.9375rem",
|
|
1267
|
-
fontWeight: 500,
|
|
1268
|
-
color: "#fff"
|
|
1269
|
-
},
|
|
1270
|
-
children: wallet.adapter.name
|
|
1271
|
-
}
|
|
1272
|
-
)
|
|
1273
|
-
] }),
|
|
1274
|
-
wallet.readyState === "Installed" && /* @__PURE__ */ jsx4(
|
|
1275
|
-
"span",
|
|
1276
|
-
{
|
|
1277
|
-
style: {
|
|
1278
|
-
fontSize: "0.6875rem",
|
|
1279
|
-
color: "#30d158",
|
|
1280
|
-
backgroundColor: "rgba(48, 209, 88, 0.15)",
|
|
1281
|
-
padding: "0.25rem 0.5rem",
|
|
1282
|
-
borderRadius: "0.25rem",
|
|
1283
|
-
flexShrink: 0
|
|
1284
|
-
},
|
|
1285
|
-
children: "Detected"
|
|
1286
|
-
}
|
|
1287
|
-
)
|
|
1288
|
-
]
|
|
1289
|
-
}
|
|
1290
|
-
) }, wallet.adapter.name)) : !isSandboxMode || displayedSandboxAccounts.length === 0 ? /* @__PURE__ */ jsx4(
|
|
1291
|
-
"div",
|
|
1292
|
-
{
|
|
1293
|
-
style: {
|
|
1294
|
-
textAlign: "center",
|
|
1295
|
-
padding: "1.5rem",
|
|
1296
|
-
color: "#8e8e93",
|
|
1297
|
-
fontSize: "0.875rem"
|
|
1298
|
-
},
|
|
1299
|
-
children: "No wallets detected"
|
|
1300
|
-
}
|
|
1301
|
-
) : null
|
|
1302
|
-
]
|
|
1303
|
-
}
|
|
1304
|
-
)
|
|
1305
|
-
] }) }),
|
|
1306
|
-
/* @__PURE__ */ jsxs3(
|
|
1307
|
-
"div",
|
|
1308
|
-
{
|
|
1309
|
-
style: {
|
|
1310
|
-
padding: "1rem 1.25rem 1.25rem",
|
|
1311
|
-
borderTop: "1px solid #3a3a3c"
|
|
1312
|
-
},
|
|
1313
|
-
children: [
|
|
1314
|
-
/* @__PURE__ */ jsxs3("div", { style: { marginBottom: "1rem" }, children: [
|
|
1315
|
-
lineItems && lineItems.length > 0 && /* @__PURE__ */ jsx4("div", { style: { marginBottom: "0.75rem" }, children: lineItems.map((item, index) => /* @__PURE__ */ jsxs3(
|
|
1316
|
-
"div",
|
|
1317
|
-
{
|
|
1318
|
-
style: {
|
|
1319
|
-
display: "flex",
|
|
1320
|
-
justifyContent: "space-between",
|
|
1321
|
-
alignItems: "center",
|
|
1322
|
-
padding: "0.5rem 0",
|
|
1323
|
-
borderBottom: index < lineItems.length - 1 ? "1px solid #3a3a3c" : "none"
|
|
1324
|
-
},
|
|
1325
|
-
children: [
|
|
1326
|
-
/* @__PURE__ */ jsxs3("div", { style: { flex: 1 }, children: [
|
|
1327
|
-
/* @__PURE__ */ jsx4("div", { style: { fontSize: "0.875rem", color: "#fff", fontWeight: 500 }, children: item.product.name }),
|
|
1328
|
-
item.quantity > 1 && /* @__PURE__ */ jsxs3("div", { style: { fontSize: "0.75rem", color: "#8e8e93" }, children: [
|
|
1329
|
-
"Qty: ",
|
|
1330
|
-
item.quantity,
|
|
1331
|
-
" \xD7 ",
|
|
1332
|
-
(item.price.unit_amount / 100).toLocaleString(void 0, { minimumFractionDigits: 2, maximumFractionDigits: 2 }),
|
|
1333
|
-
" ",
|
|
1334
|
-
item.price.currency.toUpperCase()
|
|
1335
|
-
] })
|
|
1336
|
-
] }),
|
|
1337
|
-
/* @__PURE__ */ jsxs3("div", { style: { fontSize: "0.875rem", color: "#fff", fontWeight: 500 }, children: [
|
|
1338
|
-
item.subtotal.toLocaleString(void 0, { minimumFractionDigits: 2, maximumFractionDigits: 2 }),
|
|
1339
|
-
" ",
|
|
1340
|
-
item.price.currency.toUpperCase()
|
|
1341
|
-
] })
|
|
1342
|
-
]
|
|
1343
|
-
},
|
|
1344
|
-
item.product.id + "-" + index
|
|
1345
|
-
)) }),
|
|
1346
|
-
/* @__PURE__ */ jsx4("div", { style: { fontSize: "0.875rem", color: "#8e8e93", marginBottom: "0.25rem" }, children: "Total" }),
|
|
1347
|
-
/* @__PURE__ */ jsxs3("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between" }, children: [
|
|
1348
|
-
/* @__PURE__ */ jsxs3("div", { style: { display: "flex", alignItems: "baseline", gap: "0.375rem" }, children: [
|
|
1349
|
-
/* @__PURE__ */ jsx4("span", { style: { fontSize: "2rem", fontWeight: 600, color: "#fff" }, children: amount.toLocaleString(void 0, { minimumFractionDigits: 2, maximumFractionDigits: 2 }) }),
|
|
1350
|
-
/* @__PURE__ */ jsx4("span", { style: { fontSize: "1rem", fontWeight: 500, color: "#8e8e93" }, children: currency })
|
|
1351
|
-
] }),
|
|
1352
|
-
/* @__PURE__ */ jsx4(
|
|
1353
|
-
"button",
|
|
1354
|
-
{
|
|
1355
|
-
onClick: () => setShowDetails(!showDetails),
|
|
1356
|
-
style: {
|
|
1357
|
-
width: "22px",
|
|
1358
|
-
height: "22px",
|
|
1359
|
-
borderRadius: "50%",
|
|
1360
|
-
border: "1.5px solid #8e8e93",
|
|
1361
|
-
background: "none",
|
|
1362
|
-
color: "#8e8e93",
|
|
1363
|
-
fontSize: "0.8125rem",
|
|
1364
|
-
fontWeight: 600,
|
|
1365
|
-
fontStyle: "italic",
|
|
1366
|
-
fontFamily: "Georgia, serif",
|
|
1367
|
-
cursor: "pointer",
|
|
1368
|
-
display: "flex",
|
|
1369
|
-
alignItems: "center",
|
|
1370
|
-
justifyContent: "center",
|
|
1371
|
-
padding: 0,
|
|
1372
|
-
transition: "all 150ms"
|
|
1373
|
-
},
|
|
1374
|
-
title: "Show payment details",
|
|
1375
|
-
children: "i"
|
|
1376
|
-
}
|
|
1377
|
-
)
|
|
1378
|
-
] }),
|
|
1379
|
-
showDetails && /* @__PURE__ */ jsx4(
|
|
1380
|
-
"div",
|
|
1381
|
-
{
|
|
1382
|
-
style: {
|
|
1383
|
-
marginTop: "0.75rem",
|
|
1384
|
-
padding: "0.625rem 0.75rem",
|
|
1385
|
-
backgroundColor: "#3a3a3c",
|
|
1386
|
-
borderRadius: "0.5rem",
|
|
1387
|
-
fontSize: "0.8125rem"
|
|
1388
|
-
},
|
|
1389
|
-
children: /* @__PURE__ */ jsxs3("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between" }, children: [
|
|
1390
|
-
/* @__PURE__ */ jsx4("span", { style: { color: "#8e8e93" }, children: "Recipient" }),
|
|
1391
|
-
/* @__PURE__ */ jsxs3("div", { style: { display: "flex", alignItems: "center", gap: "0.375rem" }, children: [
|
|
1392
|
-
/* @__PURE__ */ jsx4(
|
|
1393
|
-
"span",
|
|
1394
|
-
{
|
|
1395
|
-
style: {
|
|
1396
|
-
color: "#fff",
|
|
1397
|
-
fontFamily: "ui-monospace, monospace",
|
|
1398
|
-
fontSize: "0.75rem"
|
|
1399
|
-
},
|
|
1400
|
-
children: truncateAddress(recipient)
|
|
1401
|
-
}
|
|
1402
|
-
),
|
|
1403
|
-
/* @__PURE__ */ jsx4(
|
|
1404
|
-
"button",
|
|
1405
|
-
{
|
|
1406
|
-
onClick: () => copyToClipboard(recipient, "recipient"),
|
|
1407
|
-
style: {
|
|
1408
|
-
padding: 0,
|
|
1409
|
-
background: "none",
|
|
1410
|
-
border: "none",
|
|
1411
|
-
cursor: "pointer",
|
|
1412
|
-
color: copiedRecipient ? "#30d158" : "#8e8e93",
|
|
1413
|
-
display: "flex",
|
|
1414
|
-
alignItems: "center"
|
|
1415
|
-
},
|
|
1416
|
-
children: /* @__PURE__ */ jsxs3("svg", { width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [
|
|
1417
|
-
/* @__PURE__ */ jsx4("rect", { x: "9", y: "9", width: "13", height: "13", rx: "2", ry: "2" }),
|
|
1418
|
-
/* @__PURE__ */ jsx4("path", { d: "M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1" })
|
|
1419
|
-
] })
|
|
1420
|
-
}
|
|
1421
|
-
)
|
|
1422
|
-
] })
|
|
1423
|
-
] })
|
|
1424
|
-
}
|
|
1425
|
-
),
|
|
1426
|
-
showDebug && /* @__PURE__ */ jsxs3(
|
|
1427
|
-
"div",
|
|
1428
|
-
{
|
|
1429
|
-
style: {
|
|
1430
|
-
marginTop: "0.75rem",
|
|
1431
|
-
padding: "0.75rem",
|
|
1432
|
-
backgroundColor: "#1c1c1e",
|
|
1433
|
-
borderRadius: "0.5rem",
|
|
1434
|
-
fontSize: "0.75rem",
|
|
1435
|
-
fontFamily: 'ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace'
|
|
1436
|
-
},
|
|
1437
|
-
children: [
|
|
1438
|
-
/* @__PURE__ */ jsx4("div", { style: {
|
|
1439
|
-
display: "flex",
|
|
1440
|
-
alignItems: "center",
|
|
1441
|
-
gap: "0.5rem",
|
|
1442
|
-
marginBottom: "0.5rem",
|
|
1443
|
-
paddingBottom: "0.5rem",
|
|
1444
|
-
borderBottom: "1px solid #2c2c2e"
|
|
1445
|
-
}, children: /* @__PURE__ */ jsx4("span", { style: { color: "#8e8e93" }, children: "DEBUG" }) }),
|
|
1446
|
-
/* @__PURE__ */ jsxs3("div", { style: { display: "flex", alignItems: "center", justifyContent: "space-between" }, children: [
|
|
1447
|
-
/* @__PURE__ */ jsx4("span", { style: { color: "#8e8e93" }, children: "balance" }),
|
|
1448
|
-
/* @__PURE__ */ jsx4("span", { style: { color: "#30d158" }, children: accountBalance !== null ? `${accountBalance.toLocaleString(void 0, { minimumFractionDigits: 2, maximumFractionDigits: 2 })} ${currency}` : currentSelection ? "..." : "null" })
|
|
1449
|
-
] })
|
|
1450
|
-
]
|
|
1451
|
-
}
|
|
1452
|
-
)
|
|
1453
|
-
] }),
|
|
1454
|
-
/* @__PURE__ */ jsx4(
|
|
1455
|
-
"button",
|
|
1456
|
-
{
|
|
1457
|
-
onClick: handlePay,
|
|
1458
|
-
disabled: !canPay,
|
|
1459
|
-
style: {
|
|
1460
|
-
width: "100%",
|
|
1461
|
-
padding: "0.5rem 1rem",
|
|
1462
|
-
borderRadius: "0.75rem",
|
|
1463
|
-
border: "none",
|
|
1464
|
-
fontSize: "1.0625rem",
|
|
1465
|
-
fontWeight: 600,
|
|
1466
|
-
cursor: canPay ? "pointer" : "not-allowed",
|
|
1467
|
-
backgroundColor: canPay ? "#000" : "#48484a",
|
|
1468
|
-
color: canPay ? "#fff" : "#8e8e93",
|
|
1469
|
-
display: "flex",
|
|
1470
|
-
alignItems: "center",
|
|
1471
|
-
justifyContent: "center",
|
|
1472
|
-
gap: "0.25rem",
|
|
1473
|
-
transition: "opacity 150ms"
|
|
1474
|
-
},
|
|
1475
|
-
children: isSending ? /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
1476
|
-
/* @__PURE__ */ jsx4(
|
|
1477
|
-
"div",
|
|
1478
|
-
{
|
|
1479
|
-
style: {
|
|
1480
|
-
width: "1.25rem",
|
|
1481
|
-
height: "1.25rem",
|
|
1482
|
-
border: "2px solid currentColor",
|
|
1483
|
-
borderTopColor: "transparent",
|
|
1484
|
-
borderRadius: "50%",
|
|
1485
|
-
animation: "spin 1s linear infinite"
|
|
1486
|
-
}
|
|
1487
|
-
}
|
|
1488
|
-
),
|
|
1489
|
-
/* @__PURE__ */ jsx4("span", { children: "Processing..." })
|
|
1490
|
-
] }) : /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
1491
|
-
/* @__PURE__ */ jsx4(
|
|
1492
|
-
Lottie,
|
|
1493
|
-
{
|
|
1494
|
-
lottieRef,
|
|
1495
|
-
animationData: logo_animation_default,
|
|
1496
|
-
loop: false,
|
|
1497
|
-
autoplay: false,
|
|
1498
|
-
style: {
|
|
1499
|
-
width: 48,
|
|
1500
|
-
height: 48,
|
|
1501
|
-
marginTop: "-8px",
|
|
1502
|
-
marginBottom: "-8px",
|
|
1503
|
-
marginLeft: "-8px",
|
|
1504
|
-
marginRight: "4px",
|
|
1505
|
-
opacity: canPay ? 1 : 0.55,
|
|
1506
|
-
transition: "opacity 150ms"
|
|
1507
|
-
}
|
|
1508
|
-
}
|
|
1509
|
-
),
|
|
1510
|
-
/* @__PURE__ */ jsxs3("span", { children: [
|
|
1511
|
-
"Pay ",
|
|
1512
|
-
amount.toLocaleString(void 0, { minimumFractionDigits: 2, maximumFractionDigits: 2 }),
|
|
1513
|
-
" ",
|
|
1514
|
-
currency
|
|
1515
|
-
] })
|
|
1516
|
-
] })
|
|
1517
|
-
}
|
|
1518
|
-
)
|
|
1519
|
-
]
|
|
1520
|
-
}
|
|
1521
|
-
)
|
|
1522
|
-
]
|
|
1523
|
-
}
|
|
1524
|
-
)
|
|
1525
|
-
}
|
|
1526
|
-
)
|
|
1527
|
-
] });
|
|
1528
|
-
}
|
|
1529
|
-
|
|
1530
|
-
// src/checkout-button.tsx
|
|
1531
|
-
import { Fragment as Fragment3, jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
1532
|
-
var baseStyle = {
|
|
1533
|
-
position: "relative",
|
|
1534
|
-
display: "inline-flex",
|
|
1535
|
-
alignItems: "center",
|
|
1536
|
-
justifyContent: "center",
|
|
1537
|
-
gap: "0.5rem",
|
|
1538
|
-
borderRadius: "0.5rem",
|
|
1539
|
-
fontSize: "0.875rem",
|
|
1540
|
-
fontWeight: 600,
|
|
1541
|
-
padding: "0.625rem 1rem",
|
|
1542
|
-
cursor: "pointer",
|
|
1543
|
-
transition: "all 200ms",
|
|
1544
|
-
border: "none"
|
|
1545
|
-
};
|
|
1546
|
-
var solidStyle = {
|
|
1547
|
-
...baseStyle,
|
|
1548
|
-
backgroundColor: "#ec4899",
|
|
1549
|
-
color: "white",
|
|
1550
|
-
boxShadow: "0 1px 2px 0 rgb(0 0 0 / 0.05)"
|
|
1551
|
-
};
|
|
1552
|
-
var outlineStyle = {
|
|
1553
|
-
...baseStyle,
|
|
1554
|
-
backgroundColor: "transparent",
|
|
1555
|
-
color: "#ec4899",
|
|
1556
|
-
border: "1px solid #ec4899"
|
|
1557
|
-
};
|
|
1558
|
-
var CheckoutButton = forwardRef(
|
|
1559
|
-
function CheckoutButton2({
|
|
1560
|
-
basket,
|
|
1561
|
-
onSuccess,
|
|
1562
|
-
onError,
|
|
1563
|
-
variant = "solid",
|
|
1564
|
-
children,
|
|
1565
|
-
disabled,
|
|
1566
|
-
debug = false
|
|
1567
|
-
}, ref) {
|
|
1568
|
-
const client = useMoneyMQ();
|
|
1569
|
-
const [isModalOpen, setIsModalOpen] = useState5(false);
|
|
1570
|
-
const [isHovered, setIsHovered] = useState5(false);
|
|
1571
|
-
const [isLoading, setIsLoading] = useState5(true);
|
|
1572
|
-
const [error, setError] = useState5(null);
|
|
1573
|
-
const [recipient, setRecipient] = useState5("");
|
|
1574
|
-
const { totalAmount, currency, lineItems } = React5.useMemo(() => {
|
|
1575
|
-
if (!basket || basket.length === 0) {
|
|
1576
|
-
return { totalAmount: 0, currency: "USDC", lineItems: [] };
|
|
1577
|
-
}
|
|
1578
|
-
const baseCurrency = basket[0].price.currency.toUpperCase();
|
|
1579
|
-
const items = basket.map((item) => ({
|
|
1580
|
-
product: item.product,
|
|
1581
|
-
price: item.price,
|
|
1582
|
-
quantity: item.quantity ?? 1,
|
|
1583
|
-
subtotal: item.price.unit_amount / 100 * (item.quantity ?? 1)
|
|
1584
|
-
}));
|
|
1585
|
-
const total = items.reduce((sum, item) => sum + item.subtotal, 0);
|
|
1586
|
-
return {
|
|
1587
|
-
totalAmount: total,
|
|
1588
|
-
currency: baseCurrency,
|
|
1589
|
-
lineItems: items
|
|
1590
|
-
};
|
|
1591
|
-
}, [basket]);
|
|
1592
|
-
useEffect4(() => {
|
|
1593
|
-
async function fetchPaymentDetails() {
|
|
1594
|
-
setIsLoading(true);
|
|
1595
|
-
setError(null);
|
|
1596
|
-
try {
|
|
1597
|
-
if (!basket || basket.length === 0) {
|
|
1598
|
-
throw new Error("Basket is empty");
|
|
1599
|
-
}
|
|
1600
|
-
const apiUrl = client.config.endpoint;
|
|
1601
|
-
const configResponse = await fetch(`${apiUrl}/config`);
|
|
1602
|
-
if (!configResponse.ok) {
|
|
1603
|
-
throw new Error(`Failed to fetch config: ${configResponse.status}`);
|
|
1604
|
-
}
|
|
1605
|
-
const config = await configResponse.json();
|
|
1606
|
-
if (config.x402?.payoutAccount?.address) {
|
|
1607
|
-
setRecipient(config.x402.payoutAccount.address);
|
|
1608
|
-
}
|
|
1609
|
-
} catch (err) {
|
|
1610
|
-
console.error("[CheckoutButton] Error fetching payment details:", err);
|
|
1611
|
-
const errorMessage = err instanceof Error ? err.message : "Failed to load payment details";
|
|
1612
|
-
setError(errorMessage);
|
|
1613
|
-
onError?.(new Error(errorMessage));
|
|
1614
|
-
} finally {
|
|
1615
|
-
setIsLoading(false);
|
|
1616
|
-
}
|
|
1617
|
-
}
|
|
1618
|
-
fetchPaymentDetails();
|
|
1619
|
-
}, [basket, client.config.endpoint, onError]);
|
|
1620
|
-
const handleClick = () => {
|
|
1621
|
-
if (!isLoading && !error) {
|
|
1622
|
-
setIsModalOpen(true);
|
|
1623
|
-
}
|
|
1624
|
-
};
|
|
1625
|
-
const handlePaymentSuccess = (signature) => {
|
|
1626
|
-
const payment = {
|
|
1627
|
-
id: `pay_${Date.now()}`,
|
|
1628
|
-
amount: totalAmount,
|
|
1629
|
-
currency,
|
|
1630
|
-
status: "completed",
|
|
1631
|
-
signature
|
|
1632
|
-
};
|
|
1633
|
-
onSuccess?.(payment);
|
|
1634
|
-
};
|
|
1635
|
-
const handlePaymentError = (error2) => {
|
|
1636
|
-
onError?.(error2);
|
|
1637
|
-
};
|
|
1638
|
-
const isDisabled = disabled || isLoading || !!error;
|
|
1639
|
-
const buttonStyle = {
|
|
1640
|
-
...variant === "outline" ? outlineStyle : solidStyle,
|
|
1641
|
-
backgroundColor: variant === "solid" ? isHovered && !isDisabled ? "#db2777" : "#ec4899" : isHovered && !isDisabled ? "rgba(236, 72, 153, 0.1)" : "transparent",
|
|
1642
|
-
opacity: isDisabled ? 0.5 : 1,
|
|
1643
|
-
cursor: isDisabled ? "not-allowed" : "pointer"
|
|
1644
|
-
};
|
|
1645
|
-
return /* @__PURE__ */ jsxs4(Fragment3, { children: [
|
|
1646
|
-
/* @__PURE__ */ jsx5(
|
|
1647
|
-
"button",
|
|
1648
|
-
{
|
|
1649
|
-
ref,
|
|
1650
|
-
onClick: handleClick,
|
|
1651
|
-
disabled: isDisabled,
|
|
1652
|
-
style: buttonStyle,
|
|
1653
|
-
title: error || void 0,
|
|
1654
|
-
onMouseEnter: () => setIsHovered(true),
|
|
1655
|
-
onMouseLeave: () => setIsHovered(false),
|
|
1656
|
-
children: isLoading ? /* @__PURE__ */ jsx5("span", { children: "Loading..." }) : error ? /* @__PURE__ */ jsx5("span", { children: "Error" }) : children || /* @__PURE__ */ jsx5("span", { children: "Pay" })
|
|
1657
|
-
}
|
|
1658
|
-
),
|
|
1659
|
-
/* @__PURE__ */ jsx5(
|
|
1660
|
-
CheckoutModal,
|
|
1661
|
-
{
|
|
1662
|
-
visible: isModalOpen,
|
|
1663
|
-
onClose: () => setIsModalOpen(false),
|
|
1664
|
-
amount: totalAmount,
|
|
1665
|
-
currency,
|
|
1666
|
-
recipient,
|
|
1667
|
-
lineItems,
|
|
1668
|
-
onSuccess: handlePaymentSuccess,
|
|
1669
|
-
onError: handlePaymentError,
|
|
1670
|
-
debug
|
|
1671
|
-
}
|
|
1672
|
-
)
|
|
1673
|
-
] });
|
|
1674
|
-
}
|
|
1675
|
-
);
|
|
1676
|
-
|
|
1677
|
-
// src/use-payment.ts
|
|
1678
|
-
import { useCallback as useCallback4, useState as useState6 } from "react";
|
|
1679
|
-
import { useWallet as useWallet3 } from "@solana/wallet-adapter-react";
|
|
1680
|
-
function usePayment() {
|
|
1681
|
-
const [isPending, setIsPending] = useState6(false);
|
|
1682
|
-
const [lastPayment, setLastPayment] = useState6(null);
|
|
1683
|
-
const { publicKey, connected } = useWallet3();
|
|
1684
|
-
const { setVisible } = useWalletModal();
|
|
1685
|
-
const pay = useCallback4(async (priceId) => {
|
|
1686
|
-
if (!connected || !publicKey) {
|
|
1687
|
-
setVisible(true);
|
|
1688
|
-
return null;
|
|
1689
|
-
}
|
|
1690
|
-
setIsPending(true);
|
|
1691
|
-
try {
|
|
1692
|
-
const event = new CustomEvent("moneymq:pay", {
|
|
1693
|
-
detail: { priceId, publicKey: publicKey.toBase58() },
|
|
1694
|
-
bubbles: true
|
|
1695
|
-
});
|
|
1696
|
-
window.dispatchEvent(event);
|
|
1697
|
-
const result = await new Promise((resolve, reject) => {
|
|
1698
|
-
const handleSuccess = (e) => {
|
|
1699
|
-
const customEvent = e;
|
|
1700
|
-
cleanup();
|
|
1701
|
-
resolve(customEvent.detail);
|
|
1702
|
-
};
|
|
1703
|
-
const handleError = (e) => {
|
|
1704
|
-
const customEvent = e;
|
|
1705
|
-
cleanup();
|
|
1706
|
-
reject(customEvent.detail);
|
|
1707
|
-
};
|
|
1708
|
-
const cleanup = () => {
|
|
1709
|
-
window.removeEventListener("moneymq:payment-success", handleSuccess);
|
|
1710
|
-
window.removeEventListener("moneymq:payment-error", handleError);
|
|
1711
|
-
};
|
|
1712
|
-
window.addEventListener("moneymq:payment-success", handleSuccess);
|
|
1713
|
-
window.addEventListener("moneymq:payment-error", handleError);
|
|
1714
|
-
setTimeout(() => {
|
|
1715
|
-
cleanup();
|
|
1716
|
-
reject(new Error("Payment timeout"));
|
|
1717
|
-
}, 6e4);
|
|
1718
|
-
});
|
|
1719
|
-
setLastPayment(result);
|
|
1720
|
-
return result;
|
|
1721
|
-
} catch {
|
|
1722
|
-
return null;
|
|
1723
|
-
} finally {
|
|
1724
|
-
setIsPending(false);
|
|
1725
|
-
}
|
|
1726
|
-
}, [connected, publicKey, setVisible]);
|
|
1727
|
-
return { pay, isPending, lastPayment };
|
|
1728
|
-
}
|
|
1729
|
-
export {
|
|
1730
|
-
CheckoutButton,
|
|
1731
|
-
CheckoutModal,
|
|
1732
|
-
MoneyMQContext,
|
|
1733
|
-
MoneyMQProvider,
|
|
1734
|
-
SandboxContext,
|
|
1735
|
-
useMoneyMQ,
|
|
1736
|
-
usePayment,
|
|
1737
|
-
useSandbox
|
|
1738
|
-
};
|
|
1739
|
-
//# sourceMappingURL=index.mjs.map
|