diff --git a/static/js/index.js b/static/js/index.js index bd52e39..4cc5c06 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -34,6 +34,7 @@ window.app = Vue.createApp({ settingsLoaded: false, // Flag to prevent race conditions on toolbar buttons castleWalletConfigured: false, userWalletConfigured: false, + syncingAccounts: false, currentExchangeRate: null, // BTC/EUR rate (sats per EUR) expenseDialog: { show: false, @@ -539,6 +540,32 @@ window.app = Vue.createApp({ this.userWalletConfigured = false } }, + async syncAccounts() { + this.syncingAccounts = true + try { + const {data} = await LNbits.api.request( + 'POST', + '/castle/api/v1/admin/accounts/sync', + this.g.user.wallets[0].adminkey + ) + const errors = (data?.errors || []).length + const message = `Synced: ${data?.accounts_added ?? 0} added, ` + + `${data?.accounts_reactivated ?? 0} reactivated, ` + + `${data?.accounts_deactivated ?? 0} deactivated, ` + + `${data?.virtual_parents_created ?? 0} virtual parents` + + (errors ? `, ${errors} errors` : '') + this.$q.notify({ + type: errors ? 'warning' : 'positive', + message, + timeout: errors ? 8000 : 4000 + }) + await this.loadAccounts() + } catch (error) { + LNbits.utils.notifyApiError(error) + } finally { + this.syncingAccounts = false + } + }, showSettingsDialog() { this.settingsDialog.castleWalletId = this.settings?.castle_wallet_id || '' this.settingsDialog.favaUrl = this.settings?.fava_url || 'http://localhost:3333' diff --git a/templates/castle/index.html b/templates/castle/index.html index 2a1e665..98b1625 100644 --- a/templates/castle/index.html +++ b/templates/castle/index.html @@ -24,6 +24,9 @@ Manage Permissions (Admin) + + Sync Accounts from Beancount + Castle Settings (Super User Only)