diff --git a/crud.py b/crud.py index 982594a..79a31dd 100644 --- a/crud.py +++ b/crud.py @@ -514,4 +514,8 @@ async def get_client_by_user_id(user_id: str) -> Optional[dict]: ) return dict(client) if client else None except Exception: - return None \ No newline at end of file + return None + + +# Removed get_active_lamassu_config - client should not access sensitive admin config +# Client limits are now fetched via secure public API endpoint \ No newline at end of file diff --git a/static/js/index.js b/static/js/index.js index 2924342..f0f3c5f 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -7,7 +7,6 @@ window.app = Vue.createApp({ // Registration state isRegistered: false, registrationChecked: false, - showRegistrationDialog: false, registrationForm: { selectedWallet: null, dca_mode: 'flow', @@ -15,6 +14,12 @@ window.app = Vue.createApp({ username: '' }, + // Admin configuration + adminConfig: { + max_daily_limit_gtq: 2000, + currency: 'GTQ' + }, + // Dashboard state dashboardData: null, transactions: [], @@ -72,6 +77,23 @@ window.app = Vue.createApp({ }, methods: { + // Configuration Methods + async loadClientLimits() { + try { + const { data } = await LNbits.api.request( + 'GET', + '/satmachineadmin/api/v1/dca/client-limits' + // No authentication required - public endpoint with safe data only + ) + + this.adminConfig = data + console.log('Client limits loaded:', this.adminConfig) + } catch (error) { + console.error('Error loading client limits:', error) + // Keep default values if client limits fail to load + } + }, + // Registration Methods async checkRegistrationStatus() { try { @@ -85,9 +107,8 @@ window.app = Vue.createApp({ this.registrationChecked = true if (!this.isRegistered) { - this.showRegistrationDialog = true - // Pre-fill username and default wallet if available - this.registrationForm.username = this.g.user.username || '' + // Fetch current user info to get the username + await this.loadCurrentUser() this.registrationForm.selectedWallet = this.g.user.wallets[0]?.id || null } @@ -99,13 +120,29 @@ window.app = Vue.createApp({ } }, + async loadCurrentUser() { + try { + const { data } = await LNbits.api.getAuthenticatedUser() + + // Set username from API response with priority: display_name > username > email > fallback + const username = data.extra?.display_name || data.username || data.email + this.registrationForm.username = (username !== null && username !== undefined && username !== '') + ? username + : `user_${this.g.user.id.substring(0, 8)}` + } catch (error) { + console.error('Error loading current user:', error) + // Fallback to generated username + this.registrationForm.username = `user_${this.g.user.id.substring(0, 8)}` + } + }, + async registerClient() { try { - // Prepare registration data similar to the admin test client creation + // Prepare registration data using the form's username (already loaded from API) const registrationData = { dca_mode: this.registrationForm.dca_mode, fixed_mode_daily_limit: this.registrationForm.fixed_mode_daily_limit, - username: this.registrationForm.username || this.g.user.username || `user_${this.g.user.id.substring(0, 8)}` + username: this.registrationForm.username || `user_${this.g.user.id.substring(0, 8)}` } // Find the selected wallet object to get the adminkey @@ -122,7 +159,6 @@ window.app = Vue.createApp({ ) this.isRegistered = true - this.showRegistrationDialog = false this.$q.notify({ type: 'positive', @@ -754,7 +790,10 @@ window.app = Vue.createApp({ try { this.loading = true - // Check registration status first + // Load client limits first + await this.loadClientLimits() + + // Check registration status await this.checkRegistrationStatus() // Only load dashboard data if registered diff --git a/templates/satmachineclient/index.html b/templates/satmachineclient/index.html index 19097e5..a36b596 100644 --- a/templates/satmachineclient/index.html +++ b/templates/satmachineclient/index.html @@ -21,19 +21,87 @@ - + ${error} - - - - -
Welcome to Bitcoin DCA!
-
- Please complete your registration to start your Dollar Cost Averaging journey. + + + +
+
+ +
+
Welcome to DCA!
+
Let's set up your Bitcoin Dollar Cost Averaging account
+ + + + + + + + + + +
+ Flow Mode: Your Bitcoin purchases come at 0% fee when people cash ou at the machine.
+ Fixed Mode: Set a daily limit for consistent Bitcoin accumulation. +
+
+ +
+ + + Start My DCA Journey 🚀 + +
+
@@ -179,7 +247,7 @@
${formatCurrency(dashboardData.pending_fiat_deposits)} ready to DCA @@ -363,7 +431,7 @@