From 76f12c20f7fc259ffbd33ed6f05e4f70078c4032 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Fri, 26 Jun 2020 16:15:48 -0400 Subject: [PATCH] feat: add validation to send form --- ui/app/AppLayouts/Wallet/SendModal.qml | 4 +++ .../Wallet/components/SendModalContent.qml | 36 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/ui/app/AppLayouts/Wallet/SendModal.qml b/ui/app/AppLayouts/Wallet/SendModal.qml index 05c358ef42..8c7bd79280 100644 --- a/ui/app/AppLayouts/Wallet/SendModal.qml +++ b/ui/app/AppLayouts/Wallet/SendModal.qml @@ -40,6 +40,10 @@ ModalPopup { label: qsTr("Send") onClicked: { + if (!sendModalContent.validate()) { + return; + } + let result = walletModel.onSendTransaction(sendModalContent.selectedAccountAddress, sendModalContent.toText, sendModalContent.amountText, diff --git a/ui/app/AppLayouts/Wallet/components/SendModalContent.qml b/ui/app/AppLayouts/Wallet/components/SendModalContent.qml index df3b606e5b..01d919c9ff 100644 --- a/ui/app/AppLayouts/Wallet/components/SendModalContent.qml +++ b/ui/app/AppLayouts/Wallet/components/SendModalContent.qml @@ -13,6 +13,39 @@ Item { property int selectedAccountIndex: 0 property string selectedAccountAddress: accounts[selectedAccountIndex].address + property string passwordValidationError: "" + property string toValidationError: "" + property string amountValidationError: "" + + function validate() { + if (passwordText === "") { + passwordValidationError = qsTr("You need to enter a password") + } else if (passwordText.length < 4) { + passwordValidationError = qsTr("Password needs to be 4 characters or more") + } else { + passwordValidationError = "" + } + + if (toText === "") { + toValidationError = qsTr("You need to enter a destination address") + } else if (!Utils.isAddress(toText)) { + toValidationError = qsTr("This needs to be a valid address (starting with 0x)") + } else { + toValidationError = "" + } + + if (amountText === "") { + amountValidationError = qsTr("You need to enter an amount") + } else if (isNaN(amountText)) { + amountValidationError = qsTr("This needs to be a number") + // TODO check balance? + } else { + amountValidationError = "" + } + + return passwordValidationError === "" && toValidationError === "" && amountValidationError === "" + } + anchors.left: parent.left anchors.right: parent.right @@ -22,6 +55,7 @@ Item { icon: "../../../img/token-icons/eth.svg" anchors.top: parent.top placeholderText: qsTr("Enter ETH") + validationError: amountValidationError } Select { @@ -63,6 +97,7 @@ Item { placeholderText: qsTr("Send to") anchors.top: textSelectAccountAddress.bottom anchors.topMargin: Theme.padding + validationError: toValidationError } Input { @@ -72,6 +107,7 @@ Item { anchors.top: txtTo.bottom anchors.topMargin: Theme.padding textField.echoMode: TextInput.Password + validationError: passwordValidationError } }