status-desktop/ui/app/AppLayouts/Wallet/components/SendModalContent.qml

196 lines
6.4 KiB
QML
Raw Normal View History

2020-06-17 19:18:31 +00:00
import QtQuick 2.13
import QtQuick.Dialogs 1.3
2020-05-29 15:43:37 +00:00
import "../../../../imports"
import "../../../../shared"
Item {
id: sendModalContent
property var closePopup: function(){}
property alias amountInput: txtAmount
property alias passwordInput: txtPassword
2020-06-29 16:37:36 +00:00
property var accounts: []
property var assets: []
property int selectedAccountIndex: 0
property string selectedAccountAddress: accounts && accounts.length ? accounts[selectedAccountIndex].address : ""
property string selectedAccountName: accounts && accounts.length ? accounts[selectedAccountIndex].name : ""
property string selectedAccountIconColor: accounts && accounts.length ? accounts[selectedAccountIndex].iconColor : ""
2020-06-29 16:37:36 +00:00
property int selectedAssetIndex: 0
property string selectedAssetName: assets && assets.length ? assets[selectedAssetIndex].name : ""
property string selectedAssetAddress: assets && assets.length ? assets[selectedAssetIndex].address : ""
2020-06-29 16:37:36 +00:00
property string selectedAssetSymbol: assets && assets.length ? assets[selectedAssetIndex].symbol : ""
property string selectedAccountValue: assets && assets.length ? assets[selectedAssetIndex].value : ""
2020-05-29 15:43:37 +00:00
2020-06-26 20:15:48 +00:00
property string passwordValidationError: ""
property string toValidationError: ""
property string amountValidationError: ""
function send() {
if (!validate()) {
return;
}
let result = walletModel.onSendTransaction(selectedAccountAddress,
txtTo.text,
selectedAssetAddress,
txtAmount.text,
txtPassword.text)
if (!result.startsWith('0x')) {
// It's an error
sendingError.text = result
return sendingError.open()
}
sendingSuccess.text = qsTr("Transaction sent to the blockchain. You can watch the progress on Etherscan: https://etherscan.io/tx/%1").arg(result)
sendingSuccess.open()
}
2020-06-26 20:15:48 +00:00
function validate() {
if (txtPassword.text === "") {
2020-06-26 20:15:48 +00:00
passwordValidationError = qsTr("You need to enter a password")
} else if (txtPassword.text.length < 4) {
2020-06-26 20:15:48 +00:00
passwordValidationError = qsTr("Password needs to be 4 characters or more")
} else {
passwordValidationError = ""
}
if (txtTo.text === "") {
2020-06-26 20:15:48 +00:00
toValidationError = qsTr("You need to enter a destination address")
} else if (!Utils.isAddress(txtTo.text)) {
2020-06-26 20:15:48 +00:00
toValidationError = qsTr("This needs to be a valid address (starting with 0x)")
} else {
toValidationError = ""
}
if (txtAmount.text === "") {
2020-06-26 20:15:48 +00:00
amountValidationError = qsTr("You need to enter an amount")
} else if (isNaN(txtAmount.text)) {
2020-06-26 20:15:48 +00:00
amountValidationError = qsTr("This needs to be a number")
} else if (parseFloat(txtAmount.text) > parseFloat(selectedAccountValue)) {
amountValidationError = qsTr("Amount needs to be lower than your balance (%1)").arg(selectedAccountValue)
2020-06-26 20:15:48 +00:00
} else {
amountValidationError = ""
}
return passwordValidationError === "" && toValidationError === "" && amountValidationError === ""
}
anchors.left: parent.left
anchors.right: parent.right
2020-05-29 15:43:37 +00:00
MessageDialog {
id: sendingError
title: "Error sending the transaction"
icon: StandardIcon.Critical
standardButtons: StandardButton.Ok
}
MessageDialog {
id: sendingSuccess
title: qsTr("Success sending the transaction")
icon: StandardIcon.NoIcon
standardButtons: StandardButton.Ok
onAccepted: {
closePopup()
}
}
Input {
id: txtAmount
label: qsTr("Amount")
2020-05-29 15:43:37 +00:00
anchors.top: parent.top
2020-06-29 16:37:36 +00:00
placeholderText: qsTr("Enter amount...")
2020-06-26 20:15:48 +00:00
validationError: amountValidationError
2020-05-29 15:43:37 +00:00
}
2020-06-29 16:37:36 +00:00
Select {
id: assetTypeSelect
iconHeight: 24
iconWidth: 24
icon: "../../../img/tokens/" + selectedAssetSymbol.toUpperCase() + ".png"
label: qsTr("Select the asset")
anchors.top: txtAmount.bottom
anchors.topMargin: Theme.padding
selectedText: selectedAssetName
selectOptions: sendModalContent.assets.map(function (asset, index) {
return {
text: asset.name,
onClicked: function () {
selectedAssetIndex = index
}
}
})
}
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
iconWidth: 12
icon: "../../../img/walletIcon.svg"
iconColor: selectedAccountIconColor
label: qsTr("From account")
2020-06-29 16:37:36 +00:00
anchors.top: assetTypeSelect.bottom
2020-05-29 15:43:37 +00:00
anchors.topMargin: Theme.padding
selectedText: selectedAccountName
selectOptions: sendModalContent.accounts.map(function (account, index) {
return {
text: account.name,
onClicked: function () {
selectedAccountIndex = index
}
}
})
2020-05-29 15:43:37 +00:00
}
StyledText {
id: textSelectAccountAddress
text: selectedAccountAddress
font.family: Theme.fontHexRegular.name
anchors.right: parent.right
anchors.left: parent.left
anchors.leftMargin: 2
elide: Text.ElideMiddle
anchors.top: txtFrom.bottom
font.pixelSize: 12
color: Theme.darkGrey
}
Input {
id: txtTo
label: qsTr("Recipient")
placeholderText: qsTr("Send to")
anchors.top: textSelectAccountAddress.bottom
anchors.topMargin: Theme.padding
2020-06-26 20:15:48 +00:00
validationError: toValidationError
2020-05-29 15:43:37 +00:00
}
Input {
id: txtPassword
label: qsTr("Password")
placeholderText: qsTr("Enter Password")
anchors.top: txtTo.bottom
anchors.topMargin: Theme.padding
textField.echoMode: TextInput.Password
2020-06-26 20:15:48 +00:00
validationError: passwordValidationError
2020-05-29 15:43:37 +00:00
}
}
/*##^##
Designer {
D{i:0;autoSize:true;formeditorColor:"#ffffff";height:480;width:640}
2020-05-29 15:43:37 +00:00
}
##^##*/