Browse Source

add option for unformatted numbers to string

patch-4
Sander van Grieken 3 years ago
parent
commit
f2a9b5d06a
  1. 2
      electrum/gui/qml/components/Receive.qml
  2. 2
      electrum/gui/qml/components/Send.qml
  3. 16
      electrum/gui/qml/qefx.py

2
electrum/gui/qml/components/Receive.qml

@ -75,7 +75,7 @@ Pane {
inputMethodHints: Qt.ImhDigitsOnly inputMethodHints: Qt.ImhDigitsOnly
onTextChanged: { onTextChanged: {
if (amountFiat.activeFocus) if (amountFiat.activeFocus)
amount.text = Daemon.fx.satoshiValue(amountFiat.text) amount.text = text == '' ? '' : Config.satsToUnits(Daemon.fx.satoshiValue(amountFiat.text))
} }
} }

2
electrum/gui/qml/components/Send.qml

@ -83,7 +83,7 @@ Pane {
inputMethodHints: Qt.ImhPreferNumbers inputMethodHints: Qt.ImhPreferNumbers
onTextChanged: { onTextChanged: {
if (amountFiat.activeFocus) if (amountFiat.activeFocus)
amount.text = Daemon.fx.satoshiValue(amountFiat.text) amount.text = text == '' ? '' : Config.satsToUnits(Daemon.fx.satoshiValue(amountFiat.text))
} }
} }

16
electrum/gui/qml/qefx.py

@ -86,7 +86,8 @@ class QEFX(QObject):
self.enabledChanged.emit() self.enabledChanged.emit()
@pyqtSlot(str, result=str) @pyqtSlot(str, result=str)
def fiatValue(self, satoshis): @pyqtSlot(str, bool, result=str)
def fiatValue(self, satoshis, plain=True):
rate = self.fx.exchange_rate() rate = self.fx.exchange_rate()
try: try:
sd = Decimal(satoshis) sd = Decimal(satoshis)
@ -94,14 +95,23 @@ class QEFX(QObject):
return '' return ''
except: except:
return '' return ''
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, result=str) @pyqtSlot(str, result=str)
def satoshiValue(self, fiat): @pyqtSlot(str, bool, result=str)
def satoshiValue(self, fiat, plain=True):
rate = self.fx.exchange_rate() rate = self.fx.exchange_rate()
try: try:
fd = Decimal(fiat) fd = Decimal(fiat)
except: except:
return '' return ''
v = fd / Decimal(rate) * COIN v = fd / Decimal(rate) * COIN
return '' if v.is_nan() else self.config.format_amount(v) if v.is_nan():
return ''
if plain:
return str(v.to_integral_value())
else:
return self.config.format_amount(v)

Loading…
Cancel
Save