x402-mantle-sdk 0.1.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 +130 -0
- package/dist/client/index.cjs +844 -0
- package/dist/client/index.cjs.map +1 -0
- package/dist/client/index.d.cts +322 -0
- package/dist/client/index.d.ts +322 -0
- package/dist/client/index.js +793 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/react.cjs +658 -0
- package/dist/client/react.cjs.map +1 -0
- package/dist/client/react.d.cts +42 -0
- package/dist/client/react.d.ts +42 -0
- package/dist/client/react.js +631 -0
- package/dist/client/react.js.map +1 -0
- package/dist/server/index.cjs +657 -0
- package/dist/server/index.cjs.map +1 -0
- package/dist/server/index.d.cts +292 -0
- package/dist/server/index.d.ts +292 -0
- package/dist/server/index.js +617 -0
- package/dist/server/index.js.map +1 -0
- package/package.json +103 -0
|
@@ -0,0 +1,658 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/client/react.ts
|
|
21
|
+
var react_exports = {};
|
|
22
|
+
__export(react_exports, {
|
|
23
|
+
PaymentModal: () => PaymentModal
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(react_exports);
|
|
26
|
+
|
|
27
|
+
// src/client/modal-react.tsx
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
|
|
30
|
+
// src/client/constants.ts
|
|
31
|
+
var TOKENS = {
|
|
32
|
+
mantle: {
|
|
33
|
+
USDC: {
|
|
34
|
+
address: "0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9",
|
|
35
|
+
decimals: 6,
|
|
36
|
+
symbol: "USDC"
|
|
37
|
+
},
|
|
38
|
+
USDT: {
|
|
39
|
+
address: "0x201EBa5CC46D216Ce6DC03F6a759e8E766e956aE",
|
|
40
|
+
decimals: 6,
|
|
41
|
+
symbol: "USDT"
|
|
42
|
+
},
|
|
43
|
+
mETH: {
|
|
44
|
+
address: "0xcDA86A272531e8640cD7F1a92c01839911B90bb0",
|
|
45
|
+
decimals: 18,
|
|
46
|
+
symbol: "mETH"
|
|
47
|
+
},
|
|
48
|
+
WMNT: {
|
|
49
|
+
address: "0x78c1b0C915c4FAA5FffA6CAbf0219DA63d7f4cb8",
|
|
50
|
+
decimals: 18,
|
|
51
|
+
symbol: "WMNT"
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
"mantle-sepolia": {
|
|
55
|
+
USDC: {
|
|
56
|
+
address: "0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9",
|
|
57
|
+
decimals: 6,
|
|
58
|
+
symbol: "USDC"
|
|
59
|
+
},
|
|
60
|
+
mETH: {
|
|
61
|
+
address: "0xdEAddEaDdeadDEadDEADDEAddEADDEAddead1111",
|
|
62
|
+
decimals: 18,
|
|
63
|
+
symbol: "mETH"
|
|
64
|
+
},
|
|
65
|
+
WMNT: {
|
|
66
|
+
address: "0x78c1b0C915c4FAA5FffA6CAbf0219DA63d7f4cb8",
|
|
67
|
+
decimals: 18,
|
|
68
|
+
symbol: "WMNT"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"mantle-testnet": {
|
|
72
|
+
USDC: {
|
|
73
|
+
address: "0x09Bc4E0D864854c6aFB6eB9A9cdF58aC190D0dF9",
|
|
74
|
+
decimals: 6,
|
|
75
|
+
symbol: "USDC"
|
|
76
|
+
},
|
|
77
|
+
mETH: {
|
|
78
|
+
address: "0xdEAddEaDdeadDEadDEADDEAddEADDEAddead1111",
|
|
79
|
+
decimals: 18,
|
|
80
|
+
symbol: "mETH"
|
|
81
|
+
},
|
|
82
|
+
WMNT: {
|
|
83
|
+
address: "0x78c1b0C915c4FAA5FffA6CAbf0219DA63d7f4cb8",
|
|
84
|
+
decimals: 18,
|
|
85
|
+
symbol: "WMNT"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
var TREASURY_ADDRESS = "0xB27705342ACE73736AE490540Ea031cc06C3eF49";
|
|
90
|
+
var PLATFORM_FEE_BPS = 50n;
|
|
91
|
+
var BPS_DENOMINATOR = 10000n;
|
|
92
|
+
var customTokens = /* @__PURE__ */ new Map();
|
|
93
|
+
function getTokenConfig(token, network) {
|
|
94
|
+
const networkKey = network.toLowerCase();
|
|
95
|
+
const tokenKey = token.toUpperCase();
|
|
96
|
+
if (tokenKey === "MNT") {
|
|
97
|
+
return null;
|
|
98
|
+
}
|
|
99
|
+
const customMap = customTokens.get(networkKey);
|
|
100
|
+
if (customMap?.has(tokenKey)) {
|
|
101
|
+
return customMap.get(tokenKey);
|
|
102
|
+
}
|
|
103
|
+
return TOKENS[networkKey]?.[tokenKey] || null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/client/wallet.ts
|
|
107
|
+
function getEthereumProvider() {
|
|
108
|
+
if (typeof window === "undefined") {
|
|
109
|
+
return null;
|
|
110
|
+
}
|
|
111
|
+
return window.ethereum || null;
|
|
112
|
+
}
|
|
113
|
+
var MetaMaskProvider = class {
|
|
114
|
+
constructor() {
|
|
115
|
+
this.ethereum = getEthereumProvider();
|
|
116
|
+
}
|
|
117
|
+
isAvailable() {
|
|
118
|
+
return this.ethereum !== null && this.ethereum.isMetaMask === true;
|
|
119
|
+
}
|
|
120
|
+
async connect() {
|
|
121
|
+
if (!this.ethereum) {
|
|
122
|
+
throw new Error("MetaMask is not available");
|
|
123
|
+
}
|
|
124
|
+
const accounts = await this.ethereum.request({
|
|
125
|
+
method: "eth_requestAccounts"
|
|
126
|
+
});
|
|
127
|
+
if (!accounts || accounts.length === 0) {
|
|
128
|
+
throw new Error("No accounts found");
|
|
129
|
+
}
|
|
130
|
+
return accounts[0];
|
|
131
|
+
}
|
|
132
|
+
async getAccount() {
|
|
133
|
+
if (!this.ethereum) {
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
try {
|
|
137
|
+
const accounts = await this.ethereum.request({
|
|
138
|
+
method: "eth_accounts"
|
|
139
|
+
});
|
|
140
|
+
return accounts && accounts.length > 0 ? accounts[0] : null;
|
|
141
|
+
} catch {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
async getChainId() {
|
|
146
|
+
if (!this.ethereum) {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
try {
|
|
150
|
+
const chainIdHex = await this.ethereum.request({
|
|
151
|
+
method: "eth_chainId"
|
|
152
|
+
});
|
|
153
|
+
return parseInt(chainIdHex, 16);
|
|
154
|
+
} catch {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
async switchNetwork(chainId) {
|
|
159
|
+
if (!this.ethereum) {
|
|
160
|
+
throw new Error("MetaMask is not available");
|
|
161
|
+
}
|
|
162
|
+
const chainIdHex = `0x${chainId.toString(16)}`;
|
|
163
|
+
try {
|
|
164
|
+
await this.ethereum.request({
|
|
165
|
+
method: "wallet_switchEthereumChain",
|
|
166
|
+
params: [{ chainId: chainIdHex }]
|
|
167
|
+
});
|
|
168
|
+
} catch (error) {
|
|
169
|
+
const switchError = error;
|
|
170
|
+
if (switchError.code === 4902) {
|
|
171
|
+
throw new Error(`Network with chainId ${chainId} not found. Use addNetwork() first.`);
|
|
172
|
+
}
|
|
173
|
+
throw error;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
async addNetwork(params) {
|
|
177
|
+
if (!this.ethereum) {
|
|
178
|
+
throw new Error("MetaMask is not available");
|
|
179
|
+
}
|
|
180
|
+
await this.ethereum.request({
|
|
181
|
+
method: "wallet_addEthereumChain",
|
|
182
|
+
params: [params]
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
async sendTransaction(tx) {
|
|
186
|
+
if (!this.ethereum) {
|
|
187
|
+
throw new Error("MetaMask is not available");
|
|
188
|
+
}
|
|
189
|
+
const txHash = await this.ethereum.request({
|
|
190
|
+
method: "eth_sendTransaction",
|
|
191
|
+
params: [tx]
|
|
192
|
+
});
|
|
193
|
+
return txHash;
|
|
194
|
+
}
|
|
195
|
+
async signMessage(message) {
|
|
196
|
+
if (!this.ethereum) {
|
|
197
|
+
throw new Error("MetaMask is not available");
|
|
198
|
+
}
|
|
199
|
+
const account = await this.getAccount();
|
|
200
|
+
if (!account) {
|
|
201
|
+
throw new Error("No account connected");
|
|
202
|
+
}
|
|
203
|
+
const signature = await this.ethereum.request({
|
|
204
|
+
method: "personal_sign",
|
|
205
|
+
params: [message, account]
|
|
206
|
+
});
|
|
207
|
+
return signature;
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
function detectWalletProvider() {
|
|
211
|
+
const metaMask = new MetaMaskProvider();
|
|
212
|
+
if (metaMask.isAvailable()) {
|
|
213
|
+
return metaMask;
|
|
214
|
+
}
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
async function connectWallet(provider) {
|
|
218
|
+
const wallet = provider || detectWalletProvider();
|
|
219
|
+
if (!wallet) {
|
|
220
|
+
throw new Error(
|
|
221
|
+
"No wallet provider found. Please install MetaMask or another compatible wallet."
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
return wallet.connect();
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// src/client/payment.ts
|
|
228
|
+
var ERC20_TRANSFER_SIG = "0xa9059cbb";
|
|
229
|
+
function amountToWei(amount, decimals = 18) {
|
|
230
|
+
const parts = amount.split(".");
|
|
231
|
+
const whole = parts[0] || "0";
|
|
232
|
+
const fraction = (parts[1] || "").padEnd(decimals, "0").slice(0, decimals);
|
|
233
|
+
return BigInt(whole) * 10n ** BigInt(decimals) + BigInt(fraction);
|
|
234
|
+
}
|
|
235
|
+
function calculateSplit(amount) {
|
|
236
|
+
const feeAmount = amount * PLATFORM_FEE_BPS / BPS_DENOMINATOR;
|
|
237
|
+
const merchantAmount = amount - feeAmount;
|
|
238
|
+
return { merchantAmount, feeAmount };
|
|
239
|
+
}
|
|
240
|
+
function encodeERC20Transfer(to, amount) {
|
|
241
|
+
const toHex = to.slice(2).toLowerCase().padStart(64, "0");
|
|
242
|
+
const amountHex = amount.toString(16).padStart(64, "0");
|
|
243
|
+
return ERC20_TRANSFER_SIG + toHex + amountHex;
|
|
244
|
+
}
|
|
245
|
+
async function processPayment(request, wallet) {
|
|
246
|
+
const tokenConfig = getTokenConfig(request.token, request.network);
|
|
247
|
+
const decimals = tokenConfig?.decimals ?? 18;
|
|
248
|
+
const totalAmount = amountToWei(request.amount, decimals);
|
|
249
|
+
const { merchantAmount, feeAmount } = calculateSplit(totalAmount);
|
|
250
|
+
let txHash;
|
|
251
|
+
if (tokenConfig) {
|
|
252
|
+
const transferData = encodeERC20Transfer(request.recipient, totalAmount);
|
|
253
|
+
const tx = {
|
|
254
|
+
to: tokenConfig.address,
|
|
255
|
+
data: transferData
|
|
256
|
+
};
|
|
257
|
+
txHash = await wallet.sendTransaction(tx);
|
|
258
|
+
} else {
|
|
259
|
+
const merchantTx = {
|
|
260
|
+
to: request.recipient,
|
|
261
|
+
value: `0x${merchantAmount.toString(16)}`
|
|
262
|
+
};
|
|
263
|
+
txHash = await wallet.sendTransaction(merchantTx);
|
|
264
|
+
if (feeAmount > 0n) {
|
|
265
|
+
const feeTx = {
|
|
266
|
+
to: TREASURY_ADDRESS,
|
|
267
|
+
value: `0x${feeAmount.toString(16)}`
|
|
268
|
+
};
|
|
269
|
+
await wallet.sendTransaction(feeTx);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return {
|
|
273
|
+
transactionHash: txHash,
|
|
274
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// src/client/modal-react.tsx
|
|
279
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
280
|
+
function formatAddress(address) {
|
|
281
|
+
return `${address.slice(0, 6)}...${address.slice(-4)}`;
|
|
282
|
+
}
|
|
283
|
+
function PaymentModal({ request, onComplete, onCancel, isOpen }) {
|
|
284
|
+
const [walletAddress, setWalletAddress] = (0, import_react.useState)(null);
|
|
285
|
+
const [isConnecting, setIsConnecting] = (0, import_react.useState)(false);
|
|
286
|
+
const [isProcessing, setIsProcessing] = (0, import_react.useState)(false);
|
|
287
|
+
const [error, setError] = (0, import_react.useState)(null);
|
|
288
|
+
const [step, setStep] = (0, import_react.useState)("connect");
|
|
289
|
+
const checkWalletConnection = (0, import_react.useCallback)(async () => {
|
|
290
|
+
const wallet = detectWalletProvider();
|
|
291
|
+
if (wallet) {
|
|
292
|
+
try {
|
|
293
|
+
const account = await wallet.getAccount();
|
|
294
|
+
if (account) {
|
|
295
|
+
setWalletAddress(account);
|
|
296
|
+
setStep("confirm");
|
|
297
|
+
}
|
|
298
|
+
} catch {
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}, []);
|
|
302
|
+
(0, import_react.useEffect)(() => {
|
|
303
|
+
if (isOpen) {
|
|
304
|
+
checkWalletConnection();
|
|
305
|
+
} else {
|
|
306
|
+
setStep("connect");
|
|
307
|
+
setError(null);
|
|
308
|
+
setWalletAddress(null);
|
|
309
|
+
}
|
|
310
|
+
}, [isOpen, checkWalletConnection]);
|
|
311
|
+
const handleConnect = async () => {
|
|
312
|
+
setIsConnecting(true);
|
|
313
|
+
setError(null);
|
|
314
|
+
try {
|
|
315
|
+
const wallet = detectWalletProvider();
|
|
316
|
+
if (!wallet) {
|
|
317
|
+
throw new Error("No wallet found. Please install MetaMask.");
|
|
318
|
+
}
|
|
319
|
+
const address = await connectWallet(wallet);
|
|
320
|
+
setWalletAddress(address);
|
|
321
|
+
setStep("confirm");
|
|
322
|
+
} catch (err) {
|
|
323
|
+
setError(err instanceof Error ? err.message : "Failed to connect wallet");
|
|
324
|
+
} finally {
|
|
325
|
+
setIsConnecting(false);
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
const handlePay = async () => {
|
|
329
|
+
setIsProcessing(true);
|
|
330
|
+
setError(null);
|
|
331
|
+
setStep("processing");
|
|
332
|
+
try {
|
|
333
|
+
const wallet = detectWalletProvider();
|
|
334
|
+
if (!wallet) {
|
|
335
|
+
throw new Error("Wallet not connected");
|
|
336
|
+
}
|
|
337
|
+
const payment = await processPayment(request, wallet);
|
|
338
|
+
onComplete(payment);
|
|
339
|
+
} catch (err) {
|
|
340
|
+
setError(err instanceof Error ? err.message : "Payment failed");
|
|
341
|
+
setStep("confirm");
|
|
342
|
+
} finally {
|
|
343
|
+
setIsProcessing(false);
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
if (!isOpen) return null;
|
|
347
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
348
|
+
"div",
|
|
349
|
+
{
|
|
350
|
+
style: {
|
|
351
|
+
position: "fixed",
|
|
352
|
+
inset: 0,
|
|
353
|
+
zIndex: 9999,
|
|
354
|
+
display: "flex",
|
|
355
|
+
alignItems: "center",
|
|
356
|
+
justifyContent: "center",
|
|
357
|
+
background: "rgba(0, 0, 0, 0.5)",
|
|
358
|
+
backdropFilter: "blur(4px)"
|
|
359
|
+
},
|
|
360
|
+
onClick: (e) => e.target === e.currentTarget && onCancel(),
|
|
361
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
362
|
+
"div",
|
|
363
|
+
{
|
|
364
|
+
style: {
|
|
365
|
+
width: "100%",
|
|
366
|
+
maxWidth: "28rem",
|
|
367
|
+
borderRadius: "0.75rem",
|
|
368
|
+
border: "1px solid rgba(255, 255, 255, 0.1)",
|
|
369
|
+
background: "rgba(24, 24, 27, 0.95)",
|
|
370
|
+
padding: "1.5rem",
|
|
371
|
+
boxShadow: "0 20px 25px -5px rgba(0, 0, 0, 0.3)",
|
|
372
|
+
backdropFilter: "blur(16px)",
|
|
373
|
+
color: "#fafafa"
|
|
374
|
+
},
|
|
375
|
+
children: [
|
|
376
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
377
|
+
"div",
|
|
378
|
+
{
|
|
379
|
+
style: {
|
|
380
|
+
display: "flex",
|
|
381
|
+
alignItems: "center",
|
|
382
|
+
justifyContent: "space-between",
|
|
383
|
+
marginBottom: "1.5rem"
|
|
384
|
+
},
|
|
385
|
+
children: [
|
|
386
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "0.5rem" }, children: [
|
|
387
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
388
|
+
"div",
|
|
389
|
+
{
|
|
390
|
+
style: {
|
|
391
|
+
width: "2rem",
|
|
392
|
+
height: "2rem",
|
|
393
|
+
display: "flex",
|
|
394
|
+
alignItems: "center",
|
|
395
|
+
justifyContent: "center",
|
|
396
|
+
borderRadius: "0.5rem",
|
|
397
|
+
background: "rgba(255, 255, 255, 0.1)",
|
|
398
|
+
fontFamily: "monospace",
|
|
399
|
+
fontSize: "0.75rem",
|
|
400
|
+
fontWeight: "bold"
|
|
401
|
+
},
|
|
402
|
+
children: "x402"
|
|
403
|
+
}
|
|
404
|
+
),
|
|
405
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { style: { margin: 0, fontSize: "1.25rem", fontWeight: 300 }, children: "Payment Required" })
|
|
406
|
+
] }),
|
|
407
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
408
|
+
"button",
|
|
409
|
+
{
|
|
410
|
+
onClick: onCancel,
|
|
411
|
+
style: {
|
|
412
|
+
background: "none",
|
|
413
|
+
border: "none",
|
|
414
|
+
fontSize: "1.5rem",
|
|
415
|
+
cursor: "pointer",
|
|
416
|
+
color: "rgba(250, 250, 250, 0.6)",
|
|
417
|
+
lineHeight: 1
|
|
418
|
+
},
|
|
419
|
+
children: "\xD7"
|
|
420
|
+
}
|
|
421
|
+
)
|
|
422
|
+
]
|
|
423
|
+
}
|
|
424
|
+
),
|
|
425
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
426
|
+
"div",
|
|
427
|
+
{
|
|
428
|
+
style: {
|
|
429
|
+
marginBottom: "1.5rem",
|
|
430
|
+
padding: "1rem",
|
|
431
|
+
borderRadius: "0.5rem",
|
|
432
|
+
border: "1px solid rgba(255, 255, 255, 0.1)",
|
|
433
|
+
background: "rgba(255, 255, 255, 0.02)"
|
|
434
|
+
},
|
|
435
|
+
children: [
|
|
436
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
437
|
+
"div",
|
|
438
|
+
{
|
|
439
|
+
style: {
|
|
440
|
+
display: "flex",
|
|
441
|
+
justifyContent: "space-between",
|
|
442
|
+
marginBottom: "0.75rem"
|
|
443
|
+
},
|
|
444
|
+
children: [
|
|
445
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
446
|
+
"span",
|
|
447
|
+
{
|
|
448
|
+
style: { fontFamily: "monospace", fontSize: "0.75rem", color: "rgba(250,250,250,0.6)" },
|
|
449
|
+
children: "Amount"
|
|
450
|
+
}
|
|
451
|
+
),
|
|
452
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { style: { fontSize: "1.125rem", fontWeight: 500 }, children: [
|
|
453
|
+
request.amount,
|
|
454
|
+
" ",
|
|
455
|
+
request.token
|
|
456
|
+
] })
|
|
457
|
+
]
|
|
458
|
+
}
|
|
459
|
+
),
|
|
460
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
461
|
+
"div",
|
|
462
|
+
{
|
|
463
|
+
style: {
|
|
464
|
+
display: "flex",
|
|
465
|
+
justifyContent: "space-between",
|
|
466
|
+
marginBottom: "0.75rem"
|
|
467
|
+
},
|
|
468
|
+
children: [
|
|
469
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
470
|
+
"span",
|
|
471
|
+
{
|
|
472
|
+
style: { fontFamily: "monospace", fontSize: "0.75rem", color: "rgba(250,250,250,0.6)" },
|
|
473
|
+
children: "Network"
|
|
474
|
+
}
|
|
475
|
+
),
|
|
476
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontSize: "0.875rem" }, children: request.network })
|
|
477
|
+
]
|
|
478
|
+
}
|
|
479
|
+
),
|
|
480
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", justifyContent: "space-between" }, children: [
|
|
481
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
482
|
+
"span",
|
|
483
|
+
{
|
|
484
|
+
style: { fontFamily: "monospace", fontSize: "0.75rem", color: "rgba(250,250,250,0.6)" },
|
|
485
|
+
children: "Recipient"
|
|
486
|
+
}
|
|
487
|
+
),
|
|
488
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { style: { fontFamily: "monospace", fontSize: "0.875rem" }, children: formatAddress(request.recipient) })
|
|
489
|
+
] })
|
|
490
|
+
]
|
|
491
|
+
}
|
|
492
|
+
),
|
|
493
|
+
error && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
494
|
+
"div",
|
|
495
|
+
{
|
|
496
|
+
style: {
|
|
497
|
+
marginBottom: "1rem",
|
|
498
|
+
padding: "0.75rem",
|
|
499
|
+
borderRadius: "0.5rem",
|
|
500
|
+
border: "1px solid rgba(239, 68, 68, 0.5)",
|
|
501
|
+
background: "rgba(239, 68, 68, 0.1)",
|
|
502
|
+
fontFamily: "monospace",
|
|
503
|
+
fontSize: "0.75rem",
|
|
504
|
+
color: "rgba(239, 68, 68, 0.9)"
|
|
505
|
+
},
|
|
506
|
+
children: error
|
|
507
|
+
}
|
|
508
|
+
),
|
|
509
|
+
step === "connect" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
510
|
+
"button",
|
|
511
|
+
{
|
|
512
|
+
onClick: handleConnect,
|
|
513
|
+
disabled: isConnecting,
|
|
514
|
+
style: {
|
|
515
|
+
width: "100%",
|
|
516
|
+
padding: "0.75rem 1rem",
|
|
517
|
+
borderRadius: "0.5rem",
|
|
518
|
+
border: "1px solid rgba(255, 255, 255, 0.1)",
|
|
519
|
+
background: "rgba(255, 255, 255, 0.05)",
|
|
520
|
+
fontSize: "0.875rem",
|
|
521
|
+
fontWeight: 500,
|
|
522
|
+
cursor: isConnecting ? "not-allowed" : "pointer",
|
|
523
|
+
opacity: isConnecting ? 0.7 : 1,
|
|
524
|
+
color: "#fafafa"
|
|
525
|
+
},
|
|
526
|
+
children: isConnecting ? "Connecting..." : "Connect Wallet"
|
|
527
|
+
}
|
|
528
|
+
),
|
|
529
|
+
step === "confirm" && walletAddress && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
530
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
531
|
+
"div",
|
|
532
|
+
{
|
|
533
|
+
style: {
|
|
534
|
+
marginBottom: "1rem",
|
|
535
|
+
padding: "0.75rem",
|
|
536
|
+
borderRadius: "0.5rem",
|
|
537
|
+
border: "1px solid rgba(255, 255, 255, 0.1)",
|
|
538
|
+
background: "rgba(255, 255, 255, 0.02)"
|
|
539
|
+
},
|
|
540
|
+
children: [
|
|
541
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
542
|
+
"p",
|
|
543
|
+
{
|
|
544
|
+
style: {
|
|
545
|
+
margin: "0 0 0.25rem 0",
|
|
546
|
+
fontFamily: "monospace",
|
|
547
|
+
fontSize: "0.75rem",
|
|
548
|
+
color: "rgba(250, 250, 250, 0.6)"
|
|
549
|
+
},
|
|
550
|
+
children: "Connected Wallet"
|
|
551
|
+
}
|
|
552
|
+
),
|
|
553
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { style: { margin: 0, fontFamily: "monospace", fontSize: "0.875rem" }, children: formatAddress(walletAddress) })
|
|
554
|
+
]
|
|
555
|
+
}
|
|
556
|
+
),
|
|
557
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { style: { display: "flex", gap: "0.75rem" }, children: [
|
|
558
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
559
|
+
"button",
|
|
560
|
+
{
|
|
561
|
+
onClick: onCancel,
|
|
562
|
+
style: {
|
|
563
|
+
flex: 1,
|
|
564
|
+
padding: "0.75rem 1rem",
|
|
565
|
+
borderRadius: "0.5rem",
|
|
566
|
+
border: "1px solid rgba(255, 255, 255, 0.1)",
|
|
567
|
+
background: "rgba(255, 255, 255, 0.02)",
|
|
568
|
+
fontSize: "0.875rem",
|
|
569
|
+
cursor: "pointer",
|
|
570
|
+
color: "rgba(250, 250, 250, 0.8)"
|
|
571
|
+
},
|
|
572
|
+
children: "Cancel"
|
|
573
|
+
}
|
|
574
|
+
),
|
|
575
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
576
|
+
"button",
|
|
577
|
+
{
|
|
578
|
+
onClick: handlePay,
|
|
579
|
+
disabled: isProcessing,
|
|
580
|
+
style: {
|
|
581
|
+
flex: 1,
|
|
582
|
+
padding: "0.75rem 1rem",
|
|
583
|
+
borderRadius: "0.5rem",
|
|
584
|
+
border: "1px solid rgba(255, 255, 255, 0.1)",
|
|
585
|
+
background: "rgba(255, 255, 255, 0.1)",
|
|
586
|
+
fontSize: "0.875rem",
|
|
587
|
+
fontWeight: 500,
|
|
588
|
+
cursor: isProcessing ? "not-allowed" : "pointer",
|
|
589
|
+
opacity: isProcessing ? 0.7 : 1,
|
|
590
|
+
color: "#fafafa"
|
|
591
|
+
},
|
|
592
|
+
children: [
|
|
593
|
+
"Pay ",
|
|
594
|
+
request.amount,
|
|
595
|
+
" ",
|
|
596
|
+
request.token
|
|
597
|
+
]
|
|
598
|
+
}
|
|
599
|
+
)
|
|
600
|
+
] })
|
|
601
|
+
] }),
|
|
602
|
+
step === "processing" && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
603
|
+
"div",
|
|
604
|
+
{
|
|
605
|
+
style: {
|
|
606
|
+
display: "flex",
|
|
607
|
+
flexDirection: "column",
|
|
608
|
+
alignItems: "center",
|
|
609
|
+
justifyContent: "center",
|
|
610
|
+
padding: "2rem 0"
|
|
611
|
+
},
|
|
612
|
+
children: [
|
|
613
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
614
|
+
"div",
|
|
615
|
+
{
|
|
616
|
+
style: {
|
|
617
|
+
width: "2rem",
|
|
618
|
+
height: "2rem",
|
|
619
|
+
marginBottom: "1rem",
|
|
620
|
+
border: "2px solid rgba(255, 255, 255, 0.2)",
|
|
621
|
+
borderTopColor: "#fafafa",
|
|
622
|
+
borderRadius: "50%",
|
|
623
|
+
animation: "x402-spin 1s linear infinite"
|
|
624
|
+
}
|
|
625
|
+
}
|
|
626
|
+
),
|
|
627
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { style: { margin: 0, fontSize: "0.875rem", color: "rgba(250, 250, 250, 0.6)" }, children: "Processing payment..." }),
|
|
628
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
629
|
+
"p",
|
|
630
|
+
{
|
|
631
|
+
style: {
|
|
632
|
+
margin: "0.5rem 0 0 0",
|
|
633
|
+
fontFamily: "monospace",
|
|
634
|
+
fontSize: "0.75rem",
|
|
635
|
+
color: "rgba(250, 250, 250, 0.4)"
|
|
636
|
+
},
|
|
637
|
+
children: "Please confirm the transaction in your wallet"
|
|
638
|
+
}
|
|
639
|
+
),
|
|
640
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { children: `
|
|
641
|
+
@keyframes x402-spin {
|
|
642
|
+
to { transform: rotate(360deg); }
|
|
643
|
+
}
|
|
644
|
+
` })
|
|
645
|
+
]
|
|
646
|
+
}
|
|
647
|
+
)
|
|
648
|
+
]
|
|
649
|
+
}
|
|
650
|
+
)
|
|
651
|
+
}
|
|
652
|
+
);
|
|
653
|
+
}
|
|
654
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
655
|
+
0 && (module.exports = {
|
|
656
|
+
PaymentModal
|
|
657
|
+
});
|
|
658
|
+
//# sourceMappingURL=react.cjs.map
|