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
This commit is contained in:
@@ -4,6 +4,7 @@ from typing import TYPE_CHECKING
|
|||||||
|
|
||||||
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, QRegularExpression
|
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.i18n import set_language, languages
|
||||||
from electrum.logging import get_logger
|
from electrum.logging import get_logger
|
||||||
from electrum.util import DECIMAL_POINT_DEFAULT, base_unit_name_to_decimal_point
|
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)
|
@pyqtProperty('QRegularExpression', notify=baseUnitChanged)
|
||||||
def btcAmountRegex(self):
|
def btcAmountRegex(self):
|
||||||
decimal_point = base_unit_name_to_decimal_point(self.config.get_base_unit())
|
decimal_point = base_unit_name_to_decimal_point(self.config.get_base_unit())
|
||||||
exp = '[0-9]{0,8}'
|
max_digits_before_dp = (
|
||||||
if decimal_point:
|
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 += '\\.'
|
||||||
exp += '[0-9]{0,%d}' % decimal_point
|
exp += '[0-9]{0,%d}' % decimal_point
|
||||||
return QRegularExpression(exp)
|
return QRegularExpression(exp)
|
||||||
|
|||||||
@@ -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:
|
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
|
# e.g. "BTC" -> 8
|
||||||
try:
|
try:
|
||||||
return base_units[unit_name]
|
return base_units[unit_name]
|
||||||
|
|||||||
Reference in New Issue
Block a user