@@ -161,6 +161,7 @@ async def bank_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
161161 db .add (deposit )
162162 db .flush ()
163163
164+ remaining_balance = user .balance
164165 unlock_date = (datetime .utcnow () + timedelta (days = LOCK_DAYS )).strftime ("%d.%m" )
165166 weekly_interest = int (amount * INTEREST_RATE )
166167
@@ -170,7 +171,7 @@ async def bank_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
170171 f"💰 Сумма: { format_diamonds (amount )} \n "
171172 f"📈 Доход: ~{ format_diamonds (weekly_interest )} /нед\n "
172173 f"🔒 Разблокировка: { unlock_date } \n \n "
173- f"💰 Остаток: { format_diamonds (user . balance )} " ,
174+ f"💰 Остаток: { format_diamonds (remaining_balance )} " ,
174175 )
175176 logger .info ("Bank deposit" , user_id = user_id , amount = amount )
176177
@@ -239,19 +240,23 @@ async def bank_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
239240 user = db .query (User ).filter (User .telegram_id == user_id ).first ()
240241 if user :
241242 user .balance += total_return
243+ new_balance = user .balance
244+ else :
245+ new_balance = 0
242246
247+ deposit_amount = deposit .amount
243248 deposit .is_active = False
244249 deposit .withdrawn_at = now
245250
246251 await safe_edit_message (
247252 query ,
248253 f"💸 <b>Вклад закрыт</b>\n \n "
249- f"💰 Вклад: { format_diamonds (deposit . amount )} \n "
254+ f"💰 Вклад: { format_diamonds (deposit_amount )} \n "
250255 f"📈 Проценты: +{ format_diamonds (interest )} \n "
251256 f"💰 Получено: { format_diamonds (total_return )} \n \n "
252- f"💰 Баланс: { format_diamonds (user . balance )} " ,
257+ f"💰 Баланс: { format_diamonds (new_balance )} " ,
253258 )
254- logger .info ("Bank withdrawal" , user_id = user_id , amount = deposit . amount , interest = interest )
259+ logger .info ("Bank withdrawal" , user_id = user_id , amount = deposit_amount , interest = interest )
255260
256261 elif action == "collect" :
257262 # Collect accumulated interest without closing deposits
@@ -280,12 +285,15 @@ async def bank_callback(update: Update, context: ContextTypes.DEFAULT_TYPE):
280285 user = db .query (User ).filter (User .telegram_id == user_id ).first ()
281286 if user :
282287 user .balance += total_interest
288+ new_balance = user .balance
289+ else :
290+ new_balance = 0
283291
284292 await safe_edit_message (
285293 query ,
286294 f"📈 <b>Проценты собраны!</b>\n \n "
287295 f"+{ format_diamonds (total_interest )} \n \n "
288- f"💰 Баланс: { format_diamonds (user . balance )} " ,
296+ f"💰 Баланс: { format_diamonds (new_balance )} " ,
289297 )
290298 logger .info ("Bank interest collected" , user_id = user_id , interest = total_interest )
291299
0 commit comments