Skip to content

Commit 8c98350

Browse files
committed
fix config updating
1 parent ec3613e commit 8c98350

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

crud.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,14 +191,16 @@ async def create_config(user: str) -> Config:
191191

192192
async def update_config(config: Config, user: str) -> Config:
193193
_config = ConfigDb(user=user, json_data=config)
194-
await db.insert("watchonly.config", _config)
194+
await db.update("watchonly.config", _config, """WHERE "user" = :user""")
195195
return config
196196

197197

198-
async def get_config(user: str) -> Optional[Config]:
198+
async def get_config(user: str) -> Config:
199199
_config = await db.fetchone(
200200
"""SELECT * FROM watchonly.config WHERE "user" = :user""",
201201
{"user": user},
202202
ConfigDb,
203203
)
204+
if not _config:
205+
return await create_config(user)
204206
return _config.json_data

views_api.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from lnbits.helpers import urlsafe_short_hash
1414

1515
from .crud import (
16-
create_config,
1716
create_fresh_addresses,
1817
create_watch_wallet,
1918
delete_addresses_for_wallet,
@@ -117,9 +116,6 @@ async def api_wallet_create_or_update(
117116
status_code=HTTPStatus.BAD_REQUEST, detail=str(exc)
118117
) from exc
119118

120-
config = await get_config(key_info.wallet.user)
121-
if not config:
122-
await create_config(user=key_info.wallet.user)
123119
return wallet
124120

125121

@@ -408,7 +404,6 @@ async def api_update_config(
408404
data: Config, key_info: WalletTypeInfo = Depends(require_admin_key)
409405
) -> Config:
410406
config = await update_config(data, user=key_info.wallet.user)
411-
assert config
412407
return config
413408

414409

@@ -417,6 +412,4 @@ async def api_get_config(
417412
key_info: WalletTypeInfo = Depends(require_invoice_key),
418413
) -> Config:
419414
config = await get_config(key_info.wallet.user)
420-
if not config:
421-
config = await create_config(user=key_info.wallet.user)
422415
return config

0 commit comments

Comments
 (0)