From afd90f8fbf672a1fc38486e3d54c7cf2da605e1d Mon Sep 17 00:00:00 2001 From: Reckless_Satoshi Date: Mon, 3 Jan 2022 04:11:33 -0800 Subject: [PATCH] Improve content and handling on OrderPage --- api/views.py | 17 +++-- frontend/src/components/OrderPage.js | 102 ++++++++++++++++++--------- 2 files changed, 80 insertions(+), 39 deletions(-) diff --git a/api/views.py b/api/views.py index 7a9e4f4c..784cd096 100644 --- a/api/views.py +++ b/api/views.py @@ -1,4 +1,4 @@ -from rest_framework import status +from rest_framework import serializers, status from rest_framework.views import APIView from rest_framework.response import Response from django.contrib.auth import authenticate, login, logout @@ -32,8 +32,7 @@ class MakeOrder(APIView): payment_method = serializer.data.get('payment_method') premium = serializer.data.get('premium') satoshis = serializer.data.get('satoshis') - - user = User.objects.get(id=request.user.id) + is_explicit = serializer.data.get('is_explicit') # query if the user is already a maker or taker, return error queryset = Order.objects.filter(maker=request.user.id) @@ -51,7 +50,8 @@ class MakeOrder(APIView): payment_method=payment_method, premium=premium, satoshis=satoshis, - maker=user) + is_explicit=is_explicit, + maker=request.user) order.save() if not serializer.is_valid(): @@ -72,19 +72,24 @@ class OrderView(APIView): # check if exactly one order is found in the db if len(order) == 1 : - print("It is only one!") order = order[0] data = self.serializer_class(order).data nickname = request.user.username # Check if requester is participant in the order and add boolean to response data['is_participant'] = (str(order.maker) == nickname or str(order.taker) == nickname) + + #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['maker_nick'] = str(order.maker) + data['taker_nick'] = str(order.taker) if data['is_participant']: return Response(data, status=status.HTTP_200_OK) else: # Non participants should not see the status or who is the taker - data.pop('status','taker') + data.pop('status','status_message','taker','taker_nick') return Response(data, status=status.HTTP_200_OK) return Response({'Order Not Found':'Invalid Order Id'},status=status.HTTP_404_NOT_FOUND) diff --git a/frontend/src/components/OrderPage.js b/frontend/src/components/OrderPage.js index 77dff7ff..351d273e 100644 --- a/frontend/src/components/OrderPage.js +++ b/frontend/src/components/OrderPage.js @@ -1,23 +1,12 @@ import React, { Component } from "react"; +import { Button , Grid, Typography, List, ListItem, ListItemText, ListItemAvatar, Avatar, Divider} from "@material-ui/core" +import { Link } from 'react-router-dom' export default class OrderPage extends Component { constructor(props) { super(props); this.state = { - status: 0, - type: 0, - currency: 0, - currencyCode: 'USD', - is_participant: false, - amount: 1, - paymentMethod:"", isExplicit: false, - premium: 0, - satoshis: null, - makerId: "", - // makerNick:"", - // takerId: "", - // takerNick:"", }; this.orderId = this.props.match.params.orderId; this.getOrderDetails(); @@ -28,37 +17,84 @@ export default class OrderPage extends Component { .then((response) => response.json()) .then((data) => { this.setState({ - status: data.status, + statusCode: data.status, + statusText: data.status_message, type: data.type, currency: data.currency, + currencyCode: (data.currency== 1 ) ? "USD": ((data.currency == 2 ) ? "EUR":"ETH"), amount: data.amount, paymentMethod: data.payment_method, isExplicit: data.is_explicit, - //premium: data.premium, - // satoshis: satoshis, - // makerId: maker, - // isParticipant: is_participant, - // makerNick: maker_nick, - // takerId: taker, - // takerNick: taker_nick, + premium: data.premium, + satoshis: data.satoshis, + makerId: data.maker, + isParticipant: data.is_participant, + makerNick: data.maker_nick, + takerId: data.taker, + takerNick: data.taker_nick, }); }); } render (){ return ( -
-

This is the single order detail view page

-

Order id: {this.orderId}

-

Order status: {this.state.status}

-

Order type: {this.state.type}

-

Currency: {this.state.currencyCode}

-

Amount: {this.state.amount}

-

Payment method: {this.state.paymentMethod}

-

Pricing method is explicit: {this.state.isExplicit.toString()}

- {/*

Premium: {this.state.premium}

-

Maker: {this.makerId}

*/} -
+ + + + Robosat BTC {this.state.type ? " Sell " : " Buy "} Order + + + + + + + + + + + + + + + + + + + {this.state.isExplicit ? + + : + + } + + + {this.state.isParticipant ? + <> + + + + + { this.state.takerNick!='None' ? + <> + + + : ""} + + :"" + } + + + + + + + {this.state.isParticipant ? "" : } + + + ); } } \ No newline at end of file