diff --git a/lnbits/extensions/satspay/crud.py b/lnbits/extensions/satspay/crud.py index 23d391b7b..a891e3a6f 100644 --- a/lnbits/extensions/satspay/crud.py +++ b/lnbits/extensions/satspay/crud.py @@ -2,6 +2,8 @@ from typing import List, Optional import httpx +from loguru import logger + from lnbits.core.services import create_invoice from lnbits.core.views.api import api_payment from lnbits.helpers import urlsafe_short_hash @@ -10,7 +12,8 @@ from ..watchonly.crud import get_config, get_fresh_address # from lnbits.db import open_ext_db from . import db -from .models import Charges, CreateCharge +from .models import Charges, CreateCharge, SatsPaySettings + ###############CHARGES########################## @@ -129,3 +132,36 @@ async def get_charge_config(charge_id: str): """SELECT "user" FROM satspay.charges WHERE id = ?""", (charge_id,) ) return await get_config(row.user) + + +################## SETTINGS ################### +async def save_settings(user: str, data: SatsPaySettings): + # insert or update + row = await db.fetchone( + """SELECT user FROM satspay.settings WHERE user = ?""", (user,) + ) + if row: + await db.execute( + """ + UPDATE satspay.settings SET custom_css = ? WHERE user = ? + """, + ( + data.custom_css, + user + ), + ) + else: + await db.execute( + """ + INSERT INTO satspay.settings ( + user, + custom_css + ) + VALUES (?, ?) + """, + ( + user, + data.custom_css, + ), + ) + return True diff --git a/lnbits/extensions/satspay/migrations.py b/lnbits/extensions/satspay/migrations.py index 3c72f12ab..ff4304512 100644 --- a/lnbits/extensions/satspay/migrations.py +++ b/lnbits/extensions/satspay/migrations.py @@ -35,7 +35,6 @@ async def m002_add_settings_table(db): await db.execute( """ CREATE TABLE satspay.settings ( - id TEXT NOT NULL PRIMARY KEY, "user" TEXT, custom_css TEXT ); diff --git a/lnbits/extensions/satspay/models.py b/lnbits/extensions/satspay/models.py index daf63f429..f62b64fe1 100644 --- a/lnbits/extensions/satspay/models.py +++ b/lnbits/extensions/satspay/models.py @@ -54,3 +54,6 @@ class Charges(BaseModel): return True else: return False + +class SatsPaySettings(BaseModel): + custom_css: str = Query(None) \ No newline at end of file diff --git a/lnbits/extensions/satspay/templates/satspay/index.html b/lnbits/extensions/satspay/templates/satspay/index.html index 396200cf1..f93379337 100644 --- a/lnbits/extensions/satspay/templates/satspay/index.html +++ b/lnbits/extensions/satspay/templates/satspay/index.html @@ -8,6 +8,11 @@ New charge + + SatsPay settings + + @@ -389,6 +394,33 @@ + + + + + + Custom CSS to apply styles to your SatsPay invoice + +
+ Save Settings + Cancel +
+
+
+
{% endblock %} {% block scripts %} {{ window_vars(user) }}