feat: add validation on amount and show current balance

This commit is contained in:
Jonathan Rainville 2020-06-29 13:05:34 -04:00 committed by Iuri Matias
parent 70fdcb85c6
commit 19f8f8e457
2 changed files with 32 additions and 19 deletions

View File

@ -52,15 +52,7 @@ ModalPopup {
label: qsTr("Send") label: qsTr("Send")
onClicked: { onClicked: {
if (!sendModalContent.validate()) { sendModalContent.send()
return;
}
let result = walletModel.onSendTransaction(sendModalContent.selectedAccountAddress,
sendModalContent.toText,
sendModalContent.amountText,
sendModalContent.passwordText)
console.log(result)
} }
} }
} }

View File

@ -5,9 +5,6 @@ import "../../../../shared"
Item { Item {
id: sendModalContent id: sendModalContent
property alias amountInput: txtAmount property alias amountInput: txtAmount
property alias amountText: txtAmount.text
property alias toText: txtTo.text
property alias passwordText: txtPassword.text
property var accounts: [] property var accounts: []
property var assets: [] property var assets: []
property string defaultAccount: "0x1234" property string defaultAccount: "0x1234"
@ -26,28 +23,41 @@ Item {
property string toValidationError: "" property string toValidationError: ""
property string amountValidationError: "" property string amountValidationError: ""
function send() {
if (!validate()) {
return;
}
let result = walletModel.onSendTransaction(selectedAccountAddress,
txtTo.text,
txtAmount.text,
txtPassword.text)
console.log(result)
}
function validate() { function validate() {
if (passwordText === "") { if (txtPassword.text === "") {
passwordValidationError = qsTr("You need to enter a password") 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") passwordValidationError = qsTr("Password needs to be 4 characters or more")
} else { } else {
passwordValidationError = "" passwordValidationError = ""
} }
if (toText === "") { if (txtTo.text === "") {
toValidationError = qsTr("You need to enter a destination address") 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)") toValidationError = qsTr("This needs to be a valid address (starting with 0x)")
} else { } else {
toValidationError = "" toValidationError = ""
} }
if (amountText === "") { if (txtAmount.text === "") {
amountValidationError = qsTr("You need to enter an amount") 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") 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 { } else {
amountValidationError = "" 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 { Select {
id: txtFrom id: txtFrom
iconHeight: 12 iconHeight: 12