Browse Source

historic rates

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

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

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

48
electrum/gui/qml/qefx.py

@ -1,6 +1,7 @@
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject
from decimal import Decimal from decimal import Decimal
from datetime import datetime
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject
from electrum.logging import get_logger from electrum.logging import get_logger
from electrum.exchange_rate import FxThread from electrum.exchange_rate import FxThread
@ -31,12 +32,12 @@ class QEFX(QObject):
currenciesChanged = pyqtSignal() currenciesChanged = pyqtSignal()
@pyqtProperty('QVariantList', notify=currenciesChanged) @pyqtProperty('QVariantList', notify=currenciesChanged)
def currencies(self): def currencies(self):
return [''] + self.fx.get_currencies(self.historyRates) return self.fx.get_currencies(self.historicRates)
rateSourcesChanged = pyqtSignal() rateSourcesChanged = pyqtSignal()
@pyqtProperty('QVariantList', notify=rateSourcesChanged) @pyqtProperty('QVariantList', notify=rateSourcesChanged)
def rateSources(self): 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() fiatCurrencyChanged = pyqtSignal()
@pyqtProperty(str, notify=fiatCurrencyChanged) @pyqtProperty(str, notify=fiatCurrencyChanged)
@ -47,20 +48,20 @@ class QEFX(QObject):
def fiatCurrency(self, currency): def fiatCurrency(self, currency):
if currency != self.fiatCurrency: if currency != self.fiatCurrency:
self.fx.set_currency(currency) self.fx.set_currency(currency)
self.enabled = currency != '' self.enabled = self.enabled and currency != ''
self.fiatCurrencyChanged.emit() self.fiatCurrencyChanged.emit()
self.rateSourcesChanged.emit() self.rateSourcesChanged.emit()
historyRatesChanged = pyqtSignal() historicRatesChanged = pyqtSignal()
@pyqtProperty(bool, notify=historyRatesChanged) @pyqtProperty(bool, notify=historicRatesChanged)
def historyRates(self): def historicRates(self):
return self.fx.get_history_config() return self.fx.get_history_config()
@historyRates.setter @historicRates.setter
def historyRates(self, checked): def historicRates(self, checked):
if checked != self.historyRates: if checked != self.historicRates:
self.fx.set_history_config(checked) self.fx.set_history_config(checked)
self.historyRatesChanged.emit() self.historicRatesChanged.emit()
self.rateSourcesChanged.emit() self.rateSourcesChanged.emit()
rateSourceChanged = pyqtSignal() rateSourceChanged = pyqtSignal()
@ -74,8 +75,8 @@ class QEFX(QObject):
self.fx.set_exchange(source) self.fx.set_exchange(source)
self.rateSourceChanged.emit() self.rateSourceChanged.emit()
enabledChanged = pyqtSignal() enabledUpdated = pyqtSignal() # curiously, enabledChanged is clashing, so name it enabledUpdated
@pyqtProperty(bool, notify=enabledChanged) @pyqtProperty(bool, notify=enabledUpdated)
def enabled(self): def enabled(self):
return self.fx.is_enabled() return self.fx.is_enabled()
@ -83,7 +84,7 @@ class QEFX(QObject):
def enabled(self, enable): def enabled(self, enable):
if enable != self.enabled: if enable != self.enabled:
self.fx.set_enabled(enable) self.fx.set_enabled(enable)
self.enabledChanged.emit() self.enabledUpdated.emit()
@pyqtSlot(str, result=str) @pyqtSlot(str, result=str)
@pyqtSlot(str, bool, result=str) @pyqtSlot(str, bool, result=str)
@ -100,6 +101,23 @@ class QEFX(QObject):
else: 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, result=str)
@pyqtSlot(str, bool, result=str) @pyqtSlot(str, bool, result=str)
def satoshiValue(self, fiat, plain=True): def satoshiValue(self, fiat, plain=True):

Loading…
Cancel
Save