coinley-checkout 1.3.0 → 1.3.2

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.
@@ -22003,82 +22003,101 @@ const connectMetamaskWallet = async () => {
22003
22003
  const connectTrustWallet = async (targetNetwork = null) => {
22004
22004
  console.log("=== TRUST WALLET CONNECTION DEBUG ===");
22005
22005
  console.log("Connecting to Trust Wallet for network:", targetNetwork);
22006
- let trustProvider = null;
22007
22006
  let networkType = targetNetwork || NETWORK_TYPES.ETHEREUM;
22008
- if (window.ethereum) {
22009
- console.log("Available ethereum providers:", {
22010
- main: {
22007
+ try {
22008
+ if (networkType === NETWORK_TYPES.ETHEREUM || networkType === NETWORK_TYPES.BSC) {
22009
+ if (!window.ethereum) {
22010
+ throw new Error("No Ethereum provider found. Please install Trust Wallet browser extension.");
22011
+ }
22012
+ console.log("Available ethereum details:", {
22011
22013
  isMetaMask: window.ethereum.isMetaMask,
22012
22014
  isTrust: window.ethereum.isTrust,
22013
22015
  isTrustWallet: window.ethereum.isTrustWallet,
22014
- providers: window.ethereum.providers?.length || 0
22015
- }
22016
- });
22017
- if (window.ethereum.providers) {
22018
- window.ethereum.providers.forEach((provider, index) => {
22019
- console.log(`Provider ${index}:`, {
22016
+ providers: window.ethereum.providers?.length || 0,
22017
+ selectedAddress: window.ethereum.selectedAddress
22018
+ });
22019
+ const providersToTry = [];
22020
+ if (window.ethereum.providers && window.ethereum.providers.length > 0) {
22021
+ providersToTry.push(...window.ethereum.providers);
22022
+ console.log(`Found ${window.ethereum.providers.length} providers in array`);
22023
+ } else {
22024
+ providersToTry.push(window.ethereum);
22025
+ console.log("Using main ethereum provider");
22026
+ }
22027
+ if (window.trustwallet?.ethereum) {
22028
+ providersToTry.push(window.trustwallet.ethereum);
22029
+ console.log("Added trustwallet.ethereum provider");
22030
+ }
22031
+ console.log(`Total providers to try: ${providersToTry.length}`);
22032
+ let successfulProvider = null;
22033
+ let accounts = null;
22034
+ let lastError = null;
22035
+ for (let i = 0; i < providersToTry.length; i++) {
22036
+ const provider = providersToTry[i];
22037
+ console.log(`
22038
+ šŸ” Trying provider ${i + 1}/${providersToTry.length}:`, {
22020
22039
  isMetaMask: provider.isMetaMask,
22021
22040
  isTrust: provider.isTrust,
22022
- isTrustWallet: provider.isTrustWallet
22041
+ isTrustWallet: provider.isTrustWallet,
22042
+ selectedAddress: provider.selectedAddress
22023
22043
  });
22024
- });
22025
- }
22026
- }
22027
- try {
22028
- if (networkType === NETWORK_TYPES.ETHEREUM || networkType === NETWORK_TYPES.BSC) {
22029
- if (!window.ethereum) {
22030
- throw new Error("No Ethereum provider found. Please install Trust Wallet browser extension.");
22031
- }
22032
- if (window.ethereum.isTrust === true || window.ethereum.isTrustWallet === true) {
22033
- trustProvider = window.ethereum;
22034
- console.log("āœ… Found Trust Wallet via direct detection");
22035
- } else if (window.ethereum.providers && window.ethereum.providers.length > 0) {
22036
- trustProvider = window.ethereum.providers.find((p2) => p2.isTrust === true || p2.isTrustWallet === true);
22037
- if (trustProvider) {
22038
- console.log("āœ… Found Trust Wallet in providers array");
22039
- }
22040
- } else if (window.trustwallet && window.trustwallet.ethereum) {
22041
- trustProvider = window.trustwallet.ethereum;
22042
- console.log("āœ… Found Trust Wallet via global trustwallet object");
22043
- } else if (window.ethereum && !window.ethereum.isMetaMask) {
22044
- console.log("šŸ” Checking if non-MetaMask provider is Trust Wallet...");
22045
- const couldBeTrustWallet = window.ethereum.request && window.ethereum.on && typeof window.ethereum.isTrust !== "boolean" || window.ethereum.isTrust !== false;
22046
- if (couldBeTrustWallet) {
22047
- trustProvider = window.ethereum;
22048
- console.log("āœ… Assuming non-MetaMask provider is Trust Wallet");
22049
- try {
22050
- const accounts2 = await window.ethereum.request({ method: "eth_requestAccounts" });
22051
- if (accounts2 && accounts2.length > 0) {
22052
- console.log("āœ… Connection successful, confirming this is Trust Wallet");
22044
+ try {
22045
+ console.log(`šŸ“ž Requesting accounts from provider ${i + 1}...`);
22046
+ const testAccounts = await provider.request({
22047
+ method: "eth_requestAccounts"
22048
+ });
22049
+ if (testAccounts && testAccounts.length > 0) {
22050
+ console.log(`āœ… Provider ${i + 1} worked! Got ${testAccounts.length} accounts`);
22051
+ console.log(`šŸ“ First account: ${testAccounts[0]}`);
22052
+ successfulProvider = provider;
22053
+ accounts = testAccounts;
22054
+ if (!provider.isMetaMask) {
22055
+ console.log(`šŸŽÆ Provider ${i + 1} is not MetaMask - using this one!`);
22056
+ break;
22057
+ } else {
22058
+ console.log(`āš ļø Provider ${i + 1} is MetaMask - will use it if no other works`);
22053
22059
  }
22054
- } catch (testError) {
22055
- console.log("āŒ Test connection failed, might not be Trust Wallet");
22056
- trustProvider = null;
22060
+ } else {
22061
+ console.log(`āŒ Provider ${i + 1} returned no accounts`);
22062
+ }
22063
+ } catch (providerError) {
22064
+ console.log(`āŒ Provider ${i + 1} failed:`, providerError.message);
22065
+ lastError = providerError;
22066
+ if (providerError.code === 4001) {
22067
+ console.log("šŸ›‘ User rejected connection - stopping attempts");
22068
+ throw new Error("Connection rejected by user. Please approve the connection in your wallet.");
22057
22069
  }
22070
+ continue;
22058
22071
  }
22059
22072
  }
22060
- if (!trustProvider) {
22061
- const detectionResult = detectTrustWallet();
22062
- if (detectionResult) {
22063
- throw new Error(`Trust Wallet was detected but couldn't establish connection. Please:
22064
- 1. Make sure Trust Wallet browser extension is enabled
22065
- 2. Refresh the page and try again
22066
- 3. If you have multiple wallets, disable others temporarily
22067
- 4. Check if Trust Wallet is set as the default Web3 provider`);
22073
+ if (!successfulProvider || !accounts || accounts.length === 0) {
22074
+ console.error("āŒ All providers failed");
22075
+ if (lastError) {
22076
+ if (lastError.code === 4001) {
22077
+ throw new Error("Connection rejected by user. Please approve the connection in your wallet.");
22078
+ } else {
22079
+ throw new Error(`Connection failed: ${lastError.message}. Please make sure your wallet is unlocked and try again.`);
22080
+ }
22068
22081
  } else {
22069
- throw new Error("Trust Wallet not detected. Please install the Trust Wallet browser extension from https://trustwallet.com/browser-extension");
22082
+ throw new Error("No wallet accounts found. Please make sure Trust Wallet is unlocked and has at least one account.");
22070
22083
  }
22071
22084
  }
22072
- console.log("šŸš€ Attempting to connect with Trust Wallet provider...");
22073
- const accounts = await trustProvider.request({
22074
- method: "eth_requestAccounts"
22085
+ console.log("\nšŸŽ‰ Successfully connected!");
22086
+ console.log("Using provider:", {
22087
+ isMetaMask: successfulProvider.isMetaMask,
22088
+ isTrust: successfulProvider.isTrust,
22089
+ isTrustWallet: successfulProvider.isTrustWallet
22075
22090
  });
22076
- if (!accounts || accounts.length === 0) {
22077
- throw new Error("No accounts found in Trust Wallet. Please create an account or unlock your wallet.");
22078
- }
22079
22091
  const address = accounts[0];
22080
- const chainIdHex = await trustProvider.request({ method: "eth_chainId" });
22081
- const chainId = parseInt(chainIdHex, 16);
22092
+ let chainIdHex, chainId;
22093
+ try {
22094
+ chainIdHex = await successfulProvider.request({ method: "eth_chainId" });
22095
+ chainId = parseInt(chainIdHex, 16);
22096
+ console.log("Chain ID:", chainId);
22097
+ } catch (chainError) {
22098
+ console.warn("Could not get chain ID:", chainError);
22099
+ chainId = 1;
22100
+ }
22082
22101
  switch (chainId) {
22083
22102
  case 1:
22084
22103
  networkType = NETWORK_TYPES.ETHEREUM;
@@ -22089,12 +22108,13 @@ const connectTrustWallet = async (targetNetwork = null) => {
22089
22108
  default:
22090
22109
  networkType = `unknown-${chainId}`;
22091
22110
  }
22092
- const web3Provider = new BrowserProvider(trustProvider);
22111
+ const web3Provider = new BrowserProvider(successfulProvider);
22093
22112
  console.log("āœ… Trust Wallet connected successfully:", {
22094
22113
  address,
22095
22114
  network: networkType,
22096
22115
  chainId
22097
22116
  });
22117
+ console.log("=== END TRUST WALLET CONNECTION DEBUG ===");
22098
22118
  return {
22099
22119
  walletType: WALLET_TYPES.TRUST_WALLET,
22100
22120
  address,
@@ -22102,15 +22122,12 @@ const connectTrustWallet = async (targetNetwork = null) => {
22102
22122
  network: networkType,
22103
22123
  isConnected: true,
22104
22124
  chainId,
22105
- nativeProvider: trustProvider
22125
+ nativeProvider: successfulProvider
22106
22126
  };
22107
22127
  } else if (networkType === NETWORK_TYPES.TRON) {
22108
22128
  if (!window.tronWeb) {
22109
22129
  throw new Error("TronWeb not found. Please install Trust Wallet with TRON support or use Trust Wallet mobile app.");
22110
22130
  }
22111
- if (window.tronWeb.isTrust !== true && !window.trustwallet) {
22112
- console.warn("TronWeb detected but may not be from Trust Wallet");
22113
- }
22114
22131
  const waitForTronWeb = async (maxAttempts = 10, interval = 500) => {
22115
22132
  for (let attempt = 0; attempt < maxAttempts; attempt++) {
22116
22133
  if (window.tronWeb && window.tronWeb.ready) {
@@ -22175,14 +22192,12 @@ const connectTrustWallet = async (targetNetwork = null) => {
22175
22192
  console.error("=== TRUST WALLET CONNECTION ERROR ===");
22176
22193
  console.error("Error details:", error);
22177
22194
  console.log("=== END TRUST WALLET CONNECTION DEBUG ===");
22178
- if (error.code === 4001 || error.message.includes("rejected")) {
22179
- throw new Error("Connection rejected by user. Please approve the connection in Trust Wallet.");
22195
+ if (error.code === 4001 || error.message.includes("rejected by user")) {
22196
+ throw error;
22180
22197
  } else if (error.message.includes("locked")) {
22181
22198
  throw new Error("Trust Wallet is locked. Please unlock your wallet and try again.");
22182
- } else if (error.message.includes("install") || error.message.includes("not detected")) {
22183
- throw error;
22184
22199
  } else {
22185
- throw new Error(`Failed to connect to Trust Wallet: ${error.message}`);
22200
+ throw error;
22186
22201
  }
22187
22202
  }
22188
22203
  };