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'
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)

View File

@ -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),
]

View File

@ -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")

View File

@ -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()]
}

View File

@ -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({

View File

@ -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 {
</Grid>)
);
}
}
}

View File

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