import React, { Component } from "react";
import { Box, Button , Divider, CircularProgress, ListItemButton, Typography, Grid, Select, MenuItem, FormControl, FormHelperText, List, ListItem, ListItemText, Avatar, RouterLink, ListItemAvatar} from "@mui/material";
import { Link } from 'react-router-dom'
export default class BookPage extends Component {
constructor(props) {
super(props);
this.state = {
orders: new Array(),
currency: 0,
type: 1,
currencies_dict: {"0":"ANY"},
loading: true,
};
this.getCurrencyDict()
this.getOrderDetails(this.state.type,this.state.currency)
this.state.currencyCode = this.getCurrencyCode(this.state.currency)
}
getOrderDetails(type,currency) {
fetch('/api/book' + '?currency=' + currency + "&type=" + type)
.then((response) => response.json())
.then((data) =>
this.setState({
orders: data,
not_found: data.not_found,
loading: false,
}));
}
handleCardClick=(e)=>{
console.log(e)
this.props.history.push('/order/' + e);
}
handleTypeChange=(e)=>{
this.setState({
type: e.target.value,
loading: true,
});
this.getOrderDetails(e.target.value,this.state.currency);
}
handleCurrencyChange=(e)=>{
this.setState({
currency: e.target.value,
currencyCode: this.getCurrencyCode(e.target.value),
loading: true,
})
this.getOrderDetails(this.state.type, e.target.value);
}
getCurrencyDict() {
fetch('/static/assets/currencies.json')
.then((response) => response.json())
.then((data) =>
this.setState({
currencies_dict: data
}));
}
getCurrencyCode(val){
return this.state.currencies_dict[val.toString()]
}
// pretty numbers
pn(x) {
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
}
bookListItems=()=>{
return (this.state.orders.map((order) =>
<>
this.handleCardClick(order.id)}>
{order.maker_nick+" "}
{order.type ? " Sells ": " Buys "} BTC for {parseFloat(
parseFloat(order.amount).toFixed(4))+" "+ this.getCurrencyCode(order.currency)+" "}
via {order.payment_method}
at {this.pn(order.price) + " " + this.getCurrencyCode(order.currency)}/BTC
{order.premium > 1 ? "🔴" : "🔵" } {parseFloat(parseFloat(order.premium).toFixed(4))}%
>
));
}
//
//
// this.handleCardClick(order.id)}>
//
//
//
//
//
//
//
//
// {order.maker_nick}
//
//
//
// {/* CARD PARAGRAPH CONTENT */}
//
//
// â—‘{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" : (
// " at " +
// parseFloat(parseFloat(order.premium).toFixed(4)) + "% over the market"
// )}
// */}
//
// â—‘ {" 42,354 "}{this.getCurrencyCode(order.currency)}/BTC (Binance API)
//
//
//
//
//
//
//
render() {
return (
Order Book
I want to
And pay with
{ this.state.not_found ? "" :
You are {this.state.type == 0 ? " buying " : (this.state.type == 1 ? " selling ":" checking ")} BTC for {this.state.currencyCode}
}
{/* If loading, show circular progressbar */}
{this.state.loading ?
: ""}
{ this.state.not_found ?
(
No orders found to {this.state.type == 0 ? ' sell ' :' buy ' } BTC for {this.state.currencyCode}
Be the first one to create an order
)
:
{this.bookListItems()}
}
);
};
}