coinley-checkout 0.3.5 → 0.3.6
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.
@@ -167,15 +167,30 @@ const TOKEN_CONFIG = {
|
|
167
167
|
};
|
168
168
|
const getWeb3Instance = () => __async(void 0, null, function* () {
|
169
169
|
try {
|
170
|
-
if (typeof window
|
170
|
+
if (typeof window === "undefined" || !window.ethereum) {
|
171
|
+
throw new Error("No ethereum provider found");
|
172
|
+
}
|
173
|
+
let Web3Class = null;
|
174
|
+
try {
|
171
175
|
const Web3Module = yield import("web3");
|
172
|
-
|
173
|
-
|
176
|
+
Web3Class = Web3Module.default || Web3Module.Web3 || Web3Module;
|
177
|
+
console.log("Web3 imported via dynamic import:", Web3Class);
|
178
|
+
} catch (importError) {
|
179
|
+
console.log("Dynamic import failed, trying global Web3:", importError);
|
180
|
+
if (typeof window !== "undefined" && window.Web3) {
|
181
|
+
Web3Class = window.Web3;
|
182
|
+
console.log("Using global Web3:", Web3Class);
|
183
|
+
}
|
184
|
+
}
|
185
|
+
if (!Web3Class) {
|
186
|
+
throw new Error("Web3 not available. Please ensure web3 is installed or MetaMask is running.");
|
174
187
|
}
|
175
|
-
|
188
|
+
const web3Instance = new Web3Class(window.ethereum);
|
189
|
+
console.log("Web3 instance created successfully:", web3Instance);
|
190
|
+
return web3Instance;
|
176
191
|
} catch (error) {
|
177
192
|
console.error("Failed to load Web3:", error);
|
178
|
-
throw new Error(
|
193
|
+
throw new Error(`Web3 initialization failed: ${error.message}. Please ensure MetaMask is installed and running.`);
|
179
194
|
}
|
180
195
|
});
|
181
196
|
const detectWallets = () => {
|
@@ -364,6 +379,7 @@ const switchEVMNetwork = (networkConfig) => __async(void 0, null, function* () {
|
|
364
379
|
const sendTransaction = (walletConnection, transactionData) => __async(void 0, null, function* () {
|
365
380
|
const { walletType, network, address } = walletConnection;
|
366
381
|
const { to, amount, tokenAddress, tokenDecimals } = transactionData;
|
382
|
+
console.log("sendTransaction called with:", { walletConnection, transactionData });
|
367
383
|
switch (walletType) {
|
368
384
|
case WALLET_TYPES.METAMASK:
|
369
385
|
case WALLET_TYPES.TRUST_WALLET:
|
@@ -377,16 +393,24 @@ const sendTransaction = (walletConnection, transactionData) => __async(void 0, n
|
|
377
393
|
}
|
378
394
|
});
|
379
395
|
const sendEVMTransaction = (from, to, amount, tokenAddress, tokenDecimals) => __async(void 0, null, function* () {
|
396
|
+
console.log("sendEVMTransaction called with:", { from, to, amount, tokenAddress, tokenDecimals });
|
380
397
|
if (typeof window === "undefined" || !window.ethereum) {
|
381
398
|
throw new Error("Ethereum provider not found");
|
382
399
|
}
|
383
400
|
try {
|
384
|
-
const
|
385
|
-
|
386
|
-
const
|
387
|
-
|
401
|
+
const web3 = yield getWeb3Instance();
|
402
|
+
console.log("Web3 instance obtained for transaction");
|
403
|
+
const decimals = tokenDecimals || 18;
|
404
|
+
const amountBN = web3.utils.toBN(
|
405
|
+
Math.floor(parseFloat(amount) * Math.pow(10, decimals)).toString()
|
388
406
|
);
|
407
|
+
console.log("Amount calculated:", {
|
408
|
+
originalAmount: amount,
|
409
|
+
decimals,
|
410
|
+
calculatedAmount: amountBN.toString()
|
411
|
+
});
|
389
412
|
if (tokenAddress && tokenAddress !== "native") {
|
413
|
+
console.log("Preparing ERC20 token transfer...");
|
390
414
|
const tokenABI = [
|
391
415
|
{
|
392
416
|
constant: false,
|
@@ -402,21 +426,32 @@ const sendEVMTransaction = (from, to, amount, tokenAddress, tokenDecimals) => __
|
|
402
426
|
}
|
403
427
|
];
|
404
428
|
const contract = new web3.eth.Contract(tokenABI, tokenAddress);
|
405
|
-
|
429
|
+
console.log("Contract created, sending transaction...");
|
430
|
+
const receipt = yield contract.methods.transfer(to, amountBN.toString()).send({ from });
|
431
|
+
console.log("ERC20 transaction successful:", receipt.transactionHash);
|
406
432
|
return receipt.transactionHash;
|
407
433
|
} else {
|
434
|
+
console.log("Preparing native token transfer...");
|
408
435
|
const receipt = yield web3.eth.sendTransaction({
|
409
436
|
from,
|
410
437
|
to,
|
411
|
-
value:
|
438
|
+
value: amountBN.toString()
|
412
439
|
});
|
440
|
+
console.log("Native transaction successful:", receipt.transactionHash);
|
413
441
|
return receipt.transactionHash;
|
414
442
|
}
|
415
443
|
} catch (error) {
|
444
|
+
console.error("EVM transaction error:", error);
|
416
445
|
if (error.code === 4001) {
|
417
446
|
throw new Error("Transaction was rejected by user");
|
418
447
|
}
|
419
|
-
|
448
|
+
if (error.message && error.message.includes("insufficient funds")) {
|
449
|
+
throw new Error("Insufficient funds to complete the transaction");
|
450
|
+
}
|
451
|
+
if (error.message && error.message.includes("gas")) {
|
452
|
+
throw new Error("Transaction failed due to gas estimation issues. Please try again.");
|
453
|
+
}
|
454
|
+
throw new Error(`Transaction failed: ${error.message || "Unknown error"}`);
|
420
455
|
}
|
421
456
|
});
|
422
457
|
const sendTronTransaction = (to, amount, tokenAddress, tokenDecimals) => __async(void 0, null, function* () {
|