1
0

add option for unformatted numbers to string

This commit is contained in:
Sander van Grieken
2022-04-06 13:49:40 +02:00
parent fad2d879ef
commit f2a9b5d06a
3 changed files with 16 additions and 6 deletions

View File

@@ -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))
}
}

View File

@@ -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))
}
}

View File

@@ -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)