From 3a8e172a73f6a20db762d084c1edb3b4b59f80e4 Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Sat, 8 Jan 2022 07:34:09 -0800 Subject: [PATCH] Add maker waiting room --- frontend/src/components/OrderPage.js | 63 ++++++++++++++++++++++++++-- frontend/src/components/TradeBox.js | 54 +++++++++++++++++++++--- 2 files changed, 107 insertions(+), 10 deletions(-) diff --git a/frontend/src/components/OrderPage.js b/frontend/src/components/OrderPage.js index 9ad9415b..a302ab8f 100644 --- a/frontend/src/components/OrderPage.js +++ b/frontend/src/components/OrderPage.js @@ -1,6 +1,5 @@ import React, { Component } from "react"; -import { Paper, Button , Grid, Typography, List, ListItem, ListItemText, ListItemAvatar, Avatar, Divider} from "@material-ui/core" -import { Link } from 'react-router-dom' +import { Paper, Button , Grid, Typography, List, ListItem, ListItemText, ListItemAvatar, Avatar, Divider, Box, LinearProgress} from "@material-ui/core" import TradeBox from "./TradeBox"; function msToTime(duration) { @@ -14,6 +13,33 @@ function msToTime(duration) { return hours + "h " + minutes + "m " + seconds + "s"; } +// TO DO fix Progress bar to go from 100 to 0, from total_expiration time, showing time_left +function LinearDeterminate() { + const [progress, setProgress] = React.useState(0); + + React.useEffect(() => { + const timer = setInterval(() => { + setProgress((oldProgress) => { + if (oldProgress === 0) { + return 100; + } + const diff = 1; + return Math.max(oldProgress - diff, 0); + }); + }, 500); + + return () => { + clearInterval(timer); + }; + }, []); + + return ( + + + + ); +} + function getCookie(name) { let cookieValue = null; if (document.cookie && document.cookie !== '') { @@ -104,6 +130,20 @@ export default class OrderPage extends Component { .then((data) => (console.log(data) & this.getOrderDetails(data.id))); } + handleClickCancelOrderButton=()=>{ + console.log(this.state) + const requestOptions = { + method: 'POST', + headers: {'Content-Type':'application/json', 'X-CSRFToken': getCookie('csrftoken'),}, + body: JSON.stringify({ + 'action':'cancel', + }), + }; + fetch('/api/order/' + '?order_id=' + this.orderId, requestOptions) + .then((response) => response.json()) + .then((data) => (console.log(data) & this.getOrderDetails(data.id))); + } + orderBox=()=>{ return( @@ -150,7 +190,7 @@ export default class OrderPage extends Component { } - + @@ -170,10 +210,10 @@ export default class OrderPage extends Component { - + @@ -190,6 +230,21 @@ export default class OrderPage extends Component { } + + {/* Makers can cancel before commiting the bond (status 0)*/} + {this.state.isMaker & this.state.statusCode == 0 ? + + + + :""} + + {/* Takers can cancel before commiting the bond (status 3)*/} + {this.state.isTaker & this.state.statusCode == 3 ? + + + + :""} + ) } diff --git a/frontend/src/components/TradeBox.js b/frontend/src/components/TradeBox.js index f7343d85..1efceaab 100644 --- a/frontend/src/components/TradeBox.js +++ b/frontend/src/components/TradeBox.js @@ -1,11 +1,10 @@ import React, { Component } from "react"; -import { Paper, FormControl , Grid, Typography, FormHelperText, TextField} from "@material-ui/core" +import { Paper, FormControl , Grid, Typography, FormHelperText, TextField, List, ListItem, ListItemText, Divider} from "@material-ui/core" import QRCode from "react-qr-code" export default class TradeBox extends Component { constructor(props) { super(props); - // props.state = null this.data = this.props.data } @@ -29,7 +28,7 @@ export default class TradeBox extends Component { } - + ); } + showMakerWait=()=>{ + return ( + + + + Your order is public, wait for a taker. + + + + + + + + +

Be patient while robots check the book. + It might take some time. This box will ring 🔊 once a robot takes your order.

+

Please note that if your premium is too high, or if your currency or payment + methods are not popular, your order might expire untaken. Your bond will + return to you (no action needed).

+
+
+ + {/* TODO API sends data for a more confortable wait */} + + + + + + + + + + + + + + +
+
+
+ ) + } render() { return ( - + TradeBox {this.data.bondInvoice ? this.showInvoice() : ""} + {this.data.isMaker & this.data.statusCode == 1 ? this.showMakerWait() : ""}