Skip to content

Commit

Permalink
Store status notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
KoalaSat committed Sep 6, 2024
1 parent 27b8490 commit 0022f5b
Show file tree
Hide file tree
Showing 14 changed files with 184 additions and 145 deletions.
6 changes: 0 additions & 6 deletions api/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
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

admin.site.unregister(Group)
admin.site.unregister(User)
Expand Down Expand Up @@ -164,9 +163,6 @@ def cancel_public_order(self, request, queryset):
f"Order {order.id} successfully closed",
messages.SUCCESS,
)
send_notification.delay(
order_id=order.id, message="coordinator_cancelled"
)
else:
self.message_user(
request,
Expand Down Expand Up @@ -210,7 +206,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(
Expand Down Expand Up @@ -249,7 +244,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(
Expand Down
8 changes: 4 additions & 4 deletions api/lightning/cln.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,10 +617,10 @@ def handle_response():
]
)

order.update_status(Order.Status.FAI)
order.expires_at = timezone.now() + timedelta(
seconds=order.t_to_expire(Order.Status.FAI)
)
order.update_status(Order.Status.FAI)
order.save(update_fields=["expires_at"])

print(
Expand All @@ -646,10 +646,10 @@ def handle_response():
)
lnpayment.preimage = response.payment_preimage.hex()
lnpayment.save(update_fields=["status", "fee", "preimage"])
order.update_status(Order.Status.SUC)
order.expires_at = timezone.now() + timedelta(
seconds=order.t_to_expire(Order.Status.SUC)
)
order.update_status(Order.Status.SUC)
order.save(update_fields=["expires_at"])

order.log(
Expand Down Expand Up @@ -697,10 +697,10 @@ def handle_response():
]
)

order.update_status(Order.Status.FAI)
order.expires_at = timezone.now() + timedelta(
seconds=order.t_to_expire(Order.Status.FAI)
)
order.update_status(Order.Status.FAI)
order.save(update_fields=["expires_at"])

print(
Expand Down Expand Up @@ -737,10 +737,10 @@ def handle_response():
"in_flight",
]
)
order.update_status(Order.Status.FAI)
order.expires_at = timezone.now() + timedelta(
seconds=order.t_to_expire(Order.Status.FAI)
)
order.update_status(Order.Status.FAI)
order.save(update_fields=["expires_at"])

order.log(
Expand Down
7 changes: 3 additions & 4 deletions api/lightning/lnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -594,11 +594,10 @@ def handle_response(response, was_in_transit=False):
]
)

order.update_status(Order.Status.FAI)

order.expires_at = timezone.now() + timedelta(
seconds=order.t_to_expire(Order.Status.FAI)
)
order.update_status(Order.Status.FAI)
order.save(update_fields=["expires_at"])

str_failure_reason = cls.payment_failure_context[
Expand All @@ -625,10 +624,10 @@ def handle_response(response, was_in_transit=False):
lnpayment.preimage = response.payment_preimage
lnpayment.save(update_fields=["status", "fee", "preimage"])

order.update_status(Order.Status.SUC)
order.expires_at = timezone.now() + timedelta(
seconds=order.t_to_expire(Order.Status.SUC)
)
order.update_status(Order.Status.SUC)
order.save(update_fields=["expires_at"])

order.log(
Expand Down Expand Up @@ -671,10 +670,10 @@ def handle_response(response, was_in_transit=False):
update_fields=["status", "last_routing_time", "in_flight"]
)

order.update_status(Order.Status.FAI)
order.expires_at = timezone.now() + timedelta(
seconds=order.t_to_expire(Order.Status.FAI)
)
order.update_status(Order.Status.FAI)
order.save(update_fields=["expires_at"])

order.log(
Expand Down
Loading

0 comments on commit 0022f5b

Please sign in to comment.