coinley-checkout 0.3.4 → 0.3.5

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.
@@ -165,22 +165,17 @@ const TOKEN_CONFIG = {
165
165
  }
166
166
  }
167
167
  };
168
- let Web3Cache = null;
169
168
  const getWeb3Instance = () => __async(void 0, null, function* () {
170
- if (Web3Cache) {
171
- return Web3Cache;
172
- }
173
169
  try {
174
- if (typeof window !== "undefined" && window.Web3) {
175
- Web3Cache = window.Web3;
176
- return Web3Cache;
170
+ if (typeof window !== "undefined" && window.ethereum) {
171
+ const Web3Module = yield import("web3");
172
+ const Web3 = Web3Module.default || Web3Module.Web3 || Web3Module;
173
+ return new Web3(window.ethereum);
177
174
  }
178
- const Web3Module = yield import("web3");
179
- Web3Cache = Web3Module.default || Web3Module.Web3 || Web3Module;
180
- return Web3Cache;
175
+ throw new Error("No ethereum provider found");
181
176
  } catch (error) {
182
177
  console.error("Failed to load Web3:", error);
183
- throw new Error("Web3 is required for blockchain transactions. Please ensure web3 is installed: npm install web3");
178
+ throw new Error("Web3 is required for blockchain transactions. Please install MetaMask or another Web3 wallet.");
184
179
  }
185
180
  });
186
181
  const detectWallets = () => {
@@ -211,6 +206,7 @@ const getSupportedWalletsForNetwork = (network) => {
211
206
  return networkConfig.supportedWallets.filter((wallet) => availableWallets[wallet]);
212
207
  };
213
208
  const connectWallet = (walletType, network) => __async(void 0, null, function* () {
209
+ console.log("connectWallet called with:", { walletType, network });
214
210
  switch (walletType) {
215
211
  case WALLET_TYPES.METAMASK:
216
212
  return yield connectMetaMask(network);
@@ -225,28 +221,41 @@ const connectWallet = (walletType, network) => __async(void 0, null, function* (
225
221
  }
226
222
  });
227
223
  const connectMetaMask = (network) => __async(void 0, null, function* () {
228
- if (typeof window === "undefined" || !window.ethereum || !window.ethereum.isMetaMask) {
224
+ console.log("Attempting to connect MetaMask for network:", network);
225
+ if (typeof window === "undefined" || !window.ethereum) {
229
226
  throw new Error("MetaMask is not installed. Please install MetaMask extension.");
230
227
  }
228
+ if (!window.ethereum.isMetaMask) {
229
+ console.warn("MetaMask not detected as primary provider");
230
+ }
231
231
  try {
232
+ console.log("Requesting accounts from MetaMask...");
232
233
  const accounts = yield window.ethereum.request({
233
234
  method: "eth_requestAccounts"
234
235
  });
236
+ console.log("Accounts received:", accounts);
235
237
  if (!accounts || accounts.length === 0) {
236
- throw new Error("No accounts found. Please unlock MetaMask.");
238
+ throw new Error("No accounts found. Please unlock MetaMask and ensure you have at least one account.");
237
239
  }
238
240
  const networkConfig = NETWORK_CONFIG[network];
239
241
  if (networkConfig && networkConfig.chainId) {
242
+ console.log("Switching to network:", networkConfig.chainName);
240
243
  yield switchEVMNetwork(networkConfig);
241
244
  }
242
- return {
245
+ const connection = {
243
246
  address: accounts[0],
244
247
  network,
245
248
  walletType: WALLET_TYPES.METAMASK
246
249
  };
250
+ console.log("MetaMask connected successfully:", connection);
251
+ return connection;
247
252
  } catch (error) {
253
+ console.error("MetaMask connection error:", error);
248
254
  if (error.code === 4001) {
249
- throw new Error("User rejected the connection request");
255
+ throw new Error("Connection rejected by user. Please accept the connection request in MetaMask.");
256
+ }
257
+ if (error.code === -32002) {
258
+ throw new Error("Connection request already pending. Please check MetaMask.");
250
259
  }
251
260
  throw new Error(`Failed to connect MetaMask: ${error.message}`);
252
261
  }
@@ -325,24 +334,30 @@ const switchEVMNetwork = (networkConfig) => __async(void 0, null, function* () {
325
334
  throw new Error("Ethereum provider not found");
326
335
  }
327
336
  try {
337
+ console.log("Attempting to switch to:", networkConfig.chainName);
328
338
  yield window.ethereum.request({
329
339
  method: "wallet_switchEthereumChain",
330
340
  params: [{ chainId: networkConfig.chainId }]
331
341
  });
342
+ console.log("Network switched successfully");
332
343
  } catch (switchError) {
344
+ console.error("Network switch error:", switchError);
333
345
  if (switchError.code === 4902) {
346
+ console.log("Network not found, attempting to add:", networkConfig.chainName);
334
347
  try {
335
348
  yield window.ethereum.request({
336
349
  method: "wallet_addEthereumChain",
337
350
  params: [networkConfig]
338
351
  });
352
+ console.log("Network added successfully");
339
353
  } catch (addError) {
340
- throw new Error(`Failed to add ${networkConfig.chainName} to wallet: ${addError.message}`);
354
+ console.error("Failed to add network:", addError);
355
+ throw new Error(`Failed to add ${networkConfig.chainName} to wallet. Please add it manually.`);
341
356
  }
342
357
  } else if (switchError.code === 4001) {
343
- throw new Error("User rejected network switch request");
358
+ throw new Error("User rejected network switch request. Please switch network manually in MetaMask.");
344
359
  } else {
345
- throw new Error(`Failed to switch to ${networkConfig.chainName}: ${switchError.message}`);
360
+ throw new Error(`Failed to switch to ${networkConfig.chainName}. Please switch manually in MetaMask.`);
346
361
  }
347
362
  }
348
363
  });
@@ -2285,6 +2300,29 @@ const PaymentMethods = ({ onSelect, selected, theme = "light", supportedNetworks
2285
2300
  };
2286
2301
  const availableMethods = getPaymentMethodsForNetwork(selectedNetwork);
2287
2302
  const visibleMethods = showMore ? availableMethods : availableMethods.slice(0, 4);
2303
+ function getRequiredWallet(network) {
2304
+ switch (network) {
2305
+ case NETWORK_TYPES.ETHEREUM:
2306
+ case NETWORK_TYPES.BSC:
2307
+ return WALLET_TYPES.METAMASK;
2308
+ case NETWORK_TYPES.TRON:
2309
+ return WALLET_TYPES.TRONLINK;
2310
+ case NETWORK_TYPES.ALGORAND:
2311
+ return WALLET_TYPES.LUTE;
2312
+ default:
2313
+ return WALLET_TYPES.METAMASK;
2314
+ }
2315
+ }
2316
+ function getNetworkRequirement(network) {
2317
+ const wallet = getRequiredWallet(network);
2318
+ const isAvailable = availableWallets[wallet];
2319
+ const walletNames = {
2320
+ [WALLET_TYPES.METAMASK]: "MetaMask",
2321
+ [WALLET_TYPES.TRONLINK]: "TronLink",
2322
+ [WALLET_TYPES.LUTE]: "Lute Wallet"
2323
+ };
2324
+ return isAvailable ? `${walletNames[wallet]} detected - Ready to pay` : `${walletNames[wallet]} required - Please install to continue`;
2325
+ }
2288
2326
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
2289
2327
  /* @__PURE__ */ jsxRuntimeExports.jsx("h3", { className: `text-lg font-medium mb-4 ${theme === "dark" ? "text-white" : "text-gray-800"}`, children: "Select Payment Method" }),
2290
2328
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mb-6", children: [
@@ -2351,29 +2389,6 @@ const PaymentMethods = ({ onSelect, selected, theme = "light", supportedNetworks
2351
2389
  /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "text-xs", children: getNetworkRequirement(selectedNetwork) })
2352
2390
  ] }) })
2353
2391
  ] });
