mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-31 10:31:35 +00:00
Refresh orders
This commit is contained in:
parent
cf2422f924
commit
71107a7432
@ -372,7 +372,7 @@ class BookView(ListAPIView):
|
|||||||
|
|
||||||
class InfoView(ListAPIView):
|
class InfoView(ListAPIView):
|
||||||
|
|
||||||
def get(self):
|
def get(self, request):
|
||||||
context = {}
|
context = {}
|
||||||
|
|
||||||
context['num_public_buy_orders'] = len(Order.objects.filter(type=Order.Types.BUY, status=Order.Status.PUB))
|
context['num_public_buy_orders'] = len(Order.objects.filter(type=Order.Types.BUY, status=Order.Status.PUB))
|
||||||
|
@ -67,15 +67,18 @@ export default class OrderPage extends Component {
|
|||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
isExplicit: false,
|
isExplicit: false,
|
||||||
|
delay: 5000, // Refresh every 5 seconds
|
||||||
};
|
};
|
||||||
this.orderId = this.props.match.params.orderId;
|
this.orderId = this.props.match.params.orderId;
|
||||||
this.getOrderDetails();
|
this.getOrderDetails();
|
||||||
}
|
}
|
||||||
|
|
||||||
getOrderDetails() {
|
getOrderDetails() {
|
||||||
|
this.setState(null)
|
||||||
fetch('/api/order' + '?order_id=' + this.orderId)
|
fetch('/api/order' + '?order_id=' + this.orderId)
|
||||||
.then((response) => response.json())
|
.then((response) => response.json())
|
||||||
.then((data) => {
|
.then((data) => {
|
||||||
|
console.log(data) &
|
||||||
this.setState({
|
this.setState({
|
||||||
statusCode: data.status,
|
statusCode: data.status,
|
||||||
statusText: data.status_message,
|
statusText: data.status_message,
|
||||||
@ -107,6 +110,29 @@ export default class OrderPage extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// These are used to refresh the data
|
||||||
|
componentDidMount() {
|
||||||
|
this.interval = setInterval(this.tick, this.state.delay);
|
||||||
|
}
|
||||||
|
componentDidUpdate(prevProps, prevState) {
|
||||||
|
if (prevState.delay !== this.state.delay) {
|
||||||
|
clearInterval(this.interval);
|
||||||
|
this.interval = setInterval(this.tick, this.state.delay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
componentWillUnmount() {
|
||||||
|
clearInterval(this.interval);
|
||||||
|
}
|
||||||
|
tick = () => {
|
||||||
|
this.getOrderDetails();
|
||||||
|
}
|
||||||
|
handleDelayChange = (e) => {
|
||||||
|
this.setState({ delay: Number(e.target.value) });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Gets currency code (3 letters) from numeric (e.g., 1 -> USD)
|
// Gets currency code (3 letters) from numeric (e.g., 1 -> USD)
|
||||||
// Improve this function so currencies are read from json
|
// Improve this function so currencies are read from json
|
||||||
getCurrencyCode(val){
|
getCurrencyCode(val){
|
||||||
@ -162,7 +188,7 @@ export default class OrderPage extends Component {
|
|||||||
src={window.location.origin +'/static/assets/avatars/' + this.state.makerNick + '.png'}
|
src={window.location.origin +'/static/assets/avatars/' + this.state.makerNick + '.png'}
|
||||||
/>
|
/>
|
||||||
</ListItemAvatar>
|
</ListItemAvatar>
|
||||||
<ListItemText primary={this.state.makerNick} secondary="Order maker" align="right"/>
|
<ListItemText primary={this.state.makerNick + (this.state.type ? " (Buyer)" : " (Seller)")} secondary="Order maker" align="right"/>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
<Divider />
|
<Divider />
|
||||||
|
|
||||||
@ -171,7 +197,7 @@ export default class OrderPage extends Component {
|
|||||||
{this.state.takerNick!='None' ?
|
{this.state.takerNick!='None' ?
|
||||||
<>
|
<>
|
||||||
<ListItem align="left">
|
<ListItem align="left">
|
||||||
<ListItemText primary={this.state.takerNick} secondary="Order taker"/>
|
<ListItemText primary={this.state.takerNick + (this.state.type ? " (Seller)" : " (Buyer)")} secondary="Order taker"/>
|
||||||
<ListItemAvatar >
|
<ListItemAvatar >
|
||||||
<Avatar
|
<Avatar
|
||||||
alt={this.state.makerNick}
|
alt={this.state.makerNick}
|
||||||
|
@ -1,13 +1,38 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import { Paper, FormControl , Grid, Typography, FormHelperText, TextField, List, ListItem, ListItemText, Divider} 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"
|
import QRCode from "react-qr-code";
|
||||||
|
|
||||||
export default class TradeBox extends Component {
|
export default class TradeBox extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
|
this.state = {
|
||||||
|
delay: 5000, // Refresh every 5 seconds
|
||||||
|
};
|
||||||
this.data = this.props.data
|
this.data = this.props.data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// These are used to refresh the data
|
||||||
|
componentDidMount() {
|
||||||
|
this.interval = setInterval(this.tick, this.state.delay);
|
||||||
|
}
|
||||||
|
componentDidUpdate(prevProps, prevState) {
|
||||||
|
if (prevState.delay !== this.state.delay) {
|
||||||
|
clearInterval(this.interval);
|
||||||
|
this.interval = setInterval(this.tick, this.state.delay);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
componentWillUnmount() {
|
||||||
|
clearInterval(this.interval);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
handleDelayChange = (e) => {
|
||||||
|
this.setState({ delay: Number(e.target.value) });
|
||||||
|
}
|
||||||
|
tick = () => {
|
||||||
|
this.data = this.props.data;
|
||||||
|
}
|
||||||
|
|
||||||
showInvoice=()=>{
|
showInvoice=()=>{
|
||||||
return (
|
return (
|
||||||
<Grid container spacing={1}>
|
<Grid container spacing={1}>
|
||||||
@ -71,6 +96,27 @@ export default class TradeBox extends Component {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
showTakerFound=()=>{
|
||||||
|
|
||||||
|
// Make some sound here! The maker might have been waiting for long
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Grid container spacing={1}>
|
||||||
|
<Grid item xs={12} align="center">
|
||||||
|
<Typography component="subtitle1" variant="subtitle1">
|
||||||
|
<b>A taker has been found! </b>
|
||||||
|
</Typography>
|
||||||
|
</Grid>
|
||||||
|
<Divider/>
|
||||||
|
<Grid item xs={12} align="center">
|
||||||
|
<Typography component="body2" variant="body">
|
||||||
|
Please wait for the taker to confirm his commitment by locking a bond.
|
||||||
|
</Typography>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
showMakerWait=()=>{
|
showMakerWait=()=>{
|
||||||
return (
|
return (
|
||||||
<Grid container spacing={1}>
|
<Grid container spacing={1}>
|
||||||
@ -124,6 +170,7 @@ export default class TradeBox extends Component {
|
|||||||
<Paper elevation={12} style={{ padding: 8,}}>
|
<Paper elevation={12} style={{ padding: 8,}}>
|
||||||
{this.data.bondInvoice ? this.showInvoice() : ""}
|
{this.data.bondInvoice ? this.showInvoice() : ""}
|
||||||
{this.data.isMaker & this.data.statusCode == 1 ? this.showMakerWait() : ""}
|
{this.data.isMaker & this.data.statusCode == 1 ? this.showMakerWait() : ""}
|
||||||
|
{this.data.isMaker & this.data.statusCode == 3 ? this.showTakerFound() : ""}
|
||||||
{this.data.isSeller & this.data.escrowInvoice != null ? this.showEscrowInvoice() : ""}
|
{this.data.isSeller & this.data.escrowInvoice != null ? this.showEscrowInvoice() : ""}
|
||||||
</Paper>
|
</Paper>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
Loading…
Reference in New Issue
Block a user