diff --git a/electrum/gui/qml/qeconfig.py b/electrum/gui/qml/qeconfig.py index 5f1735fa8..93e45460d 100644 --- a/electrum/gui/qml/qeconfig.py +++ b/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) diff --git a/electrum/util.py b/electrum/util.py index 15da9e832..05131e812 100644 --- a/electrum/util.py +++ b/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]