2022-01-02 00:19:18 +00:00
|
|
|
import React, { Component } from "react";
|
2022-01-03 19:15:13 +00:00
|
|
|
import { Paper, Button , Grid, Typography, List, ListItem, ListItemText, ListItemAvatar, Avatar, Divider} from "@material-ui/core"
|
2022-01-03 12:11:33 +00:00
|
|
|
import { Link } from 'react-router-dom'
|
2022-01-02 00:19:18 +00:00
|
|
|
|
2022-01-03 14:27:25 +00:00
|
|
|
// pretty numbers
|
|
|
|
function pn(x) {
|
|
|
|
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
|
|
}
|
|
|
|
|
2022-01-02 00:19:18 +00:00
|
|
|
export default class OrderPage extends Component {
|
2022-01-02 12:59:48 +00:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
this.state = {
|
2022-01-02 13:35:31 +00:00
|
|
|
isExplicit: false,
|
2022-01-02 12:59:48 +00:00
|
|
|
};
|
|
|
|
this.orderId = this.props.match.params.orderId;
|
2022-01-02 13:24:35 +00:00
|
|
|
this.getOrderDetails();
|
2022-01-02 12:59:48 +00:00
|
|
|
}
|
2022-01-02 00:19:18 +00:00
|
|
|
|
2022-01-02 13:24:35 +00:00
|
|
|
getOrderDetails() {
|
|
|
|
fetch('/api/order' + '?order_id=' + this.orderId)
|
2022-01-02 12:59:48 +00:00
|
|
|
.then((response) => response.json())
|
|
|
|
.then((data) => {
|
|
|
|
this.setState({
|
2022-01-03 12:11:33 +00:00
|
|
|
statusCode: data.status,
|
|
|
|
statusText: data.status_message,
|
2022-01-02 12:59:48 +00:00
|
|
|
type: data.type,
|
|
|
|
currency: data.currency,
|
2022-01-03 12:11:33 +00:00
|
|
|
currencyCode: (data.currency== 1 ) ? "USD": ((data.currency == 2 ) ? "EUR":"ETH"),
|
2022-01-02 12:59:48 +00:00
|
|
|
amount: data.amount,
|
|
|
|
paymentMethod: data.payment_method,
|
2022-01-02 13:35:31 +00:00
|
|
|
isExplicit: data.is_explicit,
|
2022-01-03 12:11:33 +00:00
|
|
|
premium: data.premium,
|
|
|
|
satoshis: data.satoshis,
|
|
|
|
makerId: data.maker,
|
|
|
|
isParticipant: data.is_participant,
|
|
|
|
makerNick: data.maker_nick,
|
|
|
|
takerId: data.taker,
|
|
|
|
takerNick: data.taker_nick,
|
2022-01-02 12:59:48 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-01-04 15:00:34 +00:00
|
|
|
// Fix to use proper react props
|
|
|
|
handleClickBackButton=()=>{
|
|
|
|
window.history.back();
|
|
|
|
}
|
2022-01-02 12:59:48 +00:00
|
|
|
render (){
|
|
|
|
return (
|
2022-01-03 12:11:33 +00:00
|
|
|
<Grid container spacing={1}>
|
|
|
|
<Grid item xs={12} align="center">
|
|
|
|
<Typography component="h5" variant="h5">
|
2022-01-03 19:15:13 +00:00
|
|
|
BTC {this.state.type ? " Sell " : " Buy "} Order
|
2022-01-03 12:11:33 +00:00
|
|
|
</Typography>
|
2022-01-03 19:15:13 +00:00
|
|
|
<Paper elevation={12} style={{ padding: 8,}}>
|
2022-01-03 12:11:33 +00:00
|
|
|
<List component="nav" aria-label="mailbox folders">
|
|
|
|
<ListItem>
|
|
|
|
<ListItemAvatar sx={{ width: 56, height: 56 }}>
|
|
|
|
<Avatar
|
|
|
|
alt={this.state.makerNick}
|
|
|
|
src={window.location.origin +'/static/assets/avatars/' + this.state.makerNick + '.png'}
|
|
|
|
/>
|
|
|
|
</ListItemAvatar>
|
|
|
|
<ListItemText primary={this.state.makerNick} secondary="Order maker" />
|
|
|
|
</ListItem>
|
|
|
|
<Divider />
|
|
|
|
<ListItem>
|
2022-01-03 14:27:25 +00:00
|
|
|
<ListItemText primary={parseFloat(parseFloat(this.state.amount).toFixed(4))+" "+this.state.currencyCode} secondary="Amount and currency requested"/>
|
2022-01-03 12:11:33 +00:00
|
|
|
</ListItem>
|
|
|
|
<Divider />
|
|
|
|
<ListItem>
|
|
|
|
<ListItemText primary={this.state.paymentMethod} secondary="Accepted payment methods"/>
|
|
|
|
</ListItem>
|
|
|
|
<Divider />
|
|
|
|
<ListItem>
|
|
|
|
{this.state.isExplicit ?
|
2022-01-03 14:27:25 +00:00
|
|
|
<ListItemText primary={pn(this.state.satoshis)} secondary="Amount of Satoshis"/>
|
2022-01-03 12:11:33 +00:00
|
|
|
:
|
2022-01-03 14:27:25 +00:00
|
|
|
<ListItemText primary={parseFloat(parseFloat(this.state.premium).toFixed(2))+"%"} secondary="Premium over market price"/>
|
2022-01-03 12:11:33 +00:00
|
|
|
}
|
|
|
|
</ListItem>
|
|
|
|
<Divider />
|
|
|
|
{this.state.isParticipant ?
|
|
|
|
<>
|
|
|
|
<ListItem>
|
|
|
|
<ListItemText primary={this.state.statusText} secondary="Order status"/>
|
|
|
|
</ListItem>
|
|
|
|
<Divider />
|
|
|
|
{ this.state.takerNick!='None' ?
|
|
|
|
<><ListItem>
|
|
|
|
<ListItemText primary={this.state.takerNick} secondary="Order taker"/>
|
|
|
|
</ListItem>
|
|
|
|
<Divider /> </>: ""}
|
|
|
|
</>
|
|
|
|
:""
|
|
|
|
}
|
|
|
|
<ListItem>
|
|
|
|
<ListItemText primary={'#'+this.orderId} secondary="Order ID"/>
|
|
|
|
</ListItem>
|
|
|
|
</List>
|
|
|
|
|
|
|
|
<Grid item xs={12} align="center">
|
|
|
|
{this.state.isParticipant ? "" : <Button variant='contained' color='primary' to='/home' component={Link}>Take Order</Button>}
|
|
|
|
</Grid>
|
2022-01-04 15:00:34 +00:00
|
|
|
<Grid item xs={12} align="center">
|
|
|
|
{this.state.isParticipant ? "" : <Button variant='contained' color='secondary' onClick={this.handleClickBackButton}>Back</Button>}
|
|
|
|
</Grid>
|
2022-01-03 19:15:13 +00:00
|
|
|
</Paper>
|
2022-01-03 12:11:33 +00:00
|
|
|
</Grid>
|
|
|
|
</Grid>
|
2022-01-02 12:59:48 +00:00
|
|
|
);
|
|
|
|
}
|
2022-01-02 00:19:18 +00:00
|
|
|
}
|