Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GUI][Bug] Reset custom change address #1551

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 12 additions & 17 deletions src/qt/pivx/send.cpp
Expand Up @@ -582,29 +582,24 @@ void SendWidget::updateEntryLabels(QList<SendCoinsRecipient> recipients)
void SendWidget::onChangeAddressClicked()
{
showHideOp(true);
SendChangeAddressDialog* dialog = new SendChangeAddressDialog(window);
SendChangeAddressDialog* dialog = new SendChangeAddressDialog(window, walletModel);
if (!boost::get<CNoDestination>(&CoinControlDialog::coinControl->destChange)) {
dialog->setAddress(QString::fromStdString(CBitcoinAddress(CoinControlDialog::coinControl->destChange).ToString()));
}
if (openDialogWithOpaqueBackgroundY(dialog, window, 3, 5)) {
if (dialog->selected) {
QString ret;
if (dialog->getAddress(walletModel, &ret)) {
CBitcoinAddress address(ret.toStdString());

// Ask if it's what the user really wants
if (!walletModel->isMine(address) &&
!ask(tr("Warning!"), tr("The change address doesn't belong to this wallet.\n\nDo you want to continue?"))) {
return;
}
CoinControlDialog::coinControl->destChange = address.Get();
ui->btnChangeAddress->setActive(true);
} else {
inform(tr("Invalid change address"));
ui->btnChangeAddress->setActive(false);
}
CBitcoinAddress address(dialog->getAddress().toStdString());

// Ask if it's what the user really wants
if (!walletModel->isMine(address) &&
!ask(tr("Warning!"), tr("The change address doesn't belong to this wallet.\n\nDo you want to continue?"))) {
return;
}
CoinControlDialog::coinControl->destChange = address.Get();
ui->btnChangeAddress->setActive(true);
}
// check if changeAddress has been reset to NoDestination (or wasn't set at all)
if (boost::get<CNoDestination>(&CoinControlDialog::coinControl->destChange))
ui->btnChangeAddress->setActive(false);
dialog->deleteLater();
}

Expand Down
60 changes: 46 additions & 14 deletions src/qt/pivx/sendchangeaddressdialog.cpp
Expand Up @@ -4,13 +4,18 @@

#include "qt/pivx/sendchangeaddressdialog.h"
#include "qt/pivx/forms/ui_sendchangeaddressdialog.h"
#include "walletmodel.h"

#include "coincontrol.h"
#include "qt/pivx/qtutils.h"

SendChangeAddressDialog::SendChangeAddressDialog(QWidget *parent) :
SendChangeAddressDialog::SendChangeAddressDialog(QWidget* parent, WalletModel* model) :
QDialog(parent),
walletModel(model),
ui(new Ui::SendChangeAddressDialog)
{
if (!walletModel) {
throw std::runtime_error(strprintf("%s: No wallet model set", __func__));
}
ui->setupUi(this);
this->setStyleSheet(parent->styleSheet());

Expand All @@ -32,32 +37,59 @@ SendChangeAddressDialog::SendChangeAddressDialog(QWidget *parent) :
ui->btnEsc->setProperty("cssClass", "ic-close");

ui->btnCancel->setProperty("cssClass", "btn-dialog-cancel");
ui->btnSave->setText("SAVE");
ui->btnSave->setText(tr("SAVE"));
setCssBtnPrimary(ui->btnSave);

connect(ui->btnEsc, &QPushButton::clicked, this, &SendChangeAddressDialog::close);
connect(ui->btnCancel, &QPushButton::clicked, this, &SendChangeAddressDialog::close);
connect(ui->btnSave, &QPushButton::clicked, [this](){ selected = true; accept(); });
connect(ui->btnCancel, &QPushButton::clicked, this, &SendChangeAddressDialog::reset);
connect(ui->btnSave, &QPushButton::clicked, this, &SendChangeAddressDialog::save);
}

void SendChangeAddressDialog::setAddress(QString address){
void SendChangeAddressDialog::setAddress(QString address)
{
ui->lineEditAddress->setText(address);
ui->btnCancel->setText(tr("RESET"));
}

bool SendChangeAddressDialog::getAddress(WalletModel *model, QString *retAddress){
QString address = ui->lineEditAddress->text();
if(!address.isEmpty() && model->validateAddress(address)){
*retAddress = address;
return true;
}
return false;
QString SendChangeAddressDialog::getAddress() const
{
return ui->lineEditAddress->text();
}

void SendChangeAddressDialog::showEvent(QShowEvent *event)
{
if (ui->lineEditAddress) ui->lineEditAddress->setFocus();
}

SendChangeAddressDialog::~SendChangeAddressDialog(){
void SendChangeAddressDialog::reset()
{
if (!ui->lineEditAddress->text().isEmpty()) {
ui->lineEditAddress->clear();
ui->btnCancel->setText(tr("CANCEL"));
CoinControlDialog::coinControl->destChange = CNoDestination();
}
close();
}

void SendChangeAddressDialog::save()
{
// validate address
if (!walletModel->validateAddress(ui->lineEditAddress->text())) {
inform(tr("Invalid address"));
} else {
accept();
}
}

void SendChangeAddressDialog::inform(const QString& text)
{
if (!snackBar) snackBar = new SnackBar(nullptr, this);
snackBar->setText(text);
snackBar->resize(this->width(), snackBar->height());
openDialog(snackBar, this);
}

SendChangeAddressDialog::~SendChangeAddressDialog()
{
delete ui;
}
16 changes: 12 additions & 4 deletions src/qt/pivx/sendchangeaddressdialog.h
Expand Up @@ -6,6 +6,7 @@
#define SENDCHANGEADDRESSDIALOG_H

#include <QDialog>
#include "qt/pivx/snackbar.h"

class WalletModel;

Expand All @@ -18,16 +19,23 @@ class SendChangeAddressDialog : public QDialog
Q_OBJECT

public:
explicit SendChangeAddressDialog(QWidget *parent = nullptr);
explicit SendChangeAddressDialog(QWidget* parent, WalletModel* model);
~SendChangeAddressDialog();

void setAddress(QString address);
bool getAddress(WalletModel *model, QString *retAddress);
bool selected = false;
QString getAddress() const;

void showEvent(QShowEvent* event) override;

void showEvent(QShowEvent *event) override;
private:
WalletModel* walletModel;
Ui::SendChangeAddressDialog *ui;
SnackBar *snackBar = nullptr;
void inform(const QString& text);

private Q_SLOTS:
void reset();
void save();
};

#endif // SENDCHANGEADDRESSDIALOG_H