From 19759281ef307c71c61a77d47699373fea184065 Mon Sep 17 00:00:00 2001 From: SomberNight Date: Wed, 10 May 2023 13:06:38 +0000 Subject: [PATCH] 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 4df6052567cb7a53f609ae343c575cf3fae9f73f --- electrum/gui/qml/qeconfig.py | 8 ++++++-- electrum/util.py | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) 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]