PIVX Core  5.6.99
P2P Digital Currency
sendchangeaddressdialog.cpp
Go to the documentation of this file.
1 // Copyright (c) 2019-2020 The PIVX Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
6 #include "ui_sendchangeaddressdialog.h"
7 
8 #include "qtutils.h"
9 
10 SendChangeAddressDialog::SendChangeAddressDialog(QWidget* parent, WalletModel* model, bool isTransparent) : FocusedDialog(parent),
11  walletModel(model),
13 {
14  // Change address
15  dest = CNoDestination();
16  this->isTransparent = isTransparent;
17  if (!walletModel) {
18  throw std::runtime_error(strprintf("%s: No wallet model set", __func__));
19  }
20  ui->setupUi(this);
21  this->setStyleSheet(parent->styleSheet());
22 
23  // Container
24  ui->frame->setProperty("cssClass", "container-dialog");
25 
26  // Text
27  ui->labelTitle->setProperty("cssClass", "text-title-dialog");
28  ui->labelMessage->setProperty("cssClass", "text-main-grey");
29 
30  initCssEditLine(ui->lineEditAddress, true);
31 
32  // Buttons
33  ui->btnEsc->setText("");
34  ui->btnEsc->setProperty("cssClass", "ic-close");
35 
36  ui->btnCancel->setProperty("cssClass", "btn-dialog-cancel");
37  setCssBtnPrimary(ui->btnSave);
38 
39  connect(ui->btnEsc, &QPushButton::clicked, this, &SendChangeAddressDialog::close);
40  connect(ui->btnCancel, &QPushButton::clicked, this, &SendChangeAddressDialog::reset);
41  connect(ui->btnSave, &QPushButton::clicked, this, &SendChangeAddressDialog::accept);
42 }
43 
45 {
46  ui->lineEditAddress->setText(address);
47  ui->btnCancel->setText(tr("RESET"));
48 }
49 
51 {
52  return dest;
53 }
54 
55 void SendChangeAddressDialog::showEvent(QShowEvent *event)
56 {
57  if (ui->lineEditAddress) ui->lineEditAddress->setFocus();
58 }
59 
61 {
62  if (!ui->lineEditAddress->text().isEmpty()) {
63  ui->lineEditAddress->clear();
64  ui->btnCancel->setText(tr("CANCEL"));
65  }
66  close();
67 }
68 
70 {
71  if (ui->lineEditAddress->text().isEmpty()) {
72  // no custom change address set
73  dest = CNoDestination();
74  QDialog::accept();
75  } else {
76  // validate address
77  bool isStaking = false, isExchange = false, isShielded = false;
78  dest = Standard::DecodeDestination(ui->lineEditAddress->text().toStdString(), isStaking, isExchange, isShielded);
79 
81  inform(tr("Invalid address"));
82  } else if (isStaking) {
83  inform(tr("Cannot use cold staking addresses for change"));
84  } else if (!isShielded && !isTransparent) {
85  inform(tr("Cannot use a transparent change for a shield transaction"));
86  } else {
87  QDialog::accept();
88  }
89  }
90 }
91 
92 void SendChangeAddressDialog::inform(const QString& text)
93 {
94  if (!snackBar) snackBar = new SnackBar(nullptr, this);
95  snackBar->setText(text);
96  snackBar->resize(this->width(), snackBar->height());
97  openDialog(snackBar, this);
98 }
99 
101 {
102  delete ui;
103 }
void inform(const QString &text)
CWDestination getDestination() const
Ui::SendChangeAddressDialog * ui
void showEvent(QShowEvent *event) override
void setAddress(QString address)
SendChangeAddressDialog(QWidget *parent, WalletModel *model, bool isTransparent)
void setText(const QString &text)
Definition: snackbar.cpp:51
Interface to PIVX wallet from Qt view code.
Definition: walletmodel.h:109
boost::variant< CTxDestination, libzcash::SaplingPaymentAddress > CWDestination
bool IsValidDestination(const CWDestination &address)
CWDestination DecodeDestination(const std::string &strAddress)
void initCssEditLine(QLineEdit *edit, bool isDialog)
Definition: qtutils.cpp:272
void setCssBtnPrimary(QPushButton *btn, bool forceUpdate)
Definition: qtutils.cpp:302
bool openDialog(QDialog *widget, QWidget *gui)
Definition: qtutils.cpp:23
#define strprintf
Definition: tinyformat.h:1056