Browse Source

qt tx dialog: also display fiat amounts

patch-4
hcp 4 years ago
committed by SomberNight
parent
commit
e01a2014b1
No known key found for this signature in database GPG Key ID: B33B5F232C6271E9
  1. 4
      electrum/gui/qt/main_window.py
  2. 35
      electrum/gui/qt/transaction_dialog.py

4
electrum/gui/qt/main_window.py

@ -885,6 +885,10 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
text += ' (%s)'%x
return text
def format_fiat_and_units(self, amount):
# amount is in sats
return self.fx.format_amount_and_units(amount) if self.fx else ''
def format_fee_rate(self, fee_rate):
return self.config.format_fee_rate(fee_rate)

35
electrum/gui/qt/transaction_dialog.py

@ -68,6 +68,9 @@ class TxSizeLabel(QLabel):
def setAmount(self, byte_size):
self.setText(('x %s bytes =' % byte_size) if byte_size else '')
class TxFiatLabel(QLabel):
def setAmount(self, fiat_fee):
self.setText(('%s' % fiat_fee) if fiat_fee else '')
class QTextEditWithDefaultSize(QTextEdit):
def sizeHint(self):
@ -429,12 +432,15 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
desc = self.desc
base_unit = self.main_window.base_unit()
format_amount = self.main_window.format_amount
format_fiat_and_units = self.main_window.format_fiat_and_units
tx_details = self.wallet.get_tx_info(self.tx)
tx_mined_status = tx_details.tx_mined_status
exp_n = tx_details.mempool_depth_bytes
amount, fee = tx_details.amount, tx_details.fee
size = self.tx.estimated_size()
txid = self.tx.txid()
if txid is not None and self.main_window.fx.is_enabled():
tx_item_fiat = self.wallet.get_tx_item_fiat(txid, amount, self.main_window.fx, fee)
lnworker_history = self.wallet.lnworker.get_onchain_history() if self.wallet.lnworker else {}
if txid in lnworker_history:
item = lnworker_history[txid]
@ -493,14 +499,33 @@ class BaseTxDialog(QDialog, MessageBoxMixin):
amount_str = ''
elif amount > 0:
amount_str = _("Amount received:") + ' %s'% format_amount(amount) + ' ' + base_unit
if self.main_window.fx.is_enabled():
if txid is not None:
amount_str += ' (%s)'% tx_item_fiat['fiat_value'].to_ui_string()
else:
amount_str += ' (%s)'% format_fiat_and_units(amount)
else:
amount_str = _("Amount sent:") + ' %s'% format_amount(-amount) + ' ' + base_unit
if self.main_window.fx.is_enabled():
if txid is not None:
if amount == 0:
amount_str += ' (%s)'% tx_item_fiat['fiat_value'].to_ui_string()
else:
amount_str += ' (%s)'% tx_item_fiat['fiat_value'].to_ui_string()[1:]
else:
amount_str += ' (%s)'% format_fiat_and_units(-amount)
if amount_str:
self.amount_label.setText(amount_str)
else:
self.amount_label.hide()
size_str = _("Size:") + ' %d bytes'% size
fee_str = _("Fee") + ': %s' % (format_amount(fee) + ' ' + base_unit if fee is not None else _('unknown'))
if self.main_window.fx.is_enabled():
if txid is not None:
fee_str = _("Fee") + ': %s' % (format_amount(fee) + ' ' + base_unit + ' (' + tx_item_fiat['fiat_fee'].to_ui_string() + ')' if fee is not None else _("Unknown"))
else:
fee_str = _("Fee") + ': %s' % (format_amount(fee) + ' ' + base_unit + ' (' + format_fiat_and_units(fee) + ')' if fee is not None else _("Unknown"))
else:
fee_str = _("Fee") + ': %s' % (format_amount(fee) + ' ' + base_unit if fee is not None else _("Unknown"))
if fee is not None:
fee_rate = fee/size*1000
fee_str += ' ( %s ) ' % self.main_window.format_fee_rate(fee_rate)
@ -760,6 +785,11 @@ class PreviewTxDialog(BaseTxDialog, TxEditor):
self.size_e.setAmount(0)
self.size_e.setStyleSheet(ColorScheme.DEFAULT.as_stylesheet())
self.size_f = TxFiatLabel()
self.size_f.setAlignment(Qt.AlignCenter)
self.size_f.setAmount(0)
self.size_f.setStyleSheet(ColorScheme.DEFAULT.as_stylesheet())
self.feerate_e = FeerateEdit(lambda: 0)
self.feerate_e.setAmount(self.config.fee_per_byte())
self.feerate_e.textEdited.connect(partial(self.on_fee_or_feerate, self.feerate_e, False))
@ -800,6 +830,7 @@ class PreviewTxDialog(BaseTxDialog, TxEditor):
grid.addWidget(self.size_e, 0, 2)
grid.addWidget(self.fee_e, 0, 3)
grid.addWidget(self.feerounding_icon, 0, 4)
grid.addWidget(self.size_f, 0, 5)
grid.addWidget(self.fee_slider, 1, 1)
grid.addWidget(self.fee_combo, 1, 2)
hbox.addLayout(grid)
@ -893,6 +924,8 @@ class PreviewTxDialog(BaseTxDialog, TxEditor):
fee = tx.get_fee()
self.size_e.setAmount(size)
fiat_fee = self.main_window.format_fiat_and_units(fee)
self.size_f.setAmount(fiat_fee)
# Displayed fee/fee_rate values are set according to user input.
# Due to rounding or dropping dust in CoinChooser,

Loading…
Cancel
Save