mirror of
https://github.com/RoboSats/robosats.git
synced 2024-12-14 03:16:24 +00:00
Add order expiry time and rework book page
This commit is contained in:
parent
a358a89e24
commit
0823febf73
@ -45,6 +45,7 @@ class Order(models.Model):
|
|||||||
# order info, id = models.CharField(max_length=64, unique=True, null=False)
|
# order info, id = models.CharField(max_length=64, unique=True, null=False)
|
||||||
status = models.PositiveSmallIntegerField(choices=Status.choices, default=Status.WFB)
|
status = models.PositiveSmallIntegerField(choices=Status.choices, default=Status.WFB)
|
||||||
created_at = models.DateTimeField(auto_now_add=True)
|
created_at = models.DateTimeField(auto_now_add=True)
|
||||||
|
expires_at = models.DateTimeField()
|
||||||
|
|
||||||
# order details
|
# order details
|
||||||
type = models.PositiveSmallIntegerField(choices=Types.choices, null=False)
|
type = models.PositiveSmallIntegerField(choices=Types.choices, null=False)
|
||||||
|
@ -4,7 +4,7 @@ from .models import Order
|
|||||||
class OrderSerializer(serializers.ModelSerializer):
|
class OrderSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Order
|
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 MakeOrderSerializer(serializers.ModelSerializer):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
@ -17,6 +17,9 @@ from pathlib import Path
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
|
# .env
|
||||||
|
expiration_time = 8
|
||||||
|
|
||||||
avatar_path = Path('frontend/static/assets/avatars')
|
avatar_path = Path('frontend/static/assets/avatars')
|
||||||
avatar_path.mkdir(parents=True, exist_ok=True)
|
avatar_path.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
@ -54,6 +57,7 @@ class MakeOrder(APIView):
|
|||||||
premium=premium,
|
premium=premium,
|
||||||
satoshis=satoshis,
|
satoshis=satoshis,
|
||||||
is_explicit=is_explicit,
|
is_explicit=is_explicit,
|
||||||
|
expires_at= timezone.now()+timedelta(hours=expiration_time),
|
||||||
maker=request.user)
|
maker=request.user)
|
||||||
order.save()
|
order.save()
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React, { Component } from "react";
|
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 {
|
export default class BookPage extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
@ -22,8 +22,8 @@ export default class BookPage extends Component {
|
|||||||
this.setState({orders: data}));
|
this.setState({orders: data}));
|
||||||
}
|
}
|
||||||
|
|
||||||
handleCardClick=(orderId)=>{
|
handleCardClick (orderId){
|
||||||
this.props.history.push('/order/' + orderId)
|
this.props.history.push('/order/' + orderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make these two functions sequential. getOrderDetails needs setState to be finish beforehand.
|
// Make these two functions sequential. getOrderDetails needs setState to be finish beforehand.
|
||||||
@ -41,11 +41,10 @@ export default class BookPage extends Component {
|
|||||||
this.getOrderDetails();
|
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
|
// Improve this function so currencies are read from json
|
||||||
getCurrencyCode(val){
|
getCurrencyCode(val){
|
||||||
var code = (this.state.currency== 1 ) ? "USD": ((this.state.currency == 2 ) ? "EUR":"ETH")
|
return (val == 1 ) ? "USD": ((val == 2 ) ? "EUR":"ETH")
|
||||||
return (code)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// pretty numbers
|
// pretty numbers
|
||||||
@ -103,36 +102,55 @@ export default class BookPage extends Component {
|
|||||||
</FormControl>
|
</FormControl>
|
||||||
</Grid>
|
</Grid>
|
||||||
{this.state.orders.map((order) =>
|
{this.state.orders.map((order) =>
|
||||||
<Grid container item sm={6}>
|
<Grid container item sm={4}>
|
||||||
<Card >
|
<Card elevation={6} sx={{ width: 245 }}>
|
||||||
{/* Linking to order details not working yet as expected */}
|
{/* Linking to order details not working yet as expected */}
|
||||||
{/* <CardActionArea onClick={this.handleCardClick(order.id)} component={RouterLink} to="/order"> */}
|
{/* <CardActionArea onClick={this.handleCardClick(15)} component={RouterLink} to="/order"> */}
|
||||||
<CardActionArea >
|
<CardActionArea>
|
||||||
<CardContent>
|
<CardContent>
|
||||||
<Avatar
|
|
||||||
alt={order.maker_nick}
|
|
||||||
src={window.location.origin +'/static/assets/avatars/' + order.maker_nick + '.png'}
|
|
||||||
/>
|
|
||||||
<Typography gutterBottom variant="h5" component="div">
|
|
||||||
{order.maker_nick}
|
|
||||||
</Typography>
|
|
||||||
|
|
||||||
<Typography variant="body2" color="text.secondary">
|
<List dense="true">
|
||||||
|
<ListItem >
|
||||||
|
<ListItemAvatar>
|
||||||
|
<Avatar
|
||||||
|
alt={order.maker_nick}
|
||||||
|
src={window.location.origin +'/static/assets/avatars/' + order.maker_nick + '.png'}
|
||||||
|
/>
|
||||||
|
</ListItemAvatar>
|
||||||
|
<ListItemText>
|
||||||
|
<Typography gutterBottom variant="h6">
|
||||||
|
{order.maker_nick}
|
||||||
|
</Typography>
|
||||||
|
</ListItemText>
|
||||||
|
</ListItem>
|
||||||
|
|
||||||
{/* CARD PARAGRAPH CONTENT */}
|
{/* CARD PARAGRAPH CONTENT */}
|
||||||
{order.type == 0 ? "Buys bitcoin for " : "Sells bitcoin for "}
|
<ListItemText>
|
||||||
{parseFloat(parseFloat(order.amount).toFixed(4))}
|
<Typography variant="subtitle1" color="text.secondary">
|
||||||
{" " +this.getCurrencyCode(order.currency)}.
|
◑{order.type == 0 ? <b> Buys </b>: <b> Sells </b>}
|
||||||
|
<b>{parseFloat(parseFloat(order.amount).toFixed(4))}
|
||||||
|
{" " +this.getCurrencyCode(order.currency)}</b> <a> worth of bitcoin</a>
|
||||||
|
</Typography>
|
||||||
|
|
||||||
Prefers payment via {order.payment_method}.
|
<Typography variant="subtitle1" color="text.secondary">
|
||||||
|
◑ Payment via <b>{order.payment_method}</b>
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<Typography variant="subtitle1" color="text.secondary">
|
||||||
|
◑ Priced {order.is_explicit ?
|
||||||
|
" explicitly at " + this.pn(order.satoshis) + " Sats" : (
|
||||||
|
" to market with " +
|
||||||
|
parseFloat(parseFloat(order.premium).toFixed(4)) + "% premium"
|
||||||
|
)}
|
||||||
|
</Typography>
|
||||||
|
|
||||||
|
<Typography variant="subtitle1" color="text.secondary">
|
||||||
|
◑ <b>{" 42,354 "}{this.getCurrencyCode(order.currency)}/BTC</b> (Binance API)
|
||||||
|
</Typography>
|
||||||
|
</ListItemText>
|
||||||
|
|
||||||
|
</List>
|
||||||
|
|
||||||
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.
|
|
||||||
</Typography>
|
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</CardActionArea>
|
</CardActionArea>
|
||||||
</Card>
|
</Card>
|
||||||
|
@ -79,7 +79,7 @@ export default class MakerPage extends Component {
|
|||||||
premium: 0,
|
premium: 0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
handleClickisExplicit=(e)=>{
|
handleClickIsExplicit=(e)=>{
|
||||||
this.setState({
|
this.setState({
|
||||||
isExplicit: true,
|
isExplicit: true,
|
||||||
satoshis: 10000,
|
satoshis: 10000,
|
||||||
@ -104,7 +104,7 @@ export default class MakerPage extends Component {
|
|||||||
};
|
};
|
||||||
fetch("/api/make/",requestOptions)
|
fetch("/api/make/",requestOptions)
|
||||||
.then((response) => response.json())
|
.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() {
|
render() {
|
||||||
|
Loading…
Reference in New Issue
Block a user