Add Fava settings UI and fix race conditions in toolbar buttons

- Add Fava URL, ledger slug, and timeout settings to super admin Settings dialog
- Reinitialize Fava client when settings are updated via services.py
- Add settingsLoaded flag to prevent race conditions where wrong toolbar
  buttons appeared before isSuperUser was determined
- Remove premature Vue mount() call from permissions.js that caused
  "Cannot read properties of undefined (reading 'user')" error

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
padreug 2026-01-07 15:24:19 +01:00
parent 5eb007b936
commit cb9bc2d658
4 changed files with 83 additions and 10 deletions

View file

@ -31,6 +31,7 @@ window.app = Vue.createApp({
userInfo: null, // User information including equity eligibility
isAdmin: false,
isSuperUser: false,
settingsLoaded: false, // Flag to prevent race conditions on toolbar buttons
castleWalletConfigured: false,
userWalletConfigured: false,
currentExchangeRate: null, // BTC/EUR rate (sats per EUR)
@ -57,6 +58,9 @@ window.app = Vue.createApp({
settingsDialog: {
show: false,
castleWalletId: '',
favaUrl: 'http://localhost:3333',
favaLedgerSlug: 'castle-ledger',
favaTimeout: 10.0,
loading: false
},
userWalletDialog: {
@ -517,6 +521,9 @@ window.app = Vue.createApp({
} catch (error) {
// Settings not available
this.castleWalletConfigured = false
} finally {
// Mark settings as loaded to enable toolbar buttons
this.settingsLoaded = true
}
},
async loadUserWallet() {
@ -534,6 +541,9 @@ window.app = Vue.createApp({
},
showSettingsDialog() {
this.settingsDialog.castleWalletId = this.settings?.castle_wallet_id || ''
this.settingsDialog.favaUrl = this.settings?.fava_url || 'http://localhost:3333'
this.settingsDialog.favaLedgerSlug = this.settings?.fava_ledger_slug || 'castle-ledger'
this.settingsDialog.favaTimeout = this.settings?.fava_timeout || 10.0
this.settingsDialog.show = true
},
showUserWalletDialog() {
@ -549,6 +559,14 @@ window.app = Vue.createApp({
return
}
if (!this.settingsDialog.favaUrl) {
this.$q.notify({
type: 'warning',
message: 'Fava URL is required'
})
return
}
this.settingsDialog.loading = true
try {
await LNbits.api.request(
@ -556,7 +574,10 @@ window.app = Vue.createApp({
'/castle/api/v1/settings',
this.g.user.wallets[0].adminkey,
{
castle_wallet_id: this.settingsDialog.castleWalletId
castle_wallet_id: this.settingsDialog.castleWalletId,
fava_url: this.settingsDialog.favaUrl,
fava_ledger_slug: this.settingsDialog.favaLedgerSlug || 'castle-ledger',
fava_timeout: parseFloat(this.settingsDialog.favaTimeout) || 10.0
}
)
this.$q.notify({

View file

@ -1118,5 +1118,3 @@ window.app = Vue.createApp({
}
}
})
window.app.mount('#vue')