simple_config: factor out self.decimal_point and self.get_decimal_point() in favor of self.BTC_AMOUNTS_DECIMAL_POINT
This commit is contained in:
@@ -387,4 +387,4 @@ class QEConfig(AuthMixin, QObject):
|
||||
|
||||
@pyqtSlot('quint64', result=float)
|
||||
def satsToUnits(self, satoshis):
|
||||
return satoshis / pow(10, self.config.decimal_point)
|
||||
return satoshis / pow(10, self.config.BTC_AMOUNTS_DECIMAL_POINT)
|
||||
|
||||
@@ -1005,7 +1005,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, Logger, QtEventListener):
|
||||
return self.config.format_fee_rate(fee_rate)
|
||||
|
||||
def get_decimal_point(self):
|
||||
return self.config.get_decimal_point()
|
||||
return self.config.BTC_AMOUNTS_DECIMAL_POINT
|
||||
|
||||
def base_unit(self):
|
||||
return self.config.get_base_unit()
|
||||
|
||||
@@ -97,7 +97,7 @@ class SettingsDialog(QDialog, QtEventListener):
|
||||
nz_label = HelpLabel.from_configvar(self.config.cv.BTC_AMOUNTS_FORCE_NZEROS_AFTER_DECIMAL_POINT)
|
||||
nz = QSpinBox()
|
||||
nz.setMinimum(0)
|
||||
nz.setMaximum(self.config.decimal_point)
|
||||
nz.setMaximum(self.config.BTC_AMOUNTS_DECIMAL_POINT)
|
||||
nz.setValue(self.config.num_zeros)
|
||||
if not self.config.cv.BTC_AMOUNTS_FORCE_NZEROS_AFTER_DECIMAL_POINT.is_modifiable():
|
||||
for w in [nz, nz_label]: w.setEnabled(False)
|
||||
@@ -205,7 +205,7 @@ class SettingsDialog(QDialog, QtEventListener):
|
||||
if self.config.get_base_unit() == unit_result:
|
||||
return
|
||||
self.config.set_base_unit(unit_result)
|
||||
nz.setMaximum(self.config.decimal_point)
|
||||
nz.setMaximum(self.config.BTC_AMOUNTS_DECIMAL_POINT)
|
||||
self.app.refresh_tabs_signal.emit()
|
||||
self.app.update_status_signal.emit()
|
||||
self.app.refresh_amount_edits_signal.emit()
|
||||
|
||||
@@ -615,7 +615,7 @@ class ElectrumGui(BaseElectrumGui, EventListener):
|
||||
x = Decimal(text)
|
||||
except Exception:
|
||||
return None
|
||||
power = pow(10, self.config.get_decimal_point())
|
||||
power = pow(10, self.config.BTC_AMOUNTS_DECIMAL_POINT)
|
||||
return int(power * x)
|
||||
|
||||
def read_invoice(self):
|
||||
|
||||
@@ -557,7 +557,7 @@ class PaymentIdentifier(Logger):
|
||||
raise Exception("Amount is empty")
|
||||
if parse_max_spend(x):
|
||||
return x
|
||||
p = pow(10, self.config.get_decimal_point())
|
||||
p = pow(10, self.config.BTC_AMOUNTS_DECIMAL_POINT)
|
||||
try:
|
||||
return int(p * Decimal(x))
|
||||
except InvalidOperation:
|
||||
|
||||
@@ -518,7 +518,7 @@ class BitBox02Client(HardwareClientBase):
|
||||
|
||||
format_unit = bitbox02.btc.BTCSignInitRequest.FormatUnit.DEFAULT
|
||||
# Base unit is configured to be "sat":
|
||||
if self.config.get_decimal_point() == 0:
|
||||
if self.config.BTC_AMOUNTS_DECIMAL_POINT == 0:
|
||||
format_unit = bitbox02.btc.BTCSignInitRequest.FormatUnit.SAT
|
||||
|
||||
sigs = self.bitbox02_device.btc_sign(
|
||||
|
||||
@@ -324,11 +324,11 @@ class TrezorPlugin(HW_PluginBase):
|
||||
raise ValueError('unexpected txin type: {}'.format(electrum_txin_type))
|
||||
|
||||
def get_trezor_amount_unit(self):
|
||||
if self.config.decimal_point == 0:
|
||||
if self.config.BTC_AMOUNTS_DECIMAL_POINT == 0:
|
||||
return AmountUnit.SATOSHI
|
||||
elif self.config.decimal_point == 2:
|
||||
elif self.config.BTC_AMOUNTS_DECIMAL_POINT == 2:
|
||||
return AmountUnit.MICROBITCOIN
|
||||
elif self.config.decimal_point == 5:
|
||||
elif self.config.BTC_AMOUNTS_DECIMAL_POINT == 5:
|
||||
return AmountUnit.MILLIBITCOIN
|
||||
else:
|
||||
return AmountUnit.BITCOIN
|
||||
|
||||
@@ -217,12 +217,10 @@ class SimpleConfig(Logger):
|
||||
self._check_dependent_keys()
|
||||
|
||||
# units and formatting
|
||||
# FIXME is this duplication (dp, nz, post_sat, thou_sep) due to performance reasons??
|
||||
self.decimal_point = self.BTC_AMOUNTS_DECIMAL_POINT
|
||||
try:
|
||||
decimal_point_to_base_unit_name(self.decimal_point)
|
||||
decimal_point_to_base_unit_name(self.BTC_AMOUNTS_DECIMAL_POINT)
|
||||
except UnknownBaseUnit:
|
||||
self.decimal_point = DECIMAL_POINT_DEFAULT
|
||||
self.BTC_AMOUNTS_DECIMAL_POINT = DECIMAL_POINT_DEFAULT
|
||||
self.num_zeros = self.BTC_AMOUNTS_FORCE_NZEROS_AFTER_DECIMAL_POINT
|
||||
self.amt_precision_post_satoshi = self.BTC_AMOUNTS_PREC_POST_SAT
|
||||
self.amt_add_thousands_sep = self.BTC_AMOUNTS_ADD_THOUSANDS_SEP
|
||||
@@ -530,7 +528,7 @@ class SimpleConfig(Logger):
|
||||
return format_satoshis(
|
||||
amount_sat,
|
||||
num_zeros=self.num_zeros,
|
||||
decimal_point=self.decimal_point,
|
||||
decimal_point=self.BTC_AMOUNTS_DECIMAL_POINT,
|
||||
is_diff=is_diff,
|
||||
whitespaces=whitespaces,
|
||||
precision=precision,
|
||||
@@ -545,15 +543,11 @@ class SimpleConfig(Logger):
|
||||
return format_fee_satoshis(fee_rate/1000, num_zeros=self.num_zeros) + f" {util.UI_UNIT_NAME_FEERATE_SAT_PER_VBYTE}"
|
||||
|
||||
def get_base_unit(self):
|
||||
return decimal_point_to_base_unit_name(self.decimal_point)
|
||||
return decimal_point_to_base_unit_name(self.BTC_AMOUNTS_DECIMAL_POINT)
|
||||
|
||||
def set_base_unit(self, unit):
|
||||
assert unit in base_units.keys()
|
||||
self.decimal_point = base_unit_name_to_decimal_point(unit)
|
||||
self.BTC_AMOUNTS_DECIMAL_POINT = self.decimal_point
|
||||
|
||||
def get_decimal_point(self):
|
||||
return self.decimal_point
|
||||
self.BTC_AMOUNTS_DECIMAL_POINT = base_unit_name_to_decimal_point(unit)
|
||||
|
||||
def get_nostr_relays(self) -> Sequence[str]:
|
||||
relays = []
|
||||
|
||||
Reference in New Issue
Block a user