diff --git a/api/logics.py b/api/logics.py index 459f52f1..f7ad7959 100644 --- a/api/logics.py +++ b/api/logics.py @@ -55,6 +55,14 @@ class Logics(): return False, {'bad_request': 'Your order is too small. It is worth '+'{:,}'.format(order.t0_satoshis)+' Sats now, but the limit is '+'{:,}'.format(MIN_TRADE)+ ' Sats'} return True, None + def user_activity_status(last_seen): + if last_seen > (timezone.now() - timedelta(minutes=2)): + return 'Active' + elif last_seen > (timezone.now() - timedelta(minutes=10)): + return 'Seen recently' + else: + return 'Inactive' + @classmethod def take(cls, order, user): is_penalized, time_out = cls.is_penalized(user) diff --git a/api/views.py b/api/views.py index 2074f4e9..b0b8e1d2 100644 --- a/api/views.py +++ b/api/views.py @@ -136,20 +136,9 @@ class OrderView(viewsets.ViewSet): # Add activity status of participants based on last_seen if order.taker_last_seen != None: - if order.taker_last_seen > (timezone.now() - timedelta(minutes=2)): - data['taker_status'] = 'active' - elif order.taker_last_seen > (timezone.now() - timedelta(minutes=10)): - data['taker_status'] = 'seen_recently' - else: - data['taker_status'] = 'inactive' - + data['taker_status'] = Logics.user_activity_status(order.taker_last_seen) if order.maker_last_seen != None: - if order.maker_last_seen > (timezone.now() - timedelta(minutes=2)): - data['maker_status'] = 'active' - elif order.maker_last_seen > (timezone.now() - timedelta(minutes=10)): - data['maker_status'] = 'seen_recently' - else: - data['maker_status'] = 'inactive' + data['maker_status'] = Logics.user_activity_status(order.maker_last_seen) # 3.b If order is between public and WF2 if order.status >= Order.Status.PUB and order.status < Order.Status.WF2: @@ -157,7 +146,6 @@ class OrderView(viewsets.ViewSet): # 3. c) If maker and Public, add num robots in book, premium percentile and num similar orders. if data['is_maker'] and order.status == Order.Status.PUB: - data['robots_in_book'] = None # TODO data['premium_percentile'] = compute_premium_percentile(order) data['num_similar_orders'] = len(Order.objects.filter(currency=order.currency, status=Order.Status.PUB)) @@ -484,7 +472,7 @@ class BookView(ListAPIView): # Compute current premium for those orders that are explicitly priced. data['price'], data['premium'] = Logics.price_and_premium_now(order) - + data['maker_status'] = Logics.user_activity_status(order.maker_last_seen) for key in ('status','taker'): # Non participants should not see the status or who is the taker del data[key] diff --git a/frontend/src/components/BookPage.js b/frontend/src/components/BookPage.js index bdb04319..802a2538 100644 --- a/frontend/src/components/BookPage.js +++ b/frontend/src/components/BookPage.js @@ -1,5 +1,5 @@ import React, { Component } from "react"; -import { Tooltip, Paper, Button , CircularProgress, ListItemButton, Typography, Grid, Select, MenuItem, FormControl, FormHelperText, List, ListItem, ListItemText, Avatar, RouterLink, ListItemAvatar, IconButton} from "@mui/material"; +import { Badge, Tooltip, Paper, Button , CircularProgress, ListItemButton, Typography, Grid, Select, MenuItem, FormControl, FormHelperText, List, ListItem, ListItemText, Avatar, RouterLink, ListItemAvatar, IconButton} from "@mui/material"; import { Link } from 'react-router-dom' import { DataGrid } from '@mui/x-data-grid'; import MediaQuery from 'react-responsive' @@ -70,6 +70,13 @@ export default class BookPage extends Component { return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); } + // Colors for the status badges + statusBadgeColor(status){ + if(status=='Active'){return("success")} + if(status=='Seen recently'){return("warning")} + if(status=='Inactive'){return('error')} + } + bookListTableDesktop=()=>{ return (