Browse Source

kivy: unify fee dialogs

- confirm_tx_dialog and bump_fee_dialog inherit from FeeSliderDialog
 - changing the slider method does not require an extra popup
patch-4
ThomasV 4 years ago
parent
commit
abaefa362a
  1. 58
      electrum/gui/kivy/uix/dialogs/bump_fee_dialog.py
  2. 29
      electrum/gui/kivy/uix/dialogs/confirm_tx_dialog.py

58
electrum/gui/kivy/uix/dialogs/bump_fee_dialog.py

@ -10,16 +10,18 @@ from electrum.gui.kivy.i18n import _
if TYPE_CHECKING:
from ...main_window import ElectrumWindow
from .fee_dialog import FeeSliderDialog
Builder.load_string('''
<BumpFeeDialog@Popup>
title: _('Bump fee')
size_hint: 0.8, 0.8
pos_hint: {'top':0.9}
method: 0
BoxLayout:
orientation: 'vertical'
padding: '10dp'
GridLayout:
height: self.minimum_height
size_hint_y: None
@ -33,14 +35,24 @@ Builder.load_string('''
id: old_feerate
text: _('Current Fee rate')
value: ''
BoxLabel:
id: new_feerate
text: _('New Fee rate')
value: ''
BoxLayout:
orientation: 'horizontal'
size_hint: 1, 0.5
Label:
id: tooltip1
text: ''
size_hint_y: None
Label:
id: tooltip2
text: _('Target') + ' (%s):' % (_('mempool') if root.method == 2 else _('ETA') if root.method == 1 else _('static'))
Button:
id: fee_target
text: ''
size_hint_y: None
background_color: (0,0,0,0)
bold: True
on_release:
root.method = (root.method + 1) % 3
root.update_slider()
root.update_text()
Slider:
id: slider
range: 0, 4
@ -72,48 +84,32 @@ Builder.load_string('''
root.on_ok()
''')
class BumpFeeDialog(Factory.Popup):
class BumpFeeDialog(FeeSliderDialog, Factory.Popup):
def __init__(self, app: 'ElectrumWindow', fee, size, callback):
Factory.Popup.__init__(self)
FeeSliderDialog.__init__(self, app.electrum_config, self.ids.slider)
self.app = app
self.init_fee = fee
self.tx_size = size
self.callback = callback
self.config = app.electrum_config
self.mempool = self.config.use_mempool_fees()
self.dynfees = self.config.is_dynfee() and bool(self.app.network) and self.config.has_dynamic_fees_ready()
self.ids.old_fee.value = self.app.format_amount_and_units(self.init_fee)
self.ids.old_feerate.value = self.app.format_fee_rate(fee / self.tx_size * 1000)
self.update_slider()
self.update_text()
def update_text(self):
pos = int(self.ids.slider.value)
new_fee_rate = self.get_fee_rate()
text, tooltip = self.config.get_fee_text(pos, self.dynfees, self.mempool, new_fee_rate)
self.ids.tooltip1.text = text
self.ids.tooltip2.text = tooltip
def update_slider(self):
slider = self.ids.slider
maxp, pos, fee_rate = self.config.get_fee_slider(self.dynfees, self.mempool)
slider.range = (0, maxp)
slider.step = 1
slider.value = pos
def get_fee_rate(self):
pos = int(self.ids.slider.value)
if self.dynfees:
fee_rate = self.config.depth_to_fee(pos) if self.mempool else self.config.eta_to_fee(pos)
else:
fee_rate = self.config.static_fee(pos)
return fee_rate # sat/kbyte
target, tooltip, dyn = self.config.get_fee_target()
self.ids.fee_target.text = target
feerate = self.config.fee_per_kb() / 1000
self.ids.new_feerate.value = f'{feerate:.1f} sat/B'
def on_ok(self):
new_fee_rate = self.get_fee_rate() / 1000
new_fee_rate = self.config.fee_per_kb() / 1000
is_final = self.ids.final_cb.active
self.callback(new_fee_rate, is_final)
def on_slider(self, value):
self.save_config()
self.update_text()

29
electrum/gui/kivy/uix/dialogs/confirm_tx_dialog.py

@ -15,7 +15,7 @@ from electrum.gui.kivy.i18n import _
from electrum.plugin import run_hook
from electrum.util import NotEnoughFunds
from .fee_dialog import FeeSliderDialog, FeeDialog
from .fee_dialog import FeeSliderDialog
if TYPE_CHECKING:
from electrum.gui.kivy.main_window import ElectrumWindow
@ -30,6 +30,7 @@ Builder.load_string('''
show_final: False
size_hint: 0.8, 0.8
pos_hint: {'top':0.9}
method: 0
BoxLayout:
orientation: 'vertical'
BoxLayout:
@ -59,14 +60,23 @@ Builder.load_string('''
orientation: 'horizontal'
size_hint: 1, 0.5
Label:
text: _('Fee target:')
text: _('Fee rate:')
Label:
id: feerate_label
text: ''
BoxLayout:
orientation: 'horizontal'
size_hint: 1, 0.5
Label:
text: _('Target') + ' (%s):' % (_('mempool') if root.method == 2 else _('ETA') if root.method == 1 else _('static'))
Button:
id: fee_button
text: ''
background_color: (0,0,0,0)
bold: True
on_release:
root.on_fee_button()
root.method = (root.method + 1) % 3
root.on_slider(root.slider.value)
Slider:
id: slider
range: 0, 4
@ -142,8 +152,9 @@ class ConfirmTxDialog(FeeSliderDialog, Factory.Popup):
amount = self.amount if self.amount != '!' else tx.output_value()
tx_size = tx.estimated_size()
fee = tx.get_fee()
self.ids.fee_label.text = self.app.format_amount_and_units(fee)
feerate = Decimal(fee) / tx_size # sat/byte
self.ids.fee_label.text = self.app.format_amount_and_units(fee) + f' ({feerate:.1f} sat/B)'
self.ids.feerate_label.text = f'{feerate:.1f} sat/B'
self.ids.amount_label.text = self.app.format_amount_and_units(amount)
x_fee = run_hook('get_tx_extra_fee', self.app.wallet, tx)
if x_fee:
@ -168,13 +179,3 @@ class ConfirmTxDialog(FeeSliderDialog, Factory.Popup):
def update_text(self):
target, tooltip, dyn = self.config.get_fee_target()
self.ids.fee_button.text = target
def on_fee_button(self):
fee_dialog = FeeDialog(self, self.config, self.after_fee_changed)
fee_dialog.open()
def after_fee_changed(self):
self.read_config()
self.update_slider()
self.update_text()
Clock.schedule_once(lambda dt: self.update_tx())

Loading…
Cancel
Save