Browse Source

historic rates

patch-4
Sander van Grieken 3 years ago
parent
commit
b2f2dfc44f
  1. 23
      electrum/gui/qml/components/Preferences.qml
  2. 50
      electrum/gui/qml/qefx.py

23
electrum/gui/qml/components/Preferences.qml

@ -58,13 +58,19 @@ Pane {
enabled: false
}
Label {
CheckBox {
id: fiatEnable
text: qsTr('Fiat Currency')
onCheckedChanged: {
if (activeFocus)
Daemon.fx.enabled = checked
}
}
ComboBox {
id: currencies
model: Daemon.fx.currencies
enabled: Daemon.fx.enabled
onCurrentValueChanged: {
if (activeFocus)
Daemon.fx.fiatCurrency = currentValue
@ -72,24 +78,24 @@ Pane {
}
CheckBox {
id: historyRates
text: qsTr('History rates')
enabled: currencies.currentValue != ''
id: historicRates
text: qsTr('Historic rates')
enabled: Daemon.fx.enabled
Layout.columnSpan: 2
onCheckStateChanged: {
if (activeFocus)
Daemon.fx.historyRates = checked
Daemon.fx.historicRates = checked
}
}
Label {
text: qsTr('Source')
enabled: currencies.currentValue != ''
enabled: Daemon.fx.enabled
}
ComboBox {
id: rateSources
enabled: currencies.currentValue != ''
enabled: Daemon.fx.enabled
model: Daemon.fx.rateSources
onModelChanged: {
currentIndex = rateSources.indexOfValue(Daemon.fx.rateSource)
@ -109,7 +115,8 @@ Pane {
baseUnit.currentIndex = ['BTC','mBTC','bits','sat'].indexOf(Config.baseUnit)
thousands.checked = Config.thousandsSeparator
currencies.currentIndex = currencies.indexOfValue(Daemon.fx.fiatCurrency)
historyRates.checked = Daemon.fx.historyRates
historicRates.checked = Daemon.fx.historicRates
rateSources.currentIndex = rateSources.indexOfValue(Daemon.fx.rateSource)
fiatEnable.checked = Daemon.fx.enabled
}
}

50
electrum/gui/qml/qefx.py

@ -1,6 +1,7 @@
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject
from decimal import Decimal
from datetime import datetime
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject
from electrum.logging import get_logger
from electrum.exchange_rate import FxThread
@ -31,12 +32,12 @@ class QEFX(QObject):
currenciesChanged = pyqtSignal()
@pyqtProperty('QVariantList', notify=currenciesChanged)
def currencies(self):
return [''] + self.fx.get_currencies(self.historyRates)
return self.fx.get_currencies(self.historicRates)
rateSourcesChanged = pyqtSignal()
@pyqtProperty('QVariantList', notify=rateSourcesChanged)
def rateSources(self):
return self.fx.get_exchanges_by_ccy(self.fiatCurrency, self.historyRates)
return self.fx.get_exchanges_by_ccy(self.fiatCurrency, self.historicRates)
fiatCurrencyChanged = pyqtSignal()
@pyqtProperty(str, notify=fiatCurrencyChanged)
@ -47,20 +48,20 @@ class QEFX(QObject):
def fiatCurrency(self, currency):
if currency != self.fiatCurrency:
self.fx.set_currency(currency)
self.enabled = currency != ''
self.enabled = self.enabled and currency != ''
self.fiatCurrencyChanged.emit()
self.rateSourcesChanged.emit()
historyRatesChanged = pyqtSignal()
@pyqtProperty(bool, notify=historyRatesChanged)
def historyRates(self):
historicRatesChanged = pyqtSignal()
@pyqtProperty(bool, notify=historicRatesChanged)
def historicRates(self):
return self.fx.get_history_config()
@historyRates.setter
def historyRates(self, checked):
if checked != self.historyRates:
@historicRates.setter
def historicRates(self, checked):
if checked != self.historicRates:
self.fx.set_history_config(checked)
self.historyRatesChanged.emit()
self.historicRatesChanged.emit()
self.rateSourcesChanged.emit()
rateSourceChanged = pyqtSignal()
@ -74,8 +75,8 @@ class QEFX(QObject):
self.fx.set_exchange(source)
self.rateSourceChanged.emit()
enabledChanged = pyqtSignal()
@pyqtProperty(bool, notify=enabledChanged)
enabledUpdated = pyqtSignal() # curiously, enabledChanged is clashing, so name it enabledUpdated
@pyqtProperty(bool, notify=enabledUpdated)
def enabled(self):
return self.fx.is_enabled()
@ -83,7 +84,7 @@ class QEFX(QObject):
def enabled(self, enable):
if enable != self.enabled:
self.fx.set_enabled(enable)
self.enabledChanged.emit()
self.enabledUpdated.emit()
@pyqtSlot(str, result=str)
@pyqtSlot(str, bool, result=str)
@ -98,7 +99,24 @@ class QEFX(QObject):
if plain:
return self.fx.ccy_amount_str(self.fx.fiat_value(satoshis, rate), False)
else:
return self.fx.value_str(satoshis,rate)
return self.fx.value_str(satoshis, rate)
@pyqtSlot(str, str, result=str)
def fiatValueHistoric(self, satoshis, timestamp, plain=True):
try:
sd = Decimal(satoshis)
if sd == 0:
return ''
td = Decimal(timestamp)
if td == 0:
return ''
except:
return ''
dt = datetime.fromtimestamp(td)
if plain:
return self.fx.ccy_amount_str(self.fx.historical_value(satoshis, dt), False)
else:
return self.fx.historical_value_str(satoshis, dt)
@pyqtSlot(str, result=str)
@pyqtSlot(str, bool, result=str)

Loading…
Cancel
Save