From b39529d91e37df716519e4f5220fb3fd47e33609 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Thu, 3 Feb 2022 13:51:42 -0800 Subject: [PATCH] Avoid giving new robot to a user who is expecting still a payment --- api/logics.py | 12 +++++++++++- frontend/src/components/OrderPage.js | 5 ++--- frontend/src/components/TradeBox.js | 2 ++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/api/logics.py b/api/logics.py index f7ad7959..6d6aa8cb 100644 --- a/api/logics.py +++ b/api/logics.py @@ -1,6 +1,7 @@ from datetime import timedelta from django.utils import timezone from api.lightning.node import LNNode +from django.db.models import Q from api.models import Order, LNPayment, MarketTick, User, Currency from decouple import config @@ -30,7 +31,8 @@ FIAT_EXCHANGE_DURATION = int(config('FIAT_EXCHANGE_DURATION')) class Logics(): - def validate_already_maker_or_taker(user): + @classmethod + def validate_already_maker_or_taker(cls, user): '''Validates if a use is already not part of an active order''' active_order_status = [Order.Status.WFB, Order.Status.PUB, Order.Status.TAK, @@ -45,6 +47,14 @@ class Logics(): queryset = Order.objects.filter(taker=user, status__in=active_order_status) if queryset.exists(): return False, {'bad_request':'You are already taker of an active order'}, queryset[0] + + # Edge case when the user is in an order that is failing payment and he is the buyer + queryset = Order.objects.filter( Q(maker=user) | Q(taker=user), status__in=Order.Status.FAI) + if queryset.exists(): + order = queryset[0] + if cls.is_buyer(order, user): + return False, {'bad_request':'You are still pending a payment from a recent order'}, order + return True, None, None def validate_order_size(order): diff --git a/frontend/src/components/OrderPage.js b/frontend/src/components/OrderPage.js index f9f333b3..596bbfe6 100644 --- a/frontend/src/components/OrderPage.js +++ b/frontend/src/components/OrderPage.js @@ -303,12 +303,11 @@ export default class OrderPage extends Component { aria-describedby="inactive-maker-description" > - {"The maker is inactive"} + {"The maker is away"} - The maker seems to be away. You risk - wasting your time. + By taking this order you risk wasting your time. diff --git a/frontend/src/components/TradeBox.js b/frontend/src/components/TradeBox.js index 12e8ff4d..074ad77b 100644 --- a/frontend/src/components/TradeBox.js +++ b/frontend/src/components/TradeBox.js @@ -361,6 +361,8 @@ export default class TradeBox extends Component { + {/* Make confirmation sound for HTLC received. */} + Submit a LN invoice for {pn(this.props.data.invoice_amount)} Sats