change currencies.json access, fix async book filtering

This commit is contained in:
LowEntropyFace 2022-01-09 09:29:10 -05:00
parent 185e0af496
commit 229294b878
8 changed files with 13 additions and 35 deletions

View File

@ -84,7 +84,7 @@ class Order(models.Model):
MLD = 16, 'Maker lost dispute' MLD = 16, 'Maker lost dispute'
TLD = 17, 'Taker 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())] currency_choices = [(int(val), label) for val, label in list(currency_dict.items())]
print(currency_choices) print(currency_choices)

View File

@ -1,5 +1,5 @@
from django.urls import path 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 = [ urlpatterns = [
path('make/', MakerView.as_view()), path('make/', MakerView.as_view()),
@ -8,5 +8,4 @@ urlpatterns = [
path('book/', BookView.as_view()), path('book/', BookView.as_view()),
# path('robot/') # Profile Info # path('robot/') # Profile Info
path('info/', InfoView.as_view()), path('info/', InfoView.as_view()),
path('currencies/', get_currencies_json),
] ]

View File

@ -21,9 +21,6 @@ from datetime import timedelta
from django.utils import timezone from django.utils import timezone
from decouple import config from decouple import config
import json
from django.http import HttpResponse
EXP_MAKER_BOND_INVOICE = int(config('EXP_MAKER_BOND_INVOICE')) EXP_MAKER_BOND_INVOICE = int(config('EXP_MAKER_BOND_INVOICE'))
FEE = float(config('FEE')) FEE = float(config('FEE'))
@ -387,9 +384,4 @@ class InfoView(ListAPIView):
return Response(context, status.HTTP_200_OK) 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")

View File

@ -12,15 +12,15 @@ export default class BookPage extends Component {
currencies_dict: {"1":"USD"} currencies_dict: {"1":"USD"}
}; };
this.getCurrencyDict() this.getCurrencyDict()
this.getOrderDetails() this.getOrderDetails(this.state.type,this.state.currency)
this.state.currencyCode = this.getCurrencyCode(this.state.currency) this.state.currencyCode = this.getCurrencyCode(this.state.currency)
} }
// Show message to be the first one to make an order // Show message to be the first one to make an order
getOrderDetails() { getOrderDetails(type,currency) {
fetch('/api/book' + '?currency=' + this.state.currency + "&type=" + this.state.type) fetch('/api/book' + '?currency=' + currency + "&type=" + type)
.then((response) => response.json()) .then((response) => response.json())
.then((data) => //console.log(data)); .then((data) =>
this.setState({ this.setState({
orders: data, orders: data,
not_found: data.not_found, not_found: data.not_found,
@ -32,31 +32,29 @@ export default class BookPage extends Component {
this.props.history.push('/order/' + e); this.props.history.push('/order/' + e);
} }
// Make these two functions sequential. getOrderDetails needs setState to be finish beforehand.
handleTypeChange=(e)=>{ handleTypeChange=(e)=>{
this.setState({ this.setState({
type: e.target.value, type: e.target.value,
}); });
this.getOrderDetails(); this.getOrderDetails(e.target.value,this.state.currency);
} }
handleCurrencyChange=(e)=>{ handleCurrencyChange=(e)=>{
this.setState({ this.setState({
currency: e.target.value, currency: e.target.value,
currencyCode: this.getCurrencyCode(e.target.value), currencyCode: this.getCurrencyCode(e.target.value),
}) })
this.getOrderDetails(); this.getOrderDetails(this.state.type, e.target.value);
} }
getCurrencyDict() { getCurrencyDict() {
fetch('/api/currencies') fetch('/static/assets/currencies.json')
.then((response) => response.json()) .then((response) => response.json())
.then((data) => .then((data) =>
this.setState({ this.setState({
currencies_dict: data 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){ getCurrencyCode(val){
return this.state.currencies_dict[val.toString()] return this.state.currencies_dict[val.toString()]
} }

View File

@ -110,7 +110,7 @@ export default class MakerPage extends Component {
} }
getCurrencyDict() { getCurrencyDict() {
fetch('/api/currencies') fetch('/static/assets/currencies.json')
.then((response) => response.json()) .then((response) => response.json())
.then((data) => .then((data) =>
this.setState({ this.setState({

View File

@ -132,12 +132,6 @@ export default class OrderPage extends Component {
this.setState({ delay: Number(e.target.value) }); 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 // Fix to use proper react props
handleClickBackButton=()=>{ handleClickBackButton=()=>{
window.history.back(); window.history.back();
@ -157,7 +151,7 @@ export default class OrderPage extends Component {
.then((data) => (console.log(data) & this.getOrderDetails(data.id))); .then((data) => (console.log(data) & this.getOrderDetails(data.id)));
} }
getCurrencyDict() { getCurrencyDict() {
fetch('/api/currencies') fetch('/static/assets/currencies.json')
.then((response) => response.json()) .then((response) => response.json())
.then((data) => .then((data) =>
this.setState({ 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){ getCurrencyCode(val){
console.log("---------------------------------")
console.log(val)
return this.state.currencies_dict[val.toString()] return this.state.currencies_dict[val.toString()]
} }

View File

@ -9,5 +9,4 @@ urlpatterns = [
path('book/', index), path('book/', index),
path('order/<int:orderId>', index), path('order/<int:orderId>', index),
path('wait/', index), path('wait/', index),
path('currencies/',index)
] ]