import React, { Component } from "react"; 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) { super(props); this.state = { orders: new Array(), currency: 1, type: 1, }; this.getOrderDetails() this.state.currencyCode = this.getCurrencyCode(this.state.currency) } // Fix needed to handle HTTP 404 error when no order is found // Show message to be the first one to make an order getOrderDetails() { fetch('/api/book' + '?currency=' + this.state.currency + "&type=" + this.state.type) .then((response) => response.json()) .then((data) => //console.log(data)); this.setState({orders: data})); } handleCardClick (orderId){ this.props.history.push('/order/' + orderId); } // Make these two functions sequential. getOrderDetails needs setState to be finish beforehand. handleTypeChange=(e)=>{ this.setState({ type: e.target.value, }); this.getOrderDetails(); } handleCurrencyChange=(e)=>{ this.setState({ currency: e.target.value, currencyCode: this.getCurrencyCode(e.target.value), }) this.getOrderDetails(); } // Gets currency code (3 letters) from numeric (e.g., 1 -> USD) // Improve this function so currencies are read from json getCurrencyCode(val){ return (val == 1 ) ? "USD": ((val == 2 ) ? "EUR":"ETH") } // pretty numbers pn(x) { return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); } render() { return ( Order Book I want to And pay with {this.state.orders.map((order) => {/* Linking to order details not working yet as expected */} {/* */} {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" : ( " to market with " + parseFloat(parseFloat(order.premium).toFixed(4)) + "% premium" )} {" 42,354 "}{this.getCurrencyCode(order.currency)}/BTC (Binance API) )} You are {this.state.type == 0 ? " selling " : " buying "} BTC for {this.state.currencyCode} ); }; }