From e81a589a8daea22ba1e847f1c785d96d44347332 Mon Sep 17 00:00:00 2001 From: xiphon Date: Thu, 5 Dec 2019 10:13:29 +0000 Subject: [PATCH] Transfer: improve amount sanitization --- pages/Transfer.qml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pages/Transfer.qml b/pages/Transfer.qml index e9dfb3ff..9c298773 100644 --- a/pages/Transfer.qml +++ b/pages/Transfer.qml @@ -182,9 +182,17 @@ Rectangle { inlineButtonText: qsTr("All") + translationManager.emptyString inlineButton.onClicked: amountLine.text = "(all)" onTextChanged: { - if(amountLine.text.indexOf('.') === 0){ - amountLine.text = '0' + amountLine.text; - } + const match = amountLine.text.match(/^0+(\d.*)/); + if (match) { + const cursorPosition = amountLine.cursorPosition; + amountLine.text = match[1]; + amountLine.cursorPosition = Math.max(cursorPosition, 1) - 1; + } else if(amountLine.text.indexOf('.') === 0){ + amountLine.text = '0' + amountLine.text; + if (amountLine.text.length > 2) { + amountLine.cursorPosition = 1; + } + } } validator: RegExpValidator {