From d95e4a37cf45a0e8cad77bcf421bf7b7fa7df22b Mon Sep 17 00:00:00 2001 From: "moneromooo.monero" Date: Sat, 5 Nov 2016 23:19:28 +0000 Subject: [PATCH] Write support for tx notes Support still needs adding for displaying them in the history, but at least they're saved in the cache now, and not ignored. --- BasicPanel.qml | 4 ++-- MiddlePanel.qml | 4 ++-- main.qml | 30 +++++++++++++++++++++++--- pages/Transfer.qml | 4 ++-- src/libwalletqt/PendingTransaction.cpp | 9 ++++++++ src/libwalletqt/PendingTransaction.h | 2 ++ src/libwalletqt/Wallet.cpp | 9 ++++++++ src/libwalletqt/Wallet.h | 3 +++ 8 files changed, 56 insertions(+), 9 deletions(-) diff --git a/BasicPanel.qml b/BasicPanel.qml index ff3fc7cb..d85b84f9 100644 --- a/BasicPanel.qml +++ b/BasicPanel.qml @@ -47,13 +47,13 @@ Rectangle { property alias unlockedBalanceText : availableBalanceText.text; // repeating signal to the outside world signal paymentClicked(string address, string paymentId, double amount, int mixinCount, - int priority) + int priority, string description) Connections { target: transferBasic onPaymentClicked: { console.log("BasicPanel: paymentClicked") - root.paymentClicked(address, paymentId, amount, mixinCount, priority) + root.paymentClicked(address, paymentId, amount, mixinCount, priority, description) } } diff --git a/MiddlePanel.qml b/MiddlePanel.qml index 59a77ba6..ca092b43 100644 --- a/MiddlePanel.qml +++ b/MiddlePanel.qml @@ -49,7 +49,7 @@ Rectangle { property Settings settingsView: Settings { } - signal paymentClicked(string address, string paymentId, double amount, int mixinCount, int priority) + signal paymentClicked(string address, string paymentId, double amount, int mixinCount, int priority, string description) signal generatePaymentIdInvoked() // Disable transfer page if daemon isnt fully synced @@ -297,7 +297,7 @@ Rectangle { target: transferView onPaymentClicked : { console.log("MiddlePanel: paymentClicked") - paymentClicked(address, paymentId, amount, mixinCount, priority) + paymentClicked(address, paymentId, amount, mixinCount, priority, description) } } } diff --git a/main.qml b/main.qml index 7b023c87..4589b733 100644 --- a/main.qml +++ b/main.qml @@ -52,6 +52,7 @@ ApplicationWindow { property alias persistentSettings : persistentSettings property var currentWallet; property var transaction; + property var transactionDescription; property alias password : passwordDialog.password property int splashCounter: 0 property bool isNewWallet: false @@ -346,13 +347,14 @@ ApplicationWindow { // called on "transfer" - function handlePayment(address, paymentId, amount, mixinCount, priority) { + function handlePayment(address, paymentId, amount, mixinCount, priority, description) { console.log("Creating transaction: ") console.log("\taddress: ", address, ", payment_id: ", paymentId, ", amount: ", amount, ", mixins: ", mixinCount, - ", priority: ", priority); + ", priority: ", priority, + ", description: ", description); // validate amount; @@ -398,6 +400,8 @@ ApplicationWindow { console.log("Transaction created, amount: " + walletManager.displayAmount(transaction.amount) + ", fee: " + walletManager.displayAmount(transaction.fee)); + transactionDescription = description; + // here we show confirmation popup; transactionConfirmationPopup.title = qsTr("Confirmation") + translationManager.emptyString @@ -407,6 +411,7 @@ ApplicationWindow { + qsTr("\n\nAmount: ") + walletManager.displayAmount(transaction.amount) + qsTr("\nFee: ") + walletManager.displayAmount(transaction.fee) + qsTr("\n\nMixin: ") + mixinCount + + qsTr("\n\nDescription: ") + description + translationManager.emptyString transactionConfirmationPopup.icon = StandardIcon.Question transactionConfirmationPopup.open() @@ -416,6 +421,16 @@ ApplicationWindow { // called after user confirms transaction function handleTransactionConfirmed() { + // grab transaction.txid before commit, since it clears it. + // we actually need to copy it, because QML will incredibly + // call the function multiple times when the variable is used + // after commit, where it returns another result... + // Of course, this loop is also calling the function multiple + // times, but at least with the same result. + var txid = [], txid_org = transaction.txid, txid_text = "" + for (var i = 0; i < txid_org.length; ++i) + txid[i] = txid_org[i] + if (!transaction.commit()) { console.log("Error committing transaction: " + transaction.errorString); informationPopup.title = qsTr("Error") + translationManager.emptyString @@ -423,8 +438,17 @@ ApplicationWindow { informationPopup.icon = StandardIcon.Critical } else { informationPopup.title = qsTr("Information") + translationManager.emptyString - informationPopup.text = qsTr("Money sent successfully") + translationManager.emptyString + for (var i = 0; i < txid.length; ++i) { + if (txid_text.length > 0) + txid_text += ", " + txid_text += txid[i] + } + informationPopup.text = qsTr("Money sent successfully: %1 transaction(s) ").arg(txid.length) + txid_text + translationManager.emptyString informationPopup.icon = StandardIcon.Information + if (transactionDescription.length > 0) { + for (var i = 0; i < txid.length; ++i) + currentWallet.setUserNote(txid[i], transactionDescription); + } } informationPopup.onCloseCallback = null informationPopup.open() diff --git a/pages/Transfer.qml b/pages/Transfer.qml index 2ea3fb9a..1cc654d4 100644 --- a/pages/Transfer.qml +++ b/pages/Transfer.qml @@ -34,7 +34,7 @@ import "../components" Rectangle { id: root signal paymentClicked(string address, string paymentId, double amount, int mixinCount, - int priority) + int priority, string description) color: "#F0EEEE" @@ -277,7 +277,7 @@ Rectangle { addressLine.text = addressLine.text.trim() paymentIdLine.text = paymentIdLine.text.trim() root.paymentClicked(addressLine.text, paymentIdLine.text, amountLine.text, scaleValueToMixinCount(privacyLevelItem.fillLevel), - priority) + priority, descriptionLine.text) } } diff --git a/src/libwalletqt/PendingTransaction.cpp b/src/libwalletqt/PendingTransaction.cpp index 8c0d8c29..b1441f20 100644 --- a/src/libwalletqt/PendingTransaction.cpp +++ b/src/libwalletqt/PendingTransaction.cpp @@ -31,6 +31,15 @@ quint64 PendingTransaction::fee() const return m_pimpl->fee(); } +QList PendingTransaction::txid() const +{ + QList list; + std::vector txid = m_pimpl->txid(); + for (const auto &t: txid) + list.append(QString::fromStdString(t)); + return list; +} + PendingTransaction::PendingTransaction(Bitmonero::PendingTransaction *pt, QObject *parent) : QObject(parent), m_pimpl(pt) { diff --git a/src/libwalletqt/PendingTransaction.h b/src/libwalletqt/PendingTransaction.h index 8f5fca1c..866431fb 100644 --- a/src/libwalletqt/PendingTransaction.h +++ b/src/libwalletqt/PendingTransaction.h @@ -17,6 +17,7 @@ class PendingTransaction : public QObject Q_PROPERTY(quint64 amount READ amount) Q_PROPERTY(quint64 dust READ dust) Q_PROPERTY(quint64 fee READ fee) + Q_PROPERTY(QList txid READ txid) public: enum Status { @@ -39,6 +40,7 @@ public: quint64 amount() const; quint64 dust() const; quint64 fee() const; + QList txid() const; private: explicit PendingTransaction(Bitmonero::PendingTransaction * pt, QObject *parent = 0); diff --git a/src/libwalletqt/Wallet.cpp b/src/libwalletqt/Wallet.cpp index ef98828c..5ab27a27 100644 --- a/src/libwalletqt/Wallet.cpp +++ b/src/libwalletqt/Wallet.cpp @@ -260,6 +260,15 @@ void Wallet::setPaymentId(const QString &paymentId) m_paymentId = paymentId; } +bool Wallet::setUserNote(const QString &txid, const QString ¬e) +{ + return m_walletImpl->setUserNote(txid.toStdString(), note.toStdString()); +} + +QString Wallet::getUserNote(const QString &txid) const +{ + return QString::fromStdString(m_walletImpl->getUserNote(txid.toStdString())); +} Wallet::Wallet(Bitmonero::Wallet *w, QObject *parent) : QObject(parent) diff --git a/src/libwalletqt/Wallet.h b/src/libwalletqt/Wallet.h index 303dfd24..aec9b2e4 100644 --- a/src/libwalletqt/Wallet.h +++ b/src/libwalletqt/Wallet.h @@ -138,6 +138,9 @@ public: void setPaymentId(const QString &paymentId); + Q_INVOKABLE bool setUserNote(const QString &txid, const QString ¬e); + Q_INVOKABLE QString getUserNote(const QString &txid) const; + // TODO: setListenter() when it implemented in API signals: // emitted on every event happened with wallet