coinley-test 0.0.12 → 0.0.13
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.esm.js +140 -71
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -250,53 +250,55 @@ const WalletIntegration = ({
|
|
|
250
250
|
selectedToken,
|
|
251
251
|
paymentData,
|
|
252
252
|
config,
|
|
253
|
-
// Add config as prop
|
|
254
253
|
onTransactionSent,
|
|
255
254
|
onError,
|
|
256
255
|
isConnecting,
|
|
257
256
|
setIsConnecting
|
|
258
257
|
}) => {
|
|
259
|
-
const { isConnected, address } = useWallet();
|
|
258
|
+
const { isConnected, address, disconnect } = useWallet();
|
|
260
259
|
const { connectWallet, isPending } = useWalletConnect();
|
|
261
260
|
const { detectedWallets, hasWallets, walletCount } = useWalletDetection();
|
|
262
261
|
const { sendTransaction } = useWalletTransaction();
|
|
263
262
|
useWalletModal();
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
263
|
+
const ethereumWallets = detectedWallets.filter(
|
|
264
|
+
(wallet) => wallet.name.toLowerCase().includes("metamask") || wallet.provider === "injected" || wallet.name.toLowerCase().includes("coinbase") || wallet.name.toLowerCase().includes("wallet connect")
|
|
265
|
+
);
|
|
266
|
+
const handleConnectSpecificWallet = async (walletType) => {
|
|
267
|
+
try {
|
|
268
|
+
setIsConnecting(true);
|
|
269
|
+
if (isConnected) {
|
|
270
|
+
await disconnect();
|
|
271
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
272
|
+
}
|
|
273
|
+
await connectWallet(walletType);
|
|
274
|
+
} catch (error) {
|
|
275
|
+
console.error("Wallet connection failed:", error);
|
|
276
|
+
onError(error.message || "Failed to connect wallet");
|
|
277
|
+
} finally {
|
|
278
|
+
setIsConnecting(false);
|
|
271
279
|
}
|
|
272
|
-
}
|
|
273
|
-
const
|
|
280
|
+
};
|
|
281
|
+
const handleSendPayment = async () => {
|
|
274
282
|
var _a;
|
|
275
|
-
if (!isConnected || !paymentData || !selectedToken)
|
|
283
|
+
if (!isConnected || !paymentData || !selectedToken) {
|
|
284
|
+
onError("Wallet not connected or payment data missing");
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
276
287
|
try {
|
|
277
288
|
setIsConnecting(true);
|
|
278
289
|
console.log("🔍 Transaction Debug:");
|
|
290
|
+
console.log("Connected wallet address:", address);
|
|
279
291
|
console.log("Payment data:", paymentData);
|
|
280
292
|
console.log("Selected token:", selectedToken);
|
|
281
293
|
console.log("Selected network:", selectedNetwork);
|
|
282
294
|
let recipientAddress = (_a = paymentData.metadata) == null ? void 0 : _a.recipientWallet;
|
|
283
|
-
console.log("
|
|
284
|
-
if (typeof recipientAddress === "object" && recipientAddress.address) {
|
|
285
|
-
recipientAddress = recipientAddress.address;
|
|
286
|
-
}
|
|
295
|
+
console.log("Merchant recipient address:", recipientAddress);
|
|
287
296
|
if (!recipientAddress || typeof recipientAddress !== "string") {
|
|
288
|
-
throw new Error("Merchant wallet address not found in payment data
|
|
297
|
+
throw new Error("Merchant wallet address not found in payment data");
|
|
289
298
|
}
|
|
290
299
|
if (!recipientAddress.match(/^0x[a-fA-F0-9]{40}$/)) {
|
|
291
|
-
console.error("❌ Invalid merchant address format:", {
|
|
292
|
-
address: recipientAddress,
|
|
293
|
-
length: recipientAddress.length,
|
|
294
|
-
addressWithoutPrefix: recipientAddress.slice(2),
|
|
295
|
-
addressWithoutPrefixLength: recipientAddress.slice(2).length
|
|
296
|
-
});
|
|
297
300
|
throw new Error(`Invalid merchant address format: ${recipientAddress}`);
|
|
298
301
|
}
|
|
299
|
-
console.log("✅ Using merchant recipient address:", recipientAddress);
|
|
300
302
|
let txHash;
|
|
301
303
|
if (selectedToken.contractAddress) {
|
|
302
304
|
console.log("🔍 ERC-20 Transaction Details:");
|
|
@@ -306,16 +308,12 @@ const WalletIntegration = ({
|
|
|
306
308
|
const decimals = selectedToken.decimals || 6;
|
|
307
309
|
const amount = Math.floor(paymentData.totalAmount * Math.pow(10, decimals));
|
|
308
310
|
console.log("Calculated amount (with decimals):", amount);
|
|
309
|
-
console.log("Amount in hex:", amount.toString(16));
|
|
310
311
|
const methodId = "0xa9059cbb";
|
|
311
312
|
const addressWithoutPrefix = recipientAddress.slice(2);
|
|
312
313
|
const recipientPadded = addressWithoutPrefix.toLowerCase().padStart(64, "0");
|
|
313
314
|
const amountPadded = amount.toString(16).padStart(64, "0");
|
|
314
315
|
const transferData = `${methodId}${recipientPadded}${amountPadded}`;
|
|
315
|
-
console.log("🔍 Transaction Data
|
|
316
|
-
console.log("Original address:", recipientAddress);
|
|
317
|
-
console.log("Address without 0x:", addressWithoutPrefix);
|
|
318
|
-
console.log("Address length:", addressWithoutPrefix.length);
|
|
316
|
+
console.log("🔍 Transaction Data:");
|
|
319
317
|
console.log("Method ID:", methodId);
|
|
320
318
|
console.log("Recipient (padded):", recipientPadded);
|
|
321
319
|
console.log("Amount (padded):", amountPadded);
|
|
@@ -328,11 +326,8 @@ const WalletIntegration = ({
|
|
|
328
326
|
console.log("📤 Sending ERC-20 transaction:", txParams);
|
|
329
327
|
txHash = await sendTransaction(txParams);
|
|
330
328
|
} else {
|
|
331
|
-
console.log("🔍 Native Token Transaction:");
|
|
332
329
|
const value = Math.floor(paymentData.totalAmount * Math.pow(10, 18));
|
|
333
330
|
const valueHex = `0x${value.toString(16)}`;
|
|
334
|
-
console.log("Native amount:", value);
|
|
335
|
-
console.log("Native amount hex:", valueHex);
|
|
336
331
|
const txParams = {
|
|
337
332
|
to: recipientAddress,
|
|
338
333
|
value: valueHex
|
|
@@ -346,58 +341,132 @@ const WalletIntegration = ({
|
|
|
346
341
|
}
|
|
347
342
|
} catch (error) {
|
|
348
343
|
console.error("❌ Transaction failed:", error);
|
|
349
|
-
console.error("Error details:", {
|
|
350
|
-
message: error.message,
|
|
351
|
-
cause: error.cause,
|
|
352
|
-
details: error.details
|
|
353
|
-
});
|
|
354
344
|
onError(error.message || "Transaction failed");
|
|
355
345
|
} finally {
|
|
356
346
|
setIsConnecting(false);
|
|
357
347
|
}
|
|
358
348
|
};
|
|
349
|
+
const handleDisconnect = async () => {
|
|
350
|
+
try {
|
|
351
|
+
await disconnect();
|
|
352
|
+
} catch (error) {
|
|
353
|
+
console.error("Disconnect error:", error);
|
|
354
|
+
}
|
|
355
|
+
};
|
|
359
356
|
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-center space-y-6", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [
|
|
360
357
|
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "w-16 h-16 bg-[#7042D2] bg-opacity-20 rounded-full flex items-center justify-center mx-auto", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Wallet, { className: "w-8 h-8 text-[#7042D2]" }) }),
|
|
361
|
-
/* @__PURE__ */ jsxRuntimeExports.
|
|
362
|
-
|
|
363
|
-
"
|
|
364
|
-
{
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
358
|
+
!isConnected ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
359
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-lg font-semibold", children: "Connect Your Wallet" }),
|
|
360
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-gray-600 dark:text-gray-400 text-sm", children: "Choose your preferred wallet to complete the payment" }),
|
|
361
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-3", children: [
|
|
362
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
363
|
+
"button",
|
|
364
|
+
{
|
|
365
|
+
onClick: () => handleConnectSpecificWallet("injected"),
|
|
366
|
+
disabled: isPending || isConnecting,
|
|
367
|
+
className: "w-full p-3 border border-gray-300 rounded-lg hover:border-[#7042D2] flex items-center space-x-3 transition-colors disabled:opacity-50",
|
|
368
|
+
children: [
|
|
369
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-xl", children: "🦊" }),
|
|
370
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-left flex-1", children: [
|
|
371
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-medium", children: "MetaMask" }),
|
|
372
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500", children: "Connect with MetaMask" })
|
|
373
|
+
] })
|
|
374
|
+
]
|
|
375
|
+
}
|
|
376
|
+
),
|
|
377
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
378
|
+
"button",
|
|
379
|
+
{
|
|
380
|
+
onClick: () => handleConnectSpecificWallet("walletConnect"),
|
|
381
|
+
disabled: isPending || isConnecting,
|
|
382
|
+
className: "w-full p-3 border border-gray-300 rounded-lg hover:border-[#7042D2] flex items-center space-x-3 transition-colors disabled:opacity-50",
|
|
383
|
+
children: [
|
|
384
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-xl", children: "🔗" }),
|
|
385
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-left flex-1", children: [
|
|
386
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-medium", children: "WalletConnect" }),
|
|
387
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500", children: "Scan with mobile wallet" })
|
|
388
|
+
] })
|
|
389
|
+
]
|
|
390
|
+
}
|
|
391
|
+
),
|
|
392
|
+
ethereumWallets.filter(
|
|
393
|
+
(wallet) => !wallet.name.toLowerCase().includes("metamask")
|
|
394
|
+
).map((wallet, index) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
395
|
+
"button",
|
|
396
|
+
{
|
|
397
|
+
onClick: () => handleConnectSpecificWallet("injected"),
|
|
398
|
+
disabled: isPending || isConnecting,
|
|
399
|
+
className: "w-full p-3 border border-gray-300 rounded-lg hover:border-[#7042D2] flex items-center space-x-3 transition-colors disabled:opacity-50",
|
|
400
|
+
children: [
|
|
401
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-xl", children: wallet.icon }),
|
|
402
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-left flex-1", children: [
|
|
403
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-medium", children: wallet.name }),
|
|
404
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500", children: wallet.provider })
|
|
405
|
+
] })
|
|
406
|
+
]
|
|
407
|
+
},
|
|
408
|
+
index
|
|
409
|
+
))
|
|
383
410
|
] }),
|
|
384
|
-
|
|
411
|
+
isConnecting && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-center space-x-2 text-gray-600", children: [
|
|
412
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Loader2, { className: "w-4 h-4 animate-spin" }),
|
|
413
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "Connecting..." })
|
|
414
|
+
] })
|
|
415
|
+
] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
416
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-lg font-semibold text-green-600", children: "Wallet Connected ✅" }),
|
|
417
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "bg-gray-50 dark:bg-gray-800 rounded-lg p-4 space-y-3", children: [
|
|
385
418
|
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between items-center", children: [
|
|
386
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm text-gray-600 dark:text-gray-400", children: "
|
|
387
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs("
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
419
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm text-gray-600 dark:text-gray-400", children: "Address:" }),
|
|
420
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center space-x-2", children: [
|
|
421
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "font-mono text-sm", children: [
|
|
422
|
+
address == null ? void 0 : address.slice(0, 6),
|
|
423
|
+
"...",
|
|
424
|
+
address == null ? void 0 : address.slice(-4)
|
|
425
|
+
] }),
|
|
426
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
427
|
+
"button",
|
|
428
|
+
{
|
|
429
|
+
onClick: handleDisconnect,
|
|
430
|
+
className: "text-xs text-red-600 hover:text-red-800",
|
|
431
|
+
children: "Disconnect"
|
|
432
|
+
}
|
|
433
|
+
)
|
|
391
434
|
] })
|
|
392
435
|
] }),
|
|
393
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
394
|
-
/* @__PURE__ */ jsxRuntimeExports.
|
|
395
|
-
|
|
436
|
+
paymentData && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
437
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between items-center", children: [
|
|
438
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm text-gray-600 dark:text-gray-400", children: "Amount:" }),
|
|
439
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "font-medium", children: [
|
|
440
|
+
paymentData.totalAmount,
|
|
441
|
+
" ",
|
|
442
|
+
selectedToken == null ? void 0 : selectedToken.symbol
|
|
443
|
+
] })
|
|
444
|
+
] }),
|
|
445
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between items-center", children: [
|
|
446
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm text-gray-600 dark:text-gray-400", children: "Network:" }),
|
|
447
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-medium", children: selectedNetwork == null ? void 0 : selectedNetwork.name })
|
|
448
|
+
] })
|
|
396
449
|
] })
|
|
397
450
|
] }),
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
451
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
452
|
+
"button",
|
|
453
|
+
{
|
|
454
|
+
onClick: handleSendPayment,
|
|
455
|
+
disabled: isConnecting,
|
|
456
|
+
className: "w-full bg-[#7042D2] text-white py-4 rounded-lg font-semibold hover:bg-[#7042D2]/90 transition-colors disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center space-x-2",
|
|
457
|
+
children: isConnecting ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
458
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Loader2, { className: "w-5 h-5 animate-spin" }),
|
|
459
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "Processing Payment..." })
|
|
460
|
+
] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
461
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Zap, { className: "w-5 h-5" }),
|
|
462
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "Send Payment" })
|
|
463
|
+
] })
|
|
464
|
+
}
|
|
465
|
+
),
|
|
466
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-xs text-gray-500", children: [
|
|
467
|
+
"Make sure you have enough ",
|
|
468
|
+
selectedToken == null ? void 0 : selectedToken.symbol,
|
|
469
|
+
" and ETH for gas fees"
|
|
401
470
|
] })
|
|
402
471
|
] })
|
|
403
472
|
] }) });
|