coinley-test 0.0.10 → 0.0.12
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 +168 -20
- 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
|
@@ -271,35 +271,86 @@ const WalletIntegration = ({
|
|
|
271
271
|
}
|
|
272
272
|
}, [isConnected, address, paymentData]);
|
|
273
273
|
const handleSendTransaction = async () => {
|
|
274
|
-
var _a
|
|
274
|
+
var _a;
|
|
275
275
|
if (!isConnected || !paymentData || !selectedToken) return;
|
|
276
276
|
try {
|
|
277
277
|
setIsConnecting(true);
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
278
|
+
console.log("🔍 Transaction Debug:");
|
|
279
|
+
console.log("Payment data:", paymentData);
|
|
280
|
+
console.log("Selected token:", selectedToken);
|
|
281
|
+
console.log("Selected network:", selectedNetwork);
|
|
282
|
+
let recipientAddress = (_a = paymentData.metadata) == null ? void 0 : _a.recipientWallet;
|
|
283
|
+
console.log("Raw recipient address from payment metadata:", recipientAddress);
|
|
284
|
+
if (typeof recipientAddress === "object" && recipientAddress.address) {
|
|
285
|
+
recipientAddress = recipientAddress.address;
|
|
286
|
+
}
|
|
287
|
+
if (!recipientAddress || typeof recipientAddress !== "string") {
|
|
288
|
+
throw new Error("Merchant wallet address not found in payment data. Please contact support.");
|
|
281
289
|
}
|
|
290
|
+
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
|
+
throw new Error(`Invalid merchant address format: ${recipientAddress}`);
|
|
298
|
+
}
|
|
299
|
+
console.log("✅ Using merchant recipient address:", recipientAddress);
|
|
282
300
|
let txHash;
|
|
283
301
|
if (selectedToken.contractAddress) {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
302
|
+
console.log("🔍 ERC-20 Transaction Details:");
|
|
303
|
+
console.log("Token contract:", selectedToken.contractAddress);
|
|
304
|
+
console.log("Token decimals:", selectedToken.decimals);
|
|
305
|
+
console.log("Payment amount:", paymentData.totalAmount);
|
|
306
|
+
const decimals = selectedToken.decimals || 6;
|
|
307
|
+
const amount = Math.floor(paymentData.totalAmount * Math.pow(10, decimals));
|
|
308
|
+
console.log("Calculated amount (with decimals):", amount);
|
|
309
|
+
console.log("Amount in hex:", amount.toString(16));
|
|
310
|
+
const methodId = "0xa9059cbb";
|
|
311
|
+
const addressWithoutPrefix = recipientAddress.slice(2);
|
|
312
|
+
const recipientPadded = addressWithoutPrefix.toLowerCase().padStart(64, "0");
|
|
313
|
+
const amountPadded = amount.toString(16).padStart(64, "0");
|
|
314
|
+
const transferData = `${methodId}${recipientPadded}${amountPadded}`;
|
|
315
|
+
console.log("🔍 Transaction Data Encoding:");
|
|
316
|
+
console.log("Original address:", recipientAddress);
|
|
317
|
+
console.log("Address without 0x:", addressWithoutPrefix);
|
|
318
|
+
console.log("Address length:", addressWithoutPrefix.length);
|
|
319
|
+
console.log("Method ID:", methodId);
|
|
320
|
+
console.log("Recipient (padded):", recipientPadded);
|
|
321
|
+
console.log("Amount (padded):", amountPadded);
|
|
322
|
+
console.log("Full data:", transferData);
|
|
323
|
+
const txParams = {
|
|
287
324
|
to: selectedToken.contractAddress,
|
|
288
325
|
data: transferData,
|
|
289
326
|
value: "0x0"
|
|
290
|
-
}
|
|
327
|
+
};
|
|
328
|
+
console.log("📤 Sending ERC-20 transaction:", txParams);
|
|
329
|
+
txHash = await sendTransaction(txParams);
|
|
291
330
|
} else {
|
|
292
|
-
|
|
293
|
-
|
|
331
|
+
console.log("🔍 Native Token Transaction:");
|
|
332
|
+
const value = Math.floor(paymentData.totalAmount * Math.pow(10, 18));
|
|
333
|
+
const valueHex = `0x${value.toString(16)}`;
|
|
334
|
+
console.log("Native amount:", value);
|
|
335
|
+
console.log("Native amount hex:", valueHex);
|
|
336
|
+
const txParams = {
|
|
294
337
|
to: recipientAddress,
|
|
295
|
-
value:
|
|
296
|
-
}
|
|
338
|
+
value: valueHex
|
|
339
|
+
};
|
|
340
|
+
console.log("📤 Sending native transaction:", txParams);
|
|
341
|
+
txHash = await sendTransaction(txParams);
|
|
297
342
|
}
|
|
298
343
|
if (txHash) {
|
|
344
|
+
console.log("✅ Transaction sent successfully:", txHash);
|
|
299
345
|
onTransactionSent(txHash);
|
|
300
346
|
}
|
|
301
347
|
} catch (error) {
|
|
302
|
-
console.error("Transaction failed:", error);
|
|
348
|
+
console.error("❌ Transaction failed:", error);
|
|
349
|
+
console.error("Error details:", {
|
|
350
|
+
message: error.message,
|
|
351
|
+
cause: error.cause,
|
|
352
|
+
details: error.details
|
|
353
|
+
});
|
|
303
354
|
onError(error.message || "Transaction failed");
|
|
304
355
|
} finally {
|
|
305
356
|
setIsConnecting(false);
|
|
@@ -381,8 +432,35 @@ const CoinleyPayment = ({
|
|
|
381
432
|
const walletConfig = createCoinleyWalletConfig({
|
|
382
433
|
appName: merchantName || "Coinley Payment",
|
|
383
434
|
appDescription: "Crypto payment processing",
|
|
384
|
-
|
|
385
|
-
|
|
435
|
+
// Fix: Provide proper chain configurations instead of just IDs
|
|
436
|
+
chains: [
|
|
437
|
+
{
|
|
438
|
+
id: 1,
|
|
439
|
+
name: "Ethereum",
|
|
440
|
+
network: "ethereum",
|
|
441
|
+
rpcUrls: {
|
|
442
|
+
default: { http: ["https://eth.llamarpc.com"] }
|
|
443
|
+
},
|
|
444
|
+
nativeCurrency: {
|
|
445
|
+
name: "Ethereum",
|
|
446
|
+
symbol: "ETH",
|
|
447
|
+
decimals: 18
|
|
448
|
+
}
|
|
449
|
+
},
|
|
450
|
+
{
|
|
451
|
+
id: 56,
|
|
452
|
+
name: "BNB Smart Chain",
|
|
453
|
+
network: "bsc",
|
|
454
|
+
rpcUrls: {
|
|
455
|
+
default: { http: ["https://bsc-dataseed1.binance.org"] }
|
|
456
|
+
},
|
|
457
|
+
nativeCurrency: {
|
|
458
|
+
name: "BNB",
|
|
459
|
+
symbol: "BNB",
|
|
460
|
+
decimals: 18
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
]
|
|
386
464
|
});
|
|
387
465
|
useEffect(() => {
|
|
388
466
|
if (isOpen) {
|
|
@@ -422,12 +500,21 @@ const CoinleyPayment = ({
|
|
|
422
500
|
return ((_a = token.Network) == null ? void 0 : _a.shortName) === network.shortName || token.networkId === network.id;
|
|
423
501
|
}
|
|
424
502
|
);
|
|
425
|
-
if (networkTokens.length >
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
503
|
+
if (networkTokens.length > 1) {
|
|
504
|
+
setCurrentStep("select-token");
|
|
505
|
+
} else if (networkTokens.length === 1) {
|
|
506
|
+
const token = networkTokens[0];
|
|
507
|
+
setSelectedToken(token);
|
|
508
|
+
await initiatePayment(network, token);
|
|
509
|
+
} else {
|
|
510
|
+
setError(`No supported tokens found for ${network.name}`);
|
|
511
|
+
setCurrentStep("error");
|
|
429
512
|
}
|
|
430
513
|
};
|
|
514
|
+
const handleTokenSelect = async (token) => {
|
|
515
|
+
setSelectedToken(token);
|
|
516
|
+
await initiatePayment(selectedNetwork, token);
|
|
517
|
+
};
|
|
431
518
|
const initiatePayment = async (network, token) => {
|
|
432
519
|
try {
|
|
433
520
|
setLoading(true);
|
|
@@ -569,8 +656,20 @@ const CoinleyPayment = ({
|
|
|
569
656
|
const goBack = () => {
|
|
570
657
|
if (currentStep === "select-network") {
|
|
571
658
|
setCurrentStep("select-method");
|
|
572
|
-
} else if (currentStep === "
|
|
659
|
+
} else if (currentStep === "select-token") {
|
|
573
660
|
setCurrentStep("select-network");
|
|
661
|
+
} else if (currentStep === "wallet-connect" || currentStep === "qr-code") {
|
|
662
|
+
const networkTokens = tokens.filter(
|
|
663
|
+
(token) => {
|
|
664
|
+
var _a;
|
|
665
|
+
return ((_a = token.Network) == null ? void 0 : _a.shortName) === (selectedNetwork == null ? void 0 : selectedNetwork.shortName) || token.networkId === (selectedNetwork == null ? void 0 : selectedNetwork.id);
|
|
666
|
+
}
|
|
667
|
+
);
|
|
668
|
+
if (networkTokens.length > 1) {
|
|
669
|
+
setCurrentStep("select-token");
|
|
670
|
+
} else {
|
|
671
|
+
setCurrentStep("select-network");
|
|
672
|
+
}
|
|
574
673
|
}
|
|
575
674
|
};
|
|
576
675
|
if (!isOpen) return null;
|
|
@@ -698,6 +797,55 @@ const CoinleyPayment = ({
|
|
|
698
797
|
},
|
|
699
798
|
"select-network"
|
|
700
799
|
),
|
|
800
|
+
currentStep === "select-token" && /* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
801
|
+
motion.div,
|
|
802
|
+
{
|
|
803
|
+
initial: { x: 20, opacity: 0 },
|
|
804
|
+
animate: { x: 0, opacity: 1 },
|
|
805
|
+
exit: { x: -20, opacity: 0 },
|
|
806
|
+
className: "space-y-4",
|
|
807
|
+
children: [
|
|
808
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("h3", { className: "text-lg font-semibold text-center mb-6", children: [
|
|
809
|
+
"Select Token on ",
|
|
810
|
+
selectedNetwork == null ? void 0 : selectedNetwork.name
|
|
811
|
+
] }),
|
|
812
|
+
loading ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex justify-center py-8", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Loader2, { className: "w-8 h-8 animate-spin text-[#7042D2]" }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "space-y-3", children: tokens.filter(
|
|
813
|
+
(token) => {
|
|
814
|
+
var _a;
|
|
815
|
+
return ((_a = token.Network) == null ? void 0 : _a.shortName) === (selectedNetwork == null ? void 0 : selectedNetwork.shortName) || token.networkId === (selectedNetwork == null ? void 0 : selectedNetwork.id);
|
|
816
|
+
}
|
|
817
|
+
).map((token) => /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
818
|
+
motion.button,
|
|
819
|
+
{
|
|
820
|
+
whileHover: { scale: 1.02 },
|
|
821
|
+
whileTap: { scale: 0.98 },
|
|
822
|
+
onClick: () => handleTokenSelect(token),
|
|
823
|
+
className: "w-full p-4 border-2 border-gray-200 dark:border-gray-700 rounded-xl hover:border-[#7042D2] transition-colors group",
|
|
824
|
+
children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center space-x-4", children: [
|
|
825
|
+
token.logo ? /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
826
|
+
"img",
|
|
827
|
+
{
|
|
828
|
+
src: token.logo,
|
|
829
|
+
alt: token.symbol,
|
|
830
|
+
className: "w-8 h-8 rounded-full"
|
|
831
|
+
}
|
|
832
|
+
) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "w-8 h-8 bg-[#7042D2] bg-opacity-20 rounded-full flex items-center justify-center", children: /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm font-bold text-[#7042D2]", children: token.symbol.charAt(0) }) }),
|
|
833
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-left flex-1", children: [
|
|
834
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-semibold", children: token.name }),
|
|
835
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-sm text-gray-600 dark:text-gray-400", children: [
|
|
836
|
+
token.symbol,
|
|
837
|
+
token.isStablecoin && /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "ml-2 px-2 py-0.5 bg-green-100 text-green-600 text-xs rounded-full", children: "Stablecoin" })
|
|
838
|
+
] })
|
|
839
|
+
] }),
|
|
840
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(ChevronDown, { className: "w-5 h-5 text-gray-400 transform -rotate-90" })
|
|
841
|
+
] })
|
|
842
|
+
},
|
|
843
|
+
token.id
|
|
844
|
+
)) })
|
|
845
|
+
]
|
|
846
|
+
},
|
|
847
|
+
"select-token"
|
|
848
|
+
),
|
|
701
849
|
currentStep === "wallet-connect" && /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
702
850
|
motion.div,
|
|
703
851
|
{
|