diff --git a/frontend/src/components/BookPage.js b/frontend/src/components/BookPage.js index 41d00b5a..67a9b66d 100644 --- a/frontend/src/components/BookPage.js +++ b/frontend/src/components/BookPage.js @@ -1,6 +1,6 @@ import React, { Component } from "react"; import { withTranslation, Trans} from "react-i18next"; -import { Badge, Tooltip, Paper, Button, ListItemButton, Typography, Grid, Select, MenuItem, FormControl, FormHelperText, ListItemText, ListItemAvatar, IconButton} from "@mui/material"; +import { Badge, Tooltip, Stack, Paper, Button, FormControlLabel, Checkbox, RadioGroup, ListItemButton, Typography, Grid, Select, MenuItem, FormControl, FormHelperText, ListItemText, ListItemAvatar, IconButton, CircularProgress} from "@mui/material"; import { Link } from 'react-router-dom' import { DataGrid } from '@mui/x-data-grid'; import currencyDict from '../../static/assets/currencies.json'; @@ -8,10 +8,14 @@ import currencyDict from '../../static/assets/currencies.json'; import MediaQuery from 'react-responsive' import Image from 'material-ui-image' import getFlags from './getFlags' +import { pn } from "../utils/prettyNumbers"; import PaymentText from './PaymentText' // Icons import RefreshIcon from '@mui/icons-material/Refresh'; +import DoubleArrowIcon from '@mui/icons-material/DoubleArrow'; +import MoveToInboxIcon from '@mui/icons-material/MoveToInbox'; +import OutboxIcon from '@mui/icons-material/Outbox'; class BookPage extends Component { constructor(props) { @@ -21,7 +25,7 @@ class BookPage extends Component { loading: true, pageSize: 6, }; - this.getOrderDetails(this.props.type, this.props.currency) + this.getOrderDetails(2, this.props.currency) } getOrderDetails(type, currency) { @@ -38,21 +42,12 @@ class BookPage extends Component { this.props.history.push('/order/' + e); } - handleTypeChange=(e)=>{ - this.setState({ - loading: true, - }); - this.props.setAppState({bookType: e.target.value}) - this.getOrderDetails(e.target.value,this.props.currency); - } handleCurrencyChange=(e)=>{ var currency = e.target.value; - this.setState({loading: true}) this.props.setAppState({ bookCurrency: currency, bookCurrencyCode: this.getCurrencyCode(currency), }) - this.getOrderDetails(this.props.type, currency); } getCurrencyCode(val){ @@ -64,16 +59,6 @@ class BookPage extends Component { } } - // pretty numbers - pn(x) { - if(x == null){ - return 'null' - }else{ - var parts = x.toString().split("."); - parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ","); - return parts.join("."); - } - } // Colors for the status badges statusBadgeColor(status){ @@ -81,11 +66,12 @@ class BookPage extends Component { if(status=='Seen recently'){return("warning")} if(status=='Inactive'){return('error')} } + amountToString = (amount,has_range,min_amount,max_amount) => { if (has_range){ - return this.pn(parseFloat(Number(min_amount).toPrecision(2)))+'-'+this.pn(parseFloat(Number(max_amount).toPrecision(2))) + return pn(parseFloat(Number(min_amount).toPrecision(2)))+'-'+pn(parseFloat(Number(max_amount).toPrecision(2))) }else{ - return this.pn(parseFloat(Number(amount).toPrecision(3))) + return pn(parseFloat(Number(amount).toPrecision(3))) } } @@ -95,7 +81,9 @@ class BookPage extends Component {
+ this.state.orders.filter(order => order.type == this.props.type || this.props.type == 2) + .filter(order => order.currency == this.props.currency || this.props.currency == 0) + .map((order) => ({id: order.id, avatar: window.location.origin +'/static/assets/avatars/' + order.maker_nick + '.png', robot: order.maker_nick, @@ -120,6 +108,7 @@ class BookPage extends Component { + {params.row.type == t("Buyer") ? : }
}>
+ @@ -151,14 +141,27 @@ class BookPage extends Component { )} }, { field: 'price', headerName: t("Price"), type: 'number', width: 140, renderCell: (params) => {return ( -
{this.pn(params.row.price) + " " +params.row.currency+ "/BTC" }
+
{pn(params.row.price) + " " +params.row.currency+ "/BTC" }
)} }, { field: 'premium', headerName: t("Premium"), type: 'number', width: 100, renderCell: (params) => {return (
{parseFloat(parseFloat(params.row.premium).toFixed(4))+"%" }
)} }, ]} - + + components={{ + NoRowsOverlay: () => ( + +
+ + + ), + NoResultsOverlay: () => ( + + {t("Local filter returns no result")} + + ) + }} pageSize={this.state.loading ? 0 : this.state.pageSize} rowsPerPageOptions={[6,20,50]} onPageSizeChange={(newPageSize) => this.setState({pageSize:newPageSize})} @@ -175,7 +178,9 @@ class BookPage extends Component { + this.state.orders.filter(order => order.type == this.props.type || this.props.type == 2) + .filter(order => order.currency == this.props.currency || this.props.currency == 0) + .map((order) => ({id: order.id, avatar: window.location.origin +'/static/assets/avatars/' + order.maker_nick + '.png', robot: order.maker_nick, @@ -196,19 +201,23 @@ class BookPage extends Component { // { field: 'id', headerName: 'ID', width: 40 }, { field: 'robot', headerName: t("Robot"), width: 64, renderCell: (params) => {return ( - - -
- {params.row.robot} -
-
-
+
+ + + {params.row.type == t("Buyer") ? : }
}> +
+ {params.row.robot} +
+ + + +
); } }, { field: 'type', headerName: t("Is"), width: 60, hide:'true'}, @@ -231,16 +240,29 @@ class BookPage extends Component { )} }, { field: 'price', headerName: t("Price"), type: 'number', width: 140, hide:'true', renderCell: (params) => {return ( -
{this.pn(params.row.price) + " " +params.row.currency+ "/BTC" }
+
{pn(params.row.price) + " " +params.row.currency+ "/BTC" }
)} }, { field: 'premium', headerName: t("Premium"), type: 'number', width: 85, renderCell: (params) => {return ( - +
{parseFloat(parseFloat(params.row.premium).toFixed(4))+"%" }
)} }, ]} - + + components={{ + NoRowsOverlay: () => ( + +
+ + + ), + NoResultsOverlay: () => ( + + {t("Local filter returns no result")} + + ) + }} pageSize={this.state.loading ? 0 : this.state.pageSize} rowsPerPageOptions={[6,20,50]} onPageSizeChange={(newPageSize) => this.setState({pageSize:newPageSize})} @@ -251,6 +273,56 @@ class BookPage extends Component { ); } + handleTypeChange=(buyChecked, sellChecked)=>{ + this.props.setAppState({buyChecked: buyChecked, sellChecked: sellChecked}) + + if (buyChecked & sellChecked || !buyChecked & !sellChecked) { + var type = 2 + } else if (buyChecked) { + var type = 1 + } else if (sellChecked) { + var type = 0 + } + this.props.setAppState({bookType: type}) + } + + handleClickBuy=(e)=>{ + var buyChecked = e.target.checked + var sellChecked = this.props.sellChecked + this.handleTypeChange(buyChecked, sellChecked); + } + + handleClickSell=(e)=>{ + var buyChecked = this.props.buyChecked + var sellChecked = e.target.checked + this.handleTypeChange(buyChecked, sellChecked); + } + + NoOrdersFound=()=>{ + const { t } = this.props; + return( + + + + {this.props.type == 0 ? + t("No orders found to sell BTC for {{currencyCode}}",{currencyCode:this.props.currencyCode}) + : + t("No orders found to buy BTC for {{currencyCode}}",{currencyCode:this.props.currencyCode}) + } + + +
+ + + + + {t("Be the first one to create an order")} +
+
+
+
+ ) + } render() { const { t } = this.props; return ( @@ -263,29 +335,33 @@ class BookPage extends Component { - {t("I want to")} +
{t("I want to")}
- + +
+ } checkedIcon={}/>} + label={
{t("Buy")}
} + labelPlacement="bottom" + checked={this.props.buyChecked} + onChange={this.handleClickBuy} + /> +
+ } checkedIcon={}/>} + label={
{t("Sell")}
} + labelPlacement="bottom" + checked={this.props.sellChecked} + onChange={this.handleClickSell} + /> +
- {this.props.type == 0 ? t("and receive") : (this.props.type == 1 ? t("and pay with") : t("and use") )} + {this.props.type == 0 ? t("and receive") : (this.props.type == 1 ? t("and pay with") : t("and use") )}