From 5b74aa443e56a41bbca64f2f764f280d131c55ba Mon Sep 17 00:00:00 2001 From: SomberNight Date: Mon, 6 May 2024 22:08:30 +0000 Subject: [PATCH] qt settings: expose LIGHTNING_PAYMENT_BUDGET_FEE_MAX_MILLIONTHS Expose as a slider; perhaps it is less footgunny this way? --- electrum/gui/qt/settings_dialog.py | 34 +++++++++++++++++++++++++++++- electrum/simple_config.py | 5 ++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/electrum/gui/qt/settings_dialog.py b/electrum/gui/qt/settings_dialog.py index f8f755467..ed67edab9 100644 --- a/electrum/gui/qt/settings_dialog.py +++ b/electrum/gui/qt/settings_dialog.py @@ -30,7 +30,7 @@ from PyQt5.QtCore import Qt from PyQt5.QtWidgets import (QComboBox, QTabWidget, QDialog, QSpinBox, QFileDialog, QCheckBox, QLabel, QVBoxLayout, QGridLayout, QLineEdit, - QPushButton, QWidget, QHBoxLayout) + QPushButton, QWidget, QHBoxLayout, QSlider) from electrum.i18n import _, languages from electrum import util, paymentrequest @@ -155,6 +155,37 @@ class SettingsDialog(QDialog, QtEventListener): self.config.WATCHTOWER_CLIENT_URL = url self.watchtower_url_e.editingFinished.connect(on_wt_url) + lnfee_hlabel = HelpLabel.from_configvar(self.config.cv.LIGHTNING_PAYMENT_FEE_MAX_MILLIONTHS) + lnfee_map = [500, 1_000, 3_000, 5_000, 10_000, 20_000, 30_000, 50_000] + def lnfee_update_vlabel(fee_val: int): + lnfee_vlabel.setText(_("{}% of payment").format(f"{fee_val / 10 ** 4:.2f}")) + def lnfee_slider_moved(): + pos = lnfee_slider.sliderPosition() + fee_val = lnfee_map[pos] + lnfee_update_vlabel(fee_val) + def lnfee_slider_released(): + pos = lnfee_slider.sliderPosition() + fee_val = lnfee_map[pos] + self.config.LIGHTNING_PAYMENT_FEE_MAX_MILLIONTHS = fee_val + lnfee_slider = QSlider(Qt.Horizontal) + lnfee_slider.setRange(0, len(lnfee_map)-1) + lnfee_slider.setTracking(True) + try: + lnfee_spos = lnfee_map.index(self.config.LIGHTNING_PAYMENT_FEE_MAX_MILLIONTHS) + except ValueError: + lnfee_spos = 0 + lnfee_slider.setSliderPosition(lnfee_spos) + lnfee_vlabel = QLabel("") + lnfee_update_vlabel(self.config.LIGHTNING_PAYMENT_FEE_MAX_MILLIONTHS) + lnfee_slider.valueChanged.connect(lnfee_slider_moved) + lnfee_slider.sliderReleased.connect(lnfee_slider_released) + lnfee_hbox = QHBoxLayout() + lnfee_hbox.setContentsMargins(0, 0, 0, 0) + lnfee_hbox.addWidget(lnfee_vlabel) + lnfee_hbox.addWidget(lnfee_slider) + lnfee_hbox_w = QWidget() + lnfee_hbox_w.setLayout(lnfee_hbox) + alias_label = HelpLabel.from_configvar(self.config.cv.OPENALIAS_ID) alias = self.config.OPENALIAS_ID self.alias_e = QLineEdit(alias) @@ -351,6 +382,7 @@ class SettingsDialog(QDialog, QtEventListener): lightning_widgets.append((trampoline_cb, None)) lightning_widgets.append((legacy_add_trampoline_cb, None)) lightning_widgets.append((remote_wt_cb, self.watchtower_url_e)) + lightning_widgets.append((lnfee_hlabel, lnfee_hbox_w)) fiat_widgets = [] fiat_widgets.append((QLabel(_('Fiat currency')), ccy_combo)) fiat_widgets.append((QLabel(_('Source')), ex_combo)) diff --git a/electrum/simple_config.py b/electrum/simple_config.py index bbaf6b23b..c7cd8918e 100644 --- a/electrum/simple_config.py +++ b/electrum/simple_config.py @@ -1043,7 +1043,10 @@ This will result in longer routes; it might increase your fees and decrease the LIGHTNING_PAYMENT_FEE_MAX_MILLIONTHS = ConfigVar( 'lightning_payment_fee_max_millionths', default=10_000, # 1% type_=int, - short_desc=lambda: _("Max lightning fees (%) to pay"), + short_desc=lambda: _("Max lightning fees to pay"), + long_desc=lambda: _("""When sending lightning payments, this value is an upper bound for the fees we allow paying, proportional to the payment amount. The fees are paid in addition to the payment amount, by the sender. + +Warning: setting this to too low will result in lots of payment failures."""), ) LIGHTNING_PAYMENT_FEE_CUTOFF_MSAT = ConfigVar( 'lightning_payment_fee_cutoff_msat', default=10_000, # 10 sat