Skip to content

Commit

Permalink
start: /cancelall shouldn't just cancel pendings
Browse files Browse the repository at this point in the history
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]:
- lnp2pBot@90978d4
- lnp2pBot@07cf16c
  • Loading branch information
Mersho committed Mar 13, 2024
1 parent 678be5b commit fb53286
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion bot/start.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,11 +403,28 @@ const initialize = (botToken: string, options: Partial<Telegraf.Options<MainCont
// pending orders are the ones that are not taken by another user
bot.command('cancelall', userMiddleware, async (ctx: MainContext) => {
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();
Expand Down

0 comments on commit fb53286

Please sign in to comment.