Add in order user activity status badge

This commit is contained in:
Reckless_Satoshi 2022-01-30 11:45:37 -08:00
parent 13517047e0
commit 716e838442
No known key found for this signature in database
GPG Key ID: 9C4585B561315571
3 changed files with 53 additions and 12 deletions

View File

@ -147,6 +147,8 @@ class Order(models.Model):
# order participants
maker = models.ForeignKey(User, related_name='maker', on_delete=models.SET_NULL, null=True, default=None) # unique = True, a maker can only make one order
taker = models.ForeignKey(User, related_name='taker', on_delete=models.SET_NULL, null=True, default=None, blank=True) # unique = True, a taker can only take one order
maker_last_seen = models.DateTimeField(null=True,default=None, blank=True)
taker_last_seen = models.DateTimeField(null=True,default=None, blank=True)
maker_asked_cancel = models.BooleanField(default=False, null=False) # When collaborative cancel is needed and one partner has cancelled.
taker_asked_cancel = models.BooleanField(default=False, null=False) # When collaborative cancel is needed and one partner has cancelled.
is_fiat_sent = models.BooleanField(default=False, null=False)

View File

@ -125,6 +125,32 @@ class OrderView(viewsets.ViewSet):
if not data['is_participant'] and order.status != Order.Status.PUB:
return Response({'bad_request':'You are not allowed to see this order'},status.HTTP_403_FORBIDDEN)
# WRITE Update last_seen for maker and taker.
# Note down that the taker/maker was here recently, so counterpart knows if the user is paying attention.
if order.maker == request.user:
order.maker_last_seen = timezone.now()
order.save()
if order.taker == request.user:
order.taker_last_seen = timezone.now()
order.save()
# 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'
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'
# 3.b If order is between public and WF2
if order.status >= Order.Status.PUB and order.status < Order.Status.WF2:
data['price_now'], data['premium_now'] = Logics.price_and_premium_now(order)
@ -221,10 +247,8 @@ 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 or has been asked
if (data['is_maker'] and order.taker_asked_cancel) or (data['is_taker'] and order.maker_asked_cancel):
print('PENDING')
data['pending_cancel'] = True
elif (data['is_maker'] and order.maker_asked_cancel) or (data['is_taker'] and order.taker_asked_cancel):
print('ASKED')
data['asked_for_cancel'] = True
else:
data['asked_for_cancel'] = False

View File

@ -1,6 +1,5 @@
import React, { Component } from "react";
import PropTypes from 'prop-types';
import { Tab, Tabs, Alert, Paper, CircularProgress, Button , Grid, Typography, List, ListItem, ListItemIcon, ListItemText, ListItemAvatar, Avatar, Divider, Box, LinearProgress, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle} from "@mui/material"
import { Badge, Tab, Tabs, Alert, Paper, CircularProgress, Button , Grid, Typography, List, ListItem, ListItemIcon, ListItemText, ListItemAvatar, Avatar, Divider, Box, LinearProgress, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle} from "@mui/material"
import Countdown, { zeroPad, calcTimeDelta } from 'react-countdown';
import MediaQuery from 'react-responsive'
@ -341,6 +340,18 @@ export default class OrderPage extends Component {
return(null)
}
// Colors for the status badges
statusBadgeColor(status){
if(status=='active'){
return("success")
}
if(status=='seen_recently'){
return("warning")
}
if(status=='inactive'){
return('error')
}
}
orderBox=()=>{
return(
<Grid container spacing={1} >
@ -354,10 +365,12 @@ export default class OrderPage extends Component {
<List dense="true">
<ListItem >
<ListItemAvatar sx={{ width: 56, height: 56 }}>
<Avatar className="flippedSmallAvatar"
alt={this.state.maker_nick}
src={window.location.origin +'/static/assets/avatars/' + this.state.maker_nick + '.png'}
/>
<Badge variant="dot" badgeContent="" color={this.statusBadgeColor(this.state.maker_status)}>
<Avatar className="flippedSmallAvatar"
alt={this.state.maker_nick}
src={window.location.origin +'/static/assets/avatars/' + this.state.maker_nick + '.png'}
/>
</Badge>
</ListItemAvatar>
<ListItemText primary={this.state.maker_nick + (this.state.type ? " (Seller)" : " (Buyer)")} secondary="Order maker" align="right"/>
</ListItem>
@ -370,10 +383,12 @@ export default class OrderPage extends Component {
<ListItem align="left">
<ListItemText primary={this.state.taker_nick + (this.state.type ? " (Buyer)" : " (Seller)")} secondary="Order taker"/>
<ListItemAvatar >
<Avatar className="smallAvatar"
alt={this.state.maker_nick}
src={window.location.origin +'/static/assets/avatars/' + this.state.taker_nick + '.png'}
/>
<Badge variant="dot" badgeContent="" color={this.statusBadgeColor(this.state.taker_status)}>
<Avatar className="smallAvatar"
alt={this.state.taker_nick}
src={window.location.origin +'/static/assets/avatars/' + this.state.taker_nick + '.png'}
/>
</Badge>
</ListItemAvatar>
</ListItem>
<Divider />