From 229294b878f0761ec4ba74bca5d04bd413c4e77a Mon Sep 17 00:00:00 2001 From: LowEntropyFace Date: Sun, 9 Jan 2022 09:29:10 -0500 Subject: [PATCH] change currencies.json access, fix async book filtering --- api/models.py | 2 +- api/urls.py | 3 +-- api/views.py | 8 -------- frontend/src/components/BookPage.js | 18 ++++++++---------- frontend/src/components/MakerPage.js | 2 +- frontend/src/components/OrderPage.js | 14 ++------------ .../static/assets}/currencies.json | 0 frontend/urls.py | 1 - 8 files changed, 13 insertions(+), 35 deletions(-) rename {api => frontend/static/assets}/currencies.json (100%) diff --git a/api/models.py b/api/models.py index 359ba096..dfc86a9b 100644 --- a/api/models.py +++ b/api/models.py @@ -84,7 +84,7 @@ class Order(models.Model): MLD = 16, 'Maker lost dispute' TLD = 17, 'Taker lost dispute' - currency_dict = json.load(open('./api/currencies.json')) + currency_dict = json.load(open('./frontend/static/assets/currencies.json')) currency_choices = [(int(val), label) for val, label in list(currency_dict.items())] print(currency_choices) diff --git a/api/urls.py b/api/urls.py index 172994dd..563fb14c 100644 --- a/api/urls.py +++ b/api/urls.py @@ -1,5 +1,5 @@ from django.urls import path -from .views import MakerView, OrderView, UserView, BookView, InfoView, get_currencies_json +from .views import MakerView, OrderView, UserView, BookView, InfoView urlpatterns = [ path('make/', MakerView.as_view()), @@ -8,5 +8,4 @@ urlpatterns = [ path('book/', BookView.as_view()), # path('robot/') # Profile Info path('info/', InfoView.as_view()), - path('currencies/', get_currencies_json), ] \ No newline at end of file diff --git a/api/views.py b/api/views.py index 4215f793..ed6dab9e 100644 --- a/api/views.py +++ b/api/views.py @@ -21,9 +21,6 @@ from datetime import timedelta from django.utils import timezone from decouple import config -import json -from django.http import HttpResponse - EXP_MAKER_BOND_INVOICE = int(config('EXP_MAKER_BOND_INVOICE')) FEE = float(config('FEE')) @@ -386,10 +383,5 @@ class InfoView(ListAPIView): context['total_volume'] = None return Response(context, status.HTTP_200_OK) - -def get_currencies_json(request): - currency_dict = json.load(open('./api/currencies.json')) - return HttpResponse(json.dumps(currency_dict),content_type="application/json") - diff --git a/frontend/src/components/BookPage.js b/frontend/src/components/BookPage.js index 10a591ae..c119b37b 100644 --- a/frontend/src/components/BookPage.js +++ b/frontend/src/components/BookPage.js @@ -12,15 +12,15 @@ export default class BookPage extends Component { currencies_dict: {"1":"USD"} }; this.getCurrencyDict() - this.getOrderDetails() + this.getOrderDetails(this.state.type,this.state.currency) this.state.currencyCode = this.getCurrencyCode(this.state.currency) } // Show message to be the first one to make an order - getOrderDetails() { - fetch('/api/book' + '?currency=' + this.state.currency + "&type=" + this.state.type) + getOrderDetails(type,currency) { + fetch('/api/book' + '?currency=' + currency + "&type=" + type) .then((response) => response.json()) - .then((data) => //console.log(data)); + .then((data) => this.setState({ orders: data, not_found: data.not_found, @@ -32,31 +32,29 @@ export default class BookPage extends Component { this.props.history.push('/order/' + e); } - // Make these two functions sequential. getOrderDetails needs setState to be finish beforehand. handleTypeChange=(e)=>{ this.setState({ type: e.target.value, }); - this.getOrderDetails(); + this.getOrderDetails(e.target.value,this.state.currency); } handleCurrencyChange=(e)=>{ this.setState({ currency: e.target.value, currencyCode: this.getCurrencyCode(e.target.value), }) - this.getOrderDetails(); + this.getOrderDetails(this.state.type, e.target.value); } getCurrencyDict() { - fetch('/api/currencies') + fetch('/static/assets/currencies.json') .then((response) => response.json()) .then((data) => this.setState({ currencies_dict: data })); } - // Gets currency code (3 letters) from numeric (e.g., 1 -> USD) - // Improve this function so currencies are read from json + getCurrencyCode(val){ return this.state.currencies_dict[val.toString()] } diff --git a/frontend/src/components/MakerPage.js b/frontend/src/components/MakerPage.js index 5bd46427..68191be7 100644 --- a/frontend/src/components/MakerPage.js +++ b/frontend/src/components/MakerPage.js @@ -110,7 +110,7 @@ export default class MakerPage extends Component { } getCurrencyDict() { - fetch('/api/currencies') + fetch('/static/assets/currencies.json') .then((response) => response.json()) .then((data) => this.setState({ diff --git a/frontend/src/components/OrderPage.js b/frontend/src/components/OrderPage.js index 9eff532f..03045456 100644 --- a/frontend/src/components/OrderPage.js +++ b/frontend/src/components/OrderPage.js @@ -132,12 +132,6 @@ export default class OrderPage extends Component { this.setState({ delay: Number(e.target.value) }); } - // Gets currency code (3 letters) from numeric (e.g., 1 -> USD) - // Improve this function so currencies are read from json - getCurrencyCode(val){ - return (val == 1 ) ? "USD": ((val == 2 ) ? "EUR":"ETH") - } - // Fix to use proper react props handleClickBackButton=()=>{ window.history.back(); @@ -157,7 +151,7 @@ export default class OrderPage extends Component { .then((data) => (console.log(data) & this.getOrderDetails(data.id))); } getCurrencyDict() { - fetch('/api/currencies') + fetch('/static/assets/currencies.json') .then((response) => response.json()) .then((data) => this.setState({ @@ -165,11 +159,7 @@ export default class OrderPage extends Component { })); } - // Gets currency code (3 letters) from numeric (e.g., 1 -> USD) - // Improve this function so currencies are read from json getCurrencyCode(val){ - console.log("---------------------------------") - console.log(val) return this.state.currencies_dict[val.toString()] } @@ -318,4 +308,4 @@ export default class OrderPage extends Component { ) ); } -} \ No newline at end of file +} diff --git a/api/currencies.json b/frontend/static/assets/currencies.json similarity index 100% rename from api/currencies.json rename to frontend/static/assets/currencies.json diff --git a/frontend/urls.py b/frontend/urls.py index d7b68630..e938dc97 100644 --- a/frontend/urls.py +++ b/frontend/urls.py @@ -9,5 +9,4 @@ urlpatterns = [ path('book/', index), path('order/', index), path('wait/', index), - path('currencies/',index) ] \ No newline at end of file