Transfer: validate destination address

including preventing two payment ids (standalone and
from integrated address)
This commit is contained in:
moneromooo.monero 2016-10-16 16:54:53 +01:00
parent 51f89a8402
commit 628b26c429
3 changed files with 26 additions and 1 deletions

View file

@ -239,6 +239,19 @@ Rectangle {
anchors.topMargin: 5 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 { StandardButton {
id: sendButton id: sendButton
anchors.left: parent.left anchors.left: parent.left
@ -251,7 +264,7 @@ Rectangle {
shadowPressedColor: "#B32D00" shadowPressedColor: "#B32D00"
releasedColor: "#FF6C3C" releasedColor: "#FF6C3C"
pressedColor: "#FF4304" 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: { onClicked: {
console.log("Transfer: paymentClicked") console.log("Transfer: paymentClicked")
var priority = priorityModel.get(priorityDropdown.currentIndex).priority var priority = priorityModel.get(priorityDropdown.currentIndex).priority

View file

@ -154,6 +154,16 @@ bool WalletManager::paymentIdValid(const QString &payment_id) const
return Bitmonero::Wallet::paymentIdValid(payment_id.toStdString()); 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) void WalletManager::setLogLevel(int logLevel)
{ {
Bitmonero::WalletManagerFactory::setLogLevel(logLevel); Bitmonero::WalletManagerFactory::setLogLevel(logLevel);

View file

@ -90,6 +90,8 @@ public:
Q_INVOKABLE QString maximumAllowedAmountAsSting() const; Q_INVOKABLE QString maximumAllowedAmountAsSting() const;
Q_INVOKABLE bool paymentIdValid(const QString &payment_id) 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 // QML missing such functionality, implementing these helpers here
Q_INVOKABLE QString urlToLocalPath(const QUrl &url) const; Q_INVOKABLE QString urlToLocalPath(const QUrl &url) const;