qml: QEConfig.formatMilliSats to use config.format_amount
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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'
|
||||
|
||||
Reference in New Issue
Block a user