import React, { Component } from "react"; import { Button , Divider, Card, CardActionArea, CardContent, Typography, Grid, Select, MenuItem, FormControl, FormHelperText, List, ListItem, ListItemText, Avatar, RouterLink, ListItemAvatar} from "@material-ui/core" import { Link } from 'react-router-dom' export default class BookPage extends Component { constructor(props) { super(props); this.state = { orders: new Array(), currency: 1, type: 1, currencies_dict: {"1":"USD"} }; 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, })); } handleCardClick=(e)=>{ console.log(e) this.props.history.push('/order/' + e); } handleTypeChange=(e)=>{ this.setState({ type: e.target.value, }); this.getOrderDetails(e.target.value,this.state.currency); } handleCurrencyChange=(e)=>{ this.setState({ currency: e.target.value, currencyCode: this.getCurrencyCode(e.target.value), }) 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, ","); } bookCards=()=>{ return (this.state.orders.map((order) => 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 ? " selling " : " buying "} BTC for {this.state.currencyCode} } { 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.bookCards() } ); }; }