Browse Source

qml: QEConfig.formatMilliSats to use config.format_amount

master
SomberNight 3 years ago
parent
commit
fc6cbb39ea
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 21
      electrum/gui/qml/qeconfig.py
  2. 19
      electrum/simple_config.py

21
electrum/gui/qml/qeconfig.py

@ -1,5 +1,6 @@
import copy import copy
from decimal import Decimal from decimal import Decimal
from typing import TYPE_CHECKING
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject 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 .qetypes import QEAmount
from .auth import AuthMixin, auth_protect from .auth import AuthMixin, auth_protect
if TYPE_CHECKING:
from electrum.simple_config import SimpleConfig
class QEConfig(AuthMixin, QObject): class QEConfig(AuthMixin, QObject):
_logger = get_logger(__name__) _logger = get_logger(__name__)
def __init__(self, config, parent=None): def __init__(self, config: 'SimpleConfig', parent=None):
super().__init__(parent) super().__init__(parent)
self.config = config self.config = config
@ -213,15 +218,11 @@ class QEConfig(AuthMixin, QObject):
msats = amount.msatsInt msats = amount.msatsInt
else: else:
return '---' return '---'
precision = 3 # config.amt_precision_post_satoshi is not exposed in preferences
s = format_satoshis(msats/1000, if with_unit:
decimal_point=self.decimal_point(), return self.config.format_amount_and_units(msats/1000, precision=precision)
precision=3) else:
return s return self.config.format_amount(msats/1000, precision=precision)
#if with_unit:
#return self.config.format_amount_and_units(msats)
#else:
#return self.config.format_amount(satoshis)
# TODO delegate all this to config.py/util.py # TODO delegate all this to config.py/util.py
def decimal_point(self): def decimal_point(self):

19
electrum/simple_config.py

@ -677,19 +677,28 @@ class SimpleConfig(Logger):
except: except:
pass 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( return format_satoshis(
x, amount_sat,
num_zeros=self.num_zeros, num_zeros=self.num_zeros,
decimal_point=self.decimal_point, decimal_point=self.decimal_point,
is_diff=is_diff, is_diff=is_diff,
whitespaces=whitespaces, whitespaces=whitespaces,
precision=self.amt_precision_post_satoshi, precision=precision,
add_thousands_sep=self.amt_add_thousands_sep, add_thousands_sep=self.amt_add_thousands_sep,
) )
def format_amount_and_units(self, amount): def format_amount_and_units(self, *args, **kwargs) -> str:
return self.format_amount(amount) + ' '+ self.get_base_unit() return self.format_amount(*args, **kwargs) + ' ' + self.get_base_unit()
def format_fee_rate(self, fee_rate): def format_fee_rate(self, fee_rate):
return format_fee_satoshis(fee_rate/1000, num_zeros=self.num_zeros) + ' sat/byte' return format_fee_satoshis(fee_rate/1000, num_zeros=self.num_zeros) + ' sat/byte'

Loading…
Cancel
Save