1
0

qeconfig: fix btc amount regex, add msat regex property, add regex tests

This commit is contained in:
Sander van Grieken
2025-11-26 16:33:44 +01:00
parent 93c9dd9d12
commit e137c888a1
2 changed files with 83 additions and 3 deletions

View File

@@ -94,14 +94,22 @@ class QEConfig(AuthMixin, QObject):
@pyqtProperty('QRegularExpression', notify=baseUnitChanged)
def btcAmountRegex(self):
return self._btcAmountRegex()
@pyqtProperty('QRegularExpression', notify=baseUnitChanged)
def btcAmountRegexMsat(self):
return self._btcAmountRegex(3)
def _btcAmountRegex(self, extra_precision: int = 0):
decimal_point = base_unit_name_to_decimal_point(self.config.get_base_unit())
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
exp = '^[0-9]{0,%d}' % max_digits_before_dp
decimal_point += extra_precision
if decimal_point > 0:
exp += '\\.'
exp += '[0-9]{0,%d}' % decimal_point
exp += '(\\.[0-9]{0,%d})?' % decimal_point
exp += '$'
return QRegularExpression(exp)
thousandsSeparatorChanged = pyqtSignal()