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

Add warning messages with sending #1434

Merged
merged 9 commits into from
Jun 18, 2024
Merged
2 changes: 1 addition & 1 deletion src/qt/forms/sendcoinsentry.ui
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
<item>
<widget class="QLabel" name="textWarning">
<property name="text">
<string> You are using a transparent transaction, please go private. If this is a masternode transaction, you do not have to go private</string>
<string></string>
</property>
<property name="styleSheet">
<string>color: #FFA800; margin-left:-10px;</string>
Expand Down
115 changes: 37 additions & 78 deletions src/qt/sendcoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,15 +340,6 @@ void SendCoinsDialog::on_sendButton_clicked()
return;
}
} else if ((fAnonymousMode == false) && (sparkAddressCount == 0)) {
if (spark::IsSparkAllowed()) {
SendGoPrivateDialog goPrivateDialog;
bool clickedButton = goPrivateDialog.getClickedButton();
if (!clickedButton) {
setAnonymizeMode(true);
fNewRecipientAllowed = true;
return;
}
}
prepareStatus = model->prepareTransaction(currentTransaction, &ctrl);
} else {
fNewRecipientAllowed = true;
Expand All @@ -366,6 +357,37 @@ void SendCoinsDialog::on_sendButton_clicked()

// Format confirmation message
QStringList formatted;
QString warningMessage;

bool IsExchange = false;
for(int i = 0; i < recipients.size(); ++i){
std::string address = recipients[i].address.toStdString();
CBitcoinAddress add(address);
CTxDestination dest = add.Get();
if (boost::get<CExchangeKeyID>(&dest)) {
IsExchange = true;
break;
}
}

if (!fAnonymousMode) {
if (model->validateSparkAddress(recipients[0].address)) {
warningMessage = tr(" You are sending Firo from a transparent address to a Spark address.");
} else if (IsExchange) {
warningMessage = tr(" You are sending Firo into an Exchange Address. Exchange Addresses can only receive funds from a transparent address.");
} else {
warningMessage = tr(" You are sending Firo from a transparent address to another transparent address. To protect your privacy, we recommend using Spark addresses instead.");
}
} else {
for (auto i = 0; i < recipients.size(); ++i) {
if (model->validateSparkAddress(recipients[i].address)) {
warningMessage = tr(" You are sending Firo from a Spark address to another Spark address. This transaction is fully private.");
break;
}
warningMessage = tr(" You are sending Firo from a private Spark pool to a transparent address. Please note that some exchanges do not accept direct Spark deposits.");
}
}

if ((fAnonymousMode == false) && (recipients.size() == sparkAddressCount) && spark::IsSparkAllowed())
{
for(int i = 0; i < recipients.size(); i++) {
Expand Down Expand Up @@ -459,7 +481,9 @@ void SendCoinsDialog::on_sendButton_clicked()
formatted.append(recipientElement);
}
}

QString questionString = tr("Are you sure you want to send?");
questionString.append(warningMessage);
questionString.append("<br /><br />%1");
double txSize;
if ((fAnonymousMode == false) && (recipients.size() == sparkAddressCount) && spark::IsSparkAllowed())
Expand Down Expand Up @@ -562,9 +586,9 @@ void SendCoinsDialog::on_sendButton_clicked()
void SendCoinsDialog::on_switchFundButton_clicked()
{
setAnonymizeMode(!fAnonymousMode);
coinControlUpdateLabels();

entry->setfAnonymousMode(fAnonymousMode);
entry->setWarning(fAnonymousMode);
coinControlUpdateLabels();
levoncrypto marked this conversation as resolved.
Show resolved Hide resolved
}

void SendCoinsDialog::clear()
Expand Down Expand Up @@ -593,7 +617,9 @@ SendCoinsEntry *SendCoinsDialog::addEntry()
{
entry = new SendCoinsEntry(platformStyle, this);
entry->setModel(model);
entry->setfAnonymousMode(fAnonymousMode);
entry->setWarning(fAnonymousMode);

ui->entries->addWidget(entry);
connect(entry, &SendCoinsEntry::removeEntry, this, &SendCoinsDialog::removeEntry);
connect(entry, &SendCoinsEntry::payAmountChanged, this, &SendCoinsDialog::coinControlUpdateLabels);
Expand Down Expand Up @@ -685,7 +711,6 @@ void SendCoinsDialog::setAddress(const QString &address)
{
entry = addEntry();
}

entry->setAddress(address);
}

Expand Down Expand Up @@ -1212,69 +1237,3 @@ void SendConfirmationDialog::updateYesButton()
yesButton->setText(tr("Yes"));
}
}