2354
- function getRequiredWallet(network) {
2355
- switch (network) {
2356
- case NETWORK_TYPES.ETHEREUM:
2357
- case NETWORK_TYPES.BSC:
2358
- return "metamask";
2359
- case NETWORK_TYPES.TRON:
2360
- return "tronlink";
2361
- case NETWORK_TYPES.ALGORAND:
2362
- return "lute";
2363
- default:
2364
- return "metamask";
2365
- }
2366
- }
2367
- function getNetworkRequirement(network) {
2368
- const wallet = getRequiredWallet(network);
2369
- const isAvailable = availableWallets[wallet];
2370
- const walletNames = {
2371
- metamask: "MetaMask",
2372
- tronlink: "TronLink",
2373
- lute: "Lute Wallet"
2374
- };
2375
- return isAvailable ? `${walletNames[wallet]} detected - Ready to pay` : `${walletNames[wallet]} required - Please install to continue`;
2376
- }
2377
2392
  };
2378
2393
  const logo = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAJQAAAAkCAYAAABv9hOhAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAmVSURBVHgB7Vzdcdu4Fv5I+X2VCoK83pkb2xVc2ikgTgVWKog8twDJBexYrsBKBXYKWJtbQWRnZl+NrWC172txcQBQBA8B/kiKV87qm4FFgMAhAX48ODg4dISOGB4/XKsfObl9e+Y9n3wViHt3QHY5ud2fYId1caDSJyc/V+kMW4q4S2VFFurcCR0Oj+/H3kq9vSv1VyDDKX5s0Fh8VSlTifrcx/cByR046QRbjE6EQm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NZLEF5W59OiQPgNJw+8+0Z2DV9JUQ8uL2+ToHzfEmWnJ72w1x55VC9f0vdR7Of1PfVCTtQxwubBITwxXCW3gUOmfpBMeTSmiXU6QRwnVtSJzke9q6Lu4oOdMsd6Fbka6G0KkVEgbGQTQdztkxThuG8a6ARhMlG7bZvuctB9+cZHwH5DCaOFEvjJdIQwuAbMMUMgINAfD8UD41yo6dHaRgNb0reSzK+aFvNwYU1QIpWJOliHVGNU96DqkML/Bk3RLf6b6h2hvWf9n8IY9XucPhARDxva+FwIhMtQg0rEJiNLGSZI7lyvDMsXhbG1LKLeMvTBTodH9vN0IhVWnP6mNg1gDOaEnc+N+DxsIwQJQ6qBlcOnAZJDRPyMeiJ9QflhSHbuJyazCVze3JE79ZRzpCj6RY7pBH6NRNe5QfvVqgxcy4uIF5hPzCO/JlG2k44pP36g8Ip+qYyM78yZyxdPr1w3g/5yJoqv9apSGfuTX95uYgoRzrHE6hAbkrNtcG3LOVZzhnLbboqaT8aqU17mnermS+KY6Yzv5QBP7LOoOB64WR2MRxGgWsvhakNed+mkbZCzbSACSVR9Vm3BXQWEz3UNqoSquhCmJtTXbg4vjXDQFDjLtZD+pUjPQtA+F0021eRu/40NKz7ADtuMkB8urWtU/Yzq9u1UaQ+pow0WTzdV77hDlGgZgmuQLdT8HBmi1Hjfl3HnO2wbEhT2qWDniAeNIdD+z6jqQlXcuHL6MMHFYpEuDfYo2sSUtsPzQiDs6CQySTQgRldkWU6UKf+KRROxOaR4h5cF0kzk+pm2qdydUJF2D8yXH3NyPP21tf9dbYdOkDAOU3JFtF6R76EraO9PrfJC39hZv5NidG835b085Eb3qi4G/A2inrQKnVgMFAAAAABJRU5ErkJggg==";
