Skip to content

Commit c370718

Browse files
committed
add confirmation step before deleting tx from Lunch Money
1 parent 006bd3f commit c370718

3 files changed

Lines changed: 25 additions & 1 deletion

File tree

handlers/transactions.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,26 @@ async def handle_btn_skip_transaction(update: Update, _: ContextTypes.DEFAULT_TY
388388
)
389389

390390

391+
async def handle_btn_confirm_delete_transaction(update: Update, _: ContextTypes.DEFAULT_TYPE):
392+
"""Show a confirmation keyboard before actually deleting the transaction."""
393+
query = update.callback_query
394+
if query is None:
395+
return
396+
397+
tx_id = int(update.callback_data_suffix)
398+
kbd = Keyboard()
399+
kbd += ("✅ Yes, delete from Telegram and Lunch Money", f"deleteTx_{tx_id}")
400+
kbd += ("❌ Cancel", f"cancelDeleteTx_{tx_id}")
401+
await query.answer()
402+
await update.safe_edit_message_reply_markup(reply_markup=kbd.build(columns=1))
403+
404+
405+
async def handle_btn_cancel_delete_transaction(update: Update, _: ContextTypes.DEFAULT_TYPE):
406+
"""Restore the normal expanded keyboard after the user cancels deletion."""
407+
tx_id = int(update.callback_data_suffix)
408+
await update.safe_edit_message_reply_markup(reply_markup=get_tx_buttons(update.chat_id, tx_id, collapsed=False))
409+
410+
391411
async def handle_btn_delete_transaction(update: Update, _: ContextTypes.DEFAULT_TYPE):
392412
query = update.callback_query
393413
if query is None:

main.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,10 @@
7979
handle_btn_ai_categorize,
8080
handle_btn_apply_category,
8181
handle_btn_cancel_categorization,
82+
handle_btn_cancel_delete_transaction,
8283
handle_btn_close_plaid_details,
8384
handle_btn_collapse_transaction,
85+
handle_btn_confirm_delete_transaction,
8486
handle_btn_delete_transaction,
8587
handle_btn_dump_plaid_details,
8688
handle_btn_mark_tx_as_reviewed,
@@ -186,6 +188,8 @@ def add_settings_callback_query_handlers(app):
186188
def add_application_callback_query_handlers(app):
187189
# Transaction handlers
188190
app.add_handler(CallbackQueryHandler(handle_btn_skip_transaction, pattern=r"^skip_"))
191+
app.add_handler(CallbackQueryHandler(handle_btn_confirm_delete_transaction, pattern=r"^confirmDeleteTx_"))
192+
app.add_handler(CallbackQueryHandler(handle_btn_cancel_delete_transaction, pattern=r"^cancelDeleteTx_"))
189193
app.add_handler(CallbackQueryHandler(handle_btn_delete_transaction, pattern=r"^deleteTx_"))
190194
app.add_handler(CallbackQueryHandler(handle_btn_collapse_transaction, pattern=r"^collapse_"))
191195
app.add_handler(CallbackQueryHandler(handle_btn_cancel_categorization, pattern=r"^cancelCategorization_"))

tx_messaging.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def _add_expanded_buttons(
4848
kbd += ("Skip", f"skip_{transaction_id}")
4949

5050
if sync_delete:
51-
kbd += ("🗑️ Delete", f"deleteTx_{transaction_id}")
51+
kbd += ("🗑️ Delete", f"confirmDeleteTx_{transaction_id}")
5252

5353
if is_reviewed:
5454
kbd += ("Unreview", f"unreview_{transaction_id}")

0 commit comments

Comments
 (0)