From 86d2780c9f57df5dd9d4c59c554e3b923704c9c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?dni=20=E2=9A=A1?= Date: Wed, 30 Nov 2022 23:47:52 +0100 Subject: [PATCH] fix template typos and also update settings in memory after a admin PUT --- lnbits/core/crud.py | 4 ++-- lnbits/extensions/admin/crud.py | 10 ++++++---- .../extensions/admin/templates/admin/_tab_users.html | 8 +++----- lnbits/extensions/admin/templates/admin/index.html | 2 +- lnbits/extensions/admin/views_api.py | 2 -- lnbits/settings.py | 5 ----- 6 files changed, 12 insertions(+), 19 deletions(-) diff --git a/lnbits/core/crud.py b/lnbits/core/crud.py index eb0d64de8..6e498c60a 100644 --- a/lnbits/core/crud.py +++ b/lnbits/core/crud.py @@ -232,8 +232,8 @@ async def get_wallet_payment( async def get_latest_payments_by_extension(ext_name: str, ext_id: str, limit: int = 5): rows = await db.fetchall( f""" - SELECT * FROM apipayments - WHERE pending = 'false' + SELECT * FROM apipayments + WHERE pending = 'false' AND extra LIKE ? AND extra LIKE ? ORDER BY time DESC LIMIT {limit} diff --git a/lnbits/extensions/admin/crud.py b/lnbits/extensions/admin/crud.py index 7f9779b0d..c6c5a31a7 100644 --- a/lnbits/extensions/admin/crud.py +++ b/lnbits/extensions/admin/crud.py @@ -1,4 +1,4 @@ -from typing import List, Optional +from typing import Optional from lnbits.core.crud import create_payment from lnbits.helpers import urlsafe_short_hash @@ -7,10 +7,10 @@ from lnbits.tasks import internal_invoice_queue from . import db from .models import AdminSettings, UpdateSettings +from lnbits.settings import settings -async def update_wallet_balance(wallet_id: str, amount: int) -> None: - temp_id = f"temp_{urlsafe_short_hash()}" +async def update_wallet_balance(wallet_id: str, amount: int): internal_id = f"internal_{urlsafe_short_hash()}" payment = await create_payment( @@ -25,6 +25,8 @@ async def update_wallet_balance(wallet_id: str, amount: int) -> None: # manually send this for now await internal_invoice_queue.put(internal_id) + return payment + async def get_settings() -> AdminSettings: row = await db.fetchone("SELECT * FROM admin.settings") @@ -39,6 +41,7 @@ async def get_settings() -> AdminSettings: async def update_settings(data: UpdateSettings) -> Optional[Settings]: fields = [] for key, value in data.dict(exclude_none=True).items(): + setattr(settings, key, value) if not key in read_only_variables: if type(value) == list: joined = ",".join(value) @@ -52,7 +55,6 @@ async def update_settings(data: UpdateSettings) -> Optional[Settings]: fields.append(f"{key} = '{value}'") q = ", ".join(fields) - print("UPDATE", q) await db.execute(f"UPDATE admin.settings SET {q}") row = await db.fetchone("SELECT * FROM admin.settings") assert row, "Newly updated settings couldn't be retrieved" diff --git a/lnbits/extensions/admin/templates/admin/_tab_users.html b/lnbits/extensions/admin/templates/admin/_tab_users.html index 08b08a628..b0320fdaf 100644 --- a/lnbits/extensions/admin/templates/admin/_tab_users.html +++ b/lnbits/extensions/admin/templates/admin/_tab_users.html @@ -3,7 +3,7 @@
User Management

- Super Admin: {% raw %}{{settings.lnbits_admin_users[0]}}{% endraw %} + Super Admin: {{ settings.lnbits_admin_users[0] }}


@@ -19,18 +19,16 @@
- {% raw %} - {{ user }} + {{ user.id }} - {% endraw %}

diff --git a/lnbits/extensions/admin/templates/admin/index.html b/lnbits/extensions/admin/templates/admin/index.html index 103912615..afe63cb48 100644 --- a/lnbits/extensions/admin/templates/admin/index.html +++ b/lnbits/extensions/admin/templates/admin/index.html @@ -263,7 +263,7 @@ } ], [ - 'LnbitsWallet', + 'LNbitsWallet', { lnbits_endpoint: { value: null, diff --git a/lnbits/extensions/admin/views_api.py b/lnbits/extensions/admin/views_api.py index dfd6497e4..0dedb9fc7 100644 --- a/lnbits/extensions/admin/views_api.py +++ b/lnbits/extensions/admin/views_api.py @@ -12,7 +12,6 @@ from lnbits.server import server_restart from .crud import delete_settings, get_settings, update_settings, update_wallet_balance -from lnbits.settings import settings, set_settings @admin_ext.get( @@ -53,7 +52,6 @@ async def api_update_settings( data: UpdateSettings = Body(...), ): settings = await update_settings(data) - set_settings(settings) if settings: return {"status": "Success", "settings": settings.dict()} diff --git a/lnbits/settings.py b/lnbits/settings.py index f84cfb4b1..4fb86846e 100644 --- a/lnbits/settings.py +++ b/lnbits/settings.py @@ -176,11 +176,6 @@ if not settings.lnbits_admin_ui: logger.debug(f"{key}: {value}") -def set_settings(**kwargs): - for key, value in kwargs.items(): - setattr(settings, key, value) - - def set_cli_settings(**kwargs): for key, value in kwargs.items(): setattr(settings, key, value)