qml: add validators for BtcField and FiatField controls
This commit is contained in:
@@ -567,6 +567,9 @@ class FxThread(ThreadJob, EventListener):
|
||||
return text
|
||||
return text[:dp_loc] + util.DECIMAL_POINT + text[dp_loc+1:]
|
||||
|
||||
def ccy_precision(self, ccy=None) -> int:
|
||||
return CCY_PRECISIONS.get(self.ccy if ccy is None else ccy, 2)
|
||||
|
||||
async def run(self):
|
||||
while True:
|
||||
# every few minutes, refresh spot price
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import QtQuick 2.6
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.0
|
||||
|
||||
import org.electrum 1.0
|
||||
@@ -11,6 +11,10 @@ TextField {
|
||||
font.family: FixedFont
|
||||
placeholderText: qsTr('Amount')
|
||||
inputMethodHints: Qt.ImhDigitsOnly
|
||||
validator: RegularExpressionValidator {
|
||||
regularExpression: Config.btcAmountRegex
|
||||
}
|
||||
|
||||
property Amount textAsSats
|
||||
onTextChanged: {
|
||||
textAsSats = Config.unitsToSats(amount.text)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import QtQuick 2.6
|
||||
import QtQuick 2.15
|
||||
import QtQuick.Controls 2.0
|
||||
|
||||
import org.electrum 1.0
|
||||
@@ -11,6 +11,10 @@ TextField {
|
||||
font.family: FixedFont
|
||||
placeholderText: qsTr('Amount')
|
||||
inputMethodHints: Qt.ImhDigitsOnly
|
||||
validator: RegularExpressionValidator {
|
||||
regularExpression: Daemon.fx.fiatAmountRegex
|
||||
}
|
||||
|
||||
onTextChanged: {
|
||||
if (amountFiat.activeFocus)
|
||||
btcfield.text = text == ''
|
||||
|
||||
@@ -2,11 +2,11 @@ import copy
|
||||
from decimal import Decimal
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject
|
||||
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, QRegularExpression
|
||||
|
||||
from electrum.i18n import set_language, languages
|
||||
from electrum.logging import get_logger
|
||||
from electrum.util import DECIMAL_POINT_DEFAULT, format_satoshis
|
||||
from electrum.util import DECIMAL_POINT_DEFAULT, base_unit_name_to_decimal_point
|
||||
from electrum.invoices import PR_DEFAULT_EXPIRATION_WHEN_CREATING
|
||||
|
||||
from .qetypes import QEAmount
|
||||
@@ -82,6 +82,15 @@ class QEConfig(AuthMixin, QObject):
|
||||
self.config.set_base_unit(unit)
|
||||
self.baseUnitChanged.emit()
|
||||
|
||||
@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:
|
||||
exp += '\\.'
|
||||
exp += '[0-9]{0,%d}' % decimal_point
|
||||
return QRegularExpression(exp)
|
||||
|
||||
thousandsSeparatorChanged = pyqtSignal()
|
||||
@pyqtProperty(bool, notify=thousandsSeparatorChanged)
|
||||
def thousandsSeparator(self):
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from datetime import datetime
|
||||
from decimal import Decimal
|
||||
|
||||
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject
|
||||
from PyQt5.QtCore import pyqtProperty, pyqtSignal, pyqtSlot, QObject, QRegularExpression
|
||||
|
||||
from electrum.bitcoin import COIN
|
||||
from electrum.exchange_rate import FxThread
|
||||
@@ -60,6 +60,15 @@ class QEFX(QObject, QtEventListener):
|
||||
self.fiatCurrencyChanged.emit()
|
||||
self.rateSourcesChanged.emit()
|
||||
|
||||
@pyqtProperty('QRegularExpression', notify=fiatCurrencyChanged)
|
||||
def fiatAmountRegex(self):
|
||||
decimals = self.fx.ccy_precision()
|
||||
exp = '[0-9]*'
|
||||
if decimals:
|
||||
exp += '\\.'
|
||||
exp += '[0-9]{0,%d}' % decimals
|
||||
return QRegularExpression(exp)
|
||||
|
||||
historicRatesChanged = pyqtSignal()
|
||||
@pyqtProperty(bool, notify=historicRatesChanged)
|
||||
def historicRates(self):
|
||||
|
||||
Reference in New Issue
Block a user