diff --git a/api/admin.py b/api/admin.py index 0ca8e536f..ecc49ee7d 100644 --- a/api/admin.py +++ b/api/admin.py @@ -11,7 +11,7 @@ from api.logics import Logics from api.models import Currency, LNPayment, MarketTick, OnchainPayment, Order, Robot from api.utils import objects_to_hyperlinks -from api.tasks import send_notification +from api.tasks import send_status_notification admin.site.unregister(Group) admin.site.unregister(User) @@ -164,7 +164,7 @@ def cancel_public_order(self, request, queryset): f"Order {order.id} successfully closed", messages.SUCCESS, ) - send_notification.delay( + send_status_notification.delay( order_id=order.id, message="coordinator_cancelled" ) else: @@ -210,7 +210,6 @@ def maker_wins(self, request, queryset): f"Dispute of order {order.id} solved successfully on favor of the maker", messages.SUCCESS, ) - send_notification.delay(order_id=order.id, message="dispute_closed") else: self.message_user( @@ -249,7 +248,6 @@ def taker_wins(self, request, queryset): f"Dispute of order {order.id} solved successfully on favor of the taker", messages.SUCCESS, ) - send_notification.delay(order_id=order.id, message="dispute_closed") else: self.message_user( diff --git a/api/logics.py b/api/logics.py index 7049e21ce..e30854b43 100644 --- a/api/logics.py +++ b/api/logics.py @@ -8,7 +8,7 @@ from api.lightning.node import LNNode from api.models import Currency, LNPayment, MarketTick, OnchainPayment, Order -from api.tasks import send_devfund_donation, send_notification +from api.tasks import send_devfund_donation, send_status_notification from api.utils import get_minning_fee, validate_onchain_address, location_country from chat.models import Message @@ -279,10 +279,9 @@ def order_expires(cls, order): elif order.status in [Order.Status.PUB, Order.Status.PAU]: cls.return_bond(order.maker_bond) - order.update_status(Order.Status.EXP) order.expiry_reason = Order.ExpiryReasons.NTAKEN order.save(update_fields=["expiry_reason"]) - send_notification.delay(order_id=order.id, message="order_expired_untaken") + order.update_status(Order.Status.EXP) order.log("Order expired while public or paused") order.log("Maker bond was unlocked") @@ -352,7 +351,9 @@ def order_expires(cls, order): pass taker_bond = order.taker_bond cls.publish_order(order) - send_notification.delay(order_id=order.id, message="order_published") + send_status_notification.delay( + order_id=order.id, status=Order.Status.PUB + ) # Reward maker with part of the taker bond cls.add_slashed_rewards(order, taker_bond, order.maker_bond) @@ -389,7 +390,9 @@ def order_expires(cls, order): cls.return_escrow(order) taker_bond = order.taker_bond cls.publish_order(order) - send_notification.delay(order_id=order.id, message="order_published") + send_status_notification.delay( + order_id=order.id, status=Order.Status.PUB + ) # Reward maker with part of the taker bond cls.add_slashed_rewards(order, taker_bond, order.maker_bond) @@ -498,7 +501,6 @@ def automatic_dispute_resolution(cls, order): seconds=order.t_to_expire(Order.Status.DIS) ) order.save(update_fields=["is_disputed", "expires_at"]) - send_notification.delay(order_id=order.id, message="dispute_opened") return True @@ -548,7 +550,6 @@ def open_dispute(cls, order, user=None): ).append(str(order.id)) robot.save(update_fields=["num_disputes", "orders_disputes_started"]) - send_notification.delay(order_id=order.id, message="dispute_opened") order.log( f"Dispute was opened {f'by Robot({user.robot.id},{user.username})' if user else ''}" ) @@ -704,9 +705,9 @@ def payout_amount(cls, order, user): if context["invoice_amount"] < MIN_SWAP_AMOUNT: context["swap_allowed"] = False - context[ - "swap_failure_reason" - ] = f"Order amount is smaller than the minimum swap available of {MIN_SWAP_AMOUNT} Sats" + context["swap_failure_reason"] = ( + f"Order amount is smaller than the minimum swap available of {MIN_SWAP_AMOUNT} Sats" + ) order.log( f"Onchain payment option was not offered: amount is smaller than the minimum swap available of {MIN_SWAP_AMOUNT} Sats", level="WARN", @@ -714,9 +715,9 @@ def payout_amount(cls, order, user): return True, context elif context["invoice_amount"] > MAX_SWAP_AMOUNT: context["swap_allowed"] = False - context[ - "swap_failure_reason" - ] = f"Order amount is bigger than the maximum swap available of {MAX_SWAP_AMOUNT} Sats" + context["swap_failure_reason"] = ( + f"Order amount is bigger than the maximum swap available of {MAX_SWAP_AMOUNT} Sats" + ) order.log( f"Onchain payment option was not offered: amount is bigger than the maximum swap available of {MAX_SWAP_AMOUNT} Sats", level="WARN", @@ -741,9 +742,9 @@ def payout_amount(cls, order, user): ) if not valid: context["swap_allowed"] = False - context[ - "swap_failure_reason" - ] = "Not enough onchain liquidity available to offer a swap" + context["swap_failure_reason"] = ( + "Not enough onchain liquidity available to offer a swap" + ) order.log( "Onchain payment option was not offered: onchain liquidity available to offer a swap", level="WARN", @@ -948,7 +949,6 @@ def move_state_updated_payout_method(cls, order): order.expires_at = timezone.now() + timedelta( seconds=order.t_to_expire(Order.Status.CHA) ) - send_notification.delay(order_id=order.id, message="fiat_exchange_starts") # If the order status is 'Waiting for both'. Move forward to 'waiting for escrow' elif order.status == Order.Status.WF2: @@ -962,9 +962,7 @@ def move_state_updated_payout_method(cls, order): order.expires_at = timezone.now() + timedelta( seconds=order.t_to_expire(Order.Status.CHA) ) - send_notification.delay( - order_id=order.id, message="fiat_exchange_starts" - ) + order.update_status(Order.Status.CHA) else: order.update_status(Order.Status.WFE) @@ -1032,10 +1030,6 @@ def cancel_order(cls, order, user, state=None): # Return the maker bond (Maker gets returned the bond for cancelling public order) if cls.return_bond(order.maker_bond): order.update_status(Order.Status.UCA) - send_notification.delay( - order_id=order.id, message="public_order_cancelled" - ) - order.log("Order cancelled by maker while public or paused") order.log("Maker bond was unlocked") @@ -1050,9 +1044,6 @@ def cancel_order(cls, order, user, state=None): if cls.return_bond(order.maker_bond): cls.cancel_bond(order.taker_bond) order.update_status(Order.Status.UCA) - send_notification.delay( - order_id=order.id, message="public_order_cancelled" - ) order.log("Order cancelled by maker before the taker locked the bond") order.log("Maker bond was unlocked") @@ -1113,7 +1104,9 @@ def cancel_order(cls, order, user, state=None): if valid: taker_bond = order.taker_bond cls.publish_order(order) - send_notification.delay(order_id=order.id, message="order_published") + send_status_notification.delay( + order_id=order.id, status=Order.Status.PUB + ) # Reward maker with part of the taker bond cls.add_slashed_rewards(order, taker_bond, order.maker_bond) @@ -1179,7 +1172,6 @@ def collaborative_cancel(cls, order): cls.return_bond(order.taker_bond) cls.return_escrow(order) order.update_status(Order.Status.CCA) - send_notification.delay(order_id=order.id, message="collaborative_cancelled") order.log("Order was collaboratively cancelled") order.log("Maker bond was unlocked") @@ -1190,7 +1182,7 @@ def collaborative_cancel(cls, order): @classmethod def publish_order(cls, order): - order.status = Order.Status.PUB + order.update_status(Order.Status.PUB) order.expires_at = order.created_at + timedelta( seconds=order.t_to_expire(Order.Status.PUB) ) @@ -1322,7 +1314,6 @@ def finalize_contract(cls, order): order.expires_at = timezone.now() + timedelta( seconds=order.t_to_expire(Order.Status.WF2) ) - order.status = Order.Status.WF2 order.save( update_fields=[ "status", @@ -1349,7 +1340,7 @@ def finalize_contract(cls, order): ) except Exception: pass - send_notification.delay(order_id=order.id, message="order_taken_confirmed") + order.update_status(Order.Status.WF2) order.log( f"Contract formalized. Maker: Robot({order.maker.robot.id},{order.maker}). Taker: Robot({order.taker.robot.id},{order.taker}). API median price {order.currency.exchange_rate} {dict(Currency.currency_choices)[order.currency.currency]}/BTC. Premium is {order.premium}%. Contract size {order.last_satoshis} Sats" ) @@ -1451,7 +1442,7 @@ def trade_escrow_received(order): seconds=order.t_to_expire(Order.Status.CHA) ) order.save(update_fields=["expires_at"]) - send_notification.delay(order_id=order.id, message="fiat_exchange_starts") + order.update_status(Order.Status.CHA) @classmethod def gen_escrow_hold_invoice(cls, order, user): @@ -1619,11 +1610,10 @@ def pay_buyer(cls, order): order.payout.status = LNPayment.Status.FLIGHT order.payout.save(update_fields=["status"]) - order.update_status(Order.Status.PAY) order.contract_finalization_time = timezone.now() order.save(update_fields=["contract_finalization_time"]) + order.update_status(Order.Status.PAY) - send_notification.delay(order_id=order.id, message="trade_successful") order.log("Paying buyer invoice") return True @@ -1636,11 +1626,10 @@ def pay_buyer(cls, order): order.payout_tx.status = OnchainPayment.Status.QUEUE order.payout_tx.save(update_fields=["status"]) - order.update_status(Order.Status.SUC) order.contract_finalization_time = timezone.now() order.save(update_fields=["contract_finalization_time"]) + order.update_status(Order.Status.SUC) - send_notification.delay(order_id=order.id, message="trade_successful") order.log("Paying buyer onchain address") return True diff --git a/api/management/commands/follow_invoices.py b/api/management/commands/follow_invoices.py index 8b4b98c18..93b1f34c8 100644 --- a/api/management/commands/follow_invoices.py +++ b/api/management/commands/follow_invoices.py @@ -8,7 +8,7 @@ from api.lightning.node import LNNode from api.logics import Logics from api.models import LNPayment, OnchainPayment, Order -from api.tasks import follow_send_payment, send_notification +from api.tasks import follow_send_payment, send_status_notification def is_same_status(a: LNPayment.Status, b: LNPayment.Status) -> bool: @@ -229,8 +229,8 @@ def update_order_status(self, lnpayment): if hasattr(lnpayment, "order_made"): lnpayment.order_made.log("Maker bond locked") Logics.publish_order(lnpayment.order_made) - send_notification.delay( - order_id=lnpayment.order_made.id, message="order_published" + send_status_notification.delay( + order_id=lnpayment.order_made.id, status=Order.Status.PUB ) return diff --git a/api/management/commands/telegram_watcher.py b/api/management/commands/telegram_watcher.py index d626b7569..5f57dcaef 100644 --- a/api/management/commands/telegram_watcher.py +++ b/api/management/commands/telegram_watcher.py @@ -6,8 +6,8 @@ from django.db import transaction from api.models import Robot -from api.notifications import Notifications from api.utils import get_session +from api.tasks import send_telegram_notification class Command(BaseCommand): @@ -17,7 +17,6 @@ class Command(BaseCommand): bot_token = config("TELEGRAM_TOKEN") updates_url = f"https://api.telegram.org/bot{bot_token}/getUpdates" session = get_session() - notifications = Notifications() def handle(self, *args, **options): offset = 0 @@ -49,7 +48,7 @@ def handle(self, *args, **options): continue parts = message.split(" ") if len(parts) < 2: - self.notifications.send_telegram_message( + send_telegram_notification.delay( result["message"]["from"]["id"], 'You must enable the notifications bot using the RoboSats client. Click on your "Robot robot" -> "Enable Telegram" and follow the link or scan the QR code.', ) @@ -57,7 +56,7 @@ def handle(self, *args, **options): token = parts[-1] robot = Robot.objects.filter(telegram_token=token).first() if not robot: - self.notifications.send_telegram_message( + send_telegram_notification.delay( result["message"]["from"]["id"], f'Wops, invalid token! There is no Robot with telegram chat token "{token}"', ) diff --git a/api/models/order.py b/api/models/order.py index 483e6fa44..abd34a2e3 100644 --- a/api/models/order.py +++ b/api/models/order.py @@ -10,7 +10,7 @@ from django.db.models.signals import pre_delete from django.dispatch import receiver from django.utils import timezone -from api.tasks import send_notification +from api.tasks import send_status_notification if config("TESTING", cast=bool, default=False): import random @@ -350,8 +350,7 @@ def update_status(self, new_status): self.log( f"Order state went from {old_status}: {Order.Status(old_status).label} to {new_status}: {Order.Status(new_status).label}" ) - if new_status == Order.Status.FAI: - send_notification.delay(order_id=self.id, message="lightning_failed") + send_status_notification.delay(order_id=self.id, status=self.status) @receiver(pre_delete, sender=Order) diff --git a/api/notifications.py b/api/notifications.py index 57ec4a429..7792d6a00 100644 --- a/api/notifications.py +++ b/api/notifications.py @@ -57,6 +57,18 @@ def send_telegram_message(self, chat_id, title, description=""): except Exception: pass + def status_change(self, order): + Notification.objects.create( + title="", description="", robot=order.maker.robot, order=order + ) + + if order.taker: + Notification.objects.create( + title="", description="", robot=order.taker.robot, order=order + ) + + return + def welcome(self, user): """User enabled Telegram Notifications""" lang = user.robot.telegram_lang_code @@ -215,11 +227,6 @@ def new_chat_message(self, order, chat_message): return - def coordinator_cancelled(self, order): - title = f"🛠️ Your order with ID {order.id} has been cancelled by the coordinator {config('COORDINATOR_ALIAS', cast=str, default='NoAlias')} for the upcoming maintenance stop." - self.send_message(order, order.maker.robot, title) - return - def dispute_closed(self, order): lang = order.maker.robot.telegram_lang_code if order.status == Order.Status.MLD: diff --git a/api/tasks.py b/api/tasks.py index 656feb894..4df4d2543 100644 --- a/api/tasks.py +++ b/api/tasks.py @@ -251,62 +251,70 @@ def cache_market(): return -@shared_task(name="send_notification", ignore_result=True, time_limit=120) -def send_notification(order_id=None, chat_message_id=None, message=None): - if order_id: +@shared_task(name="send_chat_notification", ignore_result=True, time_limit=120) +def send_chat_notification(message_id=None, order_id=None): + if message_id and order_id: from api.models import Order + from chat.models import Message + from api.notifications import Notifications order = Order.objects.get(id=order_id) - elif chat_message_id: - from chat.models import Message + chat_message = Message.objects.get(id=message_id) + notifications = Notifications() + + notifications.new_chat_message(order, chat_message) - chat_message = Message.objects.get(id=chat_message_id) - order = chat_message.order - from api.notifications import Notifications +@shared_task(name="send_telegram_notification", ignore_result=True, time_limit=120) +def send_telegram_notification(chat_id=None, message=None): + if chat_id: + from api.notifications import Notifications - notifications = Notifications() + notifications = Notifications() - if message == "welcome": - notifications.welcome(order) + notifications.send_telegram_message(chat_id, message) - elif message == "order_expired_untaken": - notifications.order_expired_untaken(order) - elif message == "trade_successful": - notifications.trade_successful(order) +@shared_task(name="send_status_notification", ignore_result=True, time_limit=120) +def send_status_notification(order_id=None, status=None): + if order_id: + from api.models import Order + from api.notifications import Notifications - elif message == "public_order_cancelled": - notifications.public_order_cancelled(order) + order = Order.objects.get(id=order_id) + notifications = Notifications() - elif message == "taker_expired_b4bond": - notifications.taker_expired_b4bond(order) + if status == Order.Status.EXP: + notifications.order_expired_untaken(order) - elif message == "order_published": - notifications.order_published(order) + elif status == Order.Status.PAY or status == Order.Status.SUC: + notifications.trade_successful(order) - elif message == "order_taken_confirmed": - notifications.order_taken_confirmed(order) + elif status == Order.Status.UCA: + notifications.public_order_cancelled(order) - elif message == "fiat_exchange_starts": - notifications.fiat_exchange_starts(order) + elif status == Order.Status.PUB: + notifications.order_published(order) - elif message == "dispute_opened": - notifications.dispute_opened(order) + elif status == Order.Status.WF2: + notifications.order_taken_confirmed(order) - elif message == "collaborative_cancelled": - notifications.collaborative_cancelled(order) + elif status == Order.Status.CHA: + notifications.fiat_exchange_starts(order) - elif message == "new_chat_message": - notifications.new_chat_message(order, chat_message) + elif status == Order.Status.DIS: + notifications.dispute_opened(order) + + elif status == Order.Status.CCA: + notifications.collaborative_cancelled(order) - elif message == "coordinator_cancelled": - notifications.coordinator_cancelled(order) + elif status == Order.Status.TLD or status == Order.Status.MLD: + notifications.dispute_closed(order) - elif message == "dispute_closed": - notifications.dispute_closed(order) + elif status == Order.Status.FAI: + notifications.lightning_failed(order) - elif message == "lightning_failed": - notifications.lightning_failed(order) + else: + notifications.status_change(order) return diff --git a/chat/consumers.py b/chat/consumers.py index c2443e665..1c32ac872 100644 --- a/chat/consumers.py +++ b/chat/consumers.py @@ -4,7 +4,7 @@ from channels.generic.websocket import AsyncWebsocketConsumer from api.models import Order -from api.tasks import send_notification +from api.tasks import send_chat_notification from chat.models import ChatRoom, Message @@ -85,7 +85,8 @@ def save_new_PGP_message(self, PGP_message): ) # send Telegram notification for new message (if conditions apply) - send_notification.delay(chat_message_id=msg_obj.id, message="new_chat_message") + send_chat_notification.delay(message_id=msg_obj.id, order_id=order.id) + return msg_obj @database_sync_to_async diff --git a/chat/views.py b/chat/views.py index ab2881698..fc15f73dd 100644 --- a/chat/views.py +++ b/chat/views.py @@ -11,7 +11,7 @@ from rest_framework.response import Response from api.models import Order -from api.tasks import send_notification +from api.tasks import send_chat_notification from chat.models import ChatRoom, Message from chat.serializers import ChatSerializer, InMessageSerializer, PostMessageSerializer @@ -179,9 +179,7 @@ def post(self, request, format=None): ) # send Telegram notification for new message (if conditions apply) - send_notification.delay( - chat_message_id=new_message.id, message="new_chat_message" - ) + send_chat_notification.delay(message_id=new_message.id, order_id=order.id) # Send websocket message if chatroom.maker == request.user: diff --git a/tests/test_trade_pipeline.py b/tests/test_trade_pipeline.py index c226b5c01..5375acc11 100644 --- a/tests/test_trade_pipeline.py +++ b/tests/test_trade_pipeline.py @@ -1090,7 +1090,7 @@ def test_order_expires_after_only_taker_messaged(self): self.assertEqual(notifications_data[0]["order_id"], trade.order_id) self.assertEqual( notifications_data[0]["title"], - f"⚖️ Hey {data['maker_nick']}, a dispute has been opened on your order with ID {str(trade.order_id)}.", + f"⚖️ Hey {data['maker_nick']}, you lost the dispute on your order with ID {str(trade.order_id)}.", ) taker_headers = trade.get_robot_auth(trade.taker_index) response = self.client.get(reverse("notifications"), **taker_headers) @@ -1099,7 +1099,7 @@ def test_order_expires_after_only_taker_messaged(self): self.assertEqual(notifications_data[0]["order_id"], trade.order_id) self.assertEqual( notifications_data[0]["title"], - f"⚖️ Hey {data['taker_nick']}, a dispute has been opened on your order with ID {str(trade.order_id)}.", + f"⚖️ Hey {data['taker_nick']}, you won the dispute on your order with ID {str(trade.order_id)}.", ) def test_order_expires_after_only_maker_messaged(self): @@ -1151,7 +1151,7 @@ def test_order_expires_after_only_maker_messaged(self): self.assertEqual(notifications_data[0]["order_id"], trade.order_id) self.assertEqual( notifications_data[0]["title"], - f"⚖️ Hey {data['maker_nick']}, a dispute has been opened on your order with ID {str(trade.order_id)}.", + f"⚖️ Hey {data['maker_nick']}, you won the dispute on your order with ID {str(trade.order_id)}.", ) taker_headers = trade.get_robot_auth(trade.taker_index) response = self.client.get(reverse("notifications"), **taker_headers) @@ -1160,7 +1160,7 @@ def test_order_expires_after_only_maker_messaged(self): self.assertEqual(notifications_data[0]["order_id"], trade.order_id) self.assertEqual( notifications_data[0]["title"], - f"⚖️ Hey {data['taker_nick']}, a dispute has been opened on your order with ID {str(trade.order_id)}.", + f"⚖️ Hey {data['taker_nick']}, you lost the dispute on your order with ID {str(trade.order_id)}.", ) # def test_dispute_closed_maker_wins(self): diff --git a/tests/utils/node.py b/tests/utils/node.py index d5cb1289e..002de9bcc 100644 --- a/tests/utils/node.py +++ b/tests/utils/node.py @@ -269,7 +269,7 @@ def pay_invoice(node_name, invoice): node = get_node(node_name) data = {"payment_request": invoice} try: - response = requests.post( + requests.post( f'http://localhost:{node["port"]}/v1/channels/transactions', json=data, headers=node["headers"], @@ -277,7 +277,6 @@ def pay_invoice(node_name, invoice): # 0.4s is enough for LND to CLN hodl ACCEPT timeout=0.2 if LNVENDOR == "LND" else 1, ) - print(response.json()) except ReadTimeout: # Request to pay hodl invoice has timed out: that's good! return diff --git a/tests/utils/trade.py b/tests/utils/trade.py index 39bcda0a1..f0258d674 100644 --- a/tests/utils/trade.py +++ b/tests/utils/trade.py @@ -5,7 +5,11 @@ from api.management.commands.clean_orders import Command as CleanOrders from api.management.commands.follow_invoices import Command as FollowInvoices from api.models import Order -from api.tasks import follow_send_payment, send_notification +from api.tasks import ( + follow_send_payment, + send_status_notification, + send_chat_notification, +) from tests.utils.node import ( add_invoice, create_address, @@ -111,7 +115,7 @@ def get_order(self, robot_index=1, first_encounter=False): headers = self.get_robot_auth(robot_index, first_encounter) self.response = self.client.get(path + params, **headers) - @patch("api.tasks.send_notification.delay", send_notification) + @patch("api.tasks.send_status_notification.delay", send_status_notification) def cancel_order(self, robot_index=1): path = reverse("order") params = f"?order_id={self.order_id}" @@ -119,14 +123,14 @@ def cancel_order(self, robot_index=1): body = {"action": "cancel"} self.response = self.client.post(path + params, body, **headers) - @patch("api.tasks.send_notification.delay", send_notification) + @patch("api.tasks.send_chat_notification.delay", send_chat_notification) def send_chat_message(self, message, robot_index=1): path = reverse("chat") headers = self.get_robot_auth(robot_index) body = {"PGP_message": message, "order_id": self.order_id, "offset": 0} self.response = self.client.post(path, data=body, **headers) - @patch("api.tasks.send_notification.delay", send_notification) + @patch("api.tasks.send_status_notification.delay", send_status_notification) def pause_order(self, robot_index=1): path = reverse("order") params = f"?order_id={self.order_id}" @@ -134,13 +138,13 @@ def pause_order(self, robot_index=1): body = {"action": "pause"} self.response = self.client.post(path + params, body, **headers) - @patch("api.tasks.send_notification.delay", send_notification) + @patch("api.tasks.send_status_notification.delay", send_status_notification) def follow_hold_invoices(self): # A background thread checks every 5 second the status of invoices. We invoke directly during test. follower = FollowInvoices() follower.follow_hold_invoices() - @patch("api.tasks.send_notification.delay", send_notification) + @patch("api.tasks.send_status_notification.delay", send_status_notification) def clean_orders(self): # A background thread checks every 5 second order expirations. We invoke directly during test. cleaner = CleanOrders() @@ -155,7 +159,7 @@ def process_payouts(self, mine_a_block=False): generate_blocks(create_address("robot"), 1) wait_nodes_sync() - @patch("api.tasks.send_notification.delay", send_notification) + @patch("api.tasks.send_status_notification.delay", send_status_notification) def publish_order(self): # Maker's first order fetch. Should trigger maker bond hold invoice generation. self.get_order() @@ -170,7 +174,7 @@ def publish_order(self): # Get order self.get_order() - @patch("api.tasks.send_notification.delay", send_notification) + @patch("api.tasks.send_status_notification.delay", send_status_notification) def take_order(self): path = reverse("order") params = f"?order_id={self.order_id}" @@ -178,7 +182,7 @@ def take_order(self): body = {"action": "take", "amount": self.take_amount} self.response = self.client.post(path + params, body, **headers) - @patch("api.tasks.send_notification.delay", send_notification) + @patch("api.tasks.send_status_notification.delay", send_status_notification) def lock_taker_bond(self): # Takers's first order fetch. Should trigger maker bond hold invoice generation. self.get_order(self.taker_index) @@ -193,7 +197,7 @@ def lock_taker_bond(self): # Get order self.get_order(self.taker_index) - @patch("api.tasks.send_notification.delay", send_notification) + @patch("api.tasks.send_status_notification.delay", send_status_notification) def lock_escrow(self, robot_index): # Takers's order fetch. Should trigger trade escrow bond hold invoice generation. self.get_order(robot_index) @@ -208,7 +212,7 @@ def lock_escrow(self, robot_index): # Get order self.get_order() - @patch("api.tasks.send_notification.delay", send_notification) + @patch("api.tasks.send_status_notification.delay", send_status_notification) def submit_payout_address(self, robot_index=1): path = reverse("order") params = f"?order_id={self.order_id}" @@ -227,7 +231,7 @@ def submit_payout_address(self, robot_index=1): } self.response = self.client.post(path + params, body, **headers) - @patch("api.tasks.send_notification.delay", send_notification) + @patch("api.tasks.send_status_notification.delay", send_status_notification) def submit_payout_invoice(self, robot_index=1, routing_budget=0): path = reverse("order") params = f"?order_id={self.order_id}" @@ -249,7 +253,7 @@ def submit_payout_invoice(self, robot_index=1, routing_budget=0): self.response = self.client.post(path + params, body, **headers) - @patch("api.tasks.send_notification.delay", send_notification) + @patch("api.tasks.send_status_notification.delay", send_status_notification) def confirm_fiat(self, robot_index=1): path = reverse("order") params = f"?order_id={self.order_id}" @@ -257,7 +261,7 @@ def confirm_fiat(self, robot_index=1): body = {"action": "confirm"} self.response = self.client.post(path + params, body, **headers) - @patch("api.tasks.send_notification.delay", send_notification) + @patch("api.tasks.send_status_notification.delay", send_status_notification) def undo_confirm_sent(self, robot_index=1): path = reverse("order") params = f"?order_id={self.order_id}" @@ -265,14 +269,14 @@ def undo_confirm_sent(self, robot_index=1): body = {"action": "undo_confirm"} self.response = self.client.post(path + params, body, **headers) - @patch("api.tasks.send_notification.delay", send_notification) + @patch("api.tasks.send_status_notification.delay", send_status_notification) def expire_order(self): # Change order expiry to now order = Order.objects.get(id=self.order_id) order.expires_at = datetime.now() order.save() - @patch("api.tasks.send_notification.delay", send_notification) + @patch("api.tasks.send_status_notification.delay", send_status_notification) def change_order_status(self, status): # Change order expiry to now order = Order.objects.get(id=self.order_id)