From 51f89a8402291086424318338c1004896785a839 Mon Sep 17 00:00:00 2001 From: "moneromooo.monero" Date: Sun, 16 Oct 2016 13:57:56 +0100 Subject: [PATCH 1/2] Transfer: disable Send button if the payment id is invalid --- pages/Transfer.qml | 2 +- src/libwalletqt/WalletManager.cpp | 5 +++++ src/libwalletqt/WalletManager.h | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pages/Transfer.qml b/pages/Transfer.qml index 3921b1ef..ab64362b 100644 --- a/pages/Transfer.qml +++ b/pages/Transfer.qml @@ -251,7 +251,7 @@ Rectangle { shadowPressedColor: "#B32D00" releasedColor: "#FF6C3C" pressedColor: "#FF4304" - enabled : addressLine.text.length > 0 && amountLine.text.length > 0 + enabled : addressLine.text.length > 0 && amountLine.text.length > 0 && (paymentIdLine.text.trim() === "" || walletManager.paymentIdValid(paymentIdLine.text.trim())) onClicked: { console.log("Transfer: paymentClicked") var priority = priorityModel.get(priorityDropdown.currentIndex).priority diff --git a/src/libwalletqt/WalletManager.cpp b/src/libwalletqt/WalletManager.cpp index 2e1fe57b..988fd426 100644 --- a/src/libwalletqt/WalletManager.cpp +++ b/src/libwalletqt/WalletManager.cpp @@ -149,6 +149,11 @@ quint64 WalletManager::amountFromDouble(double amount) const return Bitmonero::Wallet::amountFromDouble(amount); } +bool WalletManager::paymentIdValid(const QString &payment_id) const +{ + return Bitmonero::Wallet::paymentIdValid(payment_id.toStdString()); +} + void WalletManager::setLogLevel(int logLevel) { Bitmonero::WalletManagerFactory::setLogLevel(logLevel); diff --git a/src/libwalletqt/WalletManager.h b/src/libwalletqt/WalletManager.h index 24fb60fc..ddb23b85 100644 --- a/src/libwalletqt/WalletManager.h +++ b/src/libwalletqt/WalletManager.h @@ -89,6 +89,8 @@ public: // QML JS engine doesn't support unsigned integers Q_INVOKABLE QString maximumAllowedAmountAsSting() const; + Q_INVOKABLE bool paymentIdValid(const QString &payment_id) const; + // QML missing such functionality, implementing these helpers here Q_INVOKABLE QString urlToLocalPath(const QUrl &url) const; Q_INVOKABLE QUrl localPathToUrl(const QString &path) const; From 628b26c42938172446de44f206ed7c85d3cca4e6 Mon Sep 17 00:00:00 2001 From: "moneromooo.monero" Date: Sun, 16 Oct 2016 16:54:53 +0100 Subject: [PATCH 2/2] Transfer: validate destination address including preventing two payment ids (standalone and from integrated address) --- pages/Transfer.qml | 15 ++++++++++++++- src/libwalletqt/WalletManager.cpp | 10 ++++++++++ src/libwalletqt/WalletManager.h | 2 ++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/pages/Transfer.qml b/pages/Transfer.qml index ab64362b..88ab5a92 100644 --- a/pages/Transfer.qml +++ b/pages/Transfer.qml @@ -239,6 +239,19 @@ Rectangle { anchors.topMargin: 5 } + function checkAddressAndPaymentID(address, payment_id, testnet) { + print ("testing") + if (!walletManager.addressValid(address, testnet)) + return false + print ("address is valid") + var ipid = walletManager.paymentIdFromAddress(address, testnet) + print ("ipid: [" + ipid + "]") + if (ipid.length > 0) + return payment_id === "" + print ("payment_id: [" + payment_id + "]") + return payment_id === "" || walletManager.paymentIdValid(payment_id) + } + StandardButton { id: sendButton anchors.left: parent.left @@ -251,7 +264,7 @@ Rectangle { shadowPressedColor: "#B32D00" releasedColor: "#FF6C3C" pressedColor: "#FF4304" - enabled : addressLine.text.length > 0 && amountLine.text.length > 0 && (paymentIdLine.text.trim() === "" || walletManager.paymentIdValid(paymentIdLine.text.trim())) + enabled : amountLine.text.length > 0 && checkAddressAndPaymentID(addressLine.text.trim(), paymentIdLine.text.trim(), appWindow.persistentSettings.testnet) onClicked: { console.log("Transfer: paymentClicked") var priority = priorityModel.get(priorityDropdown.currentIndex).priority diff --git a/src/libwalletqt/WalletManager.cpp b/src/libwalletqt/WalletManager.cpp index 988fd426..7b60c528 100644 --- a/src/libwalletqt/WalletManager.cpp +++ b/src/libwalletqt/WalletManager.cpp @@ -154,6 +154,16 @@ bool WalletManager::paymentIdValid(const QString &payment_id) const return Bitmonero::Wallet::paymentIdValid(payment_id.toStdString()); } +bool WalletManager::addressValid(const QString &address, bool testnet) const +{ + return Bitmonero::Wallet::addressValid(address.toStdString(), testnet); +} + +QString WalletManager::paymentIdFromAddress(const QString &address, bool testnet) const +{ + return QString::fromStdString(Bitmonero::Wallet::paymentIdFromAddress(address.toStdString(), testnet)); +} + void WalletManager::setLogLevel(int logLevel) { Bitmonero::WalletManagerFactory::setLogLevel(logLevel); diff --git a/src/libwalletqt/WalletManager.h b/src/libwalletqt/WalletManager.h index ddb23b85..51ad0dbf 100644 --- a/src/libwalletqt/WalletManager.h +++ b/src/libwalletqt/WalletManager.h @@ -90,6 +90,8 @@ public: Q_INVOKABLE QString maximumAllowedAmountAsSting() const; Q_INVOKABLE bool paymentIdValid(const QString &payment_id) const; + Q_INVOKABLE bool addressValid(const QString &address, bool testnet) const; + Q_INVOKABLE QString paymentIdFromAddress(const QString &address, bool testnet) const; // QML missing such functionality, implementing these helpers here Q_INVOKABLE QString urlToLocalPath(const QUrl &url) const;