From b7b6eaaab7b320f7a12fbc7d09f3b14f5e297782 Mon Sep 17 00:00:00 2001 From: Maxi Vila Date: Fri, 26 Jun 2026 15:42:47 -0300 Subject: [PATCH 1/2] fix: cancelall only cancels pending orders without blocking on in-progress ones --- bot/start.ts | 31 +++++-------------------------- 1 file changed, 5 insertions(+), 26 deletions(-) diff --git a/bot/start.ts b/bot/start.ts index 16594eb6..d970a2ea 100644 --- a/bot/start.ts +++ b/bot/start.ts @@ -502,38 +502,17 @@ const initialize = ( // pending orders are the ones that are not taken by another user bot.command('cancelall', userMiddleware, async (ctx: CommunityContext) => { try { - const pending_orders = - (await ordersActions.getOrders(ctx.user, 'PENDING')) || []; - const seller_orders = - (await ordersActions.getOrders(ctx.user, 'WAITING_BUYER_INVOICE')) || - []; - const buyer_orders = - (await ordersActions.getOrders(ctx.user, 'WAITING_PAYMENT')) || []; - - const orders = [...pending_orders, ...seller_orders, ...buyer_orders]; + // /cancelall only cancels PENDING orders (published orders that nobody + // has taken yet). Orders already being taken (WAITING_PAYMENT / + // WAITING_BUYER_INVOICE) must be handled individually with /cancel or + // through a dispute, just like single /cancel rejects them. + const orders = (await ordersActions.getOrders(ctx.user, 'PENDING')) || []; if (orders.length === 0) { return await messages.notOrdersMessage(ctx); } 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); - } - - // If a buyer wants cancel but the seller already pay the hold invoice - if (order.type === 'buy' && order.status === 'WAITING_BUYER_INVOICE') { - if (order.hash) await cancelHoldInvoice({ hash: order.hash }); - } - order.status = 'CANCELED'; order.canceled_by = ctx.user.id; await order.save(); From a996f1b69626eaac606211d209c1678c7ac4c623 Mon Sep 17 00:00:00 2001 From: Maxi Vila Date: Fri, 26 Jun 2026 16:01:48 -0300 Subject: [PATCH 2/2] fix: bail out of cancelall when pending orders fetch fails --- bot/start.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/bot/start.ts b/bot/start.ts index d970a2ea..04795fe4 100644 --- a/bot/start.ts +++ b/bot/start.ts @@ -506,7 +506,12 @@ const initialize = ( // has taken yet). Orders already being taken (WAITING_PAYMENT / // WAITING_BUYER_INVOICE) must be handled individually with /cancel or // through a dispute, just like single /cancel rejects them. - const orders = (await ordersActions.getOrders(ctx.user, 'PENDING')) || []; + const orders = await ordersActions.getOrders(ctx.user, 'PENDING'); + + // getOrders returns undefined when the query itself failed (already + // logged). Bail out instead of telling the user they have no orders, + // which would otherwise leave their pending orders silently uncanceled. + if (orders === undefined) return; if (orders.length === 0) { return await messages.notOrdersMessage(ctx);