commit 198cc9d7376768739e1233cbc67add0c5e416984
parent 1d2253f0d883f91258b1403f4a4b68d4e5a4fd18
Author: ThomasV <thomasv@electrum.org>
Date: Sat, 21 Oct 2017 11:15:59 +0200
fix #2614: define non-linear scale for static fees
Diffstat:
4 files changed, 16 insertions(+), 24 deletions(-)
diff --git a/gui/kivy/uix/dialogs/fee_dialog.py b/gui/kivy/uix/dialogs/fee_dialog.py
@@ -58,7 +58,6 @@ class FeeDialog(Factory.Popup):
Factory.Popup.__init__(self)
self.app = app
self.config = config
- self.fee_step = self.config.max_fee_rate() / 10
self.fee_rate = self.config.fee_per_kb()
self.callback = callback
self.dynfees = self.config.get('dynamic_fees', True)
@@ -77,9 +76,9 @@ class FeeDialog(Factory.Popup):
slider.step = 1
slider.value = self.config.get('fee_level', 2)
else:
- slider.range = (1, 10)
+ slider.range = (0, 9)
slider.step = 1
- slider.value = min(self.fee_rate / self.fee_step, 10)
+ slider.value = self.config.static_fee_index(self.fee_rate)
def get_fee_text(self, value):
if self.ids.dynfees.active:
@@ -88,7 +87,7 @@ class FeeDialog(Factory.Popup):
dynfee = self.config.dynfee(value)
tooltip += '\n' + (self.app.format_amount_and_units(dynfee)) + '/kB'
else:
- fee_rate = value * self.fee_step
+ fee_rate = self.config.static_fee(value)
tooltip = self.app.format_amount_and_units(fee_rate) + '/kB'
if self.config.has_fee_estimates():
i = self.config.reverse_dynfee(fee_rate)
@@ -101,7 +100,7 @@ class FeeDialog(Factory.Popup):
if self.dynfees:
self.config.set_key('fee_level', value, True)
else:
- self.config.set_key('fee_per_kb', value * self.fee_step, True)
+ self.config.set_key('fee_per_kb', self.config.static_fee(value), True)
self.callback()
def on_slider(self, value):
diff --git a/gui/qt/fee_slider.py b/gui/qt/fee_slider.py
@@ -28,7 +28,7 @@ class FeeSlider(QSlider):
def moved(self, pos):
with self.lock:
- fee_rate = self.config.dynfee(pos) if self.dyn else pos * self.fee_step
+ fee_rate = self.config.dynfee(pos) if self.dyn else self.config.static_fee(pos)
tooltip = self.get_tooltip(pos, fee_rate)
QToolTip.showText(QCursor.pos(), tooltip, self)
self.setToolTip(tooltip)
@@ -55,10 +55,9 @@ class FeeSlider(QSlider):
self.setRange(0, 4)
self.setValue(pos)
else:
- self.fee_step = self.config.max_fee_rate() / 10
fee_rate = self.config.fee_per_kb()
- pos = min(fee_rate / self.fee_step, 10)
- self.setRange(1, 10)
+ pos = self.config.static_fee_index(fee_rate)
+ self.setRange(0, 9)
self.setValue(pos)
tooltip = self.get_tooltip(pos, fee_rate)
self.setToolTip(tooltip)
diff --git a/gui/qt/main_window.py b/gui/qt/main_window.py
@@ -2437,21 +2437,6 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
fee_widgets.append((dynfee_cb, None))
dynfee_cb.stateChanged.connect(on_dynfee)
- def on_maxfee(x):
- m = maxfee_e.get_amount()
- if m: self.config.set_key('max_fee_rate', m)
- self.fee_slider.update()
- def update_maxfee():
- d = self.config.is_dynfee()
- maxfee_e.setDisabled(d)
- maxfee_label.setDisabled(d)
- maxfee_label = HelpLabel(_('Max static fee'), _('Max value of the static fee slider'))
- maxfee_e = BTCkBEdit(self.get_decimal_point)
- maxfee_e.setAmount(self.config.max_fee_rate())
- maxfee_e.textChanged.connect(on_maxfee)
- update_maxfee()
- fee_widgets.append((maxfee_label, maxfee_e))
-
feebox_cb = QCheckBox(_('Edit fees manually'))
feebox_cb.setChecked(self.config.get('show_fee', False))
feebox_cb.setToolTip(_("Show fee edit box in send tab."))
diff --git a/lib/simple_config.py b/lib/simple_config.py
@@ -41,6 +41,8 @@ class SimpleConfig(PrintError):
They are taken in order (1. overrides config options set in 2., that
override config set in 3.)
"""
+ fee_rates = [5000, 10000, 20000, 30000, 50000, 70000, 100000, 150000, 200000, 300000]
+
def __init__(self, options={}, read_system_config_function=None,
read_user_config_function=None, read_user_dir_function=None):
@@ -230,6 +232,13 @@ class SimpleConfig(PrintError):
min_target = -1
return min_target
+ def static_fee(self, i):
+ return self.fee_rates[i]
+
+ def static_fee_index(self, value):
+ dist = list(map(lambda x: abs(x - value), self.fee_rates))
+ return min(range(len(dist)), key=dist.__getitem__)
+
def has_fee_estimates(self):
return len(self.fee_estimates)==4