mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
315e92d645
48439b3c10391e5f5555c7d98e1a99706b77eaf7 Don't link SSL_LIBS with GUI unless BIP70 is enabled (James Hilliard) fbb643d2a55ade3c06593a7490601acd2e36dce8 Add BIP70 deprecation warning (James Hilliard) 38b98507cdda02ff02a524d41bcc3427ca9e4fd9 qt: cleanup: Move BIP70 functions together in paymentserver (Wladimir J. van der Laan) 9dcf6c0dfec51f2a49edef537f377422d6dbdceb build: Add --disable-bip70 configure option (Wladimir J. van der Laan) Pull request description: This is based off of #11622 and adds a deprecation warning when a BIP70 URL is used. Rational: - BIP70 increases attack surface in multiple ways and is difficult for third party wallets to implement in a secure manner - Very few merchants use the standard BIP70 variant supported by Bitcoin Core - The one major payment processor that doesn't support BIP21 and currently uses a customized non-standard version of BIP70 has indicated that "Unfortunately the original BIP70 is not useful for us." Tree-SHA512: 1e16ee8d2cdac9499f751ee7b50d058278150f9e38a87a47ddb5105dd0353cdedabe462903f54ead6209b249b249fe5e6a10d29631531be27400f2f69c25b9b9
315 lines
8.9 KiB
C++
315 lines
8.9 KiB
C++
// Copyright (c) 2011-2015 The Bitcoin Core developers
|
|
// Copyright (c) 2014-2020 The Dash Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#if defined(HAVE_CONFIG_H)
|
|
#include <config/dash-config.h>
|
|
#endif
|
|
|
|
#include <qt/sendcoinsentry.h>
|
|
#include <qt/forms/ui_sendcoinsentry.h>
|
|
|
|
#include <qt/addressbookpage.h>
|
|
#include <qt/addresstablemodel.h>
|
|
#include <qt/guiutil.h>
|
|
#include <qt/optionsmodel.h>
|
|
|
|
#include <QApplication>
|
|
#include <QClipboard>
|
|
|
|
SendCoinsEntry::SendCoinsEntry(QWidget* parent) :
|
|
QStackedWidget(parent),
|
|
ui(new Ui::SendCoinsEntry),
|
|
model(nullptr)
|
|
{
|
|
ui->setupUi(this);
|
|
|
|
GUIUtil::disableMacFocusRect(this);
|
|
|
|
setCurrentWidget(ui->SendCoins);
|
|
|
|
ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book"));
|
|
|
|
setButtonIcons();
|
|
|
|
// normal dash address field
|
|
GUIUtil::setupAddressWidget(ui->payTo, this, true);
|
|
|
|
GUIUtil::setFont({ui->payToLabel,
|
|
ui->labellLabel,
|
|
ui->amountLabel,
|
|
ui->messageLabel}, GUIUtil::FontWeight::Normal, 15);
|
|
|
|
GUIUtil::updateFonts();
|
|
|
|
// Connect signals
|
|
connect(ui->payAmount, &BitcoinAmountField::valueChanged, this, &SendCoinsEntry::payAmountChanged);
|
|
connect(ui->checkboxSubtractFeeFromAmount, &QCheckBox::toggled, this, &SendCoinsEntry::subtractFeeFromAmountChanged);
|
|
connect(ui->deleteButton, &QPushButton::clicked, this, &SendCoinsEntry::deleteClicked);
|
|
connect(ui->deleteButton_is, &QPushButton::clicked, this, &SendCoinsEntry::deleteClicked);
|
|
connect(ui->deleteButton_s, &QPushButton::clicked, this, &SendCoinsEntry::deleteClicked);
|
|
connect(ui->useAvailableBalanceButton, &QPushButton::clicked, this, &SendCoinsEntry::useAvailableBalanceClicked);
|
|
}
|
|
|
|
SendCoinsEntry::~SendCoinsEntry()
|
|
{
|
|
delete ui;
|
|
}
|
|
|
|
void SendCoinsEntry::on_pasteButton_clicked()
|
|
{
|
|
// Paste text from clipboard into recipient field
|
|
ui->payTo->setText(QApplication::clipboard()->text());
|
|
}
|
|
|
|
void SendCoinsEntry::on_addressBookButton_clicked()
|
|
{
|
|
if(!model)
|
|
return;
|
|
AddressBookPage dlg(AddressBookPage::ForSelection, AddressBookPage::SendingTab, this);
|
|
dlg.setModel(model->getAddressTableModel());
|
|
if(dlg.exec())
|
|
{
|
|
ui->payTo->setText(dlg.getReturnValue());
|
|
ui->payAmount->setFocus();
|
|
}
|
|
}
|
|
|
|
void SendCoinsEntry::on_payTo_textChanged(const QString &address)
|
|
{
|
|
SendCoinsRecipient rcp;
|
|
if (GUIUtil::parseBitcoinURI(address, &rcp)) {
|
|
ui->payTo->blockSignals(true);
|
|
setValue(rcp);
|
|
ui->payTo->blockSignals(false);
|
|
} else {
|
|
updateLabel(address);
|
|
}
|
|
}
|
|
|
|
void SendCoinsEntry::setModel(WalletModel *_model)
|
|
{
|
|
this->model = _model;
|
|
|
|
if (_model && _model->getOptionsModel())
|
|
connect(_model->getOptionsModel(), &OptionsModel::displayUnitChanged, this, &SendCoinsEntry::updateDisplayUnit);
|
|
|
|
clear();
|
|
}
|
|
|
|
void SendCoinsEntry::clear()
|
|
{
|
|
// clear UI elements for normal payment
|
|
ui->payTo->clear();
|
|
ui->addAsLabel->clear();
|
|
ui->payAmount->clear();
|
|
ui->checkboxSubtractFeeFromAmount->setCheckState(Qt::Unchecked);
|
|
ui->messageTextLabel->clear();
|
|
ui->messageTextLabel->hide();
|
|
ui->messageLabel->hide();
|
|
// clear UI elements for unauthenticated payment request
|
|
ui->payTo_is->clear();
|
|
ui->memoTextLabel_is->clear();
|
|
ui->payAmount_is->clear();
|
|
// clear UI elements for authenticated payment request
|
|
ui->payTo_s->clear();
|
|
ui->memoTextLabel_s->clear();
|
|
ui->payAmount_s->clear();
|
|
|
|
// update the display unit, to not use the default ("BTC")
|
|
updateDisplayUnit();
|
|
}
|
|
|
|
void SendCoinsEntry::checkSubtractFeeFromAmount()
|
|
{
|
|
ui->checkboxSubtractFeeFromAmount->setChecked(true);
|
|
}
|
|
|
|
void SendCoinsEntry::deleteClicked()
|
|
{
|
|
Q_EMIT removeEntry(this);
|
|
}
|
|
|
|
void SendCoinsEntry::useAvailableBalanceClicked()
|
|
{
|
|
Q_EMIT useAvailableBalance(this);
|
|
}
|
|
|
|
bool SendCoinsEntry::validate(interfaces::Node& node)
|
|
{
|
|
if (!model)
|
|
return false;
|
|
|
|
// Check input validity
|
|
bool retval = true;
|
|
|
|
#ifdef ENABLE_BIP70
|
|
// Skip checks for payment request
|
|
if (recipient.paymentRequest.IsInitialized())
|
|
return retval;
|
|
#endif
|
|
|
|
if (!model->validateAddress(ui->payTo->text()))
|
|
{
|
|
ui->payTo->setValid(false);
|
|
retval = false;
|
|
}
|
|
|
|
if (!ui->payAmount->validate())
|
|
{
|
|
retval = false;
|
|
}
|
|
|
|
// Sending a zero amount is invalid
|
|
if (ui->payAmount->value(nullptr) <= 0)
|
|
{
|
|
ui->payAmount->setValid(false);
|
|
retval = false;
|
|
}
|
|
|
|
// Reject dust outputs:
|
|
if (retval && GUIUtil::isDust(node, ui->payTo->text(), ui->payAmount->value())) {
|
|
ui->payAmount->setValid(false);
|
|
retval = false;
|
|
}
|
|
|
|
return retval;
|
|
}
|
|
|
|
SendCoinsRecipient SendCoinsEntry::getValue()
|
|
{
|
|
#ifdef ENABLE_BIP70
|
|
// Payment request
|
|
if (recipient.paymentRequest.IsInitialized())
|
|
return recipient;
|
|
#endif
|
|
|
|
// Normal payment
|
|
recipient.address = ui->payTo->text();
|
|
recipient.label = ui->addAsLabel->text();
|
|
recipient.amount = ui->payAmount->value();
|
|
recipient.message = ui->messageTextLabel->text();
|
|
recipient.fSubtractFeeFromAmount = (ui->checkboxSubtractFeeFromAmount->checkState() == Qt::Checked);
|
|
|
|
return recipient;
|
|
}
|
|
|
|
QWidget *SendCoinsEntry::setupTabChain(QWidget *prev)
|
|
{
|
|
QWidget::setTabOrder(prev, ui->payTo);
|
|
QWidget::setTabOrder(ui->payTo, ui->addAsLabel);
|
|
QWidget *w = ui->payAmount->setupTabChain(ui->addAsLabel);
|
|
QWidget::setTabOrder(w, ui->checkboxSubtractFeeFromAmount);
|
|
QWidget::setTabOrder(ui->checkboxSubtractFeeFromAmount, ui->addressBookButton);
|
|
QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
|
|
QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
|
|
return ui->deleteButton;
|
|
}
|
|
|
|
void SendCoinsEntry::setValue(const SendCoinsRecipient &value)
|
|
{
|
|
recipient = value;
|
|
|
|
#ifdef ENABLE_BIP70
|
|
if (recipient.paymentRequest.IsInitialized()) // payment request
|
|
{
|
|
if (recipient.authenticatedMerchant.isEmpty()) // unauthenticated
|
|
{
|
|
ui->payTo_is->setText(recipient.address);
|
|
ui->memoTextLabel_is->setText(recipient.message);
|
|
ui->payAmount_is->setValue(recipient.amount);
|
|
ui->payAmount_is->setReadOnly(true);
|
|
setCurrentWidget(ui->SendCoins_UnauthenticatedPaymentRequest);
|
|
}
|
|
else // authenticated
|
|
{
|
|
ui->payTo_s->setText(recipient.authenticatedMerchant);
|
|
ui->memoTextLabel_s->setText(recipient.message);
|
|
ui->payAmount_s->setValue(recipient.amount);
|
|
ui->payAmount_s->setReadOnly(true);
|
|
setCurrentWidget(ui->SendCoins_AuthenticatedPaymentRequest);
|
|
}
|
|
}
|
|
else // normal payment
|
|
#endif
|
|
{
|
|
// message
|
|
ui->messageTextLabel->setText(recipient.message);
|
|
ui->messageTextLabel->setVisible(!recipient.message.isEmpty());
|
|
ui->messageLabel->setVisible(!recipient.message.isEmpty());
|
|
|
|
ui->payTo->setText(recipient.address);
|
|
ui->addAsLabel->setText(recipient.label);
|
|
ui->payAmount->setValue(recipient.amount);
|
|
}
|
|
|
|
updateLabel(recipient.address);
|
|
}
|
|
|
|
void SendCoinsEntry::setAddress(const QString &address)
|
|
{
|
|
ui->payTo->setText(address);
|
|
ui->payAmount->setFocus();
|
|
}
|
|
|
|
void SendCoinsEntry::setAmount(const CAmount &amount)
|
|
{
|
|
ui->payAmount->setValue(amount);
|
|
}
|
|
|
|
bool SendCoinsEntry::isClear()
|
|
{
|
|
return ui->payTo->text().isEmpty() && ui->payTo_is->text().isEmpty() && ui->payTo_s->text().isEmpty();
|
|
}
|
|
|
|
void SendCoinsEntry::setFocus()
|
|
{
|
|
ui->payTo->setFocus();
|
|
}
|
|
|
|
void SendCoinsEntry::updateDisplayUnit()
|
|
{
|
|
if(model && model->getOptionsModel())
|
|
{
|
|
// Update payAmount with the current unit
|
|
ui->payAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
|
|
ui->payAmount_is->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
|
|
ui->payAmount_s->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
|
|
}
|
|
}
|
|
|
|
void SendCoinsEntry::changeEvent(QEvent* e)
|
|
{
|
|
QStackedWidget::changeEvent(e);
|
|
if (e->type() == QEvent::StyleChange) {
|
|
// Adjust button icon colors on theme changes
|
|
setButtonIcons();
|
|
}
|
|
}
|
|
|
|
void SendCoinsEntry::setButtonIcons()
|
|
{
|
|
GUIUtil::setIcon(ui->addressBookButton, "address-book");
|
|
GUIUtil::setIcon(ui->pasteButton, "editpaste");
|
|
GUIUtil::setIcon(ui->deleteButton, "remove", GUIUtil::ThemedColor::RED);
|
|
GUIUtil::setIcon(ui->deleteButton_is, "remove", GUIUtil::ThemedColor::RED);
|
|
GUIUtil::setIcon(ui->deleteButton_s, "remove", GUIUtil::ThemedColor::RED);
|
|
}
|
|
|
|
bool SendCoinsEntry::updateLabel(const QString &address)
|
|
{
|
|
if(!model)
|
|
return false;
|
|
|
|
// Fill in label from address book, if address has an associated label
|
|
QString associatedLabel = model->getAddressTableModel()->labelForAddress(address);
|
|
if(!associatedLabel.isEmpty())
|
|
{
|
|
ui->addAsLabel->setText(associatedLabel);
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|