From 4f99b1f752485bf7f21cdec74a95d7fe68f0c101 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Thu, 15 Nov 2018 17:05:10 -0800 Subject: [PATCH] Double opt in for custom fees --- src/mainwindow.cpp | 10 +++++++++ src/rpc.cpp | 8 +++++-- src/sendtab.cpp | 15 +++++++++---- src/settings.cpp | 52 +++++++++++++++++++++++++++------------------- src/settings.h | 7 +++++-- src/settings.ui | 25 ++++++++++++++++++---- 6 files changed, 84 insertions(+), 33 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9828407..52c49c1 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -375,6 +375,9 @@ void MainWindow::setupSettingsModal() { // Save sent transactions settings.chkSaveTxs->setChecked(Settings::getInstance()->getSaveZtxs()); + // Custom fees + settings.chkCustomFees->setChecked(Settings::getInstance()->getAllowCustomFees()); + // Connection Settings QIntValidator validator(0, 65535); settings.port->setValidator(&validator); @@ -407,6 +410,13 @@ void MainWindow::setupSettingsModal() { settings.tabWidget->setCurrentIndex(0); if (settingsDialog.exec() == QDialog::Accepted) { + // Custom fees + bool customFees = settings.chkCustomFees->isChecked(); + Settings::getInstance()->setAllowCustomFees(customFees); + ui->minerFeeAmt->setReadOnly(!customFees); + if (!customFees) + ui->minerFeeAmt->setText(Settings::getDecimalString(Settings::getMinerFee())); + if (zcashConfLocation.isEmpty()) { // Save settings Settings::getInstance()->saveSettings( diff --git a/src/rpc.cpp b/src/rpc.cpp index 881fc5d..bcdfe59 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -327,8 +327,12 @@ void RPC::fillTxJsonParams(json& params, Tx tx) { // Add sender params.push_back(tx.fromAddr.toStdString()); params.push_back(allRecepients); - params.push_back(1); // minconf - params.push_back(QString::number(tx.fee, 'f', 8).toDouble()); + + // Add fees if custom fees are allowed. + if (Settings::getInstance()->getAllowCustomFees()) { + params.push_back(1); // minconf + params.push_back(QString::number(tx.fee, 'f', 8).toDouble()); + } } diff --git a/src/sendtab.cpp b/src/sendtab.cpp index 0743e68..b4eeef2 100644 --- a/src/sendtab.cpp +++ b/src/sendtab.cpp @@ -62,6 +62,8 @@ void MainWindow::setupSendTab() { }); // Fee amount changed + // Disable custom fees if settings say no + ui->minerFeeAmt->setReadOnly(!Settings::getInstance()->getAllowCustomFees()); QObject::connect(ui->minerFeeAmt, &QLineEdit::textChanged, [=](auto txt) { ui->lblMinerFeeUSD->setText(Settings::getUSDFormat(txt.toDouble())); }); @@ -381,7 +383,12 @@ Tx MainWindow::createTxFromSendPage() { tx.toAddrs.push_back( ToFields{addr, amt, memo, memo.toUtf8().toHex()} ); } - tx.fee = ui->minerFeeAmt->text().toDouble(); + if (Settings::getInstance()->getAllowCustomFees()) { + tx.fee = ui->minerFeeAmt->text().toDouble(); + } else { + tx.fee = Settings::getMinerFee(); + } + return tx; } @@ -490,11 +497,11 @@ bool MainWindow::confirmTx(Tx tx) { confirm.gridLayout->addWidget(minerFeeUSD, i, 2, 1, 1); minerFeeUSD->setText(Settings::getUSDFormat(tx.fee)); - if (tx.fee == Settings::getMinerFee()) { + if (Settings::getInstance()->getAllowCustomFees() && tx.fee != Settings::getMinerFee()) { + confirm.warningLabel->setVisible(true); + } else { // Default fee confirm.warningLabel->setVisible(false); - } else { - confirm.warningLabel->setVisible(true); } } diff --git a/src/settings.cpp b/src/settings.cpp index 806639a..fea8c14 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -5,15 +5,6 @@ Settings* Settings::instance = nullptr; -bool Settings::getSaveZtxs() { - // Load from the QT Settings. - return QSettings().value("options/savesenttx", true).toBool(); -} - -void Settings::setSaveZtxs(bool save) { - QSettings().setValue("options/savesenttx", save); -} - Settings* Settings::init() { if (instance == nullptr) instance = new Settings(); @@ -102,6 +93,37 @@ double Settings::getZECPrice() { return zecPrice; } + +bool Settings::getAllowCustomFees() { + // Load from the QT Settings. + return QSettings().value("options/customfees", false).toBool(); +} + +void Settings::setAllowCustomFees(bool allow) { + QSettings().setValue("options/customfees", allow); +} + +bool Settings::getSaveZtxs() { + // Load from the QT Settings. + return QSettings().value("options/savesenttx", true).toBool(); +} + +void Settings::setSaveZtxs(bool save) { + QSettings().setValue("options/savesenttx", save); +} + + +//================================= +// Static Stuff +//================================= +void Settings::saveRestore(QDialog* d) { + d->restoreGeometry(QSettings().value(d->objectName() % "geometry").toByteArray()); + + QObject::connect(d, &QDialog::finished, [=](auto) { + QSettings().setValue(d->objectName() % "geometry", d->saveGeometry()); + }); +} + QString Settings::getUSDFormat(double bal) { if (!Settings::getInstance()->isTestnet() && Settings::getInstance()->getZECPrice() > 0) return "$" + QLocale(QLocale::English).toString(bal * Settings::getInstance()->getZECPrice(), 'f', 2); @@ -131,18 +153,6 @@ QString Settings::getZECUSDDisplayFormat(double bal) { return getZECDisplayFormat(bal); } -void Settings::saveRestore(QDialog* d) { - d->restoreGeometry(QSettings().value(d->objectName() % "geometry").toByteArray()); - - QObject::connect(d, &QDialog::finished, [=](auto) { - QSettings().setValue(d->objectName() % "geometry", d->saveGeometry()); - }); -} - -//================================= -// Static Stuff -//================================= - const QString Settings::txidStatusMessage = QString("Tx submitted (right click to copy) txid:"); const QString Settings::getTokenName() { diff --git a/src/settings.h b/src/settings.h index 6a450ad..f75e34f 100644 --- a/src/settings.h +++ b/src/settings.h @@ -19,8 +19,6 @@ public: static Settings* init(); static Settings* getInstance(); - static void saveRestore(QDialog* d); - Config getSettings(); void saveSettings(const QString& host, const QString& port, const QString& username, const QString& password); @@ -46,6 +44,9 @@ public: bool getSaveZtxs(); void setSaveZtxs(bool save); + bool getAllowCustomFees(); + void setAllowCustomFees(bool allow); + bool isSaplingActive(); void setUsingZcashConf(QString confLocation); @@ -56,6 +57,8 @@ public: // Static stuff static const QString txidStatusMessage; + + static void saveRestore(QDialog* d); static QString getDecimalString(double amt); static QString getUSDFormat(double bal); diff --git a/src/settings.ui b/src/settings.ui index 19a5050..027369a 100644 --- a/src/settings.ui +++ b/src/settings.ui @@ -20,7 +20,7 @@ - 0 + 1 @@ -172,11 +172,11 @@ - Remember Shielded Transactions + Remember shielded transactions - + Qt::Vertical @@ -189,13 +189,30 @@ - + Qt::Horizontal + + + + Allow custom fees + + + + + + + Allow overriding the default fees when sending transactions. Enabling this option may comprimise your privacy since fees are transparent. + + + true + + +