Skip to content

Commit

Permalink
qt settings: expose LIGHTNING_PAYMENT_BUDGET_FEE_MAX_MILLIONTHS
Browse files Browse the repository at this point in the history
Expose as a slider; perhaps it is less footgunny this way?
  • Loading branch information
SomberNight committed May 6, 2024
1 parent 1e0090f commit f6ddc44
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 2 deletions.
34 changes: 33 additions & 1 deletion electrum/gui/qt/settings_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
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
Expand Down Expand Up @@ -155,6 +155,37 @@ def on_wt_url():
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_BUDGET_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_BUDGET_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_BUDGET_FEE_MAX_MILLIONTHS)
except ValueError:
lnfee_spos = 0
lnfee_slider.setSliderPosition(lnfee_spos)
lnfee_vlabel = QLabel("")
lnfee_update_vlabel(self.config.LIGHTNING_PAYMENT_BUDGET_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)
Expand Down Expand Up @@ -351,6 +382,7 @@ def on_history_rates(checked):
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))
Expand Down
3 changes: 2 additions & 1 deletion electrum/simple_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,7 +1043,8 @@ def _default_swapserver_url(self) -> str:
LIGHTNING_PAYMENT_BUDGET_FEE_MAX_MILLIONTHS = ConfigVar(
'lightning_payment_budget_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."""),
)
LIGHTNING_PAYMENT_BUDGET_FEE_CUTOFF_MSAT = ConfigVar(
'lightning_payment_budget_fee_cutoff_msat', default=10_000, # 10 sat
Expand Down

0 comments on commit f6ddc44

Please sign in to comment.