Browse Source

qml: follow-up BtcField validator: take base unit fully into account

Not just for the fractional part, but also for the integer part.

follow-up 4df6052567
master
SomberNight 3 years ago
parent
commit
19759281ef
No known key found for this signature in database
GPG Key ID: B33B5F232C6271E9
  1. 8
      electrum/gui/qml/qeconfig.py
  2. 1
      electrum/util.py

8
electrum/gui/qml/qeconfig.py

@ -4,6 +4,7 @@ from typing import TYPE_CHECKING
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, QRegularExpression
from electrum.bitcoin import TOTAL_COIN_SUPPLY_LIMIT_IN_BTC
from electrum.i18n import set_language, languages
from electrum.logging import get_logger
from electrum.util import DECIMAL_POINT_DEFAULT, base_unit_name_to_decimal_point
@ -85,8 +86,11 @@ class QEConfig(AuthMixin, QObject):
@pyqtProperty('QRegularExpression', notify=baseUnitChanged)
def btcAmountRegex(self):
decimal_point = base_unit_name_to_decimal_point(self.config.get_base_unit())
exp = '[0-9]{0,8}'
if decimal_point:
max_digits_before_dp = (
len(str(TOTAL_COIN_SUPPLY_LIMIT_IN_BTC))
+ (base_unit_name_to_decimal_point("BTC") - decimal_point))
exp = '[0-9]{0,%d}' % max_digits_before_dp
if decimal_point > 0:
exp += '\\.'
exp += '[0-9]{0,%d}' % decimal_point
return QRegularExpression(exp)

1
electrum/util.py

@ -104,6 +104,7 @@ def decimal_point_to_base_unit_name(dp: int) -> str:
def base_unit_name_to_decimal_point(unit_name: str) -> int:
"""Returns the max number of digits allowed after the decimal point."""
# e.g. "BTC" -> 8
try:
return base_units[unit_name]

Loading…
Cancel
Save