Update handleBuyProduct
This commit is contained in:
parent
eea5d9b9e7
commit
3843dcb094
@ -496,13 +496,12 @@ Subcategory: ${product.subcategory_name}
|
|||||||
const state = userStates.get(chatId);
|
const state = userStates.get(chatId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const user = await UserService.getUserByTelegramId(telegramId)
|
const user = await UserService.getUserByTelegramId(telegramId);
|
||||||
if (!user) {
|
if (!user) {
|
||||||
throw new Error('User not found');
|
throw new Error('User not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
const product = await ProductService.getProductById(productId);
|
const product = await ProductService.getProductById(productId);
|
||||||
|
|
||||||
if (!product) {
|
if (!product) {
|
||||||
throw new Error('Product not found');
|
throw new Error('Product not found');
|
||||||
}
|
}
|
||||||
@ -510,7 +509,24 @@ Subcategory: ${product.subcategory_name}
|
|||||||
const quantity = state?.quantity || 1;
|
const quantity = state?.quantity || 1;
|
||||||
const totalPrice = product.price * quantity;
|
const totalPrice = product.price * quantity;
|
||||||
|
|
||||||
// Get user's crypto wallets with balances
|
// Проверка баланса пользователя
|
||||||
|
const userBalance = await UserService.getUserBalance(user.id);
|
||||||
|
if (userBalance < totalPrice) {
|
||||||
|
await bot.sendMessage(
|
||||||
|
chatId,
|
||||||
|
`❌ Insufficient balance. Your current balance is $${userBalance}. You need $${totalPrice} to complete this purchase.`,
|
||||||
|
{
|
||||||
|
reply_markup: {
|
||||||
|
inline_keyboard: [[
|
||||||
|
{ text: '💰 Top Up Balance', callback_data: 'top_up_wallet' }
|
||||||
|
]]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Получение криптокошельков пользователя
|
||||||
const cryptoWallets = await db.allAsync(`
|
const cryptoWallets = await db.allAsync(`
|
||||||
SELECT wallet_type, address
|
SELECT wallet_type, address
|
||||||
FROM crypto_wallets
|
FROM crypto_wallets
|
||||||
|
Loading…
Reference in New Issue
Block a user