From 6400921f48a604aa906904ceabb6a92c3a46d1a3 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Sun, 9 Jan 2022 13:24:48 -0800 Subject: [PATCH] Make book show all (any/any) --- api/lightning.py | 7 +++++++ api/views.py | 22 ++++++++++++---------- frontend/src/components/BookPage.js | 10 +++++----- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/api/lightning.py b/api/lightning.py index 38230a28..295a3085 100644 --- a/api/lightning.py +++ b/api/lightning.py @@ -84,6 +84,13 @@ class LNNode(): '''Sends sats to buyer, or cancelinvoices''' return True + def check_if_hold_invoice_is_locked(payment_hash): + '''Every hodl invoice that is in state INVGEN + Has to be checked for payment received until + the window expires''' + + return True + def settle_hold_htlcs(payment_hash): '''Charges a LN hold invoice''' return True diff --git a/api/views.py b/api/views.py index a11b7ddf..38fef9b9 100644 --- a/api/views.py +++ b/api/views.py @@ -179,7 +179,7 @@ class OrderView(viewsets.ViewSet): if order.maker_bond.status == order.taker_bond.status == order.trade_escrow.status == LNPayment.Status.LOCKED: # add whether a collaborative cancel is pending data['pending_cancel'] = order.is_pending_cancel - + return Response(data, status.HTTP_200_OK) @@ -343,25 +343,27 @@ class UserView(APIView): class BookView(ListAPIView): serializer_class = ListOrderSerializer + queryset = Order.objects.filter(status=Order.Status.PUB) def get(self,request, format=None): currency = request.GET.get('currency') - print("currency:", currency) - type = request.GET.get('type') - queryset = Order.objects.filter(currency=currency, type=type, status=int(Order.Status.PUB)) + type = request.GET.get('type') + + queryset = Order.objects.filter(status=Order.Status.PUB) + # Currency 0 and type 2 are special cases treated as "ANY". They are not possible choices. + if not (int(currency) == 0 and int(type) == 2): + queryset = Order.objects.filter(currency=currency, type=type, status=Order.Status.PUB) + 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') + # queryset = queryset.order_by('created_at') book_data = [] for order in queryset: data = ListOrderSerializer(order).data - user = User.objects.filter(id=data['maker']) - if len(user) == 1: - data['maker_nick'] = user[0].username + data['maker_nick'] = str(order.maker) - # Non participants should not see the status or who is the taker - for key in ('status','taker'): + for key in ('status','taker'): # Non participants should not see the status or who is the taker del data[key] book_data.append(data) diff --git a/frontend/src/components/BookPage.js b/frontend/src/components/BookPage.js index c423d5c1..158d7671 100644 --- a/frontend/src/components/BookPage.js +++ b/frontend/src/components/BookPage.js @@ -7,9 +7,9 @@ export default class BookPage extends Component { super(props); this.state = { orders: new Array(), - currency: 1, - type: 1, - currencies_dict: {"1":"USD"} + currency: 0, + type: 2, + currencies_dict: {"0":"ANY"} }; this.getCurrencyDict() this.getOrderDetails(this.state.type,this.state.currency) @@ -142,7 +142,7 @@ export default class BookPage extends Component { style: {textAlign:"center"} }} onChange={this.handleTypeChange} - > + > ANY BUY SELL @@ -162,7 +162,7 @@ export default class BookPage extends Component { style: {textAlign:"center"} }} onChange={this.handleCurrencyChange} - > + > ANY { Object.entries(this.state.currencies_dict) .map( ([key, value]) => {value} )