coinley-checkout 1.1.9 → 1.2.1

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.
@@ -18628,34 +18628,68 @@ const sendNativeTransaction = async (walletConnection, toAddress, amount) => {
18628
18628
  if (!phantomProvider || !phantomProvider.isConnected) {
18629
18629
  throw new Error("Phantom wallet not connected");
18630
18630
  }
18631
- const { Connection, PublicKey, Transaction: Transaction2, SystemProgram, LAMPORTS_PER_SOL } = await import("./index.browser.esm-0402aa17.mjs").then((n2) => n2.i);
18632
- const connection = new Connection(NETWORK_CONFIG[NETWORK_TYPES.SOLANA].rpcUrl);
18633
- const fromPubkey = walletConnection.publicKey;
18634
- const toPubkey = new PublicKey(toAddress);
18635
18631
  const amountFloat = parseFloat(amount);
18636
- const lamports = Math.floor(amountFloat * LAMPORTS_PER_SOL);
18637
- console.log("Sending SOL:", {
18638
- from: fromPubkey.toString(),
18639
- to: toAddress,
18640
- amount: amountFloat,
18641
- lamports,
18642
- debug: `${amountFloat} SOL = ${lamports} lamports`
18632
+ console.log("Phantom SOL Transaction Debug:", {
18633
+ originalAmount: amount,
18634
+ amountFloat,
18635
+ walletType: "Phantom Native SOL"
18643
18636
  });
18644
- if (lamports <= 0) {
18645
- throw new Error(`Invalid amount: ${amount} SOL converts to ${lamports} lamports`);
18637
+ try {
18638
+ if (phantomProvider.request) {
18639
+ const result = await phantomProvider.request({
18640
+ method: "transfer",
18641
+ params: {
18642
+ to: toAddress,
18643
+ amount: amountFloat
18644
+ // Send in SOL, not lamports
18645
+ }
18646
+ });
18647
+ console.log("Phantom transfer result:", result);
18648
+ transaction = result;
18649
+ } else {
18650
+ let Connection, PublicKey, Transaction2, SystemProgram, LAMPORTS_PER_SOL;
18651
+ try {
18652
+ const solanaWeb3 = await import("@solana/web3.js");
18653
+ Connection = solanaWeb3.Connection;
18654
+ PublicKey = solanaWeb3.PublicKey;
18655
+ Transaction2 = solanaWeb3.Transaction;
18656
+ SystemProgram = solanaWeb3.SystemProgram;
18657
+ LAMPORTS_PER_SOL = solanaWeb3.LAMPORTS_PER_SOL;
18658
+ } catch (importError) {
18659
+ console.error("Failed to import Solana libraries:", importError);
18660
+ throw new Error("Solana libraries not available. Please ensure @solana/web3.js is installed.");
18661
+ }
18662
+ const connection = new Connection(NETWORK_CONFIG[NETWORK_TYPES.SOLANA].rpcUrl);
18663
+ const fromPubkey = walletConnection.publicKey;
18664
+ const toPubkey = new PublicKey(toAddress);
18665
+ const lamports = Math.floor(amountFloat * LAMPORTS_PER_SOL);
18666
+ console.log("Manual Solana transaction:", {
18667
+ from: fromPubkey.toString(),
18668
+ to: toAddress,
18669
+ amountSOL: amountFloat,
18670
+ lamports,
18671
+ conversionCheck: `${amountFloat} SOL = ${lamports} lamports`
18672
+ });
18673
+ if (lamports <= 0) {
18674
+ throw new Error(`Invalid amount: ${amountFloat} SOL converts to ${lamports} lamports`);
18675
+ }
18676
+ const transferTransaction = new Transaction2().add(
18677
+ SystemProgram.transfer({
18678
+ fromPubkey,
18679
+ toPubkey,
18680
+ lamports
18681
+ })
18682
+ );
18683
+ const { blockhash } = await connection.getLatestBlockhash();
18684
+ transferTransaction.recentBlockhash = blockhash;
18685
+ transferTransaction.feePayer = fromPubkey;
18686
+ const signedTransaction = await phantomProvider.signAndSendTransaction(transferTransaction);
18687
+ transaction = signedTransaction;
18688
+ }
18689
+ } catch (phantomError) {
18690
+ console.error("Phantom transaction error:", phantomError);
18691
+ throw new Error(`Phantom transaction failed: ${phantomError.message || "Unknown error"}`);
18646
18692
  }
18647
- const transferTransaction = new Transaction2().add(
18648
- SystemProgram.transfer({
18649
- fromPubkey,
18650
- toPubkey,
18651
- lamports
18652
- })
18653
- );
18654
- const { blockhash } = await connection.getLatestBlockhash();
18655
- transferTransaction.recentBlockhash = blockhash;
18656
- transferTransaction.feePayer = fromPubkey;
18657
- const signedTransaction = await phantomProvider.signAndSendTransaction(transferTransaction);
18658
- transaction = signedTransaction;
18659
18693
  break;
18660
18694
  default:
18661
18695
  throw new Error(`Unsupported wallet type: ${walletConnection.walletType}`);
@@ -18715,7 +18749,9 @@ const sendTokenTransaction = async (walletConnection, tokenConfig, toAddress, am
18715
18749
  }
18716
18750
  };
18717
18751
  const sendSolanaTokenTransaction = async (walletConnection, tokenConfig, toAddress, amount) => {
18718
- console.log("Sending Solana token transaction with:", { tokenConfig, toAddress, amount });
18752
+ console.log("=== SOLANA TOKEN TRANSACTION DEBUG ===");
18753
+ console.log("Input params:", { tokenConfig, toAddress, amount });
18754
+ console.log("Wallet connection:", walletConnection);
18719
18755
  if (!walletConnection || !walletConnection.provider) {
18720
18756
  throw new Error("Phantom wallet not connected");
18721
18757
  }
@@ -18729,26 +18765,51 @@ const sendSolanaTokenTransaction = async (walletConnection, tokenConfig, toAddre
18729
18765
  const { contractAddress, decimals, symbol } = tokenConfig;
18730
18766
  const tokenAmount = parseFloat(amount);
18731
18767
  const tokenDecimals = parseInt(decimals);
18768
+ console.log("Token config details:", {
18769
+ symbol,
18770
+ contractAddress,
18771
+ decimals: tokenDecimals,
18772
+ inputAmount: tokenAmount
18773
+ });
18732
18774
  const amountInSmallestUnit = Math.floor(tokenAmount * Math.pow(10, tokenDecimals));
18733
- console.log(`Sending ${tokenAmount} ${symbol}:`, {
18775
+ console.log("Amount calculation:", {
18734
18776
  tokenAmount,
18735
18777
  decimals: tokenDecimals,
18778
+ calculation: `${tokenAmount} * 10^${tokenDecimals}`,
18736
18779
  amountInSmallestUnit,
18737
- debug: `${tokenAmount} ${symbol} = ${amountInSmallestUnit} base units (10^${tokenDecimals})`
18780
+ humanReadable: `${tokenAmount} ${symbol} = ${amountInSmallestUnit} micro-${symbol}`
18738
18781
  });
18739
18782
  if (amountInSmallestUnit <= 0) {
18740
18783
  throw new Error(`Invalid amount: ${tokenAmount} ${symbol} converts to ${amountInSmallestUnit} base units`);
18741
18784
  }
18742
18785
  if (tokenAmount < 1 && amountInSmallestUnit === 0) {
18743
- throw new Error(`Amount too small: ${tokenAmount} ${symbol} is smaller than the minimum unit (1/${Math.pow(10, tokenDecimals)})`);
18786
+ throw new Error(`Amount too small: ${tokenAmount} ${symbol} is smaller than the minimum unit (1/${Math.pow(10, tokenDecimals)} ${symbol})`);
18744
18787
  }
18745
18788
  try {
18746
- const { Connection, PublicKey, Transaction: Transaction2 } = await import("./index.browser.esm-0402aa17.mjs").then((n2) => n2.i);
18747
- const { createTransferInstruction, getAssociatedTokenAddress, TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID } = await import("./index-8e44c7ca.mjs");
18789
+ let Connection, PublicKey, Transaction2, createTransferInstruction, getAssociatedTokenAddress, TOKEN_PROGRAM_ID, ASSOCIATED_TOKEN_PROGRAM_ID;
18790
+ try {
18791
+ const solanaWeb3 = await import("@solana/web3.js");
18792
+ const splToken = await import("./index-e49d97f5.mjs");
18793
+ Connection = solanaWeb3.Connection;
18794
+ PublicKey = solanaWeb3.PublicKey;
18795
+ Transaction2 = solanaWeb3.Transaction;
18796
+ createTransferInstruction = splToken.createTransferInstruction;
18797
+ getAssociatedTokenAddress = splToken.getAssociatedTokenAddress;
18798
+ TOKEN_PROGRAM_ID = splToken.TOKEN_PROGRAM_ID;
18799
+ ASSOCIATED_TOKEN_PROGRAM_ID = splToken.ASSOCIATED_TOKEN_PROGRAM_ID;
18800
+ } catch (importError) {
18801
+ console.error("Failed to import Solana libraries:", importError);
18802
+ throw new Error("Solana libraries not available. Please ensure @solana/web3.js and @solana/spl-token are installed.");
18803
+ }
18748
18804
  const connection = new Connection(NETWORK_CONFIG[NETWORK_TYPES.SOLANA].rpcUrl);
18749
18805
  const fromPubkey = walletConnection.publicKey;
18750
18806
  const toPubkey = new PublicKey(toAddress);
18751
18807
  const mintPubkey = new PublicKey(contractAddress);
18808
+ console.log("Public keys:", {
18809
+ from: fromPubkey.toString(),
18810
+ to: toPubkey.toString(),
18811
+ mint: mintPubkey.toString()
18812
+ });
18752
18813
  const fromTokenAccount = await getAssociatedTokenAddress(
18753
18814
  mintPubkey,
18754
18815
  fromPubkey,
@@ -18764,16 +18825,15 @@ const sendSolanaTokenTransaction = async (walletConnection, tokenConfig, toAddre
18764
18825
  ASSOCIATED_TOKEN_PROGRAM_ID
18765
18826
  );
18766
18827
  console.log("Token accounts:", {
18767
- from: fromTokenAccount.toString(),
18768
- to: toTokenAccount.toString(),
18769
- mint: mintPubkey.toString()
18828
+ fromTokenAccount: fromTokenAccount.toString(),
18829
+ toTokenAccount: toTokenAccount.toString()
18770
18830
  });
18831
+ console.log("Creating transfer instruction with amount:", amountInSmallestUnit);
18771
18832
  const transferInstruction = createTransferInstruction(
18772
18833
  fromTokenAccount,
18773
18834
  toTokenAccount,
18774
18835
  fromPubkey,
18775
18836
  amountInSmallestUnit,
18776
- // This should be the correct amount now
18777
18837
  [],
18778
18838
  TOKEN_PROGRAM_ID
18779
18839
  );
@@ -18781,19 +18841,24 @@ const sendSolanaTokenTransaction = async (walletConnection, tokenConfig, toAddre
18781
18841
  const { blockhash } = await connection.getLatestBlockhash();
18782
18842
  transaction.recentBlockhash = blockhash;
18783
18843
  transaction.feePayer = fromPubkey;
18844
+ console.log("Transaction created, sending to Phantom...");
18784
18845
  const signedTransaction = await phantomProvider.signAndSendTransaction(transaction);
18785
- console.log("Solana token transaction sent:", signedTransaction);
18846
+ console.log("Solana token transaction sent successfully:", signedTransaction);
18847
+ console.log("=== END SOLANA TOKEN TRANSACTION DEBUG ===");
18786
18848
  return signedTransaction.signature || signedTransaction;
18787
18849
  } catch (error) {
18788
- console.error("Solana token transaction error:", error);
18850
+ console.error("Solana token transaction error:", error);
18851
+ console.log("=== END SOLANA TOKEN TRANSACTION DEBUG (ERROR) ===");
18789
18852
  if (error.message && error.message.includes("User rejected")) {
18790
18853
  throw new Error("Transaction rejected by user");
18791
18854
  } else if (error.message && error.message.includes("Insufficient")) {
18792
18855
  throw new Error("Insufficient token balance");
18793
- } else if (error.message && error.message.includes("Invalid amount")) {
18856
+ } else if (error.message && error.message.includes("Invalid amount") || error.message && error.message.includes("Amount too small")) {
18794
18857
  throw error;
18795
- } else {
18858
+ } else if (error.message && error.message.includes("Solana libraries not available")) {
18796
18859
  throw error;
18860
+ } else {
18861
+ throw new Error(`Token transaction failed: ${error.message || "Unknown error"}`);
18797
18862
  }
18798
18863
  }
18799
18864
  };