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