From fb53286c175df7f2390ab32388610e1e06e08eca Mon Sep 17 00:00:00 2001 From: Mehrshad Date: Wed, 13 Mar 2024 16:10:21 +0330 Subject: [PATCH] start: `/cancelall` shouldn't just cancel pendings The `/cancelall` command only cancels the `PENDING` orders. We should also cancel `WAITING_BUYER_INVOICE` and `WAITING_PAYMENT` orders, just like we do with the `/cancel` command [1]. [1]: - https://github.com/lnp2pBot/bot/commit/90978d466afbc0031f6cef9d70510fcadefe9f41 - https://github.com/lnp2pBot/bot/commit/07cf16c5da85acabf2b6b37fc3123e2285c1c888 --- bot/start.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/bot/start.ts b/bot/start.ts index 8814f319..aad979d5 100644 --- a/bot/start.ts +++ b/bot/start.ts @@ -403,11 +403,28 @@ const initialize = (botToken: string, options: Partial { try { - const orders = await ordersActions.getOrders(ctx, ctx.user, 'PENDING'); + const pending_orders = await ordersActions.getOrders(ctx, ctx.user, 'PENDING'); + const seller_orders = await ordersActions.getOrders(ctx, ctx.user, 'WAITING_BUYER_INVOICE'); + const buyer_orders = await ordersActions.getOrders(ctx, ctx.user, 'WAITING_PAYMENT'); + + const orders = [...pending_orders, ...seller_orders, ...buyer_orders] if (!orders) return; for (const order of orders) { + + // If a buyer is taking a sell offer and accidentally touch continue button we + // let the user to cancel + if (order.type === 'sell' && order.status === 'WAITING_BUYER_INVOICE') { + return await cancelAddInvoice(ctx, order); + } + + // If a seller is taking a buy offer and accidentally touch continue button we + // let the user to cancel + if (order.type === 'buy' && order.status === 'WAITING_PAYMENT') { + return await cancelShowHoldInvoice(ctx, order); + } + order.status = 'CANCELED'; order.canceled_by = ctx.user.id; await order.save();