From 0bc66ea15052572bbbd0016c851967c676502cb9 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sun, 14 Mar 2021 20:58:49 -0300 Subject: [PATCH] support all the currencies. --- lnbits/extensions/offlineshop/static/js/index.js | 11 ++++++++++- lnbits/extensions/offlineshop/views_api.py | 8 +++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lnbits/extensions/offlineshop/static/js/index.js b/lnbits/extensions/offlineshop/static/js/index.js index f7dbba9bc..00e932416 100644 --- a/lnbits/extensions/offlineshop/static/js/index.js +++ b/lnbits/extensions/offlineshop/static/js/index.js @@ -24,7 +24,7 @@ new Vue({ itemDialog: { show: false, data: {...defaultItemData}, - units: ['sat', 'USD'] + units: ['sat'] } } }, @@ -207,5 +207,14 @@ new Vue({ created() { this.selectedWallet = this.g.user.wallets[0] this.loadShop() + + LNbits.api + .request('GET', '/offlineshop/api/v1/currencies') + .then(response => { + this.itemDialog = {...this.itemDialog, units: ['sat', ...response.data]} + }) + .catch(err => { + LNbits.utils.notifyApiError(err) + }) } }) diff --git a/lnbits/extensions/offlineshop/views_api.py b/lnbits/extensions/offlineshop/views_api.py index fd60014a4..20a9eced0 100644 --- a/lnbits/extensions/offlineshop/views_api.py +++ b/lnbits/extensions/offlineshop/views_api.py @@ -3,6 +3,7 @@ from http import HTTPStatus from lnurl.exceptions import InvalidUrl as LnurlInvalidUrl # type: ignore from lnbits.decorators import api_check_wallet_key, api_validate_post_request +from lnbits.utils.exchange_rates import currencies from . import offlineshop_ext from .crud import ( @@ -16,6 +17,11 @@ from .crud import ( from .models import ShopCounter +@offlineshop_ext.route("/api/v1/currencies", methods=["GET"]) +async def api_list_currencies_available(): + return jsonify(list(currencies.keys())) + + @offlineshop_ext.route("/api/v1/offlineshop", methods=["GET"]) @api_check_wallet_key("invoice") async def api_shop_from_wallet(): @@ -51,7 +57,7 @@ async def api_shop_from_wallet(): "description": {"type": "string", "empty": False, "required": True}, "image": {"type": "string", "required": False, "nullable": True}, "price": {"type": "number", "required": True}, - "unit": {"type": "string", "allowed": ["sat", "USD"], "required": True}, + "unit": {"type": "string", "required": True}, } ) async def api_add_or_update_item(item_id=None):