SendGoPrivateDialog::SendGoPrivateDialog():QMessageBox()
{
QDialog::setWindowTitle("Make this a private transaction");
QDialog::setWindowFlags(Qt::Dialog | Qt::CustomizeWindowHint | Qt::WindowTitleHint);

QLabel *ic = new QLabel();
QIcon icon_;
icon_.addFile(QString::fromUtf8(":/icons/ic_info"), QSize(), QIcon::Normal, QIcon::On);
ic->setPixmap(icon_.pixmap(18, 18));
ic->setFixedWidth(50);
ic->setAlignment(Qt::AlignRight);
ic->setStyleSheet("color:#92400E");
QLabel *text = new QLabel();
text->setText(tr("You are using a transparent transaction, please go private. If this is a masternode transaction, you do not have to go private"));
text->setAlignment(Qt::AlignLeft);
text->setWordWrap(true);
text->setStyleSheet("color:#92400E;");

QPushButton *ignore = new QPushButton(this);
ignore->setText("Ignore");
ignore->setStyleSheet("color:#9b1c2e;background-color:none;margin-top:30px;margin-bottom:60px;margin-left:50px;margin-right:20px;border:1px solid #9b1c2e;");
QPushButton *goPrivate = new QPushButton(this);
goPrivate->setText("Go Private");
goPrivate->setStyleSheet("margin-top:30px;margin-bottom:60px;margin-left:20px;margin-right:50px;");
QHBoxLayout *groupButton = new QHBoxLayout(this);
groupButton->addWidget(ignore);
groupButton->addWidget(goPrivate);

QHBoxLayout *hlayout = new QHBoxLayout(this);
hlayout->addWidget(ic);
hlayout->addWidget(text);

QWidget *layout_ = new QWidget();
layout_->setLayout(hlayout);
layout_->setStyleSheet("background-color:#FEF3C7;");

QVBoxLayout *vlayout = new QVBoxLayout(this);
vlayout->addWidget(layout_);
vlayout->addLayout(groupButton);
vlayout->setContentsMargins(0,0,0,0);
QWidget *wbody = new QWidget();
wbody->setLayout(vlayout);
layout()->addWidget(wbody);
setContentsMargins(0, 0, 0, 0);
setStyleSheet("margin-right:-30px;");
setStandardButtons(0);
connect(ignore, &QPushButton::clicked, this, &SendGoPrivateDialog::onIgnoreClicked);
connect(goPrivate, &QPushButton::clicked, this, &SendGoPrivateDialog::onGoPrivateClicked);
exec();
}
void SendGoPrivateDialog::onIgnoreClicked()
{
setVisible(false);
clickedButton = true;
}
void SendGoPrivateDialog::onGoPrivateClicked()
{
setVisible(false);
clickedButton = false;
}

bool SendGoPrivateDialog::getClickedButton()
{
return clickedButton;
}
14 changes: 0 additions & 14 deletions src/qt/sendcoinsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,4 @@ private Q_SLOTS:
int secDelay;
};

class SendGoPrivateDialog : public QMessageBox
{
Q_OBJECT
private:
bool clickedButton;
public:
SendGoPrivateDialog();
bool getClickedButton();

private Q_SLOTS:
void onIgnoreClicked();
void onGoPrivateClicked();
};

