Avoid giving new robot to a user who is expecting still a payment

This commit is contained in:
Reckless_Satoshi 2022-02-03 13:51:42 -08:00
parent 5d4e3c5718
commit b39529d91e
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
3 changed files with 15 additions and 4 deletions

View File

@ -1,6 +1,7 @@
from datetime import timedelta from datetime import timedelta
from django.utils import timezone from django.utils import timezone
from api.lightning.node import LNNode from api.lightning.node import LNNode
from django.db.models import Q
from api.models import Order, LNPayment, MarketTick, User, Currency from api.models import Order, LNPayment, MarketTick, User, Currency
from decouple import config from decouple import config
@ -30,7 +31,8 @@ FIAT_EXCHANGE_DURATION = int(config('FIAT_EXCHANGE_DURATION'))
class Logics(): 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''' '''Validates if a use is already not part of an active order'''
active_order_status = [Order.Status.WFB, Order.Status.PUB, Order.Status.TAK, 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) queryset = Order.objects.filter(taker=user, status__in=active_order_status)
if queryset.exists(): if queryset.exists():
return False, {'bad_request':'You are already taker of an active order'}, queryset[0] 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 return True, None, None
def validate_order_size(order): def validate_order_size(order):

View File

@ -303,12 +303,11 @@ export default class OrderPage extends Component {
aria-describedby="inactive-maker-description" aria-describedby="inactive-maker-description"
> >
<DialogTitle id="inactive-maker-dialog-title"> <DialogTitle id="inactive-maker-dialog-title">
{"The maker is inactive"} {"The maker is away"}
</DialogTitle> </DialogTitle>
<DialogContent> <DialogContent>
<DialogContentText id="cancel-dialog-description"> <DialogContentText id="cancel-dialog-description">
The maker seems to be away. You risk By taking this order you risk wasting your time.
wasting your time.
</DialogContentText> </DialogContentText>
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>

View File

@ -361,6 +361,8 @@ export default class TradeBox extends Component {
<Grid container spacing={1}> <Grid container spacing={1}>
<Grid item xs={12} align="center"> <Grid item xs={12} align="center">
{/* Make confirmation sound for HTLC received. */}
<this.Sound soundFileName="locked-invoice"/>
<Typography color="primary" component="subtitle1" variant="subtitle1"> <Typography color="primary" component="subtitle1" variant="subtitle1">
<b> Submit a LN invoice for {pn(this.props.data.invoice_amount)} Sats </b> <b> Submit a LN invoice for {pn(this.props.data.invoice_amount)} Sats </b>
</Typography> </Typography>