Enhances super user experience with Castle wallet
Simplifies the user experience for super users by automatically using the Castle wallet for transactions, removing the need to configure a separate user wallet. This change streamlines the workflow for super users by: - Automatically assigning the Castle wallet to super users - Hiding the user wallet configuration options in the UI - Reloading user wallet settings to reflect the Castle wallet
This commit is contained in:
parent
f1ada5e290
commit
cb7e4ee555
3 changed files with 57 additions and 14 deletions
38
views_api.py
38
views_api.py
|
|
@ -59,13 +59,26 @@ async def check_castle_wallet_configured() -> str:
|
|||
|
||||
async def check_user_wallet_configured(user_id: str) -> str:
|
||||
"""Ensure user has configured their wallet, return wallet_id"""
|
||||
settings = await get_user_wallet(user_id)
|
||||
if not settings or not settings.user_wallet_id:
|
||||
from lnbits.settings import settings as lnbits_settings
|
||||
|
||||
# If user is super user, use the castle wallet
|
||||
if user_id == lnbits_settings.super_user:
|
||||
castle_settings = await get_settings("admin")
|
||||
if castle_settings and castle_settings.castle_wallet_id:
|
||||
return castle_settings.castle_wallet_id
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.BAD_REQUEST,
|
||||
detail="Castle wallet not configured. Please configure the Castle wallet in settings.",
|
||||
)
|
||||
|
||||
# For regular users, check their personal wallet
|
||||
user_wallet = await get_user_wallet(user_id)
|
||||
if not user_wallet or not user_wallet.user_wallet_id:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.BAD_REQUEST,
|
||||
detail="You must configure your wallet in settings before using this feature.",
|
||||
)
|
||||
return settings.user_wallet_id
|
||||
return user_wallet.user_wallet_id
|
||||
|
||||
|
||||
# ===== UTILITY ENDPOINTS =====
|
||||
|
|
@ -529,6 +542,16 @@ async def api_get_user_wallet(
|
|||
user: User = Depends(check_user_exists),
|
||||
) -> UserWalletSettings:
|
||||
"""Get current user's wallet settings"""
|
||||
from lnbits.settings import settings as lnbits_settings
|
||||
|
||||
# If user is super user, return the castle wallet
|
||||
if user.id == lnbits_settings.super_user:
|
||||
castle_settings = await get_settings("admin")
|
||||
if castle_settings and castle_settings.castle_wallet_id:
|
||||
return UserWalletSettings(user_wallet_id=castle_settings.castle_wallet_id)
|
||||
return UserWalletSettings()
|
||||
|
||||
# For regular users, get their personal wallet
|
||||
settings = await get_user_wallet(user.id)
|
||||
# Return empty settings if not configured (so UI can show setup screen)
|
||||
if not settings:
|
||||
|
|
@ -542,6 +565,15 @@ async def api_update_user_wallet(
|
|||
user: User = Depends(check_user_exists),
|
||||
) -> UserWalletSettings:
|
||||
"""Update current user's wallet settings"""
|
||||
from lnbits.settings import settings as lnbits_settings
|
||||
|
||||
# Super user cannot set their wallet separately - it's always the castle wallet
|
||||
if user.id == lnbits_settings.super_user:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.FORBIDDEN,
|
||||
detail="Super user wallet is automatically set to the Castle wallet. Update Castle settings instead.",
|
||||
)
|
||||
|
||||
if not data.user_wallet_id:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.BAD_REQUEST,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue