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
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -923,6 +923,10 @@ if ENABLE_QT
include Makefile.qt.include
endif

if ENABLE_QT_TESTS
include Makefile.qttest.include
endif

if ENABLE_TESTS
include Makefile.test.include
else
Expand Down
2 changes: 1 addition & 1 deletion src/Makefile.qt.include
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,7 @@ endif
qt_firo_qt_LDADD += -ltor

qt_firo_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) $(LIBBITCOIN_UTIL) \
$(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBFIRO_SIGMA) $(LIBLELANTUS) $(LIBSPARK)\
$(LIBBITCOIN_CONSENSUS) $(LIBBITCOIN_CRYPTO) $(LIBFIRO_SIGMA) $(LIBLELANTUS) $(LIBSPARK) \
$(LIBUNIVALUE) $(LIBLEVELDB) $(LIBLEVELDB_SSE42) $(LIBMEMENV) $(BACKTRACE_LIB) $(BOOST_LIBS) $(QT_LIBS) \
$(QT_DBUS_LIBS) $(QR_LIBS) $(BDB_LIBS) $(SSL_LIBS) \
$(CRYPTO_LIBS) $(MINIUPNPC_LIBS) $(LIBSECP256K1) $(LIBBLSSIG_LIBS) $(LIBBLSSIG_DEPENDS) \
Expand Down
11 changes: 7 additions & 4 deletions src/Makefile.qttest.include
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ TESTS += qt/test/test_bitcoin-qt
TEST_QT_MOC_CPP = \
qt/test/moc_compattests.cpp \
qt/test/moc_rpcnestedtests.cpp \
qt/test/moc_uritests.cpp
qt/test/moc_uritests.cpp \
qt/test/moc_test_sendcoinsentry.cpp

if ENABLE_WALLET
TEST_QT_MOC_CPP +=
Expand All @@ -17,7 +18,8 @@ endif
TEST_QT_H = \
qt/test/compattests.h \
qt/test/rpcnestedtests.h \
qt/test/uritests.h
qt/test/uritests.h \
qt/test/test_sendcoinsentry.h

qt_test_test_bitcoin_qt_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(BITCOIN_QT_INCLUDES) \
$(QT_INCLUDES) $(QT_TEST_INCLUDES)
Expand All @@ -27,6 +29,7 @@ qt_test_test_bitcoin_qt_SOURCES = \
qt/test/rpcnestedtests.cpp \
qt/test/test_main.cpp \
qt/test/uritests.cpp \
qt/test/test_sendcoinsentry.cpp \
$(TEST_QT_H)
if ENABLE_WALLET
qt_test_test_bitcoin_qt_SOURCES +=
Expand All @@ -43,8 +46,8 @@ qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_ZMQ) $(ZMQ_LIBS)
endif

qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_CLI) $(LIBBITCOIN_COMMON) \
$(LIBBITCOIN_UTIL) $(LIBZEROCOIN) $(LIBBITCOIN_CONSENSUS) \
$(LIBBITCOIN_CRYPTO) $(LIBFIRO_SIGMA) $(LIBLELANTUS) $(LIBUNIVALUE) $(LIBLEVELDB) \
$(LIBBITCOIN_UTIL) $(LIBZEROCOIN) $(LIBBITCOIN_CONSENSUS) $(LIBBLSSIG_LIBS) $(LIBBLSSIG_DEPENDS) \
$(LIBBITCOIN_CRYPTO) $(LIBFIRO_SIGMA) $(LIBLELANTUS) $(LIBUNIVALUE) $(LIBSPARK) $(LIBLEVELDB) \
$(LIBLEVELDB_SSE42) $(LIBMEMENV) $(BOOST_LIBS) $(QT_DBUS_LIBS) $(QT_TEST_LIBS) $(QT_LIBS) \
$(QR_LIBS) $(BDB_LIBS) $(SSL_LIBS) $(CRYPTO_LIBS) \
$(MINIUPNPC_LIBS) $(LIBSECP256K1) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS)
Expand Down
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
93 changes: 15 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,15 @@ void SendCoinsDialog::on_sendButton_clicked()

// Format confirmation message
QStringList formatted;
QString warningMessage;

for(int i = 0; i < recipients.size(); ++i) {
warningMessage = entry->generateWarningText(recipients[i].address, fAnonymousMode);
if ((model->validateSparkAddress(recipients[i].address)) || (recipients[i].address.startsWith("EX"))) {
break;
}
}

if ((fAnonymousMode == false) && (recipients.size() == sparkAddressCount) && spark::IsSparkAllowed())
{
for(int i = 0; i < recipients.size(); i++) {
Expand Down Expand Up @@ -459,7 +459,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 +564,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 +595,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 +689,6 @@ void SendCoinsDialog::setAddress(const QString &address)
{
entry = addEntry();
}

entry->setAddress(address);
}

Expand Down Expand Up @@ -1212,69 +1215,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->validateSparkAddress(address)) {
warningText = tr(" You are sending Firo from a Spark address to another Spark address. This transaction is fully private.");
} 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.");
}
}
}
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,10 @@ 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);
QString generateWarningText(const QString& address, const bool fAnonymousMode);

public Q_SLOTS:
void clear();

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

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

Expand Down
13 changes: 7 additions & 6 deletions src/qt/test/test_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@
#include "util.h"
#include "uritests.h"
#include "compattests.h"

#include "test_sendcoinsentry.h"
#include <QCoreApplication>
#include <QObject>
#include <QTest>

#include <openssl/ssl.h>

#if defined(QT_STATICPLUGIN) && QT_VERSION < 0x050000
Expand All @@ -35,7 +33,7 @@ int main(int argc, char *argv[])
ECC_Start();
SetupEnvironment();
SetupNetworking();
SelectParams(CBaseChainParams::MAIN);
SelectParams(CBaseChainParams::REGTEST);
noui_connect();

bool fInvalid = false;
Expand All @@ -47,10 +45,13 @@ int main(int argc, char *argv[])

SSL_library_init();

URITests test1;
TestSendCoinsEntry test1;
if (QTest::qExec(&test1) != 0)
fInvalid = true;
}

URITests test2;
if (QTest::qExec(&test2) != 0)
fInvalid = true;
RPCNestedTests test3;
if (QTest::qExec(&test3) != 0)
fInvalid = true;
Expand Down
11 changes: 11 additions & 0 deletions src/qt/test/test_sendcoinsentry.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "test_sendcoinsentry.h"

void TestSendCoinsEntry::testGenerateWarningText()
{
SendCoinsEntry* entry;
QCOMPARE(entry->generateWarningText("EXRSxX8yJHudk4QswGf3N5aPVTUi5Q1ZdX56", false), QObject::tr(" You are sending Firo to an Exchange Address. Exchange Addresses can only receive funds from a transparent address."));
QCOMPARE(entry->generateWarningText("TLyNUvysvUyt2u6vL74NEkB6ed8LTQd3mz", false), QObject::tr(" You are sending Firo from a transparent address to another transparent address. To protect your privacy, we recommend using Spark addresses instead."));
QCOMPARE(entry->generateWarningText("sr1ek2uspg2v4qu0lmccrnj90tfkdpp5zmpykr4ffdprqlf0s4devl8n0674s4d4cthxsa5w9p66s5x0zgw982t80xx9uzmxysxuawmupgfa0xecj9shm6pj7l3rshqxqtg94k88fg5u856r", false), QObject::tr(" You are sending Firo from a transparent address to a Spark address."));
QCOMPARE(entry->generateWarningText("sr1ek2uspg2v4qu0lmccrnj90tfkdpp5zmpykr4ffdprqlf0s4devl8n0674s4d4cthxsa5w9p66s5x0zgw982t80xx9uzmxysxuawmupgfa0xecj9shm6pj7l3rshqxqtg94k88fg5u856r", true), QObject::tr(" You are sending Firo from a Spark address to another Spark address. This transaction is fully private."));
QCOMPARE(entry->generateWarningText("TLyNUvysvUyt2u6vL74NEkB6ed8LTQd3mz", true), QObject::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."));
}
levonpetrosyan93 marked this conversation as resolved.
Show resolved Hide resolved
16 changes: 16 additions & 0 deletions src/qt/test/test_sendcoinsentry.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef BITCOIN_QT_TEST_SENDCOINSENTRY_H
#define BITCOIN_QT_TEST_SENDCOINSENTRY_H

#include <QObject>
#include <QTest>
#include "sendcoinsentry.h"

class TestSendCoinsEntry : public QObject
{
Q_OBJECT

private Q_SLOTS:
void testGenerateWarningText();
};

#endif // BITCOIN_QT_TEST_SENDCOINSENTRY_H
Loading