diff --git a/api/views.py b/api/views.py index 6b1719b2d..6baac6095 100644 --- a/api/views.py +++ b/api/views.py @@ -752,11 +752,8 @@ def get(self, request, format=None): 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, - ) + if not queryset.exists(): + return Response([], status=status.HTTP_200_OK) book_data = [] for order in queryset: diff --git a/frontend/src/models/Coordinator.model.ts b/frontend/src/models/Coordinator.model.ts index adb086251..8b36b1719 100644 --- a/frontend/src/models/Coordinator.model.ts +++ b/frontend/src/models/Coordinator.model.ts @@ -196,16 +196,13 @@ export class Coordinator { apiClient .get(this.url, `/api/book/`, undefined, true) .then((data) => { - if (!data?.not_found) { - this.book = (data as PublicOrder[]).reduce>((book, order) => { - order.coordinatorShortAlias = this.shortAlias; - return { ...book, [`${this.shortAlias}${order.id}`]: order }; - }, {}); - void this.generateAllMakerAvatars(); - onDataLoad(); - } else { - onDataLoad(); - } + const orders = Array.isArray(data) ? data : []; + this.book = orders.reduce>((book, order) => { + order.coordinatorShortAlias = this.shortAlias; + return { ...book, [`${this.shortAlias}${order.id}`]: order }; + }, {}); + void this.generateAllMakerAvatars(); + onDataLoad(); }) .catch((e) => { console.log(e); diff --git a/tests/test_trade_pipeline.py b/tests/test_trade_pipeline.py index 724ee49df..f8481bd9d 100644 --- a/tests/test_trade_pipeline.py +++ b/tests/test_trade_pipeline.py @@ -2019,6 +2019,18 @@ def test_book(self): # Cancel order to avoid leaving pending HTLCs after a successful test trade.cancel_order() + def test_book_empty(self): + """ + Tests public book view when there are no public orders. + """ + path = reverse("book") + + response = self.client.get(path) + data = response.json() + + self.assertEqual(response.status_code, 200) + self.assertEqual(data, []) + def test_robot_creation_with_valid_nostr_pubkey(self): """ Test that a robot can be created with a valid 64-character hex nostr pubkey.