2022-01-02 00:19:18 +00:00
|
|
|
import React, { Component } from "react";
|
2022-01-09 22:17:15 +00:00
|
|
|
import { Button , Divider, ListItemButton, Typography, Grid, Select, MenuItem, FormControl, FormHelperText, List, ListItem, ListItemText, Avatar, RouterLink, ListItemAvatar} from "@mui/material";
|
2022-01-08 11:51:55 +00:00
|
|
|
import { Link } from 'react-router-dom'
|
2022-01-02 00:19:18 +00:00
|
|
|
|
|
|
|
export default class BookPage extends Component {
|
2022-01-03 22:52:46 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
|
|
|
orders: new Array(),
|
2022-01-09 21:24:48 +00:00
|
|
|
currency: 0,
|
2022-01-09 21:54:13 +00:00
|
|
|
type: 1,
|
2022-01-09 21:24:48 +00:00
|
|
|
currencies_dict: {"0":"ANY"}
|
2022-01-03 22:52:46 +00:00
|
|
|
};
|
2022-01-07 23:48:23 +00:00
|
|
|
this.getCurrencyDict()
|
2022-01-09 14:29:10 +00:00
|
|
|
this.getOrderDetails(this.state.type,this.state.currency)
|
2022-01-03 22:52:46 +00:00
|
|
|
this.state.currencyCode = this.getCurrencyCode(this.state.currency)
|
|
|
|
}
|
|
|
|
|
2022-01-09 14:29:10 +00:00
|
|
|
getOrderDetails(type,currency) {
|
|
|
|
fetch('/api/book' + '?currency=' + currency + "&type=" + type)
|
2022-01-03 22:52:46 +00:00
|
|
|
.then((response) => response.json())
|
2022-01-09 14:29:10 +00:00
|
|
|
.then((data) =>
|
2022-01-05 13:39:58 +00:00
|
|
|
this.setState({
|
|
|
|
orders: data,
|
|
|
|
not_found: data.not_found,
|
|
|
|
}));
|
2022-01-03 22:52:46 +00:00
|
|
|
}
|
|
|
|
|
2022-01-04 15:00:34 +00:00
|
|
|
handleCardClick=(e)=>{
|
2022-01-04 16:27:15 +00:00
|
|
|
console.log(e)
|
|
|
|
this.props.history.push('/order/' + e);
|
2022-01-03 22:52:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
handleTypeChange=(e)=>{
|
|
|
|
this.setState({
|
|
|
|
type: e.target.value,
|
|
|
|
});
|
2022-01-09 14:29:10 +00:00
|
|
|
this.getOrderDetails(e.target.value,this.state.currency);
|
2022-01-03 22:52:46 +00:00
|
|
|
}
|
|
|
|
handleCurrencyChange=(e)=>{
|
|
|
|
this.setState({
|
|
|
|
currency: e.target.value,
|
|
|
|
currencyCode: this.getCurrencyCode(e.target.value),
|
|
|
|
})
|
2022-01-09 14:29:10 +00:00
|
|
|
this.getOrderDetails(this.state.type, e.target.value);
|
2022-01-03 22:52:46 +00:00
|
|
|
}
|
2022-01-08 11:51:55 +00:00
|
|
|
|
|
|
|
getCurrencyDict() {
|
2022-01-09 14:29:10 +00:00
|
|
|
fetch('/static/assets/currencies.json')
|
2022-01-08 11:51:55 +00:00
|
|
|
.then((response) => response.json())
|
|
|
|
.then((data) =>
|
|
|
|
this.setState({
|
|
|
|
currencies_dict: data
|
|
|
|
}));
|
|
|
|
}
|
2022-01-09 14:29:10 +00:00
|
|
|
|
2022-01-03 22:52:46 +00:00
|
|
|
getCurrencyCode(val){
|
2022-01-07 23:48:23 +00:00
|
|
|
return this.state.currencies_dict[val.toString()]
|
2022-01-03 22:52:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// pretty numbers
|
|
|
|
pn(x) {
|
|
|
|
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
|
|
}
|
|
|
|
|
2022-01-09 22:17:15 +00:00
|
|
|
bookListItems=()=>{
|
2022-01-05 13:39:58 +00:00
|
|
|
return (this.state.orders.map((order) =>
|
2022-01-09 22:17:15 +00:00
|
|
|
<ListItemButton>
|
|
|
|
<ListItemAvatar >
|
|
|
|
<Avatar
|
|
|
|
alt={order.maker_nick}
|
|
|
|
src={window.location.origin +'/static/assets/avatars/' + order.maker_nick + '.png'}
|
|
|
|
/>
|
|
|
|
</ListItemAvatar>
|
|
|
|
</ListItemButton>
|
2022-01-05 13:39:58 +00:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
2022-01-09 22:17:15 +00:00
|
|
|
// <Grid container item sm={4}>
|
|
|
|
// <Card elevation={6} sx={{ width: 945 }}>
|
|
|
|
|
|
|
|
// <CardActionArea value={order.id} onClick={() => this.handleCardClick(order.id)}>
|
|
|
|
// <CardContent>
|
|
|
|
|
|
|
|
// <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 */}
|
|
|
|
// <ListItemText>
|
|
|
|
// <Typography variant="subtitle1" color="text.secondary">
|
|
|
|
// ◑{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>
|
|
|
|
|
|
|
|
// <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" : (
|
|
|
|
// " at " +
|
|
|
|
// parseFloat(parseFloat(order.premium).toFixed(4)) + "% over the market"
|
|
|
|
// )}
|
|
|
|
// </Typography> */}
|
|
|
|
|
|
|
|
// <Typography variant="subtitle1" color="text.secondary">
|
|
|
|
// ◑ <b>{" 42,354 "}{this.getCurrencyCode(order.currency)}/BTC</b> (Binance API)
|
|
|
|
// </Typography>
|
|
|
|
// </ListItemText>
|
|
|
|
|
|
|
|
// </List>
|
|
|
|
|
|
|
|
// </CardContent>
|
|
|
|
// </CardActionArea>
|
|
|
|
// </Card>
|
|
|
|
// </Grid>
|
|
|
|
|
2022-01-03 22:52:46 +00:00
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<Grid className='orderBook' container spacing={1}>
|
|
|
|
<Grid item xs={12} align="center">
|
|
|
|
<Typography component="h4" variant="h4">
|
|
|
|
Order Book
|
|
|
|
</Typography>
|
|
|
|
</Grid>
|
|
|
|
|
|
|
|
<Grid item xs={6} align="right">
|
|
|
|
<FormControl >
|
|
|
|
<FormHelperText>
|
|
|
|
I want to
|
|
|
|
</FormHelperText>
|
|
|
|
<Select
|
|
|
|
label="Select Order Type"
|
|
|
|
required="true"
|
|
|
|
value={this.state.type}
|
|
|
|
inputProps={{
|
|
|
|
style: {textAlign:"center"}
|
|
|
|
}}
|
|
|
|
onChange={this.handleTypeChange}
|
2022-01-09 21:24:48 +00:00
|
|
|
> <MenuItem value={2}>ANY</MenuItem>
|
2022-01-03 22:52:46 +00:00
|
|
|
<MenuItem value={1}>BUY</MenuItem>
|
|
|
|
<MenuItem value={0}>SELL</MenuItem>
|
|
|
|
</Select>
|
|
|
|
</FormControl>
|
|
|
|
</Grid>
|
|
|
|
|
|
|
|
<Grid item xs={6} align="left">
|
|
|
|
<FormControl >
|
|
|
|
<FormHelperText>
|
|
|
|
And pay with
|
|
|
|
</FormHelperText>
|
|
|
|
<Select
|
|
|
|
label="Select Payment Currency"
|
|
|
|
required="true"
|
|
|
|
value={this.state.currency}
|
|
|
|
inputProps={{
|
|
|
|
style: {textAlign:"center"}
|
|
|
|
}}
|
|
|
|
onChange={this.handleCurrencyChange}
|
2022-01-09 21:24:48 +00:00
|
|
|
> <MenuItem value={0}>ANY</MenuItem>
|
2022-01-07 23:48:23 +00:00
|
|
|
{
|
|
|
|
Object.entries(this.state.currencies_dict)
|
|
|
|
.map( ([key, value]) => <MenuItem value={parseInt(key)}>{value}</MenuItem> )
|
|
|
|
}
|
2022-01-03 22:52:46 +00:00
|
|
|
</Select>
|
|
|
|
</FormControl>
|
|
|
|
</Grid>
|
2022-01-05 13:39:58 +00:00
|
|
|
{ this.state.not_found ? "" :
|
2022-01-03 22:52:46 +00:00
|
|
|
<Grid item xs={12} align="center">
|
|
|
|
<Typography component="h5" variant="h5">
|
2022-01-09 21:45:02 +00:00
|
|
|
You are {this.state.type == 0 ? " buying " : (this.state.type == 1 ? " selling ":" checking ")} BTC for {this.state.currencyCode}
|
2022-01-03 22:52:46 +00:00
|
|
|
</Typography>
|
|
|
|
</Grid>
|
2022-01-05 13:39:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{ this.state.not_found ?
|
|
|
|
(<Grid item xs={12} align="center">
|
|
|
|
<Grid item xs={12} align="center">
|
|
|
|
<Typography component="h5" variant="h5">
|
|
|
|
No orders found to {this.state.type == 0 ? ' sell ' :' buy ' } BTC for {this.state.currencyCode}
|
|
|
|
</Typography>
|
|
|
|
</Grid>
|
|
|
|
<Grid item>
|
2022-01-08 11:51:55 +00:00
|
|
|
<Button variant="contained" color='primary' to='/make/' component={Link}>Make Order</Button>
|
2022-01-05 13:39:58 +00:00
|
|
|
</Grid>
|
2022-01-08 11:51:55 +00:00
|
|
|
<Typography component="body1" variant="body1">
|
|
|
|
Be the first one to create an order
|
|
|
|
</Typography>
|
2022-01-05 13:39:58 +00:00
|
|
|
</Grid>)
|
2022-01-09 22:17:15 +00:00
|
|
|
:
|
|
|
|
<Grid item>
|
|
|
|
<List>
|
|
|
|
{this.bookListItems()}
|
|
|
|
</List>
|
|
|
|
</Grid>
|
2022-01-05 13:39:58 +00:00
|
|
|
}
|
2022-01-03 22:52:46 +00:00
|
|
|
<Grid item xs={12} align="center">
|
|
|
|
<Button color="secondary" variant="contained" to="/" component={Link}>
|
|
|
|
Back
|
|
|
|
</Button>
|
|
|
|
</Grid>
|
|
|
|
</Grid>
|
|
|
|
);
|
|
|
|
};
|
2022-01-02 00:19:18 +00:00
|
|
|
}
|