Browse Source

qml: don't show fiat amount when timestamp more than a day old and historic rates are disabled

master
Sander van Grieken 2 years ago
parent
commit
5077e013f3
No known key found for this signature in database
GPG Key ID: 9BCF8209EA402EBA
  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

@ -108,7 +108,11 @@ Item {
} else if (Daemon.fx.historicRates) { } else if (Daemon.fx.historicRates) {
text = Daemon.fx.fiatValueHistoric(model.value, model.timestamp) + ' ' + Daemon.fx.fiatCurrency text = Daemon.fx.fiatValueHistoric(model.value, model.timestamp) + ' ' + Daemon.fx.fiatCurrency
} else { } else {
text = Daemon.fx.fiatValue(model.value, false) + ' ' + Daemon.fx.fiatCurrency if (Daemon.fx.isRecent(model.timestamp)) {
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