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 all 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 @@ -517,7 +517,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
17 changes: 10 additions & 7 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,14 +29,15 @@ 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 +=
endif

nodist_qt_test_test_bitcoin_qt_SOURCES = $(TEST_QT_MOC_CPP)

qt_test_test_bitcoin_qt_LDADD = $(LIBBITCOINQT) $(LIBBITCOIN_SERVER)
qt_test_test_bitcoin_qt_LDADD = $(LIBBITCOINQT) $(LIBBITCOIN_SERVER) $(TOR_LIBS)
if ENABLE_WALLET
qt_test_test_bitcoin_qt_LDADD += $(LIBBITCOIN_WALLET)
endif
Expand All @@ -43,13 +46,13 @@ 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)
$(MINIUPNPC_LIBS) $(LIBSECP256K1) $(EVENT_PTHREADS_LIBS) $(EVENT_LIBS) $(BACKTRACE_LIB)

qt_test_test_bitcoin_qt_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS)
qt_test_test_bitcoin_qt_LDFLAGS = $(RELDFLAGS) $(AM_LDFLAGS) $(QT_LDFLAGS) $(LIBTOOL_APP_LDFLAGS) $(LDFLAGS_WRAP_EXCEPTIONS)
qt_test_test_bitcoin_qt_CXXFLAGS = $(AM_CXXFLAGS) $(QT_PIE_FLAGS)

CLEAN_BITCOIN_QT_TEST = $(TEST_QT_MOC_CPP) qt/test/*.gcda qt/test/*.gcno
Expand Down
2 changes: 1 addition & 1 deletion src/libspark/spend_transaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ bool SpendTransaction::verify(
if (tx.S1.size() != w ||
tx.C1.size() != w ||
tx.T.size() != w ||
tx.grootle_proofs.size() != w,
tx.grootle_proofs.size() != w ||
levonpetrosyan93 marked this conversation as resolved.
Show resolved Hide resolved
tx.cover_set_sizes.size() != tx.cover_set_representations.size()) {
throw std::invalid_argument("Bad spend transaction semantics");
}
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
91 changes: 14 additions & 77 deletions src/qt/sendcoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -394,15 +394,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 @@ -428,6 +419,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 @@ -530,6 +530,7 @@ void SendCoinsDialog::on_sendButton_clicked()
}

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 @@ -688,9 +689,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 @@ -719,7 +720,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 @@ -811,7 +814,6 @@ void SendCoinsDialog::setAddress(const QString &address)
{
entry = addEntry();
}

entry->setAddress(address);
}

Expand Down Expand Up @@ -1339,71 +1341,6 @@ void SendConfirmationDialog::updateYesButton()
}
}

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;
}
void SendCoinsDialog::resizeEvent(QResizeEvent* event) {
QWidget::resizeEvent(event);

Expand Down
14 changes: 0 additions & 14 deletions src/qt/sendcoinsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,4 @@ private Q_SLOTS:

};

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 @@ -11,6 +11,7 @@
#include "optionsmodel.h"
#include "platformstyle.h"
#include "walletmodel.h"
#include "../wallet/wallet.h"
levonpetrosyan93 marked this conversation as resolved.
Show resolved Hide resolved

#include <QApplication>
#include <QClipboard>
Expand Down Expand Up @@ -83,6 +84,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 @@ -123,15 +125,37 @@ 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 (pwalletMain->validateAddress(address.toStdString())) {
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 (pwalletMain->validateSparkAddress(address.toStdString())) {
warningText = tr(" You are sending Firo from a transparent address to a Spark address.");
}
} else {
if (pwalletMain->validateSparkAddress(address.toStdString())) {
warningText = tr(" You are sending Firo from a Spark address to another Spark address. This transaction is fully private.");
} else if (pwalletMain->validateAddress(address.toStdString())) {
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;
}

bool SendCoinsEntry::validate()
Expand Down Expand Up @@ -231,6 +255,11 @@ bool SendCoinsEntry::isPayToPcode() const
return isPcodeEntry;
}

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

void SendCoinsEntry::setFocus()
{
ui->payTo->setFocus();
Expand Down
6 changes: 4 additions & 2 deletions src/qt/sendcoinsentry.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ class SendCoinsEntry : public QStackedWidget

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

void setfAnonymousMode(bool fAnonymousMode);
static 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 = false;
bool updateLabel(const QString &address);
void resizeEvent(QResizeEvent* event) override;
void adjustTextSize(int width, int height);
Expand Down
17 changes: 10 additions & 7 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 @@ -50,10 +48,15 @@ int main(int argc, char *argv[])
URITests test1;
if (QTest::qExec(&test1) != 0)
fInvalid = true;
}
RPCNestedTests test3;
if (QTest::qExec(&test3) != 0)

TestSendCoinsEntry test2;
if (QTest::qExec(&test2) != 0)
fInvalid = true;

// RPCNestedTests test3;
// if (QTest::qExec(&test3) != 0)
// fInvalid = true;

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

void TestSendCoinsEntry::testGenerateWarningText()
{
QCOMPARE(SendCoinsEntry::generateWarningText("EXRSxX8yJHudk4QswGf3N5aPVTUi5Q1ZdX56", false), QObject::tr(" You are sending Firo to an Exchange Address. Exchange Addresses can only receive funds from a transparent address."));
QCOMPARE(SendCoinsEntry::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(SendCoinsEntry::generateWarningText("sr1ek2uspg2v4qu0lmccrnj90tfkdpp5zmpykr4ffdprqlf0s4devl8n0674s4d4cthxsa5w9p66s5x0zgw982t80xx9uzmxysxuawmupgfa0xecj9shm6pj7l3rshqxqtg94k88fg5u856r", false), QObject::tr(" You are sending Firo from a transparent address to a Spark address."));
QCOMPARE(SendCoinsEntry::generateWarningText("sr1ek2uspg2v4qu0lmccrnj90tfkdpp5zmpykr4ffdprqlf0s4devl8n0674s4d4cthxsa5w9p66s5x0zgw982t80xx9uzmxysxuawmupgfa0xecj9shm6pj7l3rshqxqtg94k88fg5u856r", true), QObject::tr(" You are sending Firo from a Spark address to another Spark address. This transaction is fully private."));
QCOMPARE(SendCoinsEntry::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."));
}
Loading
Loading