coinley-test 0.0.12 → 0.0.14
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 +151 -72
- 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,74 @@ 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
|
-
useWalletModal();
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
262
|
+
const { openModal } = useWalletModal();
|
|
263
|
+
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
|
+
if (walletType === "metamask" && window.ethereum && window.ethereum.isMetaMask) {
|
|
274
|
+
try {
|
|
275
|
+
await window.ethereum.request({ method: "eth_requestAccounts" });
|
|
276
|
+
console.log("✅ Connected directly to MetaMask");
|
|
277
|
+
} catch (error) {
|
|
278
|
+
console.error("MetaMask connection failed:", error);
|
|
279
|
+
throw error;
|
|
280
|
+
}
|
|
281
|
+
} else {
|
|
282
|
+
await connectWallet(walletType);
|
|
283
|
+
}
|
|
284
|
+
} catch (error) {
|
|
285
|
+
console.error("Wallet connection failed:", error);
|
|
286
|
+
onError(error.message || "Failed to connect wallet");
|
|
287
|
+
} finally {
|
|
288
|
+
setIsConnecting(false);
|
|
271
289
|
}
|
|
272
|
-
}
|
|
273
|
-
const
|
|
290
|
+
};
|
|
291
|
+
const handleOpenModal = () => {
|
|
292
|
+
try {
|
|
293
|
+
console.log("Attempting to open wallet modal...");
|
|
294
|
+
openModal();
|
|
295
|
+
} catch (error) {
|
|
296
|
+
console.error("Failed to open modal:", error);
|
|
297
|
+
handleConnectSpecificWallet("injected");
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
const handleSendPayment = async () => {
|
|
274
301
|
var _a;
|
|
275
|
-
if (!isConnected || !paymentData || !selectedToken)
|
|
302
|
+
if (!isConnected || !paymentData || !selectedToken) {
|
|
303
|
+
onError("Wallet not connected or payment data missing");
|
|
304
|
+
return;
|
|
305
|
+
}
|
|
276
306
|
try {
|
|
277
307
|
setIsConnecting(true);
|
|
278
308
|
console.log("🔍 Transaction Debug:");
|
|
309
|
+
console.log("Connected wallet address:", address);
|
|
279
310
|
console.log("Payment data:", paymentData);
|
|
280
311
|
console.log("Selected token:", selectedToken);
|
|
281
312
|
console.log("Selected network:", selectedNetwork);
|
|
282
313
|
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
|
-
}
|
|
314
|
+
console.log("Merchant recipient address:", recipientAddress);
|
|
287
315
|
if (!recipientAddress || typeof recipientAddress !== "string") {
|
|
288
|
-
throw new Error("Merchant wallet address not found in payment data
|
|
316
|
+
throw new Error("Merchant wallet address not found in payment data");
|
|
289
317
|
}
|
|
290
318
|
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
319
|
throw new Error(`Invalid merchant address format: ${recipientAddress}`);
|
|
298
320
|
}
|
|
299
|
-
console.log("✅ Using merchant recipient address:", recipientAddress);
|
|
300
321
|
let txHash;
|
|
301
322
|
if (selectedToken.contractAddress) {
|
|
302
323
|
console.log("🔍 ERC-20 Transaction Details:");
|
|
@@ -306,16 +327,12 @@ const WalletIntegration = ({
|
|
|
306
327
|
const decimals = selectedToken.decimals || 6;
|
|
307
328
|
const amount = Math.floor(paymentData.totalAmount * Math.pow(10, decimals));
|
|
308
329
|
console.log("Calculated amount (with decimals):", amount);
|
|
309
|
-
console.log("Amount in hex:", amount.toString(16));
|
|
310
330
|
const methodId = "0xa9059cbb";
|
|
311
331
|
const addressWithoutPrefix = recipientAddress.slice(2);
|
|
312
332
|
const recipientPadded = addressWithoutPrefix.toLowerCase().padStart(64, "0");
|
|
313
333
|
const amountPadded = amount.toString(16).padStart(64, "0");
|
|
314
334
|
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);
|
|
335
|
+
console.log("🔍 Transaction Data:");
|
|
319
336
|
console.log("Method ID:", methodId);
|
|
320
337
|
console.log("Recipient (padded):", recipientPadded);
|
|
321
338
|
console.log("Amount (padded):", amountPadded);
|
|
@@ -328,11 +345,8 @@ const WalletIntegration = ({
|
|
|
328
345
|
console.log("📤 Sending ERC-20 transaction:", txParams);
|
|
329
346
|
txHash = await sendTransaction(txParams);
|
|
330
347
|
} else {
|
|
331
|
-
console.log("🔍 Native Token Transaction:");
|
|
332
348
|
const value = Math.floor(paymentData.totalAmount * Math.pow(10, 18));
|
|
333
349
|
const valueHex = `0x${value.toString(16)}`;
|
|
334
|
-
console.log("Native amount:", value);
|
|
335
|
-
console.log("Native amount hex:", valueHex);
|
|
336
350
|
const txParams = {
|
|
337
351
|
to: recipientAddress,
|
|
338
352
|
value: valueHex
|
|
@@ -346,58 +360,123 @@ const WalletIntegration = ({
|
|
|
346
360
|
}
|
|
347
361
|
} catch (error) {
|
|
348
362
|
console.error("❌ Transaction failed:", error);
|
|
349
|
-
console.error("Error details:", {
|
|
350
|
-
message: error.message,
|
|
351
|
-
cause: error.cause,
|
|
352
|
-
details: error.details
|
|
353
|
-
});
|
|
354
363
|
onError(error.message || "Transaction failed");
|
|
355
364
|
} finally {
|
|
356
365
|
setIsConnecting(false);
|
|
357
366
|
}
|
|
358
367
|
};
|
|
368
|
+
const handleDisconnect = async () => {
|
|
369
|
+
try {
|
|
370
|
+
await disconnect();
|
|
371
|
+
} catch (error) {
|
|
372
|
+
console.error("Disconnect error:", error);
|
|
373
|
+
}
|
|
374
|
+
};
|
|
359
375
|
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-center space-y-6", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-4", children: [
|
|
360
376
|
/* @__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
|
-
|
|
377
|
+
!isConnected ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
378
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-lg font-semibold", children: "Connect Your Wallet" }),
|
|
379
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-gray-600 dark:text-gray-400 text-sm", children: "Choose your preferred wallet to complete the payment" }),
|
|
380
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "space-y-3", children: [
|
|
381
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
382
|
+
"button",
|
|
383
|
+
{
|
|
384
|
+
onClick: () => handleConnectSpecificWallet("metamask"),
|
|
385
|
+
disabled: isPending || isConnecting,
|
|
386
|
+
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",
|
|
387
|
+
children: [
|
|
388
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-xl", children: "🦊" }),
|
|
389
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-left flex-1", children: [
|
|
390
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-medium", children: "MetaMask" }),
|
|
391
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500", children: "Connect with MetaMask" })
|
|
392
|
+
] })
|
|
393
|
+
]
|
|
394
|
+
}
|
|
395
|
+
),
|
|
396
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
397
|
+
"button",
|
|
398
|
+
{
|
|
399
|
+
onClick: handleOpenModal,
|
|
400
|
+
disabled: isPending || isConnecting,
|
|
401
|
+
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",
|
|
402
|
+
children: [
|
|
403
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-xl", children: "💼" }),
|
|
404
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "text-left flex-1", children: [
|
|
405
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "font-medium", children: "Other Wallets" }),
|
|
406
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "text-xs text-gray-500", children: "Choose from available wallets" })
|
|
407
|
+
] })
|
|
408
|
+
]
|
|
409
|
+
}
|
|
410
|
+
),
|
|
411
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
412
|
+
"button",
|
|
413
|
+
{
|
|
414
|
+
onClick: () => handleConnectSpecificWallet("injected"),
|
|
415
|
+
disabled: isPending || isConnecting,
|
|
416
|
+
className: "w-full p-2 text-sm border border-dashed border-gray-300 rounded-lg hover:border-[#7042D2] transition-colors disabled:opacity-50",
|
|
417
|
+
children: "Try Direct Connection"
|
|
418
|
+
}
|
|
419
|
+
)
|
|
383
420
|
] }),
|
|
384
|
-
|
|
421
|
+
isConnecting && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center justify-center space-x-2 text-gray-600", children: [
|
|
422
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Loader2, { className: "w-4 h-4 animate-spin" }),
|
|
423
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "Connecting..." })
|
|
424
|
+
] })
|
|
425
|
+
] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
426
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: "text-lg font-semibold text-green-600", children: "Wallet Connected ✅" }),
|
|
427
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "bg-gray-50 dark:bg-gray-800 rounded-lg p-4 space-y-3", children: [
|
|
385
428
|
/* @__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
|
-
|
|
429
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm text-gray-600 dark:text-gray-400", children: "Address:" }),
|
|
430
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center space-x-2", children: [
|
|
431
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "font-mono text-sm", children: [
|
|
432
|
+
address == null ? void 0 : address.slice(0, 6),
|
|
433
|
+
"...",
|
|
434
|
+
address == null ? void 0 : address.slice(-4)
|
|
435
|
+
] }),
|
|
436
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
437
|
+
"button",
|
|
438
|
+
{
|
|
439
|
+
onClick: handleDisconnect,
|
|
440
|
+
className: "text-xs text-red-600 hover:text-red-800",
|
|
441
|
+
children: "Disconnect"
|
|
442
|
+
}
|
|
443
|
+
)
|
|
391
444
|
] })
|
|
392
445
|
] }),
|
|
393
|
-
/* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
394
|
-
/* @__PURE__ */ jsxRuntimeExports.
|
|
395
|
-
|
|
446
|
+
paymentData && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
447
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between items-center", children: [
|
|
448
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm text-gray-600 dark:text-gray-400", children: "Amount:" }),
|
|
449
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("span", { className: "font-medium", children: [
|
|
450
|
+
paymentData.totalAmount,
|
|
451
|
+
" ",
|
|
452
|
+
selectedToken == null ? void 0 : selectedToken.symbol
|
|
453
|
+
] })
|
|
454
|
+
] }),
|
|
455
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex justify-between items-center", children: [
|
|
456
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-sm text-gray-600 dark:text-gray-400", children: "Network:" }),
|
|
457
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "font-medium", children: selectedNetwork == null ? void 0 : selectedNetwork.name })
|
|
458
|
+
] })
|
|
396
459
|
] })
|
|
397
460
|
] }),
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
461
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
462
|
+
"button",
|
|
463
|
+
{
|
|
464
|
+
onClick: handleSendPayment,
|
|
465
|
+
disabled: isConnecting,
|
|
466
|
+
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",
|
|
467
|
+
children: isConnecting ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
468
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Loader2, { className: "w-5 h-5 animate-spin" }),
|
|
469
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "Processing Payment..." })
|
|
470
|
+
] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
471
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(Zap, { className: "w-5 h-5" }),
|
|
472
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "Send Payment" })
|
|
473
|
+
] })
|
|
474
|
+
}
|
|
475
|
+
),
|
|
476
|
+
/* @__PURE__ */ jsxRuntimeExports.jsxs("p", { className: "text-xs text-gray-500", children: [
|
|
477
|
+
"Make sure you have enough ",
|
|
478
|
+
selectedToken == null ? void 0 : selectedToken.symbol,
|
|
479
|
+
" and ETH for gas fees"
|
|
401
480
|
] })
|
|
402
481
|
] })
|
|
403
482
|
] }) });
|