feat: reduce initial requests on wallet page (#2335)

* feat: reduce initial request on wallet page
- refactor allowed_currencies into function to use in generic and api.
- remove currencies request in frontend move it to generic
- dont request balance on first payments fetch
This commit is contained in:
dni ⚡
2024-03-22 12:59:49 +01:00
committed by GitHub
parent 5b022e2ef3
commit 299228b7b5
5 changed files with 24 additions and 21 deletions

View File

@@ -71,7 +71,7 @@ from lnbits.helpers import generate_filter_params_openapi, url_for
from lnbits.lnurl import decode as lnurl_decode from lnbits.lnurl import decode as lnurl_decode
from lnbits.settings import settings from lnbits.settings import settings
from lnbits.utils.exchange_rates import ( from lnbits.utils.exchange_rates import (
currencies, allowed_currencies,
fiat_amount_as_satoshis, fiat_amount_as_satoshis,
satoshis_amount_as_fiat, satoshis_amount_as_fiat,
) )
@@ -722,14 +722,8 @@ async def api_perform_lnurlauth(
@api_router.get("/api/v1/currencies") @api_router.get("/api/v1/currencies")
async def api_list_currencies_available(): async def api_list_currencies_available() -> List[str]:
if len(settings.lnbits_allowed_currencies) > 0: return allowed_currencies()
return [
item
for item in currencies.keys()
if item.upper() in settings.lnbits_allowed_currencies
]
return list(currencies.keys())
@api_router.post("/api/v1/conversion") @api_router.post("/api/v1/conversion")

View File

@@ -21,7 +21,7 @@ from lnbits.settings import settings
from lnbits.wallets import get_wallet_class from lnbits.wallets import get_wallet_class
from ...extension_manager import InstallableExtension, get_valid_extensions from ...extension_manager import InstallableExtension, get_valid_extensions
from ...utils.exchange_rates import currencies from ...utils.exchange_rates import allowed_currencies, currencies
from ..crud import ( from ..crud import (
create_account, create_account,
create_wallet, create_wallet,
@@ -216,6 +216,7 @@ async def wallet(
"request": request, "request": request,
"user": user.dict(), "user": user.dict(),
"wallet": user_wallet.dict(), "wallet": user_wallet.dict(),
"currencies": allowed_currencies(),
"service_fee": settings.lnbits_service_fee, "service_fee": settings.lnbits_service_fee,
"service_fee_max": settings.lnbits_service_fee_max, "service_fee_max": settings.lnbits_service_fee_max,
"web_manifest": f"/manifest/{user.id}.webmanifest", "web_manifest": f"/manifest/{user.id}.webmanifest",

View File

@@ -818,8 +818,10 @@ new Vue({
} }
}, },
watch: { watch: {
payments: function () { payments: function (_, oldVal) {
this.fetchBalance() if (oldVal && oldVal.length !== 0) {
this.fetchBalance()
}
}, },
'paymentsChart.group': function () { 'paymentsChart.group': function () {
this.showChart() this.showChart()
@@ -837,18 +839,11 @@ new Vue({
this.mobileSimple = true this.mobileSimple = true
} }
this.fetchPayments() this.fetchPayments()
this.balance = Math.floor(window.wallet.balance_msat / 1000)
this.update.name = this.g.wallet.name this.update.name = this.g.wallet.name
this.update.currency = this.g.wallet.currency this.update.currency = this.g.wallet.currency
this.receive.units = ['sat', ...window.currencies]
LNbits.api
.request('GET', '/api/v1/currencies')
.then(response => {
this.receive.units = ['sat', ...response.data]
})
.catch(err => {
LNbits.utils.notifyApiError(err)
})
}, },
mounted: function () { mounted: function () {
// show disclaimer // show disclaimer

View File

@@ -1,6 +1,9 @@
{% macro window_vars(user, wallet) -%} {% macro window_vars(user, wallet) -%}
<script> <script>
window.extensions = {{ EXTENSIONS | tojson | safe }}; window.extensions = {{ EXTENSIONS | tojson | safe }};
{% if currencies %}
window.currencies = {{ currencies | tojson | safe }};
{% endif %}
{% if user %} {% if user %}
window.user = {{ user | tojson | safe }}; window.user = {{ user | tojson | safe }};
{% endif %} {% endif %}

View File

@@ -176,6 +176,16 @@ currencies = {
} }
def allowed_currencies():
if len(settings.lnbits_allowed_currencies) > 0:
return [
item
for item in currencies.keys()
if item.upper() in settings.lnbits_allowed_currencies
]
return list(currencies.keys())
class Provider(NamedTuple): class Provider(NamedTuple):
name: str name: str
domain: str domain: str