coinley-checkout 0.4.9 → 0.5.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.
@@ -2236,6 +2236,17 @@ const names = [
2236
2236
  "finney",
2237
2237
  "ether"
2238
2238
  ];
2239
+ function formatUnits(value, unit) {
2240
+ let decimals = 18;
2241
+ if (typeof unit === "string") {
2242
+ const index = names.indexOf(unit);
2243
+ assertArgument(index >= 0, "invalid unit", "unit", unit);
2244
+ decimals = 3 * index;
2245
+ } else if (unit != null) {
2246
+ decimals = getNumber(unit, "unit");
2247
+ }
2248
+ return FixedNumber.fromValue(value, decimals, { decimals, width: 512 }).toString();
2249
+ }
2239
2250
  function parseUnits$1(value, unit) {
2240
2251
  assertArgument(typeof value === "string", "value must be a string", "value", value);
2241
2252
  let decimals = 18;
@@ -18784,16 +18795,34 @@ const sendERC20Transaction = (walletConnection, tokenConfig, toAddress, amount)
18784
18795
  const tokenDecimals = parseInt(decimals);
18785
18796
  const tokenUnits = parseUnits$1(tokenAmount.toString(), tokenDecimals);
18786
18797
  console.log(`Sending ${tokenAmount} ${symbol} (${tokenUnits.toString()} base units) to ${toAddress}`);
18798
+ console.log(`Token config:`, { contractAddress, decimals, symbol });
18787
18799
  try {
18788
18800
  const tokenContract = new Contract(
18789
18801
  contractAddress,
18790
- ["function transfer(address to, uint256 amount) returns (bool)"],
18802
+ [
18803
+ "function transfer(address to, uint256 amount) returns (bool)",
18804
+ "function balanceOf(address owner) view returns (uint256)",
18805
+ "function decimals() view returns (uint8)"
18806
+ ],
18791
18807
  signer
18792
18808
  );
18809
+ const userAddress = yield signer.getAddress();
18810
+ const balance = yield tokenContract.balanceOf(userAddress);
18811
+ console.log(`User ${symbol} balance:`, formatUnits(balance, decimals));
18812
+ if (balance < tokenUnits) {
18813
+ throw new Error(`Insufficient ${symbol} balance. Required: ${tokenAmount}, Available: ${formatUnits(balance, decimals)}`);
18814
+ }
18793
18815
  try {
18794
18816
  const gasEstimate = yield tokenContract.transfer.estimateGas(toAddress, tokenUnits);
18795
18817
  console.log("Gas estimate:", gasEstimate.toString());
18796
- const gasMultiplier = symbol === "USDC" ? BigInt(120) : BigInt(110);
18818
+ let gasMultiplier;
18819
+ if (symbol === "USDC") {
18820
+ gasMultiplier = BigInt(150);
18821
+ } else if (symbol === "USDT") {
18822
+ gasMultiplier = BigInt(130);
18823
+ } else {
18824
+ gasMultiplier = BigInt(120);
18825
+ }
18797
18826
  const gasLimit = gasEstimate * gasMultiplier / BigInt(100);
18798
18827
  console.log("Using gas limit:", gasLimit.toString());
18799
18828
  const transaction = yield tokenContract.transfer(toAddress, tokenUnits, {
@@ -18803,16 +18832,20 @@ const sendERC20Transaction = (walletConnection, tokenConfig, toAddress, amount)
18803
18832
  return transaction.hash;
18804
18833
  } catch (gasError) {
18805
18834
  console.error("Gas estimation failed:", gasError);
18835
+ let fixedGasLimit;
18806
18836
  if (symbol === "USDC") {
18807
- console.log("Trying USDC transaction with fixed gas limit");
18808
- const transaction = yield tokenContract.transfer(toAddress, tokenUnits, {
18809
- gasLimit: BigInt(15e4)
18810
- // Higher fixed gas limit for USDC
18811
- });
18812
- console.log("Transaction sent with fixed gas limit:", transaction);
18813
- return transaction.hash;
18837
+ fixedGasLimit = BigInt(2e5);
18838
+ } else if (symbol === "USDT") {
18839
+ fixedGasLimit = BigInt(18e4);
18840
+ } else {
18841
+ fixedGasLimit = BigInt(15e4);
18814
18842
  }
18815
- throw new Error(`Transaction would likely fail: ${gasError.message}`);
18843
+ console.log(`Trying ${symbol} transaction with fixed gas limit:`, fixedGasLimit.toString());
18844
+ const transaction = yield tokenContract.transfer(toAddress, tokenUnits, {
18845
+ gasLimit: fixedGasLimit
18846
+ });
18847
+ console.log("Transaction sent with fixed gas limit:", transaction);
18848
+ return transaction.hash;
18816
18849
  }
18817
18850
  } catch (error) {
18818
18851
  console.error("ERC20 transaction error:", error);
@@ -18820,6 +18853,8 @@ const sendERC20Transaction = (walletConnection, tokenConfig, toAddress, amount)
18820
18853
  throw new Error("Transaction rejected by user");
18821
18854
  } else if (error.message && error.message.includes("insufficient funds")) {
18822
18855
  throw new Error("Insufficient funds for transaction");
18856
+ } else if (error.message && error.message.includes("Insufficient")) {
18857
+ throw error;
18823
18858
  } else {
18824
18859
  throw error;
18825
18860
  }
@@ -20863,13 +20898,13 @@ const PaymentMethods = ({ onSelect, selected, theme = "light", supportedNetworks
20863
20898
  )
20864
20899
  ] }),
20865
20900
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "mb-4", children: [
20866
- /* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: `block text-sm font-medium mb-3 ${theme === "dark" ? "text-white" : "text-gray-700"}`, children: "Choose Cryptocurrency" }),
20901
+ /* @__PURE__ */ jsxRuntimeExports.jsx("label", { className: `block text-sm font-medium mb-3 ${theme === "dark" ? "text-white" : "text-gray-700"}`, children: "Select Stablecoin" }),
20867
20902
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "grid grid-cols-2 gap-3 mb-4", children: visibleMethods.map((method) => /* @__PURE__ */ jsxRuntimeExports.jsx(
20868
20903
  "button",
20869
20904
  {
20870
20905
  onClick: () => handleSelectPaymentMethod(method),
20871
- className: `p-4 rounded-lg transition-all duration-200 border-2 ${(selected == null ? void 0 : selected.currency) === method.id && (selected == null ? void 0 : selected.network) === selectedNetwork ? theme === "dark" ? "bg-blue-900/30 border-[#7042D2] ring-2 ring-[#7042D2] ring-opacity-50" : "bg-blue-50 border-[#7042D2] ring-2 ring-[#7042D2] ring-opacity-50" : theme === "dark" ? "bg-gray-700 hover:bg-gray-600 border-gray-600 hover:border-gray-500" : "bg-white hover:bg-gray-50 border-gray-200 hover:border-gray-300"}`,
20872
- children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex flex-col items-center text-center", children: [
20906
+ className: `p-4 rounded-lg transition-all duration-200 border-1 ${(selected == null ? void 0 : selected.currency) === method.id && (selected == null ? void 0 : selected.network) === selectedNetwork ? theme === "dark" ? "bg-blue-900/30 border-[#7042D2] ring-2 ring-[#7042D2] ring-opacity-50" : "bg-blue-50 border-[#7042D2] ring-2 ring-[#7042D2] ring-opacity-50" : theme === "dark" ? "bg-gray-700 hover:bg-gray-600 border-gray-600 hover:border-gray-500" : "bg-white hover:bg-gray-50 border-gray-200 hover:border-gray-300"}`,
20907
+ children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "flex items-center text-center", children: [
20873
20908
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-shrink-0 h-10 w-10 bg-white rounded-full flex items-center justify-center mb-2 shadow-sm", children: /* @__PURE__ */ jsxRuntimeExports.jsx("img", { src: method.logo, alt: method.name, className: "h-6 w-6" }) }),
20874
20909
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
20875
20910
  /* @__PURE__ */ jsxRuntimeExports.jsx("h4", { className: `font-medium text-sm ${theme === "dark" ? "text-white" : "text-gray-900"}`, children: method.name }),