From f2a9b5d06a0d780fdd507d41f5b085c21e557d99 Mon Sep 17 00:00:00 2001 From: Sander van Grieken Date: Wed, 6 Apr 2022 13:49:40 +0200 Subject: [PATCH] add option for unformatted numbers to string --- electrum/gui/qml/components/Receive.qml | 2 +- electrum/gui/qml/components/Send.qml | 2 +- electrum/gui/qml/qefx.py | 18 ++++++++++++++---- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/electrum/gui/qml/components/Receive.qml b/electrum/gui/qml/components/Receive.qml index 4b73042e2..126fb4cbb 100644 --- a/electrum/gui/qml/components/Receive.qml +++ b/electrum/gui/qml/components/Receive.qml @@ -75,7 +75,7 @@ Pane { inputMethodHints: Qt.ImhDigitsOnly onTextChanged: { if (amountFiat.activeFocus) - amount.text = Daemon.fx.satoshiValue(amountFiat.text) + amount.text = text == '' ? '' : Config.satsToUnits(Daemon.fx.satoshiValue(amountFiat.text)) } } diff --git a/electrum/gui/qml/components/Send.qml b/electrum/gui/qml/components/Send.qml index dfb1df56b..223863d8e 100644 --- a/electrum/gui/qml/components/Send.qml +++ b/electrum/gui/qml/components/Send.qml @@ -83,7 +83,7 @@ Pane { inputMethodHints: Qt.ImhPreferNumbers onTextChanged: { if (amountFiat.activeFocus) - amount.text = Daemon.fx.satoshiValue(amountFiat.text) + amount.text = text == '' ? '' : Config.satsToUnits(Daemon.fx.satoshiValue(amountFiat.text)) } } diff --git a/electrum/gui/qml/qefx.py b/electrum/gui/qml/qefx.py index 08b98a69d..148484d1f 100644 --- a/electrum/gui/qml/qefx.py +++ b/electrum/gui/qml/qefx.py @@ -86,7 +86,8 @@ class QEFX(QObject): self.enabledChanged.emit() @pyqtSlot(str, result=str) - def fiatValue(self, satoshis): + @pyqtSlot(str, bool, result=str) + def fiatValue(self, satoshis, plain=True): rate = self.fx.exchange_rate() try: sd = Decimal(satoshis) @@ -94,14 +95,23 @@ class QEFX(QObject): return '' except: return '' - return self.fx.value_str(satoshis,rate) + if plain: + return self.fx.ccy_amount_str(self.fx.fiat_value(satoshis, rate), False) + else: + return self.fx.value_str(satoshis,rate) @pyqtSlot(str, result=str) - def satoshiValue(self, fiat): + @pyqtSlot(str, bool, result=str) + def satoshiValue(self, fiat, plain=True): rate = self.fx.exchange_rate() try: fd = Decimal(fiat) except: return '' 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)