Browse Source

Merge pull request #8788 from accumulator/qml_non_historic_fiat

qml: don't show fiat amount when timestamp more than a day old and historic rates are disabled
master
accumulator 2 years ago committed by GitHub
parent
commit
35d4cf4d09
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      electrum/gui/qml/components/controls/FormattedAmount.qml
  2. 6
      electrum/gui/qml/components/controls/HistoryItemDelegate.qml
  3. 14
      electrum/gui/qml/qefx.py

5
electrum/gui/qml/components/controls/FormattedAmount.qml

@ -47,8 +47,9 @@ GridLayout {
if (historic && timestamp) if (historic && timestamp)
fiatLabel.text = '(' + Daemon.fx.fiatValueHistoric(amount, timestamp) + ' ' + Daemon.fx.fiatCurrency + ')' fiatLabel.text = '(' + Daemon.fx.fiatValueHistoric(amount, timestamp) + ' ' + Daemon.fx.fiatCurrency + ')'
else else
fiatLabel.text = '(' + Daemon.fx.fiatValue(amount) + ' ' + Daemon.fx.fiatCurrency + ')' fiatLabel.text = Daemon.fx.isRecent(timestamp)
? '(' + Daemon.fx.fiatValue(amount) + ' ' + Daemon.fx.fiatCurrency + ')'
: ''
} }
onAmountChanged: setFiatValue() onAmountChanged: setFiatValue()

6
electrum/gui/qml/components/controls/HistoryItemDelegate.qml

@ -105,10 +105,14 @@ Item {
function updateText() { function updateText() {
if (!Daemon.fx.enabled) { if (!Daemon.fx.enabled) {
text = '' text = ''
} else if (Daemon.fx.historicRates) { } else if (Daemon.fx.historicRates && model.timestamp) {
text = Daemon.fx.fiatValueHistoric(model.value, model.timestamp) + ' ' + Daemon.fx.fiatCurrency text = Daemon.fx.fiatValueHistoric(model.value, model.timestamp) + ' ' + Daemon.fx.fiatCurrency
} else { } else {
if (Daemon.fx.isRecent(model.timestamp)) {
text = Daemon.fx.fiatValue(model.value, false) + ' ' + Daemon.fx.fiatCurrency text = Daemon.fx.fiatValue(model.value, false) + ' ' + Daemon.fx.fiatCurrency
} else {
text = ''
}
} }
} }
Component.onCompleted: updateText() Component.onCompleted: updateText()

14
electrum/gui/qml/qefx.py

@ -1,4 +1,4 @@
from datetime import datetime from datetime import datetime, timedelta
from decimal import Decimal from decimal import Decimal
from PyQt6.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, QRegularExpression from PyQt6.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, QRegularExpression
@ -164,3 +164,15 @@ class QEFX(QObject, QtEventListener):
return str(v.to_integral_value()) return str(v.to_integral_value())
else: else:
return self.config.format_amount(v) return self.config.format_amount(v)
@pyqtSlot(str, result=bool)
def isRecent(self, timestamp):
# return True if unknown, e.g. timestamp not known yet, tx in mempool
try:
td = Decimal(timestamp)
if td == 0:
return True
except Exception:
return True
dt = datetime.fromtimestamp(int(td))
return dt + timedelta(days=1) > datetime.today()

Loading…
Cancel
Save