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
|
||||||
return text[:dp_loc] + util.DECIMAL_POINT + text[dp_loc+1:]
|
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):
|
async def run(self):
|
||||||
while True:
|
while True:
|
||||||
# every few minutes, refresh spot price
|
# every few minutes, refresh spot price
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import QtQuick 2.6
|
import QtQuick 2.15
|
||||||
import QtQuick.Controls 2.0
|
import QtQuick.Controls 2.0
|
||||||
|
|
||||||
import org.electrum 1.0
|
import org.electrum 1.0
|
||||||
@@ -11,6 +11,10 @@ TextField {
|
|||||||
font.family: FixedFont
|
font.family: FixedFont
|
||||||
placeholderText: qsTr('Amount')
|
placeholderText: qsTr('Amount')
|
||||||
inputMethodHints: Qt.ImhDigitsOnly
|
inputMethodHints: Qt.ImhDigitsOnly
|
||||||
|
validator: RegularExpressionValidator {
|
||||||
|
regularExpression: Config.btcAmountRegex
|
||||||
|
}
|
||||||
|
|
||||||
property Amount textAsSats
|
property Amount textAsSats
|
||||||
onTextChanged: {
|
onTextChanged: {
|
||||||
textAsSats = Config.unitsToSats(amount.text)
|
textAsSats = Config.unitsToSats(amount.text)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import QtQuick 2.6
|
import QtQuick 2.15
|
||||||
import QtQuick.Controls 2.0
|
import QtQuick.Controls 2.0
|
||||||
|
|
||||||
import org.electrum 1.0
|
import org.electrum 1.0
|
||||||
@@ -11,6 +11,10 @@ TextField {
|
|||||||
font.family: FixedFont
|
font.family: FixedFont
|
||||||
placeholderText: qsTr('Amount')
|
placeholderText: qsTr('Amount')
|
||||||
inputMethodHints: Qt.ImhDigitsOnly
|
inputMethodHints: Qt.ImhDigitsOnly
|
||||||
|
validator: RegularExpressionValidator {
|
||||||
|
regularExpression: Daemon.fx.fiatAmountRegex
|
||||||
|
}
|
||||||
|
|
||||||
onTextChanged: {
|
onTextChanged: {
|
||||||
if (amountFiat.activeFocus)
|
if (amountFiat.activeFocus)
|
||||||
btcfield.text = text == ''
|
btcfield.text = text == ''
|
||||||
|
|||||||
@@ -2,11 +2,11 @@ import copy
|
|||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from typing import TYPE_CHECKING
|
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.i18n import set_language, languages
|
||||||
from electrum.logging import get_logger
|
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 electrum.invoices import PR_DEFAULT_EXPIRATION_WHEN_CREATING
|
||||||
|
|
||||||
from .qetypes import QEAmount
|
from .qetypes import QEAmount
|
||||||
@@ -82,6 +82,15 @@ class QEConfig(AuthMixin, QObject):
|
|||||||
self.config.set_base_unit(unit)
|
self.config.set_base_unit(unit)
|
||||||
self.baseUnitChanged.emit()
|
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()
|
thousandsSeparatorChanged = pyqtSignal()
|
||||||
@pyqtProperty(bool, notify=thousandsSeparatorChanged)
|
@pyqtProperty(bool, notify=thousandsSeparatorChanged)
|
||||||
def thousandsSeparator(self):
|
def thousandsSeparator(self):
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from decimal import Decimal
|
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.bitcoin import COIN
|
||||||
from electrum.exchange_rate import FxThread
|
from electrum.exchange_rate import FxThread
|
||||||
@@ -60,6 +60,15 @@ class QEFX(QObject, QtEventListener):
|
|||||||
self.fiatCurrencyChanged.emit()
|
self.fiatCurrencyChanged.emit()
|
||||||
self.rateSourcesChanged.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()
|
historicRatesChanged = pyqtSignal()
|
||||||
@pyqtProperty(bool, notify=historicRatesChanged)
|
@pyqtProperty(bool, notify=historicRatesChanged)
|
||||||
def historicRates(self):
|
def historicRates(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user