2379
2394
  const CoinleyModal = ({
@@ -2397,7 +2412,6 @@ const CoinleyModal = ({
2397
2412
  supportedWallets = [],
2398
2413
  step = "select-currency",
2399
2414
  merchantWalletAddresses = {}
2400
- // Add this prop
2401
2415
  }) => {
2402
2416
  const [paymentType, setPaymentType] = useState("wallet");
2403
2417
  const getWalletAddressForNetwork = () => {
@@ -2495,8 +2509,12 @@ const CoinleyModal = ({
2495
2509
  selectedPaymentMethod && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "mt-6", children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
2496
2510
  "button",
2497
2511
  {
2498
- onClick: () => onPaymentMethodSelect(selectedPaymentMethod),
2512
+ onClick: () => {
2513
+ console.log("Proceed button clicked, calling onPaymentMethodSelect");
2514
+ onPaymentMethodSelect(selectedPaymentMethod);
2515
+ },
2499
2516
  className: "w-full py-3 px-4 bg-[#7042D2] hover:bg-[#7042D2] text-white font-medium rounded-lg transition-colors",
2517
+ disabled: !selectedPaymentMethod,
2500
2518
  children: [
2501
2519
  "Proceed with ",
2502
2520
  selectedPaymentMethod.currency,
@@ -2603,7 +2621,10 @@ const CoinleyModal = ({
2603
2621
  ] }) : /* @__PURE__ */ jsxRuntimeExports.jsx(
2604
2622
  "button",
2605
2623
  {
2606
- onClick: () => onConnectWallet(walletType),
2624
+ onClick: () => {
2625
+ console.log("Connect wallet button clicked for:", walletType);
2626
+ onConnectWallet(walletType);
2627
+ },
2607
2628
  className: "py-2 px-4 bg-[#7042D2] hover:bg-[#7042D2] text-white font-medium rounded-md text-sm",
2608
2629
  children: "Connect"
2609
2630
  }
@@ -2829,9 +2850,14 @@ const CoinleyCheckout = forwardRef(({
2829
2850
  onClose();
2830
2851
  };
2831
2852
  const handlePaymentMethodSelect = (paymentMethod) => {
2853
+ console.log("=== PAYMENT METHOD SELECTION DEBUG ===");
2854
+ console.log("1. Payment method selected:", paymentMethod);
2855
+ console.log("2. Current step before:", step);
2832
2856
  log("Payment method selected:", paymentMethod);
2833
2857
  setSelectedPaymentMethod(paymentMethod);
2834
2858
  setStep("confirm");
2859
+ console.log("3. Step should now be: confirm");
2860
+ console.log("=== END PAYMENT METHOD SELECTION DEBUG ===");
2835
2861
  };
2836
2862
  const handleBack = () => {
2837
2863
  if (step === "confirm") {
@@ -2840,20 +2866,31 @@ const CoinleyCheckout = forwardRef(({
2840
2866
  }
2841
2867
  };
2842
2868
  const handleConnectWallet = (walletType) => __async(void 0, null, function* () {
2869
+ console.log("=== WALLET CONNECTION DEBUG ===");
2870
+ console.log("1. Wallet type requested:", walletType);
2871
+ console.log("2. Selected payment method:", selectedPaymentMethod);
2872
+ console.log("3. Available wallets:", availableWallets);
2873
+ console.log("4. Current step:", step);
2843
2874
  if (!selectedPaymentMethod) {
2875
+ console.error("No payment method selected");
2844
2876
  setError("Please select a payment method first");
2845
2877
  return;
2846
2878
  }
2847
2879
  try {
2880
+ console.log("5. Attempting to connect wallet...");
2881
+ setError(null);
2848
2882
  log("Connecting wallet:", { walletType, network: selectedPaymentMethod.network });
2849
2883
  const connection = yield connectWallet(walletType, selectedPaymentMethod.network);
2850
2884
  setWalletConnection(connection);
2851
2885
  setError(null);
2886
+ console.log("6. Connection successful:", connection);
2852
2887
  log("Wallet connected successfully:", connection);
2853
2888
  } catch (err) {
2889
+ console.error("7. Connection failed:", err);
2854
2890
  log("Wallet connection error:", err);
2855
2891
  setError(err.message || "Failed to connect wallet");
2856
2892
  }
2893
+ console.log("=== END WALLET CONNECTION DEBUG ===");
2857
2894
  });
2858
2895
  const handlePayment = () => __async(void 0, null, function* () {
2859
2896
  var _a, _b;