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-08-19 15:29:42 +00:00
property alias passwordInput: transactionSigner . passwordInput
2020-05-29 15:43:37 +00:00
2020-06-26 20:15:48 +00:00
property string passwordValidationError: ""
2020-06-29 17:05:34 +00:00
function send ( ) {
2020-08-19 15:29:42 +00:00
if ( ! validate ( ) || ! validatePassword ( ) ) {
2020-06-29 17:05:34 +00:00
return ;
}
2020-07-30 05:18:54 +00:00
let result = walletModel . onSendTransaction ( selectFromAccount . selectedAccount . address ,
2020-08-06 07:25:53 +00:00
selectRecipient . selectedRecipient ,
2020-08-13 08:24:51 +00:00
txtAmount . selectedAsset . address ,
2020-06-29 17:05:34 +00:00
txtAmount . text ,
2020-08-19 15:29:42 +00:00
transactionSigner . passwordInput . 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-08-19 15:29:42 +00:00
function validatePassword ( ) {
if ( transactionSigner . passwordInput . text === "" ) {
2020-07-06 20:39:55 +00:00
//% "You need to enter a password"
passwordValidationError = qsTrId ( "you-need-to-enter-a-password" )
2020-08-19 15:29:42 +00:00
} else if ( transactionSigner . passwordInput . 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-08-19 15:29:42 +00:00
return passwordValidationError === ""
}
2020-06-26 20:15:48 +00:00
2020-08-19 15:29:42 +00:00
function validate ( ) {
const isRecipientValid = selectRecipient . validate ( )
const isAssetAndAmountValid = txtAmount . validate ( )
return isRecipientValid && isAssetAndAmountValid
2020-08-13 08:24:51 +00:00
}
function showPreview ( ) {
pvwTransaction . visible = true
2020-08-19 15:29:42 +00:00
transactionSigner . visible = true
txtAmount . visible = selectFromAccount . visible = selectRecipient . visible = gasSelector . visible = false
2020-08-13 08:24:51 +00:00
}
function showInputs ( ) {
pvwTransaction . visible = false
2020-08-19 15:29:42 +00:00
transactionSigner . visible = false
txtAmount . visible = selectFromAccount . visible = selectRecipient . visible = gasSelector . visible = true
2020-06-26 20:15:48 +00:00
}
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
2020-08-13 08:24:51 +00:00
onAccepted: {
sendModalContent . showInputs ( )
}
2020-07-01 14:24:07 +00:00
}
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-08-13 08:24:51 +00:00
sendModalContent . showInputs ( )
2020-07-01 14:24:07 +00:00
}
}
2020-08-04 11:10:09 +00:00
AssetAndAmountInput {
2020-08-12 09:05:12 +00:00
id: txtAmount
selectedAccount: walletModel . currentAccount
defaultCurrency: walletModel . defaultCurrency
anchors.top: parent . top
getFiatValue: walletModel . getFiatValue
getCryptoValue: walletModel . getCryptoValue
2020-06-29 17:05:34 +00:00
}
2020-07-30 05:18:54 +00:00
AccountSelector {
id: selectFromAccount
accounts: walletModel . accounts
2020-08-06 02:33:30 +00:00
currency: walletModel . defaultCurrency
2020-08-04 11:10:09 +00:00
anchors.top: txtAmount . 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-08-13 08:24:51 +00:00
label: qsTr ( "From account" )
2020-08-10 18:44:42 +00:00
onSelectedAccountChanged: {
2020-08-12 09:05:12 +00:00
txtAmount . selectedAccount = selectFromAccount . selectedAccount
2020-08-04 11:10:09 +00:00
}
2020-06-26 20:02:05 +00:00
}
2020-08-13 07:27:53 +00:00
GasSelector {
2020-08-18 11:38:16 +00:00
id: gasSelector
anchors.top: selectFromAccount . bottom
anchors.topMargin: Style . current . bigPadding
slowestGasPrice: walletModel . safeLowGasPrice
fastestGasPrice: walletModel . fastestGasPrice
getGasEthValue: walletModel . getGasEthValue
getFiatValue: walletModel . getFiatValue
defaultCurrency: walletModel . defaultCurrency
2020-08-13 07:27:53 +00:00
}
2020-08-06 07:25:53 +00:00
RecipientSelector {
id: selectRecipient
accounts: walletModel . accounts
contacts: profileModel . addedContacts
label: qsTr ( "Recipient" )
2020-08-13 07:27:53 +00:00
anchors.top: gasSelector . bottom
2020-07-02 15:14:31 +00:00
anchors.topMargin: Style . current . padding
2020-08-06 07:25:53 +00:00
anchors.left: parent . left
anchors.right: parent . right
2020-05-29 15:43:37 +00:00
}
2020-08-13 08:24:51 +00:00
TransactionPreview {
id: pvwTransaction
visible: false
anchors.left: parent . left
anchors.right: parent . right
fromAccount: selectFromAccount . selectedAccount
gas: {
const value = walletModel . getGasEthValue ( gasSelector . selectedGasPrice , gasSelector . selectedGasLimit )
const fiatValue = walletModel . getFiatValue ( value , "ETH" , walletModel . defaultCurrency )
return { value , "symbol" : "ETH" , fiatValue }
}
toAccount: selectRecipient . selectedRecipient
asset: txtAmount . selectedAsset
amount: { "value" : txtAmount . selectedAmount , "fiatValue" : txtAmount . selectedFiatAmount }
currency: walletModel . defaultCurrency
}
2020-08-19 15:29:42 +00:00
TransactionSigner {
id: transactionSigner
visible: false
anchors.left: parent . left
anchors.right: parent . right
anchors.top: pvwTransaction . bottom
anchors.topMargin: Style . current . smallPadding
signingPhrase: walletModel . signingPhrase
validationError: sendModalContent . 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
}
# # ^ # # * /