coinley-checkout 1.3.1 → 1.3.3
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,104 +22003,97 @@ 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: {
|
|
22011
|
-
isMetaMask: window.ethereum.isMetaMask,
|
|
22012
|
-
isTrust: window.ethereum.isTrust,
|
|
22013
|
-
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}:`, {
|
|
22020
|
-
isMetaMask: provider.isMetaMask,
|
|
22021
|
-
isTrust: provider.isTrust,
|
|
22022
|
-
isTrustWallet: provider.isTrustWallet
|
|
22023
|
-
});
|
|
22024
|
-
});
|
|
22025
|
-
}
|
|
22026
|
-
}
|
|
22027
22007
|
try {
|
|
22028
22008
|
if (networkType === NETWORK_TYPES.ETHEREUM || networkType === NETWORK_TYPES.BSC) {
|
|
22029
22009
|
if (!window.ethereum) {
|
|
22030
22010
|
throw new Error("No Ethereum provider found. Please install Trust Wallet browser extension.");
|
|
22031
22011
|
}
|
|
22032
|
-
|
|
22033
|
-
|
|
22034
|
-
|
|
22035
|
-
|
|
22036
|
-
|
|
22037
|
-
|
|
22038
|
-
|
|
22039
|
-
|
|
22040
|
-
|
|
22041
|
-
|
|
22042
|
-
|
|
22043
|
-
|
|
22044
|
-
|
|
22045
|
-
|
|
22046
|
-
}
|
|
22047
|
-
|
|
22048
|
-
|
|
22049
|
-
|
|
22050
|
-
|
|
22051
|
-
|
|
22052
|
-
|
|
22053
|
-
|
|
22054
|
-
|
|
22055
|
-
|
|
22056
|
-
|
|
22057
|
-
|
|
22058
|
-
|
|
22059
|
-
|
|
22060
|
-
|
|
22061
|
-
|
|
22062
|
-
|
|
22063
|
-
method: "eth_requestAccounts"
|
|
22012
|
+
console.log("Available ethereum details:", {
|
|
22013
|
+
isMetaMask: window.ethereum.isMetaMask,
|
|
22014
|
+
isTrust: window.ethereum.isTrust,
|
|
22015
|
+
isTrustWallet: window.ethereum.isTrustWallet,
|
|
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}:`, {
|
|
22039
|
+
isMetaMask: provider.isMetaMask,
|
|
22040
|
+
isTrust: provider.isTrust,
|
|
22041
|
+
isTrustWallet: provider.isTrustWallet,
|
|
22042
|
+
selectedAddress: provider.selectedAddress
|
|
22064
22043
|
});
|
|
22065
|
-
|
|
22066
|
-
|
|
22067
|
-
|
|
22068
|
-
|
|
22069
|
-
|
|
22070
|
-
|
|
22071
|
-
|
|
22072
|
-
|
|
22073
|
-
|
|
22074
|
-
|
|
22075
|
-
|
|
22076
|
-
|
|
22077
|
-
|
|
22078
|
-
|
|
22079
|
-
|
|
22080
|
-
}
|
|
22081
|
-
} catch (altError) {
|
|
22082
|
-
console.log(`❌ Alternative provider ${i} failed:`, altError.message);
|
|
22083
|
-
continue;
|
|
22084
|
-
}
|
|
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`);
|
|
22085
22059
|
}
|
|
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.");
|
|
22086
22069
|
}
|
|
22070
|
+
continue;
|
|
22087
22071
|
}
|
|
22088
|
-
|
|
22089
|
-
|
|
22090
|
-
|
|
22072
|
+
}
|
|
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.");
|
|
22091
22078
|
} else {
|
|
22092
|
-
throw new Error(`
|
|
22079
|
+
throw new Error(`Connection failed: ${lastError.message}. Please make sure your wallet is unlocked and try again.`);
|
|
22093
22080
|
}
|
|
22081
|
+
} else {
|
|
22082
|
+
throw new Error("No wallet accounts found. Please make sure Trust Wallet is unlocked and has at least one account.");
|
|
22094
22083
|
}
|
|
22095
22084
|
}
|
|
22096
|
-
|
|
22097
|
-
|
|
22098
|
-
|
|
22085
|
+
console.log("\n🎉 Successfully connected!");
|
|
22086
|
+
console.log("Using provider:", {
|
|
22087
|
+
isMetaMask: successfulProvider.isMetaMask,
|
|
22088
|
+
isTrust: successfulProvider.isTrust,
|
|
22089
|
+
isTrustWallet: successfulProvider.isTrustWallet
|
|
22090
|
+
});
|
|
22099
22091
|
const address = accounts[0];
|
|
22100
22092
|
let chainIdHex, chainId;
|
|
22101
22093
|
try {
|
|
22102
|
-
chainIdHex = await
|
|
22094
|
+
chainIdHex = await successfulProvider.request({ method: "eth_chainId" });
|
|
22103
22095
|
chainId = parseInt(chainIdHex, 16);
|
|
22096
|
+
console.log("Chain ID:", chainId);
|
|
22104
22097
|
} catch (chainError) {
|
|
22105
22098
|
console.warn("Could not get chain ID:", chainError);
|
|
22106
22099
|
chainId = 1;
|
|
@@ -22115,7 +22108,7 @@ const connectTrustWallet = async (targetNetwork = null) => {
|
|
|
22115
22108
|
default:
|
|
22116
22109
|
networkType = `unknown-${chainId}`;
|
|
22117
22110
|
}
|
|
22118
|
-
const web3Provider = new BrowserProvider(
|
|
22111
|
+
const web3Provider = new BrowserProvider(successfulProvider);
|
|
22119
22112
|
console.log("✅ Trust Wallet connected successfully:", {
|
|
22120
22113
|
address,
|
|
22121
22114
|
network: networkType,
|
|
@@ -22129,15 +22122,12 @@ const connectTrustWallet = async (targetNetwork = null) => {
|
|
|
22129
22122
|
network: networkType,
|
|
22130
22123
|
isConnected: true,
|
|
22131
22124
|
chainId,
|
|
22132
|
-
nativeProvider:
|
|
22125
|
+
nativeProvider: successfulProvider
|
|
22133
22126
|
};
|
|
22134
22127
|
} else if (networkType === NETWORK_TYPES.TRON) {
|
|
22135
22128
|
if (!window.tronWeb) {
|
|
22136
22129
|
throw new Error("TronWeb not found. Please install Trust Wallet with TRON support or use Trust Wallet mobile app.");
|
|
22137
22130
|
}
|
|
22138
|
-
if (window.tronWeb.isTrust !== true && !window.trustwallet) {
|
|
22139
|
-
console.warn("TronWeb detected but may not be from Trust Wallet");
|
|
22140
|
-
}
|
|
22141
22131
|
const waitForTronWeb = async (maxAttempts = 10, interval = 500) => {
|
|
22142
22132
|
for (let attempt = 0; attempt < maxAttempts; attempt++) {
|
|
22143
22133
|
if (window.tronWeb && window.tronWeb.ready) {
|
|
@@ -22202,14 +22192,12 @@ const connectTrustWallet = async (targetNetwork = null) => {
|
|
|
22202
22192
|
console.error("=== TRUST WALLET CONNECTION ERROR ===");
|
|
22203
22193
|
console.error("Error details:", error);
|
|
22204
22194
|
console.log("=== END TRUST WALLET CONNECTION DEBUG ===");
|
|
22205
|
-
if (error.code === 4001 || error.message.includes("rejected")) {
|
|
22206
|
-
throw
|
|
22195
|
+
if (error.code === 4001 || error.message.includes("rejected by user")) {
|
|
22196
|
+
throw error;
|
|
22207
22197
|
} else if (error.message.includes("locked")) {
|
|
22208
22198
|
throw new Error("Trust Wallet is locked. Please unlock your wallet and try again.");
|
|
22209
|
-
} else if (error.message.includes("install") || error.message.includes("not detected") || error.message.includes("not found")) {
|
|
22210
|
-
throw error;
|
|
22211
22199
|
} else {
|
|
22212
|
-
throw
|
|
22200
|
+
throw error;
|
|
22213
22201
|
}
|
|
22214
22202
|
}
|
|
22215
22203
|
};
|
|
@@ -22933,7 +22921,8 @@ let apiConfig = {
|
|
|
22933
22921
|
apiKey: null,
|
|
22934
22922
|
apiSecret: null,
|
|
22935
22923
|
// apiUrl: 'https://coinleyserver-production.up.railway.app',
|
|
22936
|
-
apiUrl:
|
|
22924
|
+
// apiUrl: 'https://hub.coinley.io',
|
|
22925
|
+
apiUrl: "http://localhost:9000",
|
|
22937
22926
|
merchantWalletAddresses: {},
|
|
22938
22927
|
authToken: null,
|
|
22939
22928
|
merchantFeePercentage: null,
|