mirror of
https://github.com/RoboSats/robosats.git
synced 2025-01-31 02:21:35 +00:00
Add BookView endpoint and refactor pages
This commit is contained in:
parent
afd90f8fbf
commit
e9bcd23347
@ -1,8 +1,9 @@
|
|||||||
from django.urls import path
|
from django.urls import path
|
||||||
from .views import MakeOrder, OrderView, UserGenerator
|
from .views import MakeOrder, OrderView, UserGenerator, BookView
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('make/', MakeOrder.as_view()),
|
path('make/', MakeOrder.as_view()),
|
||||||
path('order/', OrderView.as_view()),
|
path('order/', OrderView.as_view()),
|
||||||
path('usergen/', UserGenerator.as_view()),
|
path('usergen/', UserGenerator.as_view()),
|
||||||
|
path('book/', BookView.as_view()),
|
||||||
]
|
]
|
28
api/views.py
28
api/views.py
@ -81,7 +81,7 @@ class OrderView(APIView):
|
|||||||
|
|
||||||
#To do fix: data['status_message'] = Order.Status.get(order.status).label
|
#To do fix: data['status_message'] = Order.Status.get(order.status).label
|
||||||
data['status_message'] = Order.Status.WFB.label # Hardcoded WFB, should use order.status value.
|
data['status_message'] = Order.Status.WFB.label # Hardcoded WFB, should use order.status value.
|
||||||
|
|
||||||
data['maker_nick'] = str(order.maker)
|
data['maker_nick'] = str(order.maker)
|
||||||
data['taker_nick'] = str(order.taker)
|
data['taker_nick'] = str(order.taker)
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ class UserGenerator(APIView):
|
|||||||
use_noun=True,
|
use_noun=True,
|
||||||
max_num=999)
|
max_num=999)
|
||||||
|
|
||||||
def get(self,request):
|
def get(self,request, format=None):
|
||||||
'''
|
'''
|
||||||
Get a new user derived from a high entropy token
|
Get a new user derived from a high entropy token
|
||||||
|
|
||||||
@ -159,7 +159,7 @@ class UserGenerator(APIView):
|
|||||||
if user is not None:
|
if user is not None:
|
||||||
login(request, user)
|
login(request, user)
|
||||||
# Sends the welcome back message, only if created +30 mins ago
|
# Sends the welcome back message, only if created +30 mins ago
|
||||||
if request.user.date_joined < (timezone.now()-timedelta(minutes=1)):
|
if request.user.date_joined < (timezone.now()-timedelta(minutes=30)):
|
||||||
context['found'] = 'We found your Robosat. Welcome back!'
|
context['found'] = 'We found your Robosat. Welcome back!'
|
||||||
return Response(context, status=status.HTTP_202_ACCEPTED)
|
return Response(context, status=status.HTTP_202_ACCEPTED)
|
||||||
else:
|
else:
|
||||||
@ -184,3 +184,25 @@ class UserGenerator(APIView):
|
|||||||
|
|
||||||
return Response(status=status.HTTP_403_FORBIDDEN)
|
return Response(status=status.HTTP_403_FORBIDDEN)
|
||||||
|
|
||||||
|
class BookView(APIView):
|
||||||
|
serializer_class = OrderSerializer
|
||||||
|
|
||||||
|
def get(self,request, format=None):
|
||||||
|
currency = request.GET.get('currency_code')
|
||||||
|
type = request.GET.get('order_type')
|
||||||
|
queryset = Order.objects.filter(currency=currency, type=type)
|
||||||
|
book_data = {}
|
||||||
|
for i, order in enumerate(queryset):
|
||||||
|
data = OrderSerializer(order).data
|
||||||
|
user = User.objects.filter(id=data['maker'])
|
||||||
|
print(user)
|
||||||
|
if len(user) == 1:
|
||||||
|
data['maker_nick'] = user[0].username
|
||||||
|
# TODO avoid sending status and takers for book views
|
||||||
|
#data.pop('status','taker')
|
||||||
|
book_data[i] = data
|
||||||
|
return Response(book_data,status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -133,15 +133,27 @@ export default class MakerPage extends Component {
|
|||||||
</RadioGroup>
|
</RadioGroup>
|
||||||
<FormHelperText>
|
<FormHelperText>
|
||||||
<div align='center'>
|
<div align='center'>
|
||||||
Choose Buy or Sell Bitcoin
|
Choose Buy or Sell Bitcoin
|
||||||
</div>
|
</div>
|
||||||
</FormHelperText>
|
</FormHelperText>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xs={12} align="center">
|
<Grid item xs={12} align="center">
|
||||||
<FormControl >
|
<FormControl >
|
||||||
|
<TextField
|
||||||
|
label="Amount of Fiat to Trade"
|
||||||
|
type="number"
|
||||||
|
required="true"
|
||||||
|
defaultValue={this.defaultAmount}
|
||||||
|
inputProps={{
|
||||||
|
min:0 ,
|
||||||
|
style: {textAlign:"center"}
|
||||||
|
}}
|
||||||
|
onChange={this.handleAmountChange}
|
||||||
|
/>
|
||||||
<Select
|
<Select
|
||||||
require={true}
|
label="Select Payment Currency"
|
||||||
|
required="true"
|
||||||
defaultValue={this.defaultCurrency}
|
defaultValue={this.defaultCurrency}
|
||||||
inputProps={{
|
inputProps={{
|
||||||
style: {textAlign:"center"}
|
style: {textAlign:"center"}
|
||||||
@ -152,35 +164,13 @@ export default class MakerPage extends Component {
|
|||||||
<MenuItem value={2}>EUR</MenuItem>
|
<MenuItem value={2}>EUR</MenuItem>
|
||||||
<MenuItem value={3}>ETH</MenuItem>
|
<MenuItem value={3}>ETH</MenuItem>
|
||||||
</Select>
|
</Select>
|
||||||
<FormHelperText>
|
|
||||||
<div align='center'>
|
|
||||||
Select Payment Currency
|
|
||||||
</div>
|
|
||||||
</FormHelperText>
|
|
||||||
</FormControl>
|
</FormControl>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<Grid item xs={12} align="center">
|
<Grid item xs={12} align="center">
|
||||||
<FormControl >
|
<FormControl >
|
||||||
<TextField
|
<TextField
|
||||||
type="number"
|
label="Payment Method(s)"
|
||||||
require={true}
|
|
||||||
defaultValue={this.defaultAmount}
|
|
||||||
inputProps={{
|
|
||||||
min:0 ,
|
|
||||||
style: {textAlign:"center"}
|
|
||||||
}}
|
|
||||||
onChange={this.handleAmountChange}
|
|
||||||
/>
|
|
||||||
</FormControl>
|
|
||||||
<FormHelperText>
|
|
||||||
<div align='center'>
|
|
||||||
Amount of Fiat to Trade
|
|
||||||
</div>
|
|
||||||
</FormHelperText>
|
|
||||||
</Grid>
|
|
||||||
<Grid item xs={12} align="center">
|
|
||||||
<FormControl >
|
|
||||||
<TextField
|
|
||||||
type="text"
|
type="text"
|
||||||
require={true}
|
require={true}
|
||||||
inputProps={{
|
inputProps={{
|
||||||
@ -188,11 +178,6 @@ export default class MakerPage extends Component {
|
|||||||
}}
|
}}
|
||||||
onChange={this.handlePaymentMethodChange}
|
onChange={this.handlePaymentMethodChange}
|
||||||
/>
|
/>
|
||||||
<FormHelperText>
|
|
||||||
<div align='center'>
|
|
||||||
Enter the Payment Method(s)
|
|
||||||
</div>
|
|
||||||
</FormHelperText>
|
|
||||||
</FormControl>
|
</FormControl>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xs={12} align="center">
|
<Grid item xs={12} align="center">
|
||||||
@ -224,43 +209,30 @@ export default class MakerPage extends Component {
|
|||||||
{/* conditional shows either Premium % field or Satoshis field based on pricing method */}
|
{/* conditional shows either Premium % field or Satoshis field based on pricing method */}
|
||||||
{ this.state.isExplicit
|
{ this.state.isExplicit
|
||||||
? <Grid item xs={12} align="center">
|
? <Grid item xs={12} align="center">
|
||||||
<FormControl >
|
<TextField
|
||||||
<TextField
|
label="Explicit Amount in Satoshis"
|
||||||
type="number"
|
type="number"
|
||||||
require={true}
|
required="true"
|
||||||
inputProps={{
|
inputProps={{
|
||||||
// TODO read these from .env file
|
// TODO read these from .env file
|
||||||
min:10000 ,
|
min:10000 ,
|
||||||
max:500000 ,
|
max:500000 ,
|
||||||
style: {textAlign:"center"}
|
style: {textAlign:"center"}
|
||||||
}}
|
}}
|
||||||
onChange={this.handleSatoshisChange}
|
onChange={this.handleSatoshisChange}
|
||||||
defaultValue={this.defaultSatoshis}
|
// defaultValue={this.defaultSatoshis}
|
||||||
/>
|
/>
|
||||||
<FormHelperText>
|
|
||||||
<div align='center'>
|
|
||||||
Explicit Amount in Satoshis
|
|
||||||
</div>
|
|
||||||
</FormHelperText>
|
|
||||||
</FormControl>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
: <Grid item xs={12} align="center">
|
: <Grid item xs={12} align="center">
|
||||||
<FormControl >
|
<TextField
|
||||||
<TextField
|
label="Premium over Market (%)"
|
||||||
type="number"
|
type="number"
|
||||||
require={true}
|
// defaultValue={this.defaultPremium}
|
||||||
defaultValue={this.defaultPremium}
|
inputProps={{
|
||||||
inputProps={{
|
style: {textAlign:"center"}
|
||||||
style: {textAlign:"center"}
|
}}
|
||||||
}}
|
onChange={this.handlePremiumChange}
|
||||||
onChange={this.handlePremiumChange}
|
/>
|
||||||
/>
|
|
||||||
<FormHelperText>
|
|
||||||
<div align='center'>
|
|
||||||
Premium Relative to Market Price (%)
|
|
||||||
</div>
|
|
||||||
</FormHelperText>
|
|
||||||
</FormControl>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
}
|
}
|
||||||
<Grid item xs={12} align="center">
|
<Grid item xs={12} align="center">
|
||||||
|
@ -2,6 +2,11 @@ import React, { Component } from "react";
|
|||||||
import { Button , Grid, Typography, List, ListItem, ListItemText, ListItemAvatar, Avatar, Divider} from "@material-ui/core"
|
import { Button , Grid, Typography, List, ListItem, ListItemText, ListItemAvatar, Avatar, Divider} from "@material-ui/core"
|
||||||
import { Link } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
|
|
||||||
|
// pretty numbers
|
||||||
|
function pn(x) {
|
||||||
|
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
||||||
|
}
|
||||||
|
|
||||||
export default class OrderPage extends Component {
|
export default class OrderPage extends Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props);
|
super(props);
|
||||||
@ -49,14 +54,13 @@ export default class OrderPage extends Component {
|
|||||||
<Avatar
|
<Avatar
|
||||||
alt={this.state.makerNick}
|
alt={this.state.makerNick}
|
||||||
src={window.location.origin +'/static/assets/avatars/' + this.state.makerNick + '.png'}
|
src={window.location.origin +'/static/assets/avatars/' + this.state.makerNick + '.png'}
|
||||||
sx={{ width: 56, height: 56 }}
|
|
||||||
/>
|
/>
|
||||||
</ListItemAvatar>
|
</ListItemAvatar>
|
||||||
<ListItemText primary={this.state.makerNick} secondary="Order maker" />
|
<ListItemText primary={this.state.makerNick} secondary="Order maker" />
|
||||||
</ListItem>
|
</ListItem>
|
||||||
<Divider />
|
<Divider />
|
||||||
<ListItem>
|
<ListItem>
|
||||||
<ListItemText primary={this.state.amount+" "+this.state.currencyCode} secondary="Amount and currency requested"/>
|
<ListItemText primary={parseFloat(parseFloat(this.state.amount).toFixed(4))+" "+this.state.currencyCode} secondary="Amount and currency requested"/>
|
||||||
</ListItem>
|
</ListItem>
|
||||||
<Divider />
|
<Divider />
|
||||||
<ListItem>
|
<ListItem>
|
||||||
@ -65,9 +69,9 @@ export default class OrderPage extends Component {
|
|||||||
<Divider />
|
<Divider />
|
||||||
<ListItem>
|
<ListItem>
|
||||||
{this.state.isExplicit ?
|
{this.state.isExplicit ?
|
||||||
<ListItemText primary={this.state.satoshis} secondary="Amount of Satoshis"/>
|
<ListItemText primary={pn(this.state.satoshis)} secondary="Amount of Satoshis"/>
|
||||||
:
|
:
|
||||||
<ListItemText primary={this.state.premium} secondary="Premium over market price"/>
|
<ListItemText primary={parseFloat(parseFloat(this.state.premium).toFixed(2))+"%"} secondary="Premium over market price"/>
|
||||||
}
|
}
|
||||||
</ListItem>
|
</ListItem>
|
||||||
<Divider />
|
<Divider />
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import { Button , Grid, Typography, TextField, Select, FormHelperText, MenuItem, FormControl, Radio, FormControlLabel, RadioGroup, Menu} from "@material-ui/core"
|
import { Button , Grid, Typography, TextField, ButtonGroup} from "@material-ui/core"
|
||||||
import { Link } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
import Image from 'material-ui-image'
|
import Image from 'material-ui-image'
|
||||||
|
|
||||||
@ -88,6 +88,31 @@ export default class UserGenPage extends Component {
|
|||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<Grid container spacing={1}>
|
<Grid container spacing={1}>
|
||||||
|
<Grid item xs={12} align="center">
|
||||||
|
<Typography component="h5" variant="h5">
|
||||||
|
<b>{this.state.nickname ? "⚡"+this.state.nickname+"⚡" : ""}</b>
|
||||||
|
</Typography>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={12} align="center">
|
||||||
|
<div style={{ maxWidth: 200, maxHeight: 200 }}>
|
||||||
|
<Image className='newAvatar'
|
||||||
|
disableError='true'
|
||||||
|
cover='true'
|
||||||
|
color='null'
|
||||||
|
src={this.state.avatar_url}
|
||||||
|
/>
|
||||||
|
</div><br/>
|
||||||
|
</Grid>
|
||||||
|
{
|
||||||
|
this.state.found ?
|
||||||
|
<Grid item xs={12} align="center">
|
||||||
|
<Typography component="subtitle2" variant="subtitle2" color='primary'>
|
||||||
|
{this.state.found}<br/>
|
||||||
|
</Typography>
|
||||||
|
</Grid>
|
||||||
|
:
|
||||||
|
""
|
||||||
|
}
|
||||||
<Grid item xs={12} align="center">
|
<Grid item xs={12} align="center">
|
||||||
<TextField
|
<TextField
|
||||||
error={this.state.bad_request}
|
error={this.state.bad_request}
|
||||||
@ -102,36 +127,19 @@ export default class UserGenPage extends Component {
|
|||||||
/>
|
/>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xs={12} align="center">
|
<Grid item xs={12} align="center">
|
||||||
<div style={{ maxWidth: 200, maxHeight: 200 }}>
|
<Button onClick={this.handleAnotherButtonPressed}>Generate Another Robosat</Button>
|
||||||
<Image className='newAvatar'
|
</Grid>
|
||||||
disableError='true'
|
<Grid item xs={12} align="center">
|
||||||
cover='true'
|
<ButtonGroup variant="contained" aria-label="outlined primary button group">
|
||||||
color='null'
|
<Button color='primary' to='/home' component={Link}>Buy BTC</Button>
|
||||||
src={this.state.avatar_url}
|
<Button to='/home' component={Link}>INFO</Button>
|
||||||
/>
|
<Button color='secondary' to='/home' component={Link}>Sell BTC</Button>
|
||||||
</div>
|
</ButtonGroup>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xs={12} align="center">
|
<Grid item xs={12} align="center">
|
||||||
<Typography component="h5" variant="h5">
|
<Typography component="h5" variant="h5">
|
||||||
<b>{this.state.nickname ? "⚡"+this.state.nickname+"⚡" : ""}</b>
|
Easy and Private Lightning peer-to-peer Exchange
|
||||||
</Typography>
|
</Typography>
|
||||||
</Grid>
|
|
||||||
{
|
|
||||||
this.state.found ?
|
|
||||||
<Grid item xs={12} align="center">
|
|
||||||
<Typography component="subtitle2" variant="subtitle2" color='primary'>
|
|
||||||
{this.state.found}<br/>
|
|
||||||
</Typography>
|
|
||||||
<Button variant='contained' color='primary' to='/home' component={Link}>Cool!</Button>
|
|
||||||
</Grid>
|
|
||||||
:
|
|
||||||
<Grid item xs={12} align="center">
|
|
||||||
<Button variant='contained' color='primary' to='/home' component={Link}>Take This Robosat!</Button>
|
|
||||||
</Grid>
|
|
||||||
}
|
|
||||||
|
|
||||||
<Grid item xs={12} align="center">
|
|
||||||
<Button variant='contained' to='/' component={Link} onClick={this.handleAnotherButtonPressed}>Give Me Another</Button>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user