coinley-test 0.0.21 → 0.0.22
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.
- package/dist/index.esm.js +90 -6
- package/dist/index.esm.js.map +1 -1
- package/dist/index.umd.js +1 -1
- package/dist/index.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -1310,16 +1310,39 @@ class SimpleMetaMaskWallet {
|
|
|
1310
1310
|
if (!window.ethereum) {
|
|
1311
1311
|
throw new Error("MetaMask not installed. Please install MetaMask extension.");
|
|
1312
1312
|
}
|
|
1313
|
+
if (window.ethereum.providers) {
|
|
1314
|
+
console.log("🔍 Multiple wallets detected:", window.ethereum.providers.length);
|
|
1315
|
+
const metamaskProvider = window.ethereum.providers.find((provider) => provider.isMetaMask);
|
|
1316
|
+
if (!metamaskProvider) {
|
|
1317
|
+
throw new Error("MetaMask not found among installed wallets");
|
|
1318
|
+
}
|
|
1319
|
+
console.log("🦊 Using MetaMask provider specifically");
|
|
1320
|
+
window.ethereum = metamaskProvider;
|
|
1321
|
+
} else if (!window.ethereum.isMetaMask) {
|
|
1322
|
+
throw new Error("Please use MetaMask wallet");
|
|
1323
|
+
}
|
|
1313
1324
|
try {
|
|
1325
|
+
console.log("🦊 Requesting MetaMask account access...");
|
|
1314
1326
|
const accounts = await window.ethereum.request({
|
|
1315
1327
|
method: "eth_requestAccounts"
|
|
1316
1328
|
});
|
|
1329
|
+
if (!accounts || accounts.length === 0) {
|
|
1330
|
+
throw new Error("No accounts found in MetaMask");
|
|
1331
|
+
}
|
|
1317
1332
|
const chainId = await window.ethereum.request({
|
|
1318
1333
|
method: "eth_chainId"
|
|
1319
1334
|
});
|
|
1320
1335
|
this.account = accounts[0];
|
|
1321
1336
|
this.chainId = chainId;
|
|
1322
|
-
console.log("✅ MetaMask connected:"
|
|
1337
|
+
console.log("✅ MetaMask connected successfully:");
|
|
1338
|
+
console.log(" Account:", this.account);
|
|
1339
|
+
console.log(" Chain ID:", this.chainId);
|
|
1340
|
+
if (this.account.toLowerCase() !== "0xa0419a048a1469b34a5245f08c0697ba956a56ab") {
|
|
1341
|
+
console.warn("⚠️ Connected to different account than expected");
|
|
1342
|
+
console.warn(" Expected: 0xa0419a048A1469B34a5245f08C0697Ba956a56Ab");
|
|
1343
|
+
console.warn(" Connected:", this.account);
|
|
1344
|
+
throw new Error(`Please switch MetaMask to account 0xa041...56Ab. Currently connected to ${this.account.slice(0, 6)}...${this.account.slice(-4)}`);
|
|
1345
|
+
}
|
|
1323
1346
|
return { account: this.account, chainId: this.chainId };
|
|
1324
1347
|
} catch (error) {
|
|
1325
1348
|
console.error("MetaMask connection failed:", error);
|
|
@@ -1332,14 +1355,71 @@ class SimpleMetaMaskWallet {
|
|
|
1332
1355
|
}
|
|
1333
1356
|
try {
|
|
1334
1357
|
console.log("🦊 Sending MetaMask transaction:", txParams);
|
|
1358
|
+
if (!window.ethereum.isMetaMask) {
|
|
1359
|
+
throw new Error("Not using MetaMask provider");
|
|
1360
|
+
}
|
|
1361
|
+
if (txParams.data && txParams.data.includes("a9059cbb")) {
|
|
1362
|
+
console.log("🔍 Checking USDT balance...");
|
|
1363
|
+
try {
|
|
1364
|
+
const balanceHex = await window.ethereum.request({
|
|
1365
|
+
method: "eth_call",
|
|
1366
|
+
params: [{
|
|
1367
|
+
to: txParams.to,
|
|
1368
|
+
// USDT contract
|
|
1369
|
+
data: `0x70a08231000000000000000000000000${this.account.slice(2)}`
|
|
1370
|
+
// balanceOf(address)
|
|
1371
|
+
}, "latest"]
|
|
1372
|
+
});
|
|
1373
|
+
const balance = parseInt(balanceHex, 16);
|
|
1374
|
+
const balanceUSDT = balance / 1e6;
|
|
1375
|
+
console.log("💰 USDT Balance:", balanceUSDT);
|
|
1376
|
+
const amountHex = txParams.data.slice(-64);
|
|
1377
|
+
const transactionAmount = parseInt(amountHex, 16);
|
|
1378
|
+
const transactionAmountUSDT = transactionAmount / 1e6;
|
|
1379
|
+
console.log("💸 Transaction Amount:", transactionAmountUSDT);
|
|
1380
|
+
if (balance < transactionAmount) {
|
|
1381
|
+
throw new Error(`Insufficient USDT balance. You have ${balanceUSDT} USDT but need ${transactionAmountUSDT} USDT`);
|
|
1382
|
+
}
|
|
1383
|
+
} catch (balanceError) {
|
|
1384
|
+
console.warn("Could not check balance:", balanceError);
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
try {
|
|
1388
|
+
const ethBalanceHex = await window.ethereum.request({
|
|
1389
|
+
method: "eth_getBalance",
|
|
1390
|
+
params: [this.account, "latest"]
|
|
1391
|
+
});
|
|
1392
|
+
const ethBalance = parseInt(ethBalanceHex, 16) / Math.pow(10, 18);
|
|
1393
|
+
console.log("⛽ ETH Balance for gas:", ethBalance);
|
|
1394
|
+
if (ethBalance < 1e-3) {
|
|
1395
|
+
throw new Error(`Insufficient ETH for gas fees. You have ${ethBalance.toFixed(4)} ETH but need at least 0.001 ETH`);
|
|
1396
|
+
}
|
|
1397
|
+
} catch (gasError) {
|
|
1398
|
+
console.warn("Could not check ETH balance:", gasError);
|
|
1399
|
+
}
|
|
1400
|
+
const fullTxParams = {
|
|
1401
|
+
...txParams,
|
|
1402
|
+
from: this.account
|
|
1403
|
+
};
|
|
1404
|
+
try {
|
|
1405
|
+
const gasEstimate = await window.ethereum.request({
|
|
1406
|
+
method: "eth_estimateGas",
|
|
1407
|
+
params: [fullTxParams]
|
|
1408
|
+
});
|
|
1409
|
+
const gasLimit = Math.floor(parseInt(gasEstimate, 16) * 1.2);
|
|
1410
|
+
fullTxParams.gas = `0x${gasLimit.toString(16)}`;
|
|
1411
|
+
console.log("⛽ Gas estimate:", parseInt(gasEstimate, 16));
|
|
1412
|
+
console.log("⛽ Gas limit (with buffer):", gasLimit);
|
|
1413
|
+
} catch (gasError) {
|
|
1414
|
+
console.warn("Gas estimation failed:", gasError);
|
|
1415
|
+
fullTxParams.gas = "0x15F90";
|
|
1416
|
+
}
|
|
1417
|
+
console.log("📤 Final transaction params:", fullTxParams);
|
|
1335
1418
|
const txHash = await window.ethereum.request({
|
|
1336
1419
|
method: "eth_sendTransaction",
|
|
1337
|
-
params: [
|
|
1338
|
-
...txParams,
|
|
1339
|
-
from: this.account
|
|
1340
|
-
}]
|
|
1420
|
+
params: [fullTxParams]
|
|
1341
1421
|
});
|
|
1342
|
-
console.log("✅ Transaction sent:", txHash);
|
|
1422
|
+
console.log("✅ Transaction sent successfully:", txHash);
|
|
1343
1423
|
return txHash;
|
|
1344
1424
|
} catch (error) {
|
|
1345
1425
|
console.error("Transaction failed:", error);
|
|
@@ -1347,6 +1427,10 @@ class SimpleMetaMaskWallet {
|
|
|
1347
1427
|
throw new Error("Transaction cancelled by user");
|
|
1348
1428
|
} else if (error.message.includes("insufficient funds")) {
|
|
1349
1429
|
throw new Error("Insufficient funds in wallet");
|
|
1430
|
+
} else if (error.message.includes("gas")) {
|
|
1431
|
+
throw new Error("Gas estimation failed. You may not have enough ETH for gas fees.");
|
|
1432
|
+
} else if (error.message.includes("invalid opcode")) {
|
|
1433
|
+
throw new Error("Transaction failed - invalid operation. This usually means insufficient token balance or contract interaction failed.");
|
|
1350
1434
|
} else {
|
|
1351
1435
|
throw new Error(error.message || "Transaction failed");
|
|
1352
1436
|
}
|