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: if TYPE_CHECKING:
from ...main_window import ElectrumWindow from ...main_window import ElectrumWindow
from .fee_dialog import FeeSliderDialog
Builder.load_string(''' Builder.load_string('''
<BumpFeeDialog@Popup> <BumpFeeDialog@Popup>
title: _('Bump fee') title: _('Bump fee')
size_hint: 0.8, 0.8 size_hint: 0.8, 0.8
pos_hint: {'top':0.9} pos_hint: {'top':0.9}
method: 0
BoxLayout: BoxLayout:
orientation: 'vertical' orientation: 'vertical'
padding: '10dp' padding: '10dp'
GridLayout: GridLayout:
height: self.minimum_height height: self.minimum_height
size_hint_y: None size_hint_y: None
@ -33,14 +35,24 @@ Builder.load_string('''
id: old_feerate id: old_feerate
text: _('Current Fee rate') text: _('Current Fee rate')
value: '' value: ''
BoxLabel:
id: new_feerate
text: _('New Fee rate')
value: ''
BoxLayout:
orientation: 'horizontal'
size_hint: 1, 0.5
Label: Label:
id: tooltip1 text: _('Target') + ' (%s):' % (_('mempool') if root.method == 2 else _('ETA') if root.method == 1 else _('static'))
text: '' Button:
size_hint_y: None id: fee_target
Label:
id: tooltip2
text: '' 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: Slider:
id: slider id: slider
range: 0, 4 range: 0, 4
@ -72,48 +84,32 @@ Builder.load_string('''
root.on_ok() root.on_ok()
''') ''')
class BumpFeeDialog(Factory.Popup): class BumpFeeDialog(FeeSliderDialog, Factory.Popup):
def __init__(self, app: 'ElectrumWindow', fee, size, callback): def __init__(self, app: 'ElectrumWindow', fee, size, callback):
Factory.Popup.__init__(self) Factory.Popup.__init__(self)
FeeSliderDialog.__init__(self, app.electrum_config, self.ids.slider)
self.app = app self.app = app
self.init_fee = fee self.init_fee = fee
self.tx_size = size self.tx_size = size
self.callback = callback self.callback = callback
self.config = app.electrum_config 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_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.ids.old_feerate.value = self.app.format_fee_rate(fee / self.tx_size * 1000)
self.update_slider() self.update_slider()
self.update_text() self.update_text()
def update_text(self): def update_text(self):
pos = int(self.ids.slider.value) target, tooltip, dyn = self.config.get_fee_target()
new_fee_rate = self.get_fee_rate() self.ids.fee_target.text = target
text, tooltip = self.config.get_fee_text(pos, self.dynfees, self.mempool, new_fee_rate) feerate = self.config.fee_per_kb() / 1000
self.ids.tooltip1.text = text self.ids.new_feerate.value = f'{feerate:.1f} sat/B'
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
def on_ok(self): 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 is_final = self.ids.final_cb.active
self.callback(new_fee_rate, is_final) self.callback(new_fee_rate, is_final)
def on_slider(self, value): def on_slider(self, value):
self.save_config()
self.update_text() 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.plugin import run_hook
from electrum.util import NotEnoughFunds from electrum.util import NotEnoughFunds
from .fee_dialog import FeeSliderDialog, FeeDialog from .fee_dialog import FeeSliderDialog
if TYPE_CHECKING: if TYPE_CHECKING:
from electrum.gui.kivy.main_window import ElectrumWindow from electrum.gui.kivy.main_window import ElectrumWindow
@ -30,6 +30,7 @@ Builder.load_string('''
show_final: False show_final: False
size_hint: 0.8, 0.8 size_hint: 0.8, 0.8
pos_hint: {'top':0.9} pos_hint: {'top':0.9}
method: 0
BoxLayout: BoxLayout:
orientation: 'vertical' orientation: 'vertical'
BoxLayout: BoxLayout:
@ -59,14 +60,23 @@ Builder.load_string('''
orientation: 'horizontal' orientation: 'horizontal'
size_hint: 1, 0.5 size_hint: 1, 0.5
Label: 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: Button:
id: fee_button id: fee_button
text: '' text: ''
background_color: (0,0,0,0) background_color: (0,0,0,0)
bold: True bold: True
on_release: on_release:
root.on_fee_button() root.method = (root.method + 1) % 3
root.on_slider(root.slider.value)
Slider: Slider:
id: slider id: slider
range: 0, 4 range: 0, 4
@ -142,8 +152,9 @@ class ConfirmTxDialog(FeeSliderDialog, Factory.Popup):
amount = self.amount if self.amount != '!' else tx.output_value() amount = self.amount if self.amount != '!' else tx.output_value()
tx_size = tx.estimated_size() tx_size = tx.estimated_size()
fee = tx.get_fee() fee = tx.get_fee()
self.ids.fee_label.text = self.app.format_amount_and_units(fee)
feerate = Decimal(fee) / tx_size # sat/byte 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) self.ids.amount_label.text = self.app.format_amount_and_units(amount)
x_fee = run_hook('get_tx_extra_fee', self.app.wallet, tx) x_fee = run_hook('get_tx_extra_fee', self.app.wallet, tx)
if x_fee: if x_fee:
@ -168,13 +179,3 @@ class ConfirmTxDialog(FeeSliderDialog, Factory.Popup):
def update_text(self): def update_text(self):
target, tooltip, dyn = self.config.get_fee_target() target, tooltip, dyn = self.config.get_fee_target()
self.ids.fee_button.text = 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