Skip to content

Commit fea5d84

Browse files
authored
Fix/cancelall pending only (#848)
* fix: cancelall only cancels pending orders without blocking on in-progress ones * fix: bail out of cancelall when pending orders fetch fails
1 parent bf32684 commit fea5d84

1 file changed

Lines changed: 9 additions & 25 deletions

File tree

bot/start.ts

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -502,38 +502,22 @@ const initialize = (
502502
// pending orders are the ones that are not taken by another user
503503
bot.command('cancelall', userMiddleware, async (ctx: CommunityContext) => {
504504
try {
505-
const pending_orders =
506-
(await ordersActions.getOrders(ctx.user, 'PENDING')) || [];
507-
const seller_orders =
508-
(await ordersActions.getOrders(ctx.user, 'WAITING_BUYER_INVOICE')) ||
509-
[];
510-
const buyer_orders =
511-
(await ordersActions.getOrders(ctx.user, 'WAITING_PAYMENT')) || [];
505+
// /cancelall only cancels PENDING orders (published orders that nobody
506+
// has taken yet). Orders already being taken (WAITING_PAYMENT /
507+
// WAITING_BUYER_INVOICE) must be handled individually with /cancel or
508+
// through a dispute, just like single /cancel rejects them.
509+
const orders = await ordersActions.getOrders(ctx.user, 'PENDING');
512510

513-
const orders = [...pending_orders, ...seller_orders, ...buyer_orders];
511+
// getOrders returns undefined when the query itself failed (already
512+
// logged). Bail out instead of telling the user they have no orders,
513+
// which would otherwise leave their pending orders silently uncanceled.
514+
if (orders === undefined) return;
514515

515516
if (orders.length === 0) {
516517
return await messages.notOrdersMessage(ctx);
517518
}
518519

519520
for (const order of orders) {
520-
// If a buyer is taking a sell offer and accidentally touch continue button we
521-
// let the user to cancel
522-
if (order.type === 'sell' && order.status === 'WAITING_BUYER_INVOICE') {
523-
return await cancelAddInvoice(ctx, order);
524-
}
525-
526-
// If a seller is taking a buy offer and accidentally touch continue button we
527-
// let the user to cancel
528-
if (order.type === 'buy' && order.status === 'WAITING_PAYMENT') {
529-
return await cancelShowHoldInvoice(ctx, order);
530-
}
531-
532-
// If a buyer wants cancel but the seller already pay the hold invoice
533-
if (order.type === 'buy' && order.status === 'WAITING_BUYER_INVOICE') {
534-
if (order.hash) await cancelHoldInvoice({ hash: order.hash });
535-
}
536-
537521
order.status = 'CANCELED';
538522
order.canceled_by = ctx.user.id;
539523
await order.save();

0 commit comments

Comments
 (0)