2018-07-27 00:36:45 +02:00
|
|
|
// Copyright (c) 2011-2018 The Bitcoin Core developers
|
2014-12-13 05:09:33 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-11-04 16:20:43 +01:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2017-11-06 19:12:47 +01:00
|
|
|
#if defined(HAVE_CONFIG_H)
|
|
|
|
#include <config/bitcoin-config.h>
|
|
|
|
#endif
|
|
|
|
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <qt/sendcoinsentry.h>
|
2017-08-15 17:31:26 +02:00
|
|
|
#include <qt/forms/ui_sendcoinsentry.h>
|
2013-01-23 21:51:02 +01:00
|
|
|
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <qt/addressbookpage.h>
|
|
|
|
#include <qt/addresstablemodel.h>
|
|
|
|
#include <qt/guiutil.h>
|
|
|
|
#include <qt/optionsmodel.h>
|
|
|
|
#include <qt/platformstyle.h>
|
2011-07-16 19:01:05 +02:00
|
|
|
|
2011-08-07 16:09:49 +02:00
|
|
|
#include <QApplication>
|
|
|
|
#include <QClipboard>
|
2011-07-16 19:01:05 +02:00
|
|
|
|
2016-09-09 13:43:29 +02:00
|
|
|
SendCoinsEntry::SendCoinsEntry(const PlatformStyle *_platformStyle, QWidget *parent) :
|
2013-07-22 08:50:39 +02:00
|
|
|
QStackedWidget(parent),
|
2011-07-16 19:01:05 +02:00
|
|
|
ui(new Ui::SendCoinsEntry),
|
2015-07-28 15:20:14 +02:00
|
|
|
model(0),
|
2016-09-09 13:43:29 +02:00
|
|
|
platformStyle(_platformStyle)
|
2011-07-16 19:01:05 +02:00
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
2015-07-28 15:20:14 +02:00
|
|
|
ui->addressBookButton->setIcon(platformStyle->SingleColorIcon(":/icons/address-book"));
|
|
|
|
ui->pasteButton->setIcon(platformStyle->SingleColorIcon(":/icons/editpaste"));
|
|
|
|
ui->deleteButton->setIcon(platformStyle->SingleColorIcon(":/icons/remove"));
|
|
|
|
ui->deleteButton_is->setIcon(platformStyle->SingleColorIcon(":/icons/remove"));
|
|
|
|
ui->deleteButton_s->setIcon(platformStyle->SingleColorIcon(":/icons/remove"));
|
2014-11-06 20:55:52 +01:00
|
|
|
|
2013-10-24 16:02:39 +02:00
|
|
|
setCurrentWidget(ui->SendCoins);
|
2013-07-22 08:50:39 +02:00
|
|
|
|
2015-07-28 15:20:14 +02:00
|
|
|
if (platformStyle->getUseExtraSpacing())
|
|
|
|
ui->payToLayout->setSpacing(4);
|
2012-05-07 00:19:22 +02:00
|
|
|
ui->addAsLabel->setPlaceholderText(tr("Enter a label for this address to add it to your address book"));
|
2011-07-16 19:01:05 +02:00
|
|
|
|
2013-10-24 16:02:39 +02:00
|
|
|
// normal bitcoin address field
|
2011-07-16 19:01:05 +02:00
|
|
|
GUIUtil::setupAddressWidget(ui->payTo, this);
|
2013-10-24 16:02:39 +02:00
|
|
|
// just a label for displaying bitcoin address(es)
|
2015-10-22 13:33:58 +02:00
|
|
|
ui->payTo_is->setFont(GUIUtil::fixedPitchFont());
|
2014-07-22 09:30:04 +02:00
|
|
|
|
|
|
|
// Connect signals
|
2018-06-24 17:18:22 +02:00
|
|
|
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);
|
2011-07-16 19:01:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
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()
|
|
|
|
{
|
2011-11-08 21:18:36 +01:00
|
|
|
if(!model)
|
|
|
|
return;
|
2015-07-28 15:20:14 +02:00
|
|
|
AddressBookPage dlg(platformStyle, AddressBookPage::ForSelection, AddressBookPage::SendingTab, this);
|
2011-07-16 19:01:05 +02:00
|
|
|
dlg.setModel(model->getAddressTableModel());
|
|
|
|
if(dlg.exec())
|
|
|
|
{
|
|
|
|
ui->payTo->setText(dlg.getReturnValue());
|
|
|
|
ui->payAmount->setFocus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendCoinsEntry::on_payTo_textChanged(const QString &address)
|
|
|
|
{
|
2013-10-16 17:11:39 +02:00
|
|
|
updateLabel(address);
|
2012-04-13 21:08:46 +02:00
|
|
|
}
|
2011-07-16 19:01:05 +02:00
|
|
|
|
2016-09-09 13:43:29 +02:00
|
|
|
void SendCoinsEntry::setModel(WalletModel *_model)
|
2011-07-16 19:01:05 +02:00
|
|
|
{
|
2016-09-09 13:43:29 +02:00
|
|
|
this->model = _model;
|
2012-06-09 15:41:21 +02:00
|
|
|
|
2016-09-09 13:43:29 +02:00
|
|
|
if (_model && _model->getOptionsModel())
|
2018-06-24 17:18:22 +02:00
|
|
|
connect(_model->getOptionsModel(), &OptionsModel::displayUnitChanged, this, &SendCoinsEntry::updateDisplayUnit);
|
2012-06-09 15:41:21 +02:00
|
|
|
|
2012-03-16 13:23:59 +01:00
|
|
|
clear();
|
2011-07-16 19:01:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void SendCoinsEntry::clear()
|
|
|
|
{
|
2013-10-24 16:02:39 +02:00
|
|
|
// clear UI elements for normal payment
|
2011-07-16 19:01:05 +02:00
|
|
|
ui->payTo->clear();
|
|
|
|
ui->addAsLabel->clear();
|
2011-07-22 17:06:37 +02:00
|
|
|
ui->payAmount->clear();
|
2014-07-23 14:34:36 +02:00
|
|
|
ui->checkboxSubtractFeeFromAmount->setCheckState(Qt::Unchecked);
|
2014-01-21 23:39:29 +01:00
|
|
|
ui->messageTextLabel->clear();
|
|
|
|
ui->messageTextLabel->hide();
|
|
|
|
ui->messageLabel->hide();
|
2015-03-18 11:22:27 +01:00
|
|
|
// clear UI elements for unauthenticated payment request
|
2013-10-24 16:02:39 +02:00
|
|
|
ui->payTo_is->clear();
|
|
|
|
ui->memoTextLabel_is->clear();
|
|
|
|
ui->payAmount_is->clear();
|
2015-03-18 11:22:27 +01:00
|
|
|
// clear UI elements for authenticated payment request
|
2013-10-11 14:22:43 +02:00
|
|
|
ui->payTo_s->clear();
|
|
|
|
ui->memoTextLabel_s->clear();
|
|
|
|
ui->payAmount_s->clear();
|
|
|
|
|
2012-06-09 15:41:21 +02:00
|
|
|
// update the display unit, to not use the default ("BTC")
|
|
|
|
updateDisplayUnit();
|
2011-07-16 19:01:05 +02:00
|
|
|
}
|
|
|
|
|
2017-08-20 07:04:56 +02:00
|
|
|
void SendCoinsEntry::checkSubtractFeeFromAmount()
|
|
|
|
{
|
|
|
|
ui->checkboxSubtractFeeFromAmount->setChecked(true);
|
|
|
|
}
|
|
|
|
|
2013-11-22 13:53:05 +01:00
|
|
|
void SendCoinsEntry::deleteClicked()
|
2011-07-16 19:01:05 +02:00
|
|
|
{
|
2015-07-14 13:59:05 +02:00
|
|
|
Q_EMIT removeEntry(this);
|
2011-07-16 19:01:05 +02:00
|
|
|
}
|
|
|
|
|
2017-08-20 07:04:56 +02:00
|
|
|
void SendCoinsEntry::useAvailableBalanceClicked()
|
|
|
|
{
|
|
|
|
Q_EMIT useAvailableBalance(this);
|
|
|
|
}
|
|
|
|
|
2018-04-07 09:42:02 +02:00
|
|
|
bool SendCoinsEntry::validate(interfaces::Node& node)
|
2011-07-16 19:01:05 +02:00
|
|
|
{
|
2013-10-24 16:02:39 +02:00
|
|
|
if (!model)
|
|
|
|
return false;
|
|
|
|
|
2011-07-16 19:01:05 +02:00
|
|
|
// Check input validity
|
|
|
|
bool retval = true;
|
|
|
|
|
2017-11-06 19:12:47 +01:00
|
|
|
#ifdef ENABLE_BIP70
|
2013-10-24 16:02:39 +02:00
|
|
|
// Skip checks for payment request
|
|
|
|
if (recipient.paymentRequest.IsInitialized())
|
2013-07-22 08:50:39 +02:00
|
|
|
return retval;
|
2017-11-06 19:12:47 +01:00
|
|
|
#endif
|
2013-07-22 08:50:39 +02:00
|
|
|
|
2013-11-20 15:56:51 +01:00
|
|
|
if (!model->validateAddress(ui->payTo->text()))
|
2011-07-16 19:01:05 +02:00
|
|
|
{
|
2013-08-08 05:09:07 +02:00
|
|
|
ui->payTo->setValid(false);
|
2011-07-16 19:01:05 +02:00
|
|
|
retval = false;
|
|
|
|
}
|
2013-08-08 05:09:07 +02:00
|
|
|
|
2013-10-24 16:02:39 +02:00
|
|
|
if (!ui->payAmount->validate())
|
2011-07-26 13:08:34 +02:00
|
|
|
{
|
2013-08-08 05:09:07 +02:00
|
|
|
retval = false;
|
2011-07-26 13:08:34 +02:00
|
|
|
}
|
|
|
|
|
2014-07-18 16:31:13 +02:00
|
|
|
// Sending a zero amount is invalid
|
|
|
|
if (ui->payAmount->value(0) <= 0)
|
|
|
|
{
|
|
|
|
ui->payAmount->setValid(false);
|
|
|
|
retval = false;
|
|
|
|
}
|
|
|
|
|
2013-08-08 05:09:07 +02:00
|
|
|
// Reject dust outputs:
|
2017-04-18 23:06:13 +02:00
|
|
|
if (retval && GUIUtil::isDust(node, ui->payTo->text(), ui->payAmount->value())) {
|
2013-08-08 05:09:07 +02:00
|
|
|
ui->payAmount->setValid(false);
|
2011-07-16 19:01:05 +02:00
|
|
|
retval = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
SendCoinsRecipient SendCoinsEntry::getValue()
|
|
|
|
{
|
2017-11-06 19:12:47 +01:00
|
|
|
#ifdef ENABLE_BIP70
|
2013-10-24 16:02:39 +02:00
|
|
|
// Payment request
|
|
|
|
if (recipient.paymentRequest.IsInitialized())
|
2013-07-22 08:50:39 +02:00
|
|
|
return recipient;
|
2017-11-06 19:12:47 +01:00
|
|
|
#endif
|
2011-07-16 19:01:05 +02:00
|
|
|
|
2013-10-24 16:02:39 +02:00
|
|
|
// Normal payment
|
2013-07-22 08:50:39 +02:00
|
|
|
recipient.address = ui->payTo->text();
|
|
|
|
recipient.label = ui->addAsLabel->text();
|
|
|
|
recipient.amount = ui->payAmount->value();
|
2014-01-21 23:39:29 +01:00
|
|
|
recipient.message = ui->messageTextLabel->text();
|
2014-07-23 14:34:36 +02:00
|
|
|
recipient.fSubtractFeeFromAmount = (ui->checkboxSubtractFeeFromAmount->checkState() == Qt::Checked);
|
2011-07-16 19:01:05 +02:00
|
|
|
|
2013-07-22 08:50:39 +02:00
|
|
|
return recipient;
|
2011-07-16 19:01:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
QWidget *SendCoinsEntry::setupTabChain(QWidget *prev)
|
|
|
|
{
|
|
|
|
QWidget::setTabOrder(prev, ui->payTo);
|
2014-01-02 09:32:03 +01:00
|
|
|
QWidget::setTabOrder(ui->payTo, ui->addAsLabel);
|
|
|
|
QWidget *w = ui->payAmount->setupTabChain(ui->addAsLabel);
|
2014-07-23 14:34:36 +02:00
|
|
|
QWidget::setTabOrder(w, ui->checkboxSubtractFeeFromAmount);
|
|
|
|
QWidget::setTabOrder(ui->checkboxSubtractFeeFromAmount, ui->addressBookButton);
|
2011-07-16 19:01:05 +02:00
|
|
|
QWidget::setTabOrder(ui->addressBookButton, ui->pasteButton);
|
|
|
|
QWidget::setTabOrder(ui->pasteButton, ui->deleteButton);
|
2014-01-02 09:32:03 +01:00
|
|
|
return ui->deleteButton;
|
2011-07-16 19:01:05 +02:00
|
|
|
}
|
2011-08-07 16:04:48 +02:00
|
|
|
|
|
|
|
void SendCoinsEntry::setValue(const SendCoinsRecipient &value)
|
|
|
|
{
|
2013-07-22 08:50:39 +02:00
|
|
|
recipient = value;
|
|
|
|
|
2017-11-06 19:12:47 +01:00
|
|
|
#ifdef ENABLE_BIP70
|
2013-10-24 16:02:39 +02:00
|
|
|
if (recipient.paymentRequest.IsInitialized()) // payment request
|
|
|
|
{
|
2015-03-18 11:22:27 +01:00
|
|
|
if (recipient.authenticatedMerchant.isEmpty()) // unauthenticated
|
2013-10-24 16:02:39 +02:00
|
|
|
{
|
|
|
|
ui->payTo_is->setText(recipient.address);
|
2013-10-27 21:52:01 +01:00
|
|
|
ui->memoTextLabel_is->setText(recipient.message);
|
2013-10-24 16:02:39 +02:00
|
|
|
ui->payAmount_is->setValue(recipient.amount);
|
|
|
|
ui->payAmount_is->setReadOnly(true);
|
2015-03-18 11:22:27 +01:00
|
|
|
setCurrentWidget(ui->SendCoins_UnauthenticatedPaymentRequest);
|
2013-10-24 16:02:39 +02:00
|
|
|
}
|
2015-03-18 11:22:27 +01:00
|
|
|
else // authenticated
|
2013-10-24 16:02:39 +02:00
|
|
|
{
|
|
|
|
ui->payTo_s->setText(recipient.authenticatedMerchant);
|
2013-10-27 21:52:01 +01:00
|
|
|
ui->memoTextLabel_s->setText(recipient.message);
|
2013-10-24 16:02:39 +02:00
|
|
|
ui->payAmount_s->setValue(recipient.amount);
|
|
|
|
ui->payAmount_s->setReadOnly(true);
|
2015-03-18 11:22:27 +01:00
|
|
|
setCurrentWidget(ui->SendCoins_AuthenticatedPaymentRequest);
|
2013-10-24 16:02:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else // normal payment
|
2017-11-06 19:12:47 +01:00
|
|
|
#endif
|
2013-10-11 14:22:43 +02:00
|
|
|
{
|
2014-01-21 23:39:29 +01:00
|
|
|
// message
|
|
|
|
ui->messageTextLabel->setText(recipient.message);
|
|
|
|
ui->messageTextLabel->setVisible(!recipient.message.isEmpty());
|
|
|
|
ui->messageLabel->setVisible(!recipient.message.isEmpty());
|
|
|
|
|
2014-03-12 17:03:56 +01:00
|
|
|
ui->addAsLabel->clear();
|
|
|
|
ui->payTo->setText(recipient.address); // this may set a label from addressbook
|
2015-04-28 16:48:28 +02:00
|
|
|
if (!recipient.label.isEmpty()) // if a label had been set from the addressbook, don't overwrite with an empty label
|
2014-03-12 17:03:56 +01:00
|
|
|
ui->addAsLabel->setText(recipient.label);
|
2013-10-11 14:22:43 +02:00
|
|
|
ui->payAmount->setValue(recipient.amount);
|
|
|
|
}
|
2011-08-07 16:04:48 +02:00
|
|
|
}
|
|
|
|
|
2013-01-25 18:46:53 +01:00
|
|
|
void SendCoinsEntry::setAddress(const QString &address)
|
|
|
|
{
|
|
|
|
ui->payTo->setText(address);
|
|
|
|
ui->payAmount->setFocus();
|
|
|
|
}
|
|
|
|
|
2017-08-20 07:04:56 +02:00
|
|
|
void SendCoinsEntry::setAmount(const CAmount &amount)
|
|
|
|
{
|
|
|
|
ui->payAmount->setValue(amount);
|
|
|
|
}
|
|
|
|
|
2011-08-07 16:04:48 +02:00
|
|
|
bool SendCoinsEntry::isClear()
|
|
|
|
{
|
2013-10-24 16:02:39 +02:00
|
|
|
return ui->payTo->text().isEmpty() && ui->payTo_is->text().isEmpty() && ui->payTo_s->text().isEmpty();
|
2011-08-07 16:04:48 +02:00
|
|
|
}
|
|
|
|
|
2011-12-07 06:00:04 +01:00
|
|
|
void SendCoinsEntry::setFocus()
|
|
|
|
{
|
|
|
|
ui->payTo->setFocus();
|
|
|
|
}
|
|
|
|
|
2012-06-09 15:41:21 +02:00
|
|
|
void SendCoinsEntry::updateDisplayUnit()
|
|
|
|
{
|
|
|
|
if(model && model->getOptionsModel())
|
|
|
|
{
|
|
|
|
// Update payAmount with the current unit
|
|
|
|
ui->payAmount->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
|
2013-10-24 16:02:39 +02:00
|
|
|
ui->payAmount_is->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
|
2013-07-22 08:50:39 +02:00
|
|
|
ui->payAmount_s->setDisplayUnit(model->getOptionsModel()->getDisplayUnit());
|
2012-06-09 15:41:21 +02:00
|
|
|
}
|
|
|
|
}
|
2013-10-16 17:11:39 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|