From 39cb75e58c2823e6a25e229596af4e276d77b2ae Mon Sep 17 00:00:00 2001 From: Ilya Kitaev Date: Tue, 28 Jun 2016 22:37:14 +0300 Subject: [PATCH] Send money: confirmation popups added --- main.cpp | 1 + main.qml | 79 ++++++++++++++++++++++---- src/libwalletqt/PendingTransaction.cpp | 1 + src/libwalletqt/Wallet.h | 2 +- 4 files changed, 71 insertions(+), 12 deletions(-) diff --git a/main.cpp b/main.cpp index 70390a80..7b2799d4 100644 --- a/main.cpp +++ b/main.cpp @@ -56,6 +56,7 @@ int main(int argc, char *argv[]) qmlRegisterUncreatableType("Bitmonero.Wallet", 1, 0, "Wallet", "Wallet can't be instantiated directly"); qmlRegisterUncreatableType("Bitmonero.PendingTransaction", 1, 0, "PendingTransaction", "PendingTransaction can't be instantiated directly"); + qRegisterMetaType(); QQmlApplicationEngine engine; diff --git a/main.qml b/main.qml index a4a8b3ff..721c69e4 100644 --- a/main.qml +++ b/main.qml @@ -30,6 +30,7 @@ import QtQuick 2.2 import QtQuick.Window 2.0 import QtQuick.Controls 1.1 import QtQuick.Controls.Styles 1.1 +import QtQuick.Dialogs 1.2 import Qt.labs.settings 1.0 import Bitmonero.Wallet 1.0 import Bitmonero.PendingTransaction 1.0 @@ -47,6 +48,7 @@ ApplicationWindow { property bool osx: false property alias persistentSettings : persistentSettings property var wallet; + property var transaction; function altKeyReleased() { ctrlPressed = false; } @@ -133,6 +135,10 @@ ApplicationWindow { wallet = walletManager.openWallet(wallet_path, "", persistentSettings.testnet); if (wallet.status !== Wallet.Status_Ok) { console.log("Error opening wallet: ", wallet.errorString); + informationPopup.title = qsTr("Error"); + informationPopup.text = qsTr("Couldn't open wallet: ") + wallet.errorString; + informationPopup.icon = StandardIcon.Critical + informationPopup.open() return; } console.log("Wallet opened successfully: ", wallet.errorString); @@ -169,6 +175,8 @@ ApplicationWindow { return wallets.length > 0; } + + // called on "transfer" function handlePayment(address, paymentId, amount, mixinCount, priority) { console.log("Creating transaction: ") console.log("\taddress: ", address, @@ -180,22 +188,53 @@ ApplicationWindow { var amountxmr = walletManager.amountFromString(amount); console.log("integer amount: ", amountxmr); - var pendingTransaction = wallet.createTransaction(address, paymentId, amountxmr, mixinCount, priority); - if (pendingTransaction.status !== PendingTransaction.Status_Ok) { - console.error("Can't create transaction: ", pendingTransaction.errorString); + transaction = wallet.createTransaction(address, paymentId, amountxmr, mixinCount, priority); + if (transaction.status !== PendingTransaction.Status_Ok) { + console.error("Can't create transaction: ", transaction.errorString); + informationPopup.title = qsTr("Error"); + informationPopup.text = qsTr("Can't create transaction: ") + transaction.errorString + informationPopup.icon = StandardIcon.Critical + informationPopup.open(); + // deleting transaction object, we don't want memleaks + wallet.disposeTransaction(transaction); + } else { - console.log("Transaction created, amount: " + walletManager.displayAmount(pendingTransaction.amount) - + ", fee: " + walletManager.displayAmount(pendingTransaction.fee)); - if (!pendingTransaction.commit()) { - console.log("Error committing transaction: " + pendingTransaction.errorString); - } else { - wallet.refresh(); - } + console.log("Transaction created, amount: " + walletManager.displayAmount(transaction.amount) + + ", fee: " + walletManager.displayAmount(transaction.fee)); + + // here we show confirmation popup; + + transactionConfirmationPopup.title = qsTr("Confirmation") + transactionConfirmationPopup.text = qsTr("Please confirm transaction:\n\n") + + "\naddress: " + address + + "\npayment id: " + paymentId + + "\namount: " + walletManager.displayAmount(transaction.amount) + + "\nfee: " + walletManager.displayAmount(transaction.fee) + transactionConfirmationPopup.icon = StandardIcon.Question + transactionConfirmationPopup.open() + // committing transaction + } + } + + // called after user confirms transaction + function handleTransactionConfirmed() { + if (!transaction.commit()) { + console.log("Error committing transaction: " + transaction.errorString); + informationPopup.title = qsTr("Error"); + informationPopup.text = qsTr("Couldn't send the money: ") + transaction.errorString + informationPopup.icon = StandardIcon.Critical + } else { + informationPopup.title = qsTr("Information") + informationPopup.text = qsTr("Money sent successfully") + informationPopup.icon = StandardIcon.Information } - wallet.disposeTransaction(pendingTransaction); + informationPopup.open() + wallet.refresh() + wallet.disposeTransaction(transaction) } + visible: true width: rightPanelExpanded ? 1269 : 1269 - 300 height: 800 @@ -232,6 +271,24 @@ ApplicationWindow { property string payment_id } + // TODO: replace with customized popups + + // Information dialog + MessageDialog { + id: informationPopup + standardButtons: StandardButton.Ok + } + + // Confrirmation aka question dialog + MessageDialog { + id: transactionConfirmationPopup + standardButtons: StandardButton.Ok + StandardButton.Cancel + onAccepted: { + handleTransactionConfirmed() + } + } + + Item { id: rootItem anchors.fill: parent diff --git a/src/libwalletqt/PendingTransaction.cpp b/src/libwalletqt/PendingTransaction.cpp index a5dc458d..8c0d8c29 100644 --- a/src/libwalletqt/PendingTransaction.cpp +++ b/src/libwalletqt/PendingTransaction.cpp @@ -1,5 +1,6 @@ #include "PendingTransaction.h" + PendingTransaction::Status PendingTransaction::status() const { return static_cast(m_pimpl->status()); diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index a62c0f14..241b89d8 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -80,7 +80,7 @@ public: //! creates transaction Q_INVOKABLE PendingTransaction * createTransaction(const QString &dst_addr, const QString &payment_id, quint64 amount, quint32 mixin_count, - PendingTransaction::Priority priority = PendingTransaction::Priority_Low); + PendingTransaction::Priority priority); //! deletes transaction and frees memory Q_INVOKABLE void disposeTransaction(PendingTransaction * t);