update planned wallets function
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
// walletUtils.js
|
||||
|
||||
import axios from 'axios';
|
||||
import db from '../config/database.js'; // Импортируем базу данных
|
||||
|
||||
@@ -264,24 +266,24 @@ export default class WalletUtils {
|
||||
|
||||
async getAllBalancesFromDB() {
|
||||
const prices = await WalletUtils.getCryptoPrices();
|
||||
|
||||
|
||||
const balances = {
|
||||
BTC: { amount: 0, usdValue: 0 },
|
||||
LTC: { amount: 0, usdValue: 0 },
|
||||
ETH: { amount: 0, usdValue: 0 },
|
||||
'USDT ERC-20': { amount: 0, usdValue: 0 },
|
||||
'USDC ERC-20': { amount: 0, usdValue: 0 }
|
||||
USDT: { amount: 0, usdValue: 0 },
|
||||
USDC: { amount: 0, usdValue: 0 }
|
||||
};
|
||||
|
||||
|
||||
// Получаем балансы из таблицы crypto_wallets
|
||||
const wallets = await db.allAsync(`
|
||||
SELECT wallet_type, balance FROM crypto_wallets WHERE user_id = ?
|
||||
`, [this.userId]);
|
||||
|
||||
|
||||
for (const wallet of wallets) {
|
||||
const baseType = WalletUtils.getBaseWalletType(wallet.wallet_type);
|
||||
const [baseType] = wallet.wallet_type.split('_'); // Учитываем только базовый тип
|
||||
const balance = wallet.balance || 0;
|
||||
|
||||
|
||||
switch (baseType) {
|
||||
case 'BTC':
|
||||
balances.BTC.amount += balance;
|
||||
@@ -296,16 +298,16 @@ export default class WalletUtils {
|
||||
balances.ETH.usdValue += balance * prices.eth;
|
||||
break;
|
||||
case 'USDT':
|
||||
balances['USDT ERC-20'].amount += balance;
|
||||
balances['USDT ERC-20'].usdValue += balance;
|
||||
balances.USDT.amount += balance;
|
||||
balances.USDT.usdValue += balance;
|
||||
break;
|
||||
case 'USDC':
|
||||
balances['USDC ERC-20'].amount += balance;
|
||||
balances['USDC ERC-20'].usdValue += balance;
|
||||
balances.USDC.amount += balance;
|
||||
balances.USDC.usdValue += balance;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return balances;
|
||||
}
|
||||
|
||||
@@ -315,7 +317,7 @@ export default class WalletUtils {
|
||||
|
||||
async getAllBalancesExt() {
|
||||
console.log('[DEBUG] getAllBalancesExt called'); // Логируем вызов метода
|
||||
|
||||
|
||||
const [
|
||||
btcBalance,
|
||||
ltcBalance,
|
||||
@@ -331,7 +333,7 @@ export default class WalletUtils {
|
||||
this.getUsdcErc20Balance(),
|
||||
WalletUtils.getCryptoPrices()
|
||||
]);
|
||||
|
||||
|
||||
console.log('[DEBUG] Balances fetched:', { // Логируем полученные балансы
|
||||
btcBalance,
|
||||
ltcBalance,
|
||||
@@ -340,13 +342,13 @@ export default class WalletUtils {
|
||||
usdcErc20Balance,
|
||||
prices
|
||||
});
|
||||
|
||||
|
||||
return {
|
||||
BTC: { amount: btcBalance, usdValue: btcBalance * prices.btc },
|
||||
LTC: { amount: ltcBalance, usdValue: ltcBalance * prices.ltc },
|
||||
ETH: { amount: ethBalance, usdValue: ethBalance * prices.eth },
|
||||
'USDT ERC-20': { amount: usdtErc20Balance, usdValue: usdtErc20Balance },
|
||||
'USDC ERC-20': { amount: usdcErc20Balance, usdValue: usdcErc20Balance }
|
||||
USDT: { amount: usdtErc20Balance, usdValue: usdtErc20Balance },
|
||||
USDC: { amount: usdcErc20Balance, usdValue: usdcErc20Balance }
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user