update check ETH USDT USDC balance function

This commit is contained in:
NW
2025-01-08 12:01:02 +00:00
parent e64f185eda
commit 66f5251795
8 changed files with 686 additions and 304 deletions

View File

@@ -3,7 +3,6 @@ import WalletUtils from "../utils/walletUtils.js";
export default class Wallet {
static getBaseWalletType(walletType) {
if (walletType.includes('TRC-20')) return 'TRON';
if (walletType.includes('ERC-20')) return 'ETH';
return walletType;
}
@@ -14,37 +13,33 @@ export default class Wallet {
`, [userId]);
const btcAddress = archivedWallets.find(w => w.wallet_type.startsWith('BTC'))?.address;
const ltcAddress = archivedWallets.find(w => w.wallet_type.startsWith('LTC'))?.address;
const tronAddress = archivedWallets.find(w => w.wallet_type.startsWith('TRON'))?.address;
const ltcAddress = archivedWallets.find(w => w.wallet_type.startsWith('LTC'))?.address;
const ethAddress = archivedWallets.find(w => w.wallet_type.startsWith('ETH'))?.address;
return {
btc: btcAddress,
ltc: ltcAddress,
tron: tronAddress,
eth: ethAddress,
wallets: archivedWallets
}
};
}
static async getActiveWallets(userId) {
const activeWallets = await db.allAsync(
`SELECT wallet_type, address FROM crypto_wallets WHERE user_id = ? ORDER BY wallet_type`,
[userId]
)
);
const btcAddress = activeWallets.find(w => w.wallet_type === 'BTC')?.address;
const ltcAddress = activeWallets.find(w => w.wallet_type === 'LTC')?.address;
const tronAddress = activeWallets.find(w => w.wallet_type === 'TRON')?.address;
const ethAddress = activeWallets.find(w => w.wallet_type === 'ETH')?.address;
return {
btc: btcAddress,
ltc: ltcAddress,
tron: tronAddress,
eth: ethAddress,
wallets: activeWallets
}
};
}
static async getActiveWalletsBalance(userId) {
@@ -53,7 +48,6 @@ export default class Wallet {
const walletUtilsInstance = new WalletUtils(
activeWallets.btc,
activeWallets.ltc,
activeWallets.tron,
activeWallets.eth,
userId,
Date.now() - 30 * 24 * 60 * 60 * 1000
@@ -67,7 +61,6 @@ export default class Wallet {
const baseType = this.getBaseWalletType(type);
const wallet = activeWallets.wallets.find(w =>
w.wallet_type === baseType ||
(type.includes('TRC-20') && w.wallet_type === 'TRON') ||
(type.includes('ERC-20') && w.wallet_type === 'ETH')
);
@@ -75,9 +68,7 @@ export default class Wallet {
continue;
}
if (wallet) {
totalUsdBalance += balance.usdValue;
}
totalUsdBalance += balance.usdValue;
}
return totalUsdBalance;
@@ -89,7 +80,6 @@ export default class Wallet {
const walletUtilsInstance = new WalletUtils(
archiveWallets.btc,
archiveWallets.ltc,
archiveWallets.tron,
archiveWallets.eth,
userId,
Date.now() - 30 * 24 * 60 * 60 * 1000
@@ -103,7 +93,6 @@ export default class Wallet {
const baseType = this.getBaseWalletType(type);
const wallet = archiveWallets.wallets.find(w =>
w.wallet_type === baseType ||
(type.includes('TRC-20') && w.wallet_type.startsWith('TRON')) ||
(type.includes('ERC-20') && w.wallet_type.startsWith('ETH'))
);
@@ -111,9 +100,7 @@ export default class Wallet {
continue;
}
if (wallet) {
totalUsdBalance += balance.usdValue;
}
totalUsdBalance += balance.usdValue;
}
return totalUsdBalance;