From 1d605be021b35f1eef85be1a7f2ff143ab9d225f Mon Sep 17 00:00:00 2001 From: padreug Date: Mon, 10 Nov 2025 11:13:25 +0100 Subject: [PATCH] Removes redundant payment recording Removes the explicit call to the record-payment API when settling a receivable. The webhook (on_invoice_paid in tasks.py) automatically handles recording the payment in Fava, making the API call redundant. This simplifies the frontend logic. Also, in the `showPayUserDialog` function, it now correctly identifies users who are owed payments based on a negative balance instead of a positive balance. --- static/js/index.js | 47 +++++++++++++++------------------------------- 1 file changed, 15 insertions(+), 32 deletions(-) diff --git a/static/js/index.js b/static/js/index.js index 2eaaa79..dbc5bcd 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -1184,38 +1184,21 @@ window.app = Vue.createApp({ clearInterval(this.settleReceivableDialog.pollIntervalId) this.settleReceivableDialog.pollIntervalId = null - // Record payment in accounting - this creates the journal entry - // that settles the receivable - try { - const recordResponse = await LNbits.api.request( - 'POST', - '/castle/api/v1/record-payment', - this.g.user.wallets[0].adminkey, - { - payment_hash: paymentHash - } - ) - console.log('Settlement payment recorded:', recordResponse.data) + // Payment detected! The webhook (on_invoice_paid in tasks.py) will automatically + // record this in Fava, so we don't need to call record-payment API here. + // Just notify the user and refresh the UI. + this.$q.notify({ + type: 'positive', + message: 'Payment received! Receivable has been settled.', + timeout: 3000 + }) - this.$q.notify({ - type: 'positive', - message: 'Payment received! Receivable has been settled.', - timeout: 3000 - }) + // Close dialog and refresh + this.settleReceivableDialog.show = false + await this.loadBalance() + await this.loadTransactions() + await this.loadAllUserBalances() - // Close dialog and refresh - this.settleReceivableDialog.show = false - await this.loadBalance() - await this.loadTransactions() - await this.loadAllUserBalances() - } catch (error) { - console.error('Error recording settlement payment:', error) - this.$q.notify({ - type: 'negative', - message: 'Payment detected but failed to record: ' + (error.response?.data?.detail || error.message), - timeout: 5000 - }) - } return true } return false @@ -1297,8 +1280,8 @@ window.app = Vue.createApp({ } }, showPayUserDialog(userBalance) { - // Only show for users castle owes (positive balance) - if (userBalance.balance <= 0) return + // Only show for users castle owes (negative balance = payable) + if (userBalance.balance >= 0) return // Extract fiat balances (e.g., EUR) const fiatBalances = userBalance.fiat_balances || {}