From 19f8f8e4573a41e5eacafc6c9e58325ee2d27962 Mon Sep 17 00:00:00 2001 From: Jonathan Rainville Date: Mon, 29 Jun 2020 13:05:34 -0400 Subject: [PATCH] feat: add validation on amount and show current balance --- ui/app/AppLayouts/Wallet/SendModal.qml | 10 +---- .../Wallet/components/SendModalContent.qml | 41 ++++++++++++++----- 2 files changed, 32 insertions(+), 19 deletions(-) diff --git a/ui/app/AppLayouts/Wallet/SendModal.qml b/ui/app/AppLayouts/Wallet/SendModal.qml index ddd64c90f9..f079762822 100644 --- a/ui/app/AppLayouts/Wallet/SendModal.qml +++ b/ui/app/AppLayouts/Wallet/SendModal.qml @@ -52,15 +52,7 @@ ModalPopup { label: qsTr("Send") onClicked: { - if (!sendModalContent.validate()) { - return; - } - - let result = walletModel.onSendTransaction(sendModalContent.selectedAccountAddress, - sendModalContent.toText, - sendModalContent.amountText, - sendModalContent.passwordText) - console.log(result) + sendModalContent.send() } } } diff --git a/ui/app/AppLayouts/Wallet/components/SendModalContent.qml b/ui/app/AppLayouts/Wallet/components/SendModalContent.qml index 5875ef1bef..b11dd3ddc2 100644 --- a/ui/app/AppLayouts/Wallet/components/SendModalContent.qml +++ b/ui/app/AppLayouts/Wallet/components/SendModalContent.qml @@ -5,9 +5,6 @@ import "../../../../shared" Item { id: sendModalContent property alias amountInput: txtAmount - property alias amountText: txtAmount.text - property alias toText: txtTo.text - property alias passwordText: txtPassword.text property var accounts: [] property var assets: [] property string defaultAccount: "0x1234" @@ -26,28 +23,41 @@ Item { property string toValidationError: "" property string amountValidationError: "" + function send() { + if (!validate()) { + return; + } + + let result = walletModel.onSendTransaction(selectedAccountAddress, + txtTo.text, + txtAmount.text, + txtPassword.text) + console.log(result) + } + function validate() { - if (passwordText === "") { + if (txtPassword.text === "") { passwordValidationError = qsTr("You need to enter a password") - } else if (passwordText.length < 4) { + } else if (txtPassword.text.length < 4) { passwordValidationError = qsTr("Password needs to be 4 characters or more") } else { passwordValidationError = "" } - if (toText === "") { + if (txtTo.text === "") { toValidationError = qsTr("You need to enter a destination address") - } else if (!Utils.isAddress(toText)) { + } else if (!Utils.isAddress(txtTo.text)) { toValidationError = qsTr("This needs to be a valid address (starting with 0x)") } else { toValidationError = "" } - if (amountText === "") { + if (txtAmount.text === "") { amountValidationError = qsTr("You need to enter an amount") - } else if (isNaN(amountText)) { + } else if (isNaN(txtAmount.text)) { amountValidationError = qsTr("This needs to be a number") - // TODO check balance? + } else if (parseInt(txtAmount.text, 10) > parseInt(selectedAccountValue, 10)) { + amountValidationError = qsTr("Amount needs to be lower than your balance (%1)").arg(selectedAccountValue) } else { amountValidationError = "" } @@ -86,6 +96,17 @@ Item { }) } + StyledText { + id: currentBalanceText + text: qsTr("Balance: %1").arg(selectedAccountValue) + font.pixelSize: 13 + color: Theme.darkGrey + anchors.top: assetTypeSelect.top + anchors.topMargin: 0 + anchors.right: assetTypeSelect.right + anchors.rightMargin: 0 + } + Select { id: txtFrom iconHeight: 12