separate wallet ETH USDT USDC

This commit is contained in:
NW
2025-01-02 19:31:28 +00:00
parent 22f76c64a6
commit e64f185eda
4 changed files with 230 additions and 233 deletions

View File

@@ -16,23 +16,24 @@ export default class AdminWalletsHandler {
// Проверяем, является ли пользователь администратором // Проверяем, является ли пользователь администратором
if (!this.isAdmin(msg.from.id)) { if (!this.isAdmin(msg.from.id)) {
await bot.sendMessage(chatId, 'Unauthorized access.'); await bot.sendMessage(chatId, 'Unauthorized access.');
return; return;
} }
const keyboard = { const keyboard = {
reply_markup: { reply_markup: {
inline_keyboard: [ inline_keyboard: [
[ [
{ text: 'Bitcoin (BTC)', callback_data: 'wallet_type_BTC' }, { text: 'Bitcoin (BTC)', callback_data: 'wallet_type_BTC' },
{ text: 'Litecoin (LTC)', callback_data: 'wallet_type_LTC' } { text: 'Litecoin (LTC)', callback_data: 'wallet_type_LTC' }
], ],
[ [
{ text: 'Tether (USDT)', callback_data: 'wallet_type_USDT' }, { text: 'Tether (USDT)', callback_data: 'wallet_type_USDT' },
{ text: 'Ethereum (ETH)', callback_data: 'wallet_type_ETH' } { text: 'USD Coin (USDC)', callback_data: 'wallet_type_USDC' },
] { text: 'Ethereum (ETH)', callback_data: 'wallet_type_ETH' }
] ]
} ]
}
}; };
await bot.sendMessage(chatId, 'Select wallet type:', keyboard); await bot.sendMessage(chatId, 'Select wallet type:', keyboard);
@@ -76,9 +77,9 @@ export default class AdminWalletsHandler {
let walletList = ''; let walletList = '';
for (const wallet of walletsPage) { for (const wallet of walletsPage) {
const walletUtilsInstance = new WalletUtils( const walletUtilsInstance = new WalletUtils(
wallet.wallet_type.startsWith('BTC') ? wallet.address : null, wallet.wallet_type === 'BTC' ? wallet.address : null,
wallet.wallet_type.startsWith('LTC') ? wallet.address : null, wallet.wallet_type === 'LTC' ? wallet.address : null,
wallet.wallet_type.startsWith('ETH') ? wallet.address : null, wallet.wallet_type === 'ETH' || wallet.wallet_type === 'USDT' || wallet.wallet_type === 'USDC' ? wallet.address : null,
null, // userId не нужен для админки null, // userId не нужен для админки
Date.now() - 30 * 24 * 60 * 60 * 1000 Date.now() - 30 * 24 * 60 * 60 * 1000
); );
@@ -87,7 +88,7 @@ export default class AdminWalletsHandler {
const balance = balances[wallet.wallet_type] || { amount: 0, usdValue: 0 }; const balance = balances[wallet.wallet_type] || { amount: 0, usdValue: 0 };
walletList += `💰 *${wallet.wallet_type}*\n`; walletList += `💰 *${wallet.wallet_type}*\n`;
walletList += `├ Balance: ${balance.amount.toFixed(8)} ${wallet.wallet_type.split(' ')[0]}\n`; walletList += `├ Balance: ${balance.amount.toFixed(8)} ${wallet.wallet_type}\n`;
walletList += `├ Value: $${balance.usdValue.toFixed(2)}\n`; walletList += `├ Value: $${balance.usdValue.toFixed(2)}\n`;
walletList += `└ Address: \`${wallet.address}\`\n\n`; walletList += `└ Address: \`${wallet.address}\`\n\n`;
} }
@@ -132,9 +133,9 @@ export default class AdminWalletsHandler {
for (const wallet of wallets) { for (const wallet of wallets) {
const walletUtilsInstance = new WalletUtils( const walletUtilsInstance = new WalletUtils(
wallet.wallet_type.startsWith('BTC') ? wallet.address : null, wallet.wallet_type === 'BTC' ? wallet.address : null,
wallet.wallet_type.startsWith('LTC') ? wallet.address : null, wallet.wallet_type === 'LTC' ? wallet.address : null,
wallet.wallet_type.startsWith('ETH') ? wallet.address : null, wallet.wallet_type === 'ETH' || wallet.wallet_type === 'USDT' || wallet.wallet_type === 'USDC' ? wallet.address : null,
null, // userId не нужен для админки null, // userId не нужен для админки
Date.now() - 30 * 24 * 60 * 60 * 1000 Date.now() - 30 * 24 * 60 * 60 * 1000
); );
@@ -205,9 +206,9 @@ export default class AdminWalletsHandler {
} }
const walletUtilsInstance = new WalletUtils( const walletUtilsInstance = new WalletUtils(
wallet.wallet_type.startsWith('BTC') ? wallet.address : null, wallet.wallet_type === 'BTC' ? wallet.address : null,
wallet.wallet_type.startsWith('LTC') ? wallet.address : null, wallet.wallet_type === 'LTC' ? wallet.address : null,
wallet.wallet_type.startsWith('ETH') ? wallet.address : null, wallet.wallet_type === 'ETH' || wallet.wallet_type === 'USDT' || wallet.wallet_type === 'USDC' ? wallet.address : null,
null, // userId не нужен для админки null, // userId не нужен для админки
Date.now() - 30 * 24 * 60 * 60 * 1000 Date.now() - 30 * 24 * 60 * 60 * 1000
); );
@@ -248,7 +249,6 @@ export default class AdminWalletsHandler {
} }
} }
// Метод для возврата к списку типов кошельков
static async handleBackToWalletTypes(callbackQuery) { static async handleBackToWalletTypes(callbackQuery) {
const chatId = callbackQuery.message.chat.id; const chatId = callbackQuery.message.chat.id;
@@ -265,6 +265,7 @@ export default class AdminWalletsHandler {
], ],
[ [
{ text: 'Tether (USDT)', callback_data: 'wallet_type_USDT' }, { text: 'Tether (USDT)', callback_data: 'wallet_type_USDT' },
{ text: 'USD Coin (USDC)', callback_data: 'wallet_type_USDC' },
{ text: 'Ethereum (ETH)', callback_data: 'wallet_type_ETH' } { text: 'Ethereum (ETH)', callback_data: 'wallet_type_ETH' }
] ]
] ]

View File

@@ -6,102 +6,101 @@ import WalletService from "../../services/walletService.js";
import bot from "../../context/bot.js"; import bot from "../../context/bot.js";
export default class UserWalletsHandler { export default class UserWalletsHandler {
static async showBalance(msg) { static async showBalance(msg) {
const chatId = msg.chat.id; const chatId = msg.chat.id;
const telegramId = msg.from.id; const telegramId = msg.from.id;
try { try {
const user = await UserService.getUserByTelegramId(telegramId.toString()); const user = await UserService.getUserByTelegramId(telegramId.toString());
if (!user) { if (!user) {
await bot.sendMessage(chatId, 'Profile not found. Please use /start to create one.'); await bot.sendMessage(chatId, 'Profile not found. Please use /start to create one.');
return; return;
}
// Get active crypto wallets only
const cryptoWallets = await db.allAsync(`
SELECT wallet_type, address
FROM crypto_wallets
WHERE user_id = ?
ORDER BY wallet_type
`, [user.id]);
let message = '💰 *Your Active Wallets:*\n\n';
if (cryptoWallets.length > 0) {
const walletUtilsInstance = new WalletUtils(
cryptoWallets.find(w => w.wallet_type === 'BTC')?.address, // BTC address
cryptoWallets.find(w => w.wallet_type === 'LTC')?.address, // LTC address
cryptoWallets.find(w => w.wallet_type === 'ETH')?.address, // ETH address
cryptoWallets.find(w => w.wallet_type === 'USDT')?.address, // USDT address
cryptoWallets.find(w => w.wallet_type === 'USDC')?.address, // USDC address
user.id,
Date.now() - 30 * 24 * 60 * 60 * 1000
);
const balances = await walletUtilsInstance.getAllBalances();
let totalUsdValue = 0;
// Show active wallets
for (const [type, balance] of Object.entries(balances)) {
const wallet = cryptoWallets.find(w => w.wallet_type === type.split(' ')[0]);
if (wallet) {
message += `🔐 *${type}*\n`;
message += `├ Balance: ${balance.amount.toFixed(8)} ${type.split(' ')[0]}\n`;
message += `├ Value: $${balance.usdValue.toFixed(2)}\n`;
message += `└ Address: \`${wallet.address}\`\n\n`;
totalUsdValue += balance.usdValue;
}
} }
// Get active crypto wallets only // Add total crypto balance
const cryptoWallets = await db.allAsync(` message += `📊 *Total Crypto Balance:* $${totalUsdValue.toFixed(2)}\n`;
SELECT wallet_type, address
FROM crypto_wallets
WHERE user_id = ?
ORDER BY wallet_type
`, [user.id]);
let message = '💰 *Your Active Wallets:*\n\n'; // Add bonus balance
message += `🎁 *Bonus Balance:* $${user.bonus_balance.toFixed(2)}\n`;
if (cryptoWallets.length > 0) { // Add total balance
const walletUtilsInstance = new WalletUtils( const totalBalance = totalUsdValue + user.bonus_balance;
cryptoWallets.find(w => w.wallet_type === 'BTC')?.address, message += `💰 *Total Balance:* $${totalBalance.toFixed(2)}\n`;
cryptoWallets.find(w => w.wallet_type === 'LTC')?.address, } else {
cryptoWallets.find(w => w.wallet_type === 'ETH')?.address, message = 'You don\'t have any active wallets yet.';
user.id, }
Date.now() - 30 * 24 * 60 * 60 * 1000
);
const balances = await walletUtilsInstance.getAllBalances(); // Check if user has archived wallets
let totalUsdValue = 0; const archivedCount = await WalletService.getArchivedWalletsCount(user);
// Show active wallets const keyboard = {
for (const [type, balance] of Object.entries(balances)) { inline_keyboard: [
const baseType = this.getBaseWalletType(type); [
const wallet = cryptoWallets.find(w => { text: ' Add Crypto Wallet', callback_data: 'add_wallet' },
w.wallet_type === baseType || { text: '💸 Top Up', callback_data: 'top_up_wallet' }
(type.includes('ERC-20') && w.wallet_type === 'ETH') ],
); [{ text: '🔄 Refresh Balance', callback_data: 'refresh_balance' }]
]
};
if (wallet) { // Add archived wallets button if any exist
message += `🔐 *${type}*\n`; if (archivedCount > 0) {
message += `├ Balance: ${balance.amount.toFixed(8)} ${type.split(' ')[0]}\n`; keyboard.inline_keyboard.splice(2, 0, [
message += `├ Value: $${balance.usdValue.toFixed(2)}\n`; { text: `📁 Archived Wallets (${archivedCount})`, callback_data: 'view_archived_wallets' }
message += `└ Address: \`${wallet.address}\`\n\n`;
totalUsdValue += balance.usdValue;
}
}
// Add total crypto balance
message += `📊 *Total Crypto Balance:* $${totalUsdValue.toFixed(2)}\n`;
// Add bonus balance
message += `🎁 *Bonus Balance:* $${user.bonus_balance.toFixed(2)}\n`;
// Add total balance
const totalBalance = totalUsdValue + user.bonus_balance;
message += `💰 *Total Balance:* $${totalBalance.toFixed(2)}\n`;
} else {
message = 'You don\'t have any active wallets yet.';
}
// Check if user has archived wallets
const archivedCount = await WalletService.getArchivedWalletsCount(user);
const keyboard = {
inline_keyboard: [
[
{ text: ' Add Crypto Wallet', callback_data: 'add_wallet' },
{ text: '💸 Top Up', callback_data: 'top_up_wallet' }
],
[{ text: '🔄 Refresh Balance', callback_data: 'refresh_balance' }]
]
};
// Add archived wallets button if any exist
if (archivedCount > 0) {
keyboard.inline_keyboard.splice(2, 0, [
{ text: `📁 Archived Wallets (${archivedCount})`, callback_data: 'view_archived_wallets' }
]);
}
// Add "Transaction History" button
keyboard.inline_keyboard.splice(3, 0, [
{ text: '📊 Transaction History', callback_data: 'view_transaction_history_0' }
]); ]);
}
await bot.sendMessage(chatId, message, { // Add "Transaction History" button
reply_markup: keyboard, keyboard.inline_keyboard.splice(3, 0, [
parse_mode: 'Markdown' { text: '📊 Transaction History', callback_data: 'view_transaction_history_0' }
}); ]);
await bot.sendMessage(chatId, message, {
reply_markup: keyboard,
parse_mode: 'Markdown'
});
} catch (error) { } catch (error) {
console.error('Error in showBalance:', error); console.error('Error in showBalance:', error);
await bot.sendMessage(chatId, 'Error loading balance. Please try again.'); await bot.sendMessage(chatId, 'Error loading balance. Please try again.');
} }
} }
@@ -229,7 +228,7 @@ export default class UserWalletsHandler {
const cryptoOptions = [ const cryptoOptions = [
['BTC', 'ETH', 'LTC'], ['BTC', 'ETH', 'LTC'],
['USDT ERC-20', 'USDC ERC-20'] ['USDT', 'USDC']
]; ];
const keyboard = { const keyboard = {
@@ -273,40 +272,50 @@ export default class UserWalletsHandler {
const mnemonic = await WalletGenerator.generateMnemonic(); const mnemonic = await WalletGenerator.generateMnemonic();
const wallets = await WalletGenerator.generateWallets(mnemonic); const wallets = await WalletGenerator.generateWallets(mnemonic);
// Get the base wallet type (ETH for ERC-20) // Определяем базовый тип кошелька и путь деривации
const baseType = this.getBaseWalletType(walletType); let baseType, derivationPath;
if (walletType === 'USDT') {
baseType = 'ETH';
derivationPath = "m/44'/60'/0'/0/1"; // Путь для USDT
} else if (walletType === 'USDC') {
baseType = 'ETH';
derivationPath = "m/44'/60'/0'/0/2"; // Путь для USDC
} else {
baseType = walletType;
derivationPath = wallets[walletType].path; // Путь для других кошельков
}
// Get existing wallet of this type // Получаем существующий кошелек этого типа
const existingWallet = await db.getAsync( const existingWallet = await db.getAsync(
'SELECT id, address FROM crypto_wallets WHERE user_id = ? AND wallet_type = ?', 'SELECT id, address FROM crypto_wallets WHERE user_id = ? AND wallet_type = ?',
[user.id, baseType] [user.id, walletType]
); );
if (existingWallet) { if (existingWallet) {
// Archive the old wallet by adding a suffix to its type // Архивируем старый кошелек, добавляя суффикс с таймштампом
const timestamp = Date.now(); const timestamp = Date.now();
await db.runAsync( await db.runAsync(
'UPDATE crypto_wallets SET wallet_type = ? WHERE id = ?', 'UPDATE crypto_wallets SET wallet_type = ? WHERE id = ?',
[`${baseType}_${timestamp}`, existingWallet.id] [`${walletType}_${timestamp}`, existingWallet.id]
); );
} }
// Store the new wallet // Сохраняем новый кошелек
await db.runAsync( await db.runAsync(
`INSERT INTO crypto_wallets ( `INSERT INTO crypto_wallets (
user_id, wallet_type, address, derivation_path, mnemonic user_id, wallet_type, address, derivation_path, mnemonic
) VALUES (?, ?, ?, ?, ?)`, ) VALUES (?, ?, ?, ?, ?)`,
[ [
user.id, user.id,
baseType, walletType, // Используем выбранный тип (USDT, USDC, ETH и т.д.)
wallets[baseType].address, wallets[baseType].address, // Адрес берется из базового типа
wallets[baseType].path, derivationPath, // Используем корректный путь деривации
mnemonic mnemonic
] ]
); );
// Get the appropriate address for the requested wallet type // Получаем адрес для отображения
const displayAddress = this.getWalletAddress(wallets, walletType); const displayAddress = wallets[baseType].address;
const network = this.getNetworkName(walletType); const network = this.getNetworkName(walletType);
let message = `✅ New wallet generated successfully!\n\n`; let message = `✅ New wallet generated successfully!\n\n`;
@@ -541,7 +550,7 @@ export default class UserWalletsHandler {
const walletUtilsInstance = new WalletUtils( const walletUtilsInstance = new WalletUtils(
groupedWallets['BTC']?.[0]?.address, groupedWallets['BTC']?.[0]?.address,
groupedWallets['LTC']?.[0]?.address, groupedWallets['LTC']?.[0]?.address,
groupedWallets['ETH']?.[0]?.address, groupedWallets['ETH']?.[0]?.address || groupedWallets['USDT']?.[0]?.address || groupedWallets['USDC']?.[0]?.address,
user.id, user.id,
Date.now() - 30 * 24 * 60 * 60 * 1000 Date.now() - 30 * 24 * 60 * 60 * 1000
); );
@@ -577,8 +586,10 @@ export default class UserWalletsHandler {
usdValue = balances.LTC.usdValue; usdValue = balances.LTC.usdValue;
break; break;
case 'ETH': case 'ETH':
balance = balances.ETH.amount; case 'USDT':
usdValue = balances.ETH.usdValue; case 'USDC':
balance = balances[baseType]?.amount || 0;
usdValue = balances[baseType]?.usdValue || 0;
break; break;
} }
@@ -677,10 +688,16 @@ export default class UserWalletsHandler {
} }
static getNetworkName(walletType) { static getNetworkName(walletType) {
if (walletType.includes('ERC-20')) return 'Ethereum Network (ERC-20)'; if (walletType.includes('USDT')) return 'Ethereum Network (ERC-20)';
if (walletType.includes('USDC')) return 'Ethereum Network (ERC-20)';
if (walletType === 'BTC') return 'Bitcoin Network'; if (walletType === 'BTC') return 'Bitcoin Network';
if (walletType === 'LTC') return 'Litecoin Network'; if (walletType === 'LTC') return 'Litecoin Network';
if (walletType === 'ETH') return 'Ethereum Network'; if (walletType === 'ETH') return 'Ethereum Network';
return 'Unknown Network'; return 'Unknown Network';
} }
static getBaseWalletType(walletType) {
// Убираем суффиксы, такие как ERC-20, TRC-20 и т.д.
return walletType.replace(/ (ERC-20|TRC-20)$/, '');
}
} }

View File

@@ -33,6 +33,14 @@ export default class WalletGenerator {
const ethNode = hdkey.derive("m/44'/60'/0'/0/0"); const ethNode = hdkey.derive("m/44'/60'/0'/0/0");
const ethAddress = '0x' + publicToAddress(ethNode.publicKey, true).toString('hex'); const ethAddress = '0x' + publicToAddress(ethNode.publicKey, true).toString('hex');
// Generate USDT wallet (BIP44, same as ETH but different index)
const usdtNode = hdkey.derive("m/44'/60'/0'/0/1");
const usdtAddress = '0x' + publicToAddress(usdtNode.publicKey, true).toString('hex');
// Generate USDC wallet (BIP44, same as ETH but different index)
const usdcNode = hdkey.derive("m/44'/60'/0'/0/2");
const usdcAddress = '0x' + publicToAddress(usdcNode.publicKey, true).toString('hex');
// Generate LTC wallet (BIP84 - Native SegWit) // Generate LTC wallet (BIP84 - Native SegWit)
const ltcNode = hdkey.derive("m/84'/2'/0'/0/0"); const ltcNode = hdkey.derive("m/84'/2'/0'/0/0");
const ltcKeyPair = ECPair.fromPrivateKey(ltcNode.privateKey); const ltcKeyPair = ECPair.fromPrivateKey(ltcNode.privateKey);
@@ -60,6 +68,14 @@ export default class WalletGenerator {
address: ethAddress, address: ethAddress,
path: "m/44'/60'/0'/0/0", path: "m/44'/60'/0'/0/0",
}, },
USDT: {
address: usdtAddress,
path: "m/44'/60'/0'/0/1",
},
USDC: {
address: usdcAddress,
path: "m/44'/60'/0'/0/2",
},
LTC: { LTC: {
address: ltcAddress, address: ltcAddress,
path: "m/84'/2'/0'/0/0", path: "m/84'/2'/0'/0/0",

View File

@@ -1,31 +1,30 @@
import axios from 'axios'; import axios from 'axios';
export default class WalletUtils{ export default class WalletUtils {
constructor(btcAddress, ltcAddress, trxAddress, ethAddress, userId, minTimestamp) { constructor(btcAddress, ltcAddress, ethAddress, usdtAddress, usdcAddress, userId, minTimestamp) {
this.btcAddress = btcAddress; this.btcAddress = btcAddress;
this.ltcAddress = ltcAddress; this.ltcAddress = ltcAddress;
this.trxAddress = trxAddress;
this.ethAddress = ethAddress; this.ethAddress = ethAddress;
this.usdtAddress = usdtAddress;
this.usdcAddress = usdcAddress;
this.userId = userId; this.userId = userId;
this.minTimestamp = minTimestamp; this.minTimestamp = minTimestamp;
} }
static async getCryptoPrices() { static async getCryptoPrices() {
try { try {
const response = await axios.get('https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,litecoin,tether,usd-coin,tron,ethereum&vs_currencies=usd'); const response = await axios.get('https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,litecoin,ethereum&vs_currencies=usd');
return { return {
btc: response.data.bitcoin?.usd || 0, btc: response.data.bitcoin?.usd || 0,
ltc: response.data.litecoin?.usd || 0, ltc: response.data.litecoin?.usd || 0,
eth: response.data.ethereum?.usd || 0, eth: response.data.ethereum?.usd || 0,
usdt: 1, // Stablecoin usdt: 1, // USDT — это стейблкоин, его цена всегда 1 USD
usdc: 1, // Stablecoin usdc: 1 // USDC — это стейблкоин, его цена всегда 1 USD
trx: response.data.tron?.usd || 0,
usdd: 1 // Stablecoin
}; };
} catch (error) { } catch (error) {
console.error('Error fetching crypto prices:', error); console.error('Error fetching crypto prices:', error);
return { return {
btc: 0, ltc: 0, eth: 0, usdt: 1, usdc: 1, trx: 0, usdd: 1 btc: 0, ltc: 0, eth: 0, usdt: 1, usdc: 1
}; };
} }
} }
@@ -77,9 +76,9 @@ export default class WalletUtils{
} }
async getUsdtErc20Balance() { async getUsdtErc20Balance() {
if (!this.ethAddress) return 0; if (!this.usdtAddress) return 0;
try { try {
const url = `https://api.etherscan.io/api?module=account&action=tokenbalance&contractaddress=0xdac17f958d2ee523a2206206994597c13d831ec7&address=${this.ethAddress}&tag=latest`; const url = `https://api.etherscan.io/api?module=account&action=tokenbalance&contractaddress=0xdac17f958d2ee523a2206206994597c13d831ec7&address=${this.usdtAddress}&tag=latest`;
const data = await this.fetchApiRequest(url); const data = await this.fetchApiRequest(url);
return data?.result ? parseFloat(data.result) / 1e6 : 0; return data?.result ? parseFloat(data.result) / 1e6 : 0;
} catch (error) { } catch (error) {
@@ -89,9 +88,9 @@ export default class WalletUtils{
} }
async getUsdcErc20Balance() { async getUsdcErc20Balance() {
if (!this.ethAddress) return 0; if (!this.usdcAddress) return 0;
try { try {
const url = `https://api.etherscan.io/api?module=account&action=tokenbalance&contractaddress=0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48&address=${this.ethAddress}&tag=latest`; const url = `https://api.etherscan.io/api?module=account&action=tokenbalance&contractaddress=0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48&address=${this.usdcAddress}&tag=latest`;
const data = await this.fetchApiRequest(url); const data = await this.fetchApiRequest(url);
return data?.result ? parseFloat(data.result) / 1e6 : 0; return data?.result ? parseFloat(data.result) / 1e6 : 0;
} catch (error) { } catch (error) {
@@ -100,36 +99,6 @@ export default class WalletUtils{
} }
} }
async getUsdtTrc20Balance() {
if (!this.trxAddress) return 0;
try {
const url = `https://apilist.tronscan.org/api/account?address=${this.trxAddress}`;
const data = await this.fetchApiRequest(url);
const usdtToken = data?.trc20token_balances?.find(token =>
token.tokenId === 'TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t'
);
return usdtToken ? parseFloat(usdtToken.balance) / 1e6 : 0;
} catch (error) {
console.error('Error getting USDT TRC20 balance:', error);
return 0;
}
}
async getUsddTrc20Balance() {
if (!this.trxAddress) return 0;
try {
const url = `https://apilist.tronscan.org/api/account?address=${this.trxAddress}`;
const data = await this.fetchApiRequest(url);
const usddToken = data?.trc20token_balances?.find(token =>
token.tokenId === 'TPYmHEhy5n8TCEfYGqW2rPxsghSfzghPDn'
);
return usddToken ? parseFloat(usddToken.balance) / 1e18 : 0;
} catch (error) {
console.error('Error getting USDD TRC20 balance:', error);
return 0;
}
}
async getAllBalances() { async getAllBalances() {
const [ const [
btcBalance, btcBalance,
@@ -137,8 +106,6 @@ export default class WalletUtils{
ethBalance, ethBalance,
usdtErc20Balance, usdtErc20Balance,
usdcErc20Balance, usdcErc20Balance,
usdtTrc20Balance,
usddTrc20Balance,
prices prices
] = await Promise.all([ ] = await Promise.all([
this.getBtcBalance(), this.getBtcBalance(),
@@ -146,8 +113,6 @@ export default class WalletUtils{
this.getEthBalance(), this.getEthBalance(),
this.getUsdtErc20Balance(), this.getUsdtErc20Balance(),
this.getUsdcErc20Balance(), this.getUsdcErc20Balance(),
this.getUsdtTrc20Balance(),
this.getUsddTrc20Balance(),
WalletUtils.getCryptoPrices() WalletUtils.getCryptoPrices()
]); ]);
@@ -156,9 +121,7 @@ export default class WalletUtils{
LTC: { amount: ltcBalance, usdValue: ltcBalance * prices.ltc }, LTC: { amount: ltcBalance, usdValue: ltcBalance * prices.ltc },
ETH: { amount: ethBalance, usdValue: ethBalance * prices.eth }, ETH: { amount: ethBalance, usdValue: ethBalance * prices.eth },
'USDT ERC-20': { amount: usdtErc20Balance, usdValue: usdtErc20Balance }, 'USDT ERC-20': { amount: usdtErc20Balance, usdValue: usdtErc20Balance },
'USDC ERC-20': { amount: usdcErc20Balance, usdValue: usdcErc20Balance }, 'USDC ERC-20': { amount: usdcErc20Balance, usdValue: usdcErc20Balance }
'USDT TRC-20': { amount: usdtTrc20Balance, usdValue: usdtTrc20Balance },
'USDD TRC-20': { amount: usddTrc20Balance, usdValue: usddTrc20Balance }
}; };
} }
} }