From 400fb2b21e28430c697dfa562742981398fb3a62 Mon Sep 17 00:00:00 2001 From: LowEntropyFace Date: Sat, 8 Jan 2022 07:48:03 -0500 Subject: [PATCH] OrderPage.js, MakerPage.js use currencies.json --- api/currencies.json | 4 +++- api/models.py | 2 +- frontend/src/components/BookPage.js | 2 +- frontend/src/components/MakerPage.js | 7 ++++--- frontend/src/components/OrderPage.js | 24 ++++++++++++++++++------ 5 files changed, 27 insertions(+), 12 deletions(-) diff --git a/api/currencies.json b/api/currencies.json index bf3a4382..f246908d 100644 --- a/api/currencies.json +++ b/api/currencies.json @@ -2,5 +2,7 @@ "1":"USD", "2":"EUR", "3":"ETH", - "4":"ABC" + "4":"AUD", + "5":"BRL", + "6":"CAD" } diff --git a/api/models.py b/api/models.py index 8dbfe09a..bda4d442 100644 --- a/api/models.py +++ b/api/models.py @@ -128,7 +128,7 @@ class Order(models.Model): def __str__(self): # Make relational back to ORDER - return (f'Order {self.id}: {self.Types(self.type).label} BTC for {self.amount} {self.Currencies(self.currency).label}') + return (f'Order {self.id}: {self.Types(self.type).label} BTC for {self.amount} {self.currency_dict[str(self.currency)]}') @receiver(pre_delete, sender=Order) def delelete_HTLCs_at_order_deletion(sender, instance, **kwargs): diff --git a/frontend/src/components/BookPage.js b/frontend/src/components/BookPage.js index 961c72b9..10a591ae 100644 --- a/frontend/src/components/BookPage.js +++ b/frontend/src/components/BookPage.js @@ -11,8 +11,8 @@ export default class BookPage extends Component { type: 1, currencies_dict: {"1":"USD"} }; - this.getOrderDetails() this.getCurrencyDict() + this.getOrderDetails() this.state.currencyCode = this.getCurrencyCode(this.state.currency) } diff --git a/frontend/src/components/MakerPage.js b/frontend/src/components/MakerPage.js index e3912385..f0635c59 100644 --- a/frontend/src/components/MakerPage.js +++ b/frontend/src/components/MakerPage.js @@ -178,9 +178,10 @@ export default class MakerPage extends Component { }} onChange={this.handleCurrencyChange} > - USD - EUR - ETH + { + Object.entries(this.state.currencies_dict) + .map( ([key, value]) => {value} ) + } diff --git a/frontend/src/components/OrderPage.js b/frontend/src/components/OrderPage.js index 86ed50ec..adc11cc3 100644 --- a/frontend/src/components/OrderPage.js +++ b/frontend/src/components/OrderPage.js @@ -40,8 +40,10 @@ export default class OrderPage extends Component { super(props); this.state = { isExplicit: false, + currencies_dict: {"1":"USD"} }; this.orderId = this.props.match.params.orderId; + this.getCurrencyDict(); this.getOrderDetails(); } @@ -49,6 +51,7 @@ export default class OrderPage extends Component { fetch('/api/order' + '?order_id=' + this.orderId) .then((response) => response.json()) .then((data) => { + console.log(data) this.setState({ statusCode: data.status, statusText: data.status_message, @@ -73,12 +76,6 @@ 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){ - return (val == 1 ) ? "USD": ((val == 2 ) ? "EUR":"ETH") - } - // Fix to use proper react props handleClickBackButton=()=>{ window.history.back(); @@ -97,6 +94,21 @@ export default class OrderPage extends Component { .then((response) => response.json()) .then((data) => (console.log(data) & this.getOrderDetails(data.id))); } + getCurrencyDict() { + fetch('/api/currencies') + .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){ + console.log("---------------------------------") + console.log(val) + return this.state.currencies_dict[val.toString()] + } render (){ return (