From fc6cbb39ea355fc8562fe4a4df699930eeb060ff Mon Sep 17 00:00:00 2001 From: SomberNight Date: Fri, 31 Mar 2023 22:17:53 +0000 Subject: [PATCH] qml: QEConfig.formatMilliSats to use config.format_amount --- electrum/gui/qml/qeconfig.py | 21 +++++++++++---------- electrum/simple_config.py | 19 ++++++++++++++----- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/electrum/gui/qml/qeconfig.py b/electrum/gui/qml/qeconfig.py index 007a0e3d0..6dc934221 100644 --- a/electrum/gui/qml/qeconfig.py +++ b/electrum/gui/qml/qeconfig.py @@ -1,5 +1,6 @@ import copy from decimal import Decimal +from typing import TYPE_CHECKING from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject @@ -11,10 +12,14 @@ from electrum.invoices import PR_DEFAULT_EXPIRATION_WHEN_CREATING from .qetypes import QEAmount from .auth import AuthMixin, auth_protect +if TYPE_CHECKING: + from electrum.simple_config import SimpleConfig + + class QEConfig(AuthMixin, QObject): _logger = get_logger(__name__) - def __init__(self, config, parent=None): + def __init__(self, config: 'SimpleConfig', parent=None): super().__init__(parent) self.config = config @@ -213,15 +218,11 @@ class QEConfig(AuthMixin, QObject): msats = amount.msatsInt else: return '---' - - s = format_satoshis(msats/1000, - decimal_point=self.decimal_point(), - precision=3) - return s - #if with_unit: - #return self.config.format_amount_and_units(msats) - #else: - #return self.config.format_amount(satoshis) + precision = 3 # config.amt_precision_post_satoshi is not exposed in preferences + if with_unit: + return self.config.format_amount_and_units(msats/1000, precision=precision) + else: + return self.config.format_amount(msats/1000, precision=precision) # TODO delegate all this to config.py/util.py def decimal_point(self): diff --git a/electrum/simple_config.py b/electrum/simple_config.py index 0ecdfa6b7..d57418b5f 100644 --- a/electrum/simple_config.py +++ b/electrum/simple_config.py @@ -677,19 +677,28 @@ class SimpleConfig(Logger): except: pass - def format_amount(self, x, is_diff=False, whitespaces=False): + def format_amount( + self, + amount_sat, + *, + is_diff=False, + whitespaces=False, + precision=None, + ) -> str: + if precision is None: + precision = self.amt_precision_post_satoshi return format_satoshis( - x, + amount_sat, num_zeros=self.num_zeros, decimal_point=self.decimal_point, is_diff=is_diff, whitespaces=whitespaces, - precision=self.amt_precision_post_satoshi, + precision=precision, add_thousands_sep=self.amt_add_thousands_sep, ) - def format_amount_and_units(self, amount): - return self.format_amount(amount) + ' '+ self.get_base_unit() + def format_amount_and_units(self, *args, **kwargs) -> str: + return self.format_amount(*args, **kwargs) + ' ' + self.get_base_unit() def format_fee_rate(self, fee_rate): return format_fee_satoshis(fee_rate/1000, num_zeros=self.num_zeros) + ' sat/byte'