- Add pino + pino-pretty dependencies - Create src/utils/logger.js with env-based LOG_LEVEL - Replace all 207 console.log/error/warn calls across 46 source files - Remove [DEBUG], [ERROR] string prefixes (levels convey this) - Add pino redact for sensitive fields (mnemonic, privateKey, token, etc.) - Structured logging with context objects instead of string interpolation - NODE_ENV=production disables pino-pretty transport 49 files changed, 5601 insertions, 6056 deletions
62 lines
2.8 KiB
JavaScript
62 lines
2.8 KiB
JavaScript
import db from '../../../config/database.js';
|
||
import WalletUtils from '../../../utils/walletUtils.js';
|
||
import UserService from '../../../services/userService.js';
|
||
import bot from '../../../context/bot.js';
|
||
import logger from '../../../utils/logger.js';
|
||
|
||
export default class TopUpHandler {
|
||
static async handleTopUpWallet(callbackQuery) {
|
||
const chatId = callbackQuery.message.chat.id;
|
||
const telegramId = callbackQuery.from.id;
|
||
|
||
try {
|
||
const user = await UserService.getUserByTelegramId(telegramId);
|
||
const cryptoWallets = await db.allAsync(`
|
||
SELECT wallet_type, address FROM crypto_wallets
|
||
WHERE user_id = ? ORDER BY wallet_type
|
||
`, [user.id]);
|
||
|
||
if (cryptoWallets.length === 0) {
|
||
await bot.editMessageText('You don\'t have any wallets yet.', {
|
||
chat_id: chatId, message_id: callbackQuery.message.message_id,
|
||
reply_markup: { inline_keyboard: [[{ text: '➕ Add Wallet', callback_data: 'add_wallet' }]] }
|
||
});
|
||
return;
|
||
}
|
||
|
||
let message = '💰 *Available wallets for replenishment.* Click on a wallet to copy the address:\n\n';
|
||
|
||
const walletUtilsInstance = new WalletUtils(
|
||
cryptoWallets.find(w => w.wallet_type === 'BTC')?.address,
|
||
cryptoWallets.find(w => w.wallet_type === 'LTC')?.address,
|
||
cryptoWallets.find(w => w.wallet_type === 'ETH')?.address,
|
||
user.id,
|
||
Date.now() - 30 * 24 * 60 * 60 * 1000
|
||
);
|
||
|
||
const balances = await walletUtilsInstance.getAllBalances();
|
||
|
||
for (const [type, balance] of Object.entries(balances)) {
|
||
const wallet = cryptoWallets.find(w =>
|
||
w.wallet_type === type.split(' ')[0] ||
|
||
(type.includes('ERC-20') && w.wallet_type === 'ETH')
|
||
);
|
||
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`;
|
||
}
|
||
}
|
||
|
||
await bot.editMessageText(message, {
|
||
chat_id: chatId, message_id: callbackQuery.message.message_id,
|
||
parse_mode: 'Markdown',
|
||
reply_markup: { inline_keyboard: [[{ text: '« Back', callback_data: 'back_to_balance' }]] }
|
||
});
|
||
} catch (error) {
|
||
logger.error({ err: error }, 'Error in handleTopUpWallet');
|
||
await bot.sendMessage(chatId, 'Error loading wallets. Please try again.');
|
||
}
|
||
}
|
||
} |