1
0

qt lightning_tx_dialog: use historical fx rate for fiat amounts

This commit is contained in:
SomberNight
2021-03-12 18:29:00 +01:00
parent 24e4aa3ab9
commit 1ba5997238
4 changed files with 26 additions and 19 deletions

View File

@@ -64,11 +64,12 @@ class LightningTxDialog(WindowModalDialog):
vbox = QVBoxLayout()
self.setLayout(vbox)
# FIXME fiat values here are using today's FX rate instead of historical
vbox.addWidget(QLabel(_("Amount") + ": " + self.parent.format_amount_and_units(self.amount)))
amount_str = self.parent.format_amount_and_units(self.amount, timestamp=self.timestamp)
vbox.addWidget(QLabel(_("Amount") + f": {amount_str}"))
if self.is_sent:
fee = Decimal(tx_item['fee_msat']) / 1000
vbox.addWidget(QLabel(_("Fee") + ": " + self.parent.format_amount_and_units(fee)))
fee_str = self.parent.format_amount_and_units(fee, timestamp=self.timestamp)
vbox.addWidget(QLabel(_("Fee") + f": {fee_str}"))
time_str = datetime.datetime.fromtimestamp(self.timestamp).isoformat(' ')[:-3]
vbox.addWidget(QLabel(_("Date") + ": " + time_str))

View File

@@ -878,14 +878,14 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger):
"""
return self.config.format_amount(amount_sat, is_diff=is_diff, whitespaces=whitespaces)
def format_amount_and_units(self, amount_sat) -> str:
def format_amount_and_units(self, amount_sat, *, timestamp: int = None) -> str:
"""Returns string with both bitcoin and fiat amounts, in desired units.
E.g. 500_000 -> '0.005 BTC (191.42 EUR)'
"""
text = self.config.format_amount_and_units(amount_sat)
x = self.fx.format_amount_and_units(amount_sat) if self.fx else None
if text and x:
text += ' (%s)'%x
fiat = self.fx.format_amount_and_units(amount_sat, timestamp=timestamp) if self.fx else None
if text and fiat:
text += f' ({fiat})'
return text
def format_fiat_and_units(self, amount_sat) -> str: