diff --git a/api/logics.py b/api/logics.py
index 4818d908..291cb572 100644
--- a/api/logics.py
+++ b/api/logics.py
@@ -40,12 +40,12 @@ class Logics():
'''Checks if the user is already partipant of an active order'''
queryset = Order.objects.filter(maker=user, status__in=active_order_status)
if queryset.exists():
- return False, {'bad_request':'You are already maker of an active order'}
+ return False, {'bad_request':'You are already maker of an active order'}, queryset[0]
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'}
- return True, None
+ return False, {'bad_request':'You are already taker of an active order'}, queryset[0]
+ return True, None, None
def validate_order_size(order):
'''Validates if order is withing limits in satoshis at t0'''
@@ -769,13 +769,12 @@ class Logics():
# Double check the escrow is settled.
if LNNode.double_check_htlc_is_settled(order.trade_escrow.payment_hash):
+ # RETURN THE BONDS // Probably best also do it even if payment failed
+ cls.return_bond(order.taker_bond)
+ cls.return_bond(order.maker_bond)
is_payed, context = follow_send_payment(order.payout) ##### !!! KEY LINE - PAYS THE BUYER INVOICE !!!
if is_payed:
- # RETURN THE BONDS // Probably best also do it even if payment failed
- cls.return_bond(order.taker_bond)
- cls.return_bond(order.maker_bond)
order.save()
-
return True, context
else:
# error handling here
diff --git a/api/views.py b/api/views.py
index 33a669b8..21b7b9b8 100644
--- a/api/views.py
+++ b/api/views.py
@@ -49,7 +49,7 @@ class MakerView(CreateAPIView):
satoshis = serializer.data.get('satoshis')
is_explicit = serializer.data.get('is_explicit')
- valid, context = Logics.validate_already_maker_or_taker(request.user)
+ valid, context, _ = Logics.validate_already_maker_or_taker(request.user)
if not valid: return Response(context, status.HTTP_409_CONFLICT)
# Creates a new order
@@ -270,7 +270,7 @@ class OrderView(viewsets.ViewSet):
# 1) If action is take, it is a taker request!
if action == 'take':
if order.status == Order.Status.PUB:
- valid, context = Logics.validate_already_maker_or_taker(request.user)
+ valid, context, _ = Logics.validate_already_maker_or_taker(request.user)
if not valid: return Response(context, status=status.HTTP_409_CONFLICT)
valid, context = Logics.take(order, request.user)
if not valid: return Response(context, status=status.HTTP_403_FORBIDDEN)
@@ -345,7 +345,7 @@ class UserView(APIView):
# If an existing user opens the main page by mistake, we do not want it to create a new nickname/profile for him
if request.user.is_authenticated:
context = {'nickname': request.user.username}
- not_participant, _ = Logics.validate_already_maker_or_taker(request.user)
+ not_participant, _, _ = Logics.validate_already_maker_or_taker(request.user)
# Does not allow this 'mistake' if an active order
if not not_participant:
@@ -449,7 +449,6 @@ class BookView(ListAPIView):
if len(queryset)== 0:
return Response({'not_found':'No orders found, be the first to make one'}, status=status.HTTP_404_NOT_FOUND)
- # queryset = queryset.order_by('created_at')
book_data = []
for order in queryset:
data = ListOrderSerializer(order).data
@@ -509,6 +508,11 @@ class InfoView(ListAPIView):
context['robosats_running_commit_hash'] = get_commit_robosats()
context['fee'] = FEE
context['bond_size'] = float(config('BOND_SIZE'))
+ if request.user.is_authenticated:
+ context['nickname'] = request.user.username
+ has_no_active_order, _, order = Logics.validate_already_maker_or_taker(request.user)
+ if not has_no_active_order:
+ context['active_order_id'] = order.id
return Response(context, status.HTTP_200_OK)
diff --git a/frontend/src/components/App.js b/frontend/src/components/App.js
index 6cf5659a..b07b8b20 100644
--- a/frontend/src/components/App.js
+++ b/frontend/src/components/App.js
@@ -7,16 +7,23 @@ import BottomBar from "./BottomBar";
export default class App extends Component {
constructor(props) {
super(props);
+ this.state = {
+ nickname: null,
+ }
+ }
+
+ setAppState=(newState)=>{
+ this.setState(newState)
}
render() {
return (
<>