diff --git a/bot/commands.js b/bot/commands.js index 44fcd44a..8472efaf 100644 --- a/bot/commands.js +++ b/bot/commands.js @@ -82,9 +82,7 @@ const waitPayment = async (ctx, bot, buyer, seller, order, buyerInvoice) => { ); await messages.takeSellWaitingSellerToPayMessage(ctx, bot, buyer, order); } - await order.save(); - // We update the nostr event - OrderEvents.orderUpdated(order); + await order.save(); } catch (error) { logger.error(`Error in waitPayment: ${error}`); } @@ -333,8 +331,7 @@ const cancelAddInvoice = async (ctx, order, job) => { } } else { await messages.successCancelOrderMessage(ctx, user, order, i18nCtx); - } - OrderEvents.orderUpdated(order); + } } } catch (error) { logger.error(error); @@ -507,8 +504,7 @@ const cancelShowHoldInvoice = async (ctx, order, job) => { } } else { await messages.successCancelOrderMessage(ctx, user, order, i18nCtx); - } - OrderEvents.orderUpdated(order); + } } } catch (error) { logger.error(error); @@ -648,6 +644,8 @@ const cancelOrder = async (ctx, orderId, user) => { ); await messages.refundCooperativeCancelMessage(ctx, seller, i18nCtxSeller); logger.info(`Order ${order._id} was cancelled cooperatively!`); + logger.info('cancelOrder => OrderEvents.orderUpdated(order);'); + OrderEvents.orderUpdated(order); } else { await messages.initCooperativeCancelMessage(ctx, order); await messages.counterPartyWantsCooperativeCancelMessage( @@ -658,7 +656,6 @@ const cancelOrder = async (ctx, orderId, user) => { ); } await order.save(); - OrderEvents.orderUpdated(order); } catch (error) { logger.error(error); } @@ -682,7 +679,6 @@ const fiatSent = async (ctx, orderId, user) => { order.status = 'FIAT_SENT'; const seller = await User.findOne({ _id: order.seller_id }); await order.save(); - OrderEvents.orderUpdated(order); // We sent messages to both parties // We need to create i18n context for each user const i18nCtxBuyer = await getUserI18nContext(user); diff --git a/bot/modules/dispute/commands.js b/bot/modules/dispute/commands.js index 1d323b2d..7f48be90 100644 --- a/bot/modules/dispute/commands.js +++ b/bot/modules/dispute/commands.js @@ -7,7 +7,6 @@ const { const messages = require('./messages'); const globalMessages = require('../../messages'); const { logger } = require('../../../logger'); -const OrderEvents = require('../../modules/events/orders'); const { removeAtSymbol } = require('../../../util'); const dispute = async ctx => { @@ -35,14 +34,13 @@ const dispute = async ctx => { if (user._id == order.buyer_id) initiator = 'buyer'; order[`${initiator}_dispute`] = true; - order.previous_dispute_status = order.status + order.previous_dispute_status = order.status; order.status = 'DISPUTE'; const sellerToken = Math.floor(Math.random() * 899 + 100); const buyerToken = Math.floor(Math.random() * 899 + 100); order.buyer_dispute_token = buyerToken; order.seller_dispute_token = sellerToken; await order.save(); - OrderEvents.orderUpdated(order); // If this is a non community order, we may ban the user globally if (order.community_id) { diff --git a/bot/modules/orders/takeOrder.js b/bot/modules/orders/takeOrder.js index e57d31e9..03a175f3 100644 --- a/bot/modules/orders/takeOrder.js +++ b/bot/modules/orders/takeOrder.js @@ -57,8 +57,9 @@ exports.takebuy = async (ctx, bot, orderId) => { // if the user don't do anything order.status = 'WAITING_PAYMENT'; order.seller_id = user._id; - order.taken_at = Date.now(); + order.taken_at = new Date(Date.now()); await order.save(); + order.status = 'in-progress'; OrderEvents.orderUpdated(order); // We delete the messages related to that order from the channel await deleteOrderFromChannel(order, bot.telegram); @@ -79,9 +80,10 @@ exports.takesell = async (ctx, bot, orderId) => { if (!(await validateTakeSellOrder(ctx, bot, user, order))) return; order.status = 'WAITING_BUYER_INVOICE'; order.buyer_id = user._id; - order.taken_at = Date.now(); + order.taken_at = new Date(Date.now()); await order.save(); + order.status = 'in-progress'; OrderEvents.orderUpdated(order); // We delete the messages related to that order from the channel await deleteOrderFromChannel(order, bot.telegram); diff --git a/bot/scenes.js b/bot/scenes.js index fb1f7637..76b190f4 100644 --- a/bot/scenes.js +++ b/bot/scenes.js @@ -8,7 +8,6 @@ const messages = require('./messages'); const { isPendingPayment } = require('../ln'); const { logger } = require('../logger'); const { resolvLightningAddress } = require('../lnurl/lnurl-pay'); -const OrderEvents = require('./modules/events/orders'); const addInvoiceWizard = new Scenes.WizardScene( 'ADD_INVOICE_WIZARD_SCENE_ID', @@ -23,10 +22,8 @@ const addInvoiceWizard = new Scenes.WizardScene( order.fiat_code, expirationTime ); - order.status = 'WAITING_BUYER_INVOICE'; await order.save(); - OrderEvents.orderUpdated(order); return ctx.wizard.next(); } catch (error) { diff --git a/bot/start.ts b/bot/start.ts index 25984393..876d4278 100644 --- a/bot/start.ts +++ b/bot/start.ts @@ -309,7 +309,6 @@ const initialize = (botToken: string, options: Partial { } logger.info(`Invoices resubscribed: ${invoicesReSubscribed}`); } catch (error) { - logger.error(`ResubcribeInvoice catch: ${error.toString()}`); + logger.error(`ResubscribeInvoice catch: ${error.toString()}`); return false; } }; diff --git a/ln/subscribe_invoice.js b/ln/subscribe_invoice.js index b39d9c55..21302cec 100644 --- a/ln/subscribe_invoice.js +++ b/ln/subscribe_invoice.js @@ -6,7 +6,6 @@ const messages = require('../bot/messages'); const ordersActions = require('../bot/ordersActions'); const { getUserI18nContext, getEmojiRate, decimalRound } = require('../util'); const { logger } = require('../logger'); -const OrderEvents = require('../bot/modules/events/orders'); const subscribeInvoice = async (bot, id, resub) => { try { @@ -50,7 +49,6 @@ const subscribeInvoice = async (bot, id, resub) => { } order.invoice_held_at = Date.now(); order.save(); - OrderEvents.orderUpdated(order); } if (invoice.is_confirmed) { const order = await Order.findOne({ hash: id }); @@ -76,7 +74,6 @@ const payHoldInvoice = async (bot, order) => { try { order.status = 'PAID_HOLD_INVOICE'; await order.save(); - OrderEvents.orderUpdated(order); const buyerUser = await User.findOne({ _id: order.buyer_id }); const sellerUser = await User.findOne({ _id: order.seller_id }); // We need two i18n contexts to send messages to each user