feat: add configurable threshold for balance delta notification (#3433)

Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: Vlad Stan <stan.v.vlad@gmail.com>
This commit is contained in:
Ben Weeks 2025-11-12 09:36:19 +00:00 committed by GitHub
parent 1e6e97c12d
commit c89721223f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 14 additions and 12 deletions

View file

@ -70,7 +70,8 @@ async def check_balance_delta_changed():
if settings.latest_balance_delta_sats is None: if settings.latest_balance_delta_sats is None:
settings.latest_balance_delta_sats = status.delta_sats settings.latest_balance_delta_sats = status.delta_sats
return return
if status.delta_sats != settings.latest_balance_delta_sats: delta_change = abs(status.delta_sats - settings.latest_balance_delta_sats)
if delta_change >= settings.notification_balance_delta_threshold_sats:
enqueue_admin_notification( enqueue_admin_notification(
NotificationType.balance_delta, NotificationType.balance_delta,
{ {

View file

@ -392,7 +392,7 @@ def _is_message_type_enabled(message_type: NotificationType) -> bool:
if message_type == NotificationType.watchdog_check: if message_type == NotificationType.watchdog_check:
return settings.lnbits_notification_watchdog return settings.lnbits_notification_watchdog
if message_type == NotificationType.balance_delta: if message_type == NotificationType.balance_delta:
return settings.notification_balance_delta_changed return settings.notification_balance_delta_threshold_sats > 0
if message_type == NotificationType.server_start_stop: if message_type == NotificationType.server_start_stop:
return settings.lnbits_notification_server_start_stop return settings.lnbits_notification_server_start_stop
if message_type == NotificationType.server_status: if message_type == NotificationType.server_status:

View file

@ -35,7 +35,7 @@ async def run_by_the_minute_tasks() -> None:
while settings.lnbits_running: while settings.lnbits_running:
status_minutes = settings.lnbits_notification_server_status_hours * 60 status_minutes = settings.lnbits_notification_server_status_hours * 60
if settings.notification_balance_delta_changed: if settings.notification_balance_delta_threshold_sats > 0:
try: try:
# runs by default every minute, the delta should not change that often # runs by default every minute, the delta should not change that often
await check_balance_delta_changed() await check_balance_delta_changed()

View file

@ -429,7 +429,7 @@ class NotificationsSettings(LNbitsSettings):
lnbits_notification_settings_update: bool = Field(default=True) lnbits_notification_settings_update: bool = Field(default=True)
lnbits_notification_credit_debit: bool = Field(default=True) lnbits_notification_credit_debit: bool = Field(default=True)
notification_balance_delta_changed: bool = Field(default=True) notification_balance_delta_threshold_sats: int = Field(default=1, ge=0)
lnbits_notification_server_start_stop: bool = Field(default=True) lnbits_notification_server_start_stop: bool = Field(default=True)
lnbits_notification_watchdog: bool = Field(default=False) lnbits_notification_watchdog: bool = Field(default=False)
lnbits_notification_server_status_hours: int = Field(default=24, gt=0) lnbits_notification_server_status_hours: int = Field(default=24, gt=0)

File diff suppressed because one or more lines are too long

View file

@ -314,7 +314,7 @@ window.localisation.en = {
notification_balance_delta_changed: 'Balance Delta Changed', notification_balance_delta_changed: 'Balance Delta Changed',
notification_balance_delta_changed_desc: notification_balance_delta_changed_desc:
'Notify when the diference between the node balance and the LNbits balance has changed even by 1 sat. This runs every minute.', 'Notify when the difference between the node balance and the LNbits balance has changed by more than the specified amount (in sats). Set to 0 to disable. This runs every minute.',
enable_watchdog: 'Enable Watchdog Switch', enable_watchdog: 'Enable Watchdog Switch',
enable_watchdog_desc: enable_watchdog_desc:

View file

@ -404,13 +404,14 @@
v-text="$t('notification_balance_delta_changed_desc')" v-text="$t('notification_balance_delta_changed_desc')"
></q-item-label> ></q-item-label>
</q-item-section> </q-item-section>
<q-item-section avatar> <q-item-section avatar>
<q-toggle <q-input
size="md" class="flow-right"
v-model="formData.notification_balance_delta_changed" type="number"
checked-icon="check" min="0"
color="green" filled
unchecked-icon="clear" v-model="formData.notification_balance_delta_threshold_sats"
/> />
</q-item-section> </q-item-section>
</q-item> </q-item>