You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

114 lines
3.5 KiB

9 years ago
from kivy.app import App
from kivy.factory import Factory
from kivy.properties import ObjectProperty
from kivy.lang import Builder
from electrum.util import fee_levels
from electrum_gui.kivy.i18n import _
9 years ago
9 years ago
Builder.load_string('''
<FeeDialog@Popup>
id: popup
9 years ago
title: _('Transaction Fees')
9 years ago
size_hint: 0.8, 0.8
pos_hint: {'top':0.9}
BoxLayout:
orientation: 'vertical'
9 years ago
BoxLayout:
orientation: 'horizontal'
size_hint: 1, 0.5
Label:
id: fee_per_kb
text: ''
Slider:
id: slider
range: 0, 4
step: 1
9 years ago
on_value: root.on_slider(self.value)
9 years ago
BoxLayout:
orientation: 'horizontal'
size_hint: 1, 0.5
Label:
text: _('Dynamic Fees')
9 years ago
CheckBox:
id: dynfees
9 years ago
on_active: root.on_checkbox(self.active)
Widget:
size_hint: 1, 1
9 years ago
BoxLayout:
orientation: 'horizontal'
size_hint: 1, 0.5
Button:
text: 'Cancel'
size_hint: 0.5, None
height: '48dp'
on_release: popup.dismiss()
Button:
text: 'OK'
size_hint: 0.5, None
height: '48dp'
on_release:
root.on_ok()
root.dismiss()
''')
class FeeDialog(Factory.Popup):
9 years ago
def __init__(self, app, config, callback):
9 years ago
Factory.Popup.__init__(self)
9 years ago
self.app = app
9 years ago
self.config = config
self.fee_step = self.config.max_fee_rate() / 10
self.fee_rate = self.config.fee_per_kb()
9 years ago
self.callback = callback
self.dynfees = self.config.get('dynamic_fees', True)
9 years ago
self.ids.dynfees.active = self.dynfees
self.update_slider()
self.update_text()
def update_text(self):
value = int(self.ids.slider.value)
self.ids.fee_per_kb.text = self.get_fee_text(value)
9 years ago
def update_slider(self):
slider = self.ids.slider
if self.dynfees:
slider.range = (0, 4)
slider.step = 1
slider.value = self.config.get('fee_level', 2)
9 years ago
else:
slider.range = (1, 10)
slider.step = 1
slider.value = min(self.fee_rate / self.fee_step, 10)
9 years ago
def get_fee_text(self, value):
9 years ago
if self.ids.dynfees.active:
tooltip = fee_levels[value]
if self.config.has_fee_estimates():
dynfee = self.config.dynfee(value)
tooltip += '\n' + (self.app.format_amount_and_units(dynfee)) + '/kB'
9 years ago
else:
fee_rate = value * self.fee_step
tooltip = self.app.format_amount_and_units(fee_rate) + '/kB'
if self.config.has_fee_estimates():
i = self.config.reverse_dynfee(fee_rate)
tooltip += '\n' + (_('low fee') if i < 0 else 'Within %d blocks'%i)
return tooltip
9 years ago
def on_ok(self):
value = int(self.ids.slider.value)
9 years ago
self.config.set_key('dynamic_fees', self.dynfees, False)
if self.dynfees:
self.config.set_key('fee_level', value, True)
9 years ago
else:
self.config.set_key('fee_per_kb', value * self.fee_step, True)
9 years ago
self.callback()
9 years ago
def on_slider(self, value):
self.update_text()
def on_checkbox(self, b):
self.dynfees = b
self.update_slider()
self.update_text()