2020-06-17 19:18:31 +00:00
import QtQuick 2.13
2020-07-30 05:18:54 +00:00
import QtQuick . Controls 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-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-30 05:18:54 +00:00
let result = walletModel . onSendTransaction ( selectFromAccount . selectedAccount . address ,
2020-06-29 17:05:34 +00:00
txtTo . text ,
2020-08-03 05:36:54 +00:00
selectAsset . selectedAsset . address ,
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-21 07:15:04 +00:00
sendingSuccess . text = qsTr ( "Transaction sent to the blockchain. You can watch the progress on Etherscan: %2/%1" ) . arg ( result ) . arg ( walletModel . etherscanLink )
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-08-03 05:36:54 +00:00
} else if ( parseFloat ( txtAmount . text ) > parseFloat ( selectAsset . selectedAsset . Value ) ) {
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-08-03 05:36:54 +00:00
AssetSelector {
id: selectAsset
assets: walletModel . assets
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-08-03 05:36:54 +00:00
anchors.right: parent . right
width: 86
height: 28
2020-06-29 17:05:34 +00:00
}
2020-07-30 05:18:54 +00:00
AccountSelector {
id: selectFromAccount
accounts: walletModel . accounts
2020-08-03 05:36:54 +00:00
anchors.top: selectAsset . bottom
2020-07-02 15:14:31 +00:00
anchors.topMargin: Style . current . padding
2020-06-26 20:02:05 +00:00
anchors.left: parent . left
2020-07-30 05:18:54 +00:00
anchors.right: parent . right
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-07-30 05:18:54 +00:00
anchors.top: selectFromAccount . 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
}
# # ^ # # * /