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
This commit is contained in:
@@ -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()
|
||||
|
||||
@@ -105,10 +105,14 @@ Item {
|
||||
function updateText() {
|
||||
if (!Daemon.fx.enabled) {
|
||||
text = ''
|
||||
} else if (Daemon.fx.historicRates) {
|
||||
} else if (Daemon.fx.historicRates && model.timestamp) {
|
||||
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()
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user