1
0

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

This commit is contained in:
Sander van Grieken
2024-01-04 12:25:40 +01:00
parent 88058df409
commit 5077e013f3
3 changed files with 21 additions and 4 deletions

View File

@@ -47,8 +47,9 @@ GridLayout {
if (historic && timestamp)
fiatLabel.text = '(' + Daemon.fx.fiatValueHistoric(amount, timestamp) + ' ' + Daemon.fx.fiatCurrency + ')'
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()

View File

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

View File

@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timedelta
from decimal import Decimal
from PyQt6.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, QRegularExpression
@@ -164,3 +164,15 @@ class QEFX(QObject, QtEventListener):
return str(v.to_integral_value())
else:
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()