From 0823febf73eb8ade9ae0dbb56dc4a188d17bbc82 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Tue, 4 Jan 2022 02:21:45 -0800 Subject: [PATCH] Add order expiry time and rework book page --- api/models.py | 1 + api/serializers.py | 2 +- api/views.py | 4 ++ frontend/src/components/BookPage.js | 80 +++++++++++++++++----------- frontend/src/components/MakerPage.js | 4 +- 5 files changed, 57 insertions(+), 34 deletions(-) diff --git a/api/models.py b/api/models.py index 4ca3e704..ad8028e9 100644 --- a/api/models.py +++ b/api/models.py @@ -45,6 +45,7 @@ class Order(models.Model): # order info, id = models.CharField(max_length=64, unique=True, null=False) status = models.PositiveSmallIntegerField(choices=Status.choices, default=Status.WFB) created_at = models.DateTimeField(auto_now_add=True) + expires_at = models.DateTimeField() # order details type = models.PositiveSmallIntegerField(choices=Types.choices, null=False) diff --git a/api/serializers.py b/api/serializers.py index 7fa68069..b73cb157 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -4,7 +4,7 @@ from .models import Order class OrderSerializer(serializers.ModelSerializer): class Meta: model = Order - fields = ('id','status','created_at','type','currency','amount','payment_method','is_explicit','premium','satoshis','maker','taker') + fields = ('id','status','created_at','expires_at','type','currency','amount','payment_method','is_explicit','premium','satoshis','maker','taker') class MakeOrderSerializer(serializers.ModelSerializer): class Meta: diff --git a/api/views.py b/api/views.py index 7b37be5a..358b7d1d 100644 --- a/api/views.py +++ b/api/views.py @@ -17,6 +17,9 @@ from pathlib import Path from datetime import timedelta from django.utils import timezone +# .env +expiration_time = 8 + avatar_path = Path('frontend/static/assets/avatars') avatar_path.mkdir(parents=True, exist_ok=True) @@ -54,6 +57,7 @@ class MakeOrder(APIView): premium=premium, satoshis=satoshis, is_explicit=is_explicit, + expires_at= timezone.now()+timedelta(hours=expiration_time), maker=request.user) order.save() diff --git a/frontend/src/components/BookPage.js b/frontend/src/components/BookPage.js index 0c2420c1..1cc7c4e3 100644 --- a/frontend/src/components/BookPage.js +++ b/frontend/src/components/BookPage.js @@ -1,5 +1,5 @@ import React, { Component } from "react"; -import { Paper, Button , Card, CardActionArea, CardContent, Typography, Grid, Select, MenuItem, FormControl, FormHelperText, List, ListItem, ListItemText, Avatar, Link, RouterLink} from "@material-ui/core" +import { Paper, Button , Divider, Card, CardActionArea, CardContent, Typography, Grid, Select, MenuItem, FormControl, FormHelperText, List, ListItem, ListItemText, Avatar, Link, RouterLink, ListItemAvatar} from "@material-ui/core" export default class BookPage extends Component { constructor(props) { @@ -22,8 +22,8 @@ export default class BookPage extends Component { this.setState({orders: data})); } - handleCardClick=(orderId)=>{ - this.props.history.push('/order/' + orderId) + handleCardClick (orderId){ + this.props.history.push('/order/' + orderId); } // Make these two functions sequential. getOrderDetails needs setState to be finish beforehand. @@ -41,11 +41,10 @@ export default class BookPage extends Component { this.getOrderDetails(); } - // Gets currency 3 letters code from numeric (e.g., 1 -> USD) + // Gets currency code (3 letters) from numeric (e.g., 1 -> USD) // Improve this function so currencies are read from json getCurrencyCode(val){ - var code = (this.state.currency== 1 ) ? "USD": ((this.state.currency == 2 ) ? "EUR":"ETH") - return (code) + return (val == 1 ) ? "USD": ((val == 2 ) ? "EUR":"ETH") } // pretty numbers @@ -103,36 +102,55 @@ export default class BookPage extends Component { {this.state.orders.map((order) => - - + + {/* Linking to order details not working yet as expected */} - {/* */} - + {/* */} + - - - {order.maker_nick} - - + + + + + + + + {order.maker_nick} + + + + {/* CARD PARAGRAPH CONTENT */} - {order.type == 0 ? "Buys bitcoin for " : "Sells bitcoin for "} - {parseFloat(parseFloat(order.amount).toFixed(4))} - {" " +this.getCurrencyCode(order.currency)}. + + + ◑{order.type == 0 ? Buys : Sells } + {parseFloat(parseFloat(order.amount).toFixed(4))} + {" " +this.getCurrencyCode(order.currency)} worth of bitcoin + + + + ◑ Payment via {order.payment_method} + + + + ◑ Priced {order.is_explicit ? + " explicitly at " + this.pn(order.satoshis) + " Sats" : ( + " to market with " + + parseFloat(parseFloat(order.premium).toFixed(4)) + "% premium" + )} + + + + ◑ {" 42,354 "}{this.getCurrencyCode(order.currency)}/BTC (Binance API) + + + + - Prefers payment via {order.payment_method}. - - This offer is priced - {order.is_explicit ? - " explicitly at " + this.pn(order.satoshis) + " Sats" : ( - " relative to the market at a premium of " + - parseFloat(parseFloat(order.premium).toFixed(4)) + "%" - )}. - Currently that is {"42,354"} {this.getCurrencyCode(order.currency)}/BTC. - diff --git a/frontend/src/components/MakerPage.js b/frontend/src/components/MakerPage.js index ea434a15..de0d97bb 100644 --- a/frontend/src/components/MakerPage.js +++ b/frontend/src/components/MakerPage.js @@ -79,7 +79,7 @@ export default class MakerPage extends Component { premium: 0, }); } - handleClickisExplicit=(e)=>{ + handleClickIsExplicit=(e)=>{ this.setState({ isExplicit: true, satoshis: 10000, @@ -104,7 +104,7 @@ export default class MakerPage extends Component { }; fetch("/api/make/",requestOptions) .then((response) => response.json()) - .then((data) => this.props.history.push('/order/' + data.id)); + .then((data) => (console.log(data) & this.props.history.push('/order/' + data.id))); } render() {