#endif // BITCOIN_QT_SENDCOINSDIALOG_H
41 changes: 35 additions & 6 deletions src/qt/sendcoinsentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ void SendCoinsEntry::on_addressBookButton_clicked()
void SendCoinsEntry::on_payTo_textChanged(const QString &address)
{
updateLabel(address);
setWarning(fAnonymousMode);
}

void SendCoinsEntry::setModel(WalletModel *_model)
Expand Down Expand Up @@ -122,17 +123,40 @@ void SendCoinsEntry::deleteClicked()
Q_EMIT removeEntry(this);
}

void SendCoinsEntry::setWarning(bool fAnonymousMode)
void SendCoinsEntry::setWarning(bool fAnonymousMode) {
const QString address = ui->payTo->text();
const QString warningText = generateWarningText(address, fAnonymousMode);
const bool hasValidAddress = model->validateAddress(address) || model->validateSparkAddress(address);
ui->textWarning->setText(warningText);
ui->textWarning->setVisible(!warningText.isEmpty() && hasValidAddress);
ui->iconWarning->setVisible(!warningText.isEmpty() && hasValidAddress);
}
levoncrypto marked this conversation as resolved.
Show resolved Hide resolved

QString SendCoinsEntry::generateWarningText(const QString& address, const bool fAnonymousMode)
{
if(fAnonymousMode) {
ui->textWarning->hide();
ui->iconWarning->hide();
QString warningText;

if (address.startsWith("EX")) {
warningText = tr("You are sending Firo to an Exchange Address. Exchange Addresses can only receive funds from a transparent address.");
} else {
ui->textWarning->show();
ui->iconWarning->show();
if (!fAnonymousMode) {
if (model->validateAddress(address)) {
warningText = tr("You are sending Firo from a transparent address to another transparent address. To protect your privacy, we recommend using Spark addresses instead.");
} else if (model->validateSparkAddress(address)) {
warningText = tr("You are sending Firo from a transparent address to a Spark address.");
}
} else {
if (model->validateAddress(address)) {
warningText = tr("You are sending Firo from a private Spark pool to a transparent address. Please note that some exchanges do not accept direct Spark deposits.");
} else if (model->validateSparkAddress(address)) {
warningText = tr("You are sending Firo from a Spark address to another Spark address. This transaction is fully private.");
}
}
}
return warningText;
levonpetrosyan93 marked this conversation as resolved.
Show resolved Hide resolved
}


bool SendCoinsEntry::validate()
{
if (!model)
Expand Down Expand Up @@ -230,6 +254,11 @@ bool SendCoinsEntry::isPayToPcode() const
return isPcodeEntry;
}

void SendCoinsEntry::setfAnonymousMode(bool fAnonymousMode)
{
this->fAnonymousMode = fAnonymousMode;
}

void SendCoinsEntry::setFocus()
{
ui->payTo->setFocus();
Expand Down
8 changes: 5 additions & 3 deletions src/qt/sendcoinsentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ class SendCoinsEntry : public QStackedWidget
QWidget *setupTabChain(QWidget *prev);

void setFocus();
void setWarning(bool fAnonymousMode);

void setWarning(const bool fAnonymousMode);
levoncrypto marked this conversation as resolved.
Show resolved Hide resolved
void setfAnonymousMode(bool fAnonymousMode);

public Q_SLOTS:
void clear();

Expand All @@ -71,7 +72,8 @@ private Q_SLOTS:
WalletModel *model;
const PlatformStyle *platformStyle;
bool isPcodeEntry;

bool fAnonymousMode;
levonpetrosyan93 marked this conversation as resolved.
Show resolved Hide resolved
QString generateWarningText(const QString& address, const bool fAnonymousMode);
bool updateLabel(const QString &address);
};

Expand Down
Loading