Browse Source

Discretize fee levels (follow-up 3314b3a). Fixes #1753

283
ThomasV 9 years ago
parent
commit
0273936b07
  1. 22
      gui/kivy/uix/dialogs/fee_dialog.py
  2. 4
      gui/kivy/uix/dialogs/settings.py
  3. 3
      gui/qt/main_window.py
  4. 1
      lib/bitcoin.py
  5. 1
      lib/util.py

22
gui/kivy/uix/dialogs/fee_dialog.py

@ -3,7 +3,8 @@ from kivy.factory import Factory
from kivy.properties import ObjectProperty from kivy.properties import ObjectProperty
from kivy.lang import Builder from kivy.lang import Builder
from electrum.bitcoin import RECOMMENDED_FEE from electrum.bitcoin import FEE_STEP, RECOMMENDED_FEE
from electrum.util import fee_levels
from electrum_gui.kivy.i18n import _ from electrum_gui.kivy.i18n import _
Builder.load_string(''' Builder.load_string('''
@ -22,7 +23,8 @@ Builder.load_string('''
text: '' text: ''
Slider: Slider:
id: slider id: slider
range: 0, 100 range: 0, 4
step: 1
on_value: root.on_slider(self.value) on_value: root.on_slider(self.value)
BoxLayout: BoxLayout:
orientation: 'horizontal' orientation: 'horizontal'
@ -68,7 +70,7 @@ class FeeDialog(Factory.Popup):
self.callback = callback self.callback = callback
self.dynfees = self.config.get('dynamic_fees', False) self.dynfees = self.config.get('dynamic_fees', False)
self.fee_factor = self.config.get('fee_factor', 50) self.fee_level = self.config.get('fee_level', 2)
self.static_fee = self.config.get('fee_per_kb', RECOMMENDED_FEE) self.static_fee = self.config.get('fee_per_kb', RECOMMENDED_FEE)
self.ids.dynfees.active = self.dynfees self.ids.dynfees.active = self.dynfees
@ -84,29 +86,31 @@ class FeeDialog(Factory.Popup):
def update_slider(self): def update_slider(self):
slider = self.ids.slider slider = self.ids.slider
if self.dynfees: if self.dynfees:
slider.value = self.fee_factor slider.value = self.fee_level
slider.range = (0, 100) slider.range = (0, 4)
slider.step = 1
else: else:
slider.value = self.static_fee slider.value = self.static_fee
slider.range = (0, 2*RECOMMENDED_FEE) slider.range = (FEE_STEP, 2*RECOMMENDED_FEE)
slider.step = FEE_STEP
def get_fee_text(self): def get_fee_text(self):
if self.ids.dynfees.active: if self.ids.dynfees.active:
return 'Recommendation x %d%%'%(self.fee_factor + 50) return fee_levels[self.fee_level] + ' (%d%%)'% (100 * (self.fee_level + 1)/3)
else: else:
return self.app.format_amount_and_units(self.static_fee) + '/kB' return self.app.format_amount_and_units(self.static_fee) + '/kB'
def on_ok(self): def on_ok(self):
self.config.set_key('dynamic_fees', self.dynfees, False) self.config.set_key('dynamic_fees', self.dynfees, False)
if self.dynfees: if self.dynfees:
self.config.set_key('fee_factor', self.fee_factor, True) self.config.set_key('fee_level', self.fee_level, True)
else: else:
self.config.set_key('fee_per_kb', self.static_fee, True) self.config.set_key('fee_per_kb', self.static_fee, True)
self.callback() self.callback()
def on_slider(self, value): def on_slider(self, value):
if self.dynfees: if self.dynfees:
self.fee_factor = int(value) self.fee_level = int(value)
else: else:
self.static_fee = int(value) self.static_fee = int(value)
self.update_text() self.update_text()

4
gui/kivy/uix/dialogs/settings.py

@ -204,8 +204,8 @@ class SettingsDialog(Factory.Popup):
def fee_status(self): def fee_status(self):
if self.config.get('dynamic_fees'): if self.config.get('dynamic_fees'):
f = self.config.get('fee_factor', 50) + 50 from electrum.util import fee_levels
return 'Dynamic, %d%%'%f return fee_levels[self.config.get('fee_level', 2)]
else: else:
F = self.config.get('fee_per_kb', RECOMMENDED_FEE) F = self.config.get('fee_per_kb', RECOMMENDED_FEE)
return self.app.format_amount_and_units(F) + '/kB' return self.app.format_amount_and_units(F) + '/kB'

3
gui/qt/main_window.py

@ -1032,8 +1032,9 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError):
self.fee_slider.setRange(0, 4) self.fee_slider.setRange(0, 4)
self.fee_slider.setToolTip(_('')) self.fee_slider.setToolTip(_(''))
def slider_moved(): def slider_moved():
from electrum.util import fee_levels
i = self.fee_slider.sliderPosition() i = self.fee_slider.sliderPosition()
tooltip = ['very slow', 'slow', 'within 2 blocks', 'fast', 'very fast'][i] tooltip = fee_levels[i] + ' (%d%%)'% (100 * (i + 1)/3)
QToolTip.showText(QCursor.pos(), tooltip, self.fee_slider) QToolTip.showText(QCursor.pos(), tooltip, self.fee_slider)
def slider_released(): def slider_released():
self.config.set_key('fee_level', self.fee_slider.sliderPosition(), False) self.config.set_key('fee_level', self.fee_slider.sliderPosition(), False)

1
lib/bitcoin.py

@ -37,6 +37,7 @@ import aes
################################## transactions ################################## transactions
FEE_STEP = 10000
RECOMMENDED_FEE = 50000 RECOMMENDED_FEE = 50000
COINBASE_MATURITY = 100 COINBASE_MATURITY = 100
COIN = 100000000 COIN = 100000000

1
lib/util.py

@ -36,6 +36,7 @@ import threading
from i18n import _ from i18n import _
base_units = {'BTC':8, 'mBTC':5, 'uBTC':2} base_units = {'BTC':8, 'mBTC':5, 'uBTC':2}
fee_levels = [_('Very low'), _('Low'), _('Normal'), _('High'), _('Very high')]
def normalize_version(v): def normalize_version(v):
return [int(x) for x in re.sub(r'(\.0+)*$','', v).split(".")] return [int(x) for x in re.sub(r'(\.0+)*$','', v).split(".")]

Loading…
Cancel
Save