diff --git a/static/js/index.js b/static/js/index.js index a5eb17e..b80dd16 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -176,6 +176,10 @@ window.app = Vue.createApp({ }) this.settingsDialog.show = false await this.loadSettings() + // Reload user wallet to reflect castle wallet for super user + if (this.isSuperUser) { + await this.loadUserWallet() + } } catch (error) { LNbits.utils.notifyApiError(error) } finally { diff --git a/templates/castle/index.html b/templates/castle/index.html index faadb6a..9fadea4 100644 --- a/templates/castle/index.html +++ b/templates/castle/index.html @@ -17,7 +17,7 @@

Track expenses, receivables, and balances for the collective

- + Configure Your Wallet @@ -50,7 +50,7 @@
- + @@ -106,13 +106,13 @@ Add Expense Castle wallet must be configured first - + You must configure your wallet first @@ -344,20 +344,27 @@
Configure Your Wallet
- + emit-value + v-model="userWalletDialog.userWalletId" + :options="g.user.walletOptions" + label="Your Wallet *" + >
- This is the wallet you'll use for Castle transactions. You can find your wallet ID in the LNbits wallet settings. + Select the wallet you'll use for Castle transactions.
- + Save Wallet Cancel diff --git a/views_api.py b/views_api.py index 42ed6b7..466730e 100644 --- a/views_api.py +++ b/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,