From 1b4d42cfdfd976c8eba2aa675edad69bf6c16da1 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Mon, 9 May 2022 15:34:10 -0700 Subject: [PATCH] Implement last order always shown on robot profile --- api/views.py | 6 +++++- frontend/src/components/BottomBar.js | 23 ++++++++++++++++++----- frontend/src/locales/es.json | 4 +++- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/api/views.py b/api/views.py index 61532ff5..ac2103df 100644 --- a/api/views.py +++ b/api/views.py @@ -1,6 +1,6 @@ import os from re import T -from django.db.models import Sum +from django.db.models import Sum, Q from rest_framework import status, viewsets from rest_framework.generics import CreateAPIView, ListAPIView from rest_framework.views import APIView @@ -768,6 +768,10 @@ class InfoView(ListAPIView): request.user) if not has_no_active_order: context["active_order_id"] = order.id + else: + last_order = Order.objects.filter(Q(maker=request.user) | Q(taker=request.user)).last() + if last_order: + context["last_order_id"] = last_order.id return Response(context, status.HTTP_200_OK) diff --git a/frontend/src/components/BottomBar.js b/frontend/src/components/BottomBar.js index a007d4a3..a64d5d82 100644 --- a/frontend/src/components/BottomBar.js +++ b/frontend/src/components/BottomBar.js @@ -69,7 +69,9 @@ class BottomBar extends Component { this.setState(null) fetch('/api/info/') .then((response) => response.json()) - .then((data) => this.setState(data) & this.setState({active_order_id: data.active_order_id ? data.active_order_id : null}) + .then((data) => this.setState(data) + & this.setState({active_order_id: data.active_order_id ? data.active_order_id : null, + last_order_id: data.last_order_id ? data.last_order_id : null}) & this.props.setAppState({nickname:data.nickname, loading:false})); } @@ -305,6 +307,7 @@ class BottomBar extends Component { + {this.state.active_order_id ? @@ -315,10 +318,20 @@ class BottomBar extends Component { : - - - - + + this.state.last_order_id ? + + + + + + + : + + + + + } diff --git a/frontend/src/locales/es.json b/frontend/src/locales/es.json index b3f729fb..36e37bcb 100644 --- a/frontend/src/locales/es.json +++ b/frontend/src/locales/es.json @@ -172,7 +172,9 @@ "Taker fee":"Comisión del tomador", "Number of public BUY orders": "Nº de órdenes públicas de COMPRA", "Number of public SELL orders": "Nº de órdenes públicas de VENTA", - + "Your last order #{{orderID}}":"Tu última orden #{{orderID}}", + "Inactive order":"Orden inactiva", + "You do not have previous orders":"No tienes órdenes previas", "ORDER PAGE - OrderPage.js": "Order details page", "Order Box": "Orden",