feat: show dialog for send errors and success

This commit is contained in:
Jonathan Rainville 2020-07-01 10:24:07 -04:00 committed by Iuri Matias
parent 81e7dffaa2
commit e378d94ca8
2 changed files with 32 additions and 12 deletions

View File

@ -14,6 +14,7 @@ ModalPopup {
onOpened: { onOpened: {
sendModalContent.amountInput.text = "" sendModalContent.amountInput.text = ""
sendModalContent.passwordInput.text = ""
sendModalContent.amountInput.forceActiveFocus(Qt.MouseFocusReason) sendModalContent.amountInput.forceActiveFocus(Qt.MouseFocusReason)
const accounts = walletModel.accounts const accounts = walletModel.accounts
const numAccounts = accounts.rowCount() const numAccounts = accounts.rowCount()
@ -43,6 +44,9 @@ ModalPopup {
SendModalContent { SendModalContent {
id: sendModalContent id: sendModalContent
closePopup: function () {
popup.close()
}
} }
footer: StyledButton { footer: StyledButton {

View File

@ -1,13 +1,15 @@
import QtQuick 2.13 import QtQuick 2.13
import QtQuick.Dialogs 1.3
import "../../../../imports" import "../../../../imports"
import "../../../../shared" import "../../../../shared"
Item { Item {
id: sendModalContent id: sendModalContent
property var closePopup: function(){}
property alias amountInput: txtAmount property alias amountInput: txtAmount
property alias passwordInput: txtPassword
property var accounts: [] property var accounts: []
property var assets: [] property var assets: []
property string defaultAccount: "0x8558BFe81d00333379Af1Cd4c07F3dc50081FEC4"
property int selectedAccountIndex: 0 property int selectedAccountIndex: 0
property string selectedAccountAddress: accounts && accounts.length ? accounts[selectedAccountIndex].address : "" property string selectedAccountAddress: accounts && accounts.length ? accounts[selectedAccountIndex].address : ""
@ -28,22 +30,21 @@ Item {
if (!validate()) { if (!validate()) {
return; return;
} }
// Convert to Wei
// TODO use the decimal value fo the token, it's not always 18
// TODO add big number support
// const weiValue = parseFloat(txtAmount.text, 10) * 1000000000000000000
console.log('SENDING', selectedAccountAddress,
txtTo.text,
selectedAssetAddress,
txtAmount.text,
txtPassword.text)
let result = walletModel.onSendTransaction(selectedAccountAddress, let result = walletModel.onSendTransaction(selectedAccountAddress,
txtTo.text, txtTo.text,
selectedAssetAddress, selectedAssetAddress,
txtAmount.text, txtAmount.text,
txtPassword.text) txtPassword.text)
console.log('hash', result)
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()
} }
function validate() { function validate() {
@ -79,6 +80,22 @@ Item {
anchors.left: parent.left anchors.left: parent.left
anchors.right: parent.right anchors.right: parent.right
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 { Input {
id: txtAmount id: txtAmount
label: qsTr("Amount") label: qsTr("Amount")
@ -154,7 +171,6 @@ Item {
Input { Input {
id: txtTo id: txtTo
label: qsTr("Recipient") label: qsTr("Recipient")
text: defaultAccount
placeholderText: qsTr("Send to") placeholderText: qsTr("Send to")
anchors.top: textSelectAccountAddress.bottom anchors.top: textSelectAccountAddress.bottom
anchors.topMargin: Theme.padding anchors.topMargin: Theme.padding