diff --git a/lnbits/extensions/satspay/crud.py b/lnbits/extensions/satspay/crud.py index 2591da9e..7f4161a5 100644 --- a/lnbits/extensions/satspay/crud.py +++ b/lnbits/extensions/satspay/crud.py @@ -100,17 +100,6 @@ async def get_charges(user: str) -> List[Charges]: return [Charges.from_row(row) for row in rows] -async def get_settings(user: str) -> SatsPaySettings: - row = await db.fetchone( - """SELECT * FROM satspay.settings WHERE "user" = ?""", - (user,), - ) - if row: - return SatsPaySettings.from_row(row) - else: - return None - - async def delete_charge(charge_id: str) -> None: await db.execute("DELETE FROM satspay.charges WHERE id = ?", (charge_id,)) @@ -135,30 +124,41 @@ async def check_address_balance(charge_id: str) -> Optional[Charges]: ################## SETTINGS ################### -async def save_settings(user: str, data: SatsPaySettings): +async def save_settings(user_id: str, data: SatsPaySettings): # insert or update row = await db.fetchone( - """SELECT user FROM satspay.settings WHERE user = ?""", (user,) + """SELECT user_id FROM satspay.settings WHERE user_id = ?""", (user_id,) ) if row: await db.execute( """ - UPDATE satspay.settings SET custom_css = ? WHERE user = ? + UPDATE satspay.settings SET custom_css = ? WHERE user_id = ? """, - (data.custom_css, user), + (data.custom_css, user_id), ) else: await db.execute( """ INSERT INTO satspay.settings ( - user, + user_id, custom_css ) VALUES (?, ?) """, ( - user, + user_id, data.custom_css, ), ) return True + + +async def get_settings(user_id: str) -> SatsPaySettings: + row = await db.fetchone( + """SELECT * FROM satspay.settings WHERE user_id = ?""", + (user_id,), + ) + if row: + return SatsPaySettings.from_row(row) + else: + return None \ No newline at end of file diff --git a/lnbits/extensions/satspay/migrations.py b/lnbits/extensions/satspay/migrations.py index 4a4b5460..fe0a9d9c 100644 --- a/lnbits/extensions/satspay/migrations.py +++ b/lnbits/extensions/satspay/migrations.py @@ -46,7 +46,7 @@ async def m002_add_settings_table(db): await db.execute( """ CREATE TABLE satspay.settings ( - "user" TEXT, + user_id TEXT, custom_css TEXT ); """ diff --git a/lnbits/extensions/satspay/templates/satspay/index.html b/lnbits/extensions/satspay/templates/satspay/index.html index 78c45a8b..02d74653 100644 --- a/lnbits/extensions/satspay/templates/satspay/index.html +++ b/lnbits/extensions/satspay/templates/satspay/index.html @@ -630,7 +630,9 @@ '/satspay/api/v1/settings', this.g.user.wallets[0].inkey ) - this.formDialogSettings.data = data + if(data) { + this.formDialogSettings.data.custom_css = data.custom_css + } } catch (error) { LNbits.utils.notifyApiError(error) } diff --git a/lnbits/extensions/satspay/views_api.py b/lnbits/extensions/satspay/views_api.py index b8c424b2..429453df 100644 --- a/lnbits/extensions/satspay/views_api.py +++ b/lnbits/extensions/satspay/views_api.py @@ -152,7 +152,7 @@ async def api_charge_balance(charge_id): async def api_settings_save( data: SatsPaySettings, wallet: WalletTypeInfo = Depends(require_invoice_key) ): - await save_settings(user=wallet.wallet.user, data=data) + await save_settings(user_id=wallet.wallet.user, data=data) return True