From 448b2ceca8345d29ccc39cbcab3af799f73e8d15 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Tue, 13 Nov 2018 21:58:50 -0800 Subject: [PATCH] Custom fees --- src/mainwindow.ui | 16 +++++++++++----- src/rpc.cpp | 2 ++ src/sendtab.cpp | 32 ++++++++++++++++++-------------- src/settings.cpp | 12 ++++++++---- src/settings.h | 1 + 5 files changed, 40 insertions(+), 23 deletions(-) diff --git a/src/mainwindow.ui b/src/mainwindow.ui index f61dc23..dd2a0c4 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -503,23 +503,29 @@ - + - Miner Fee: + Miner Fee - + + + + 0 + 0 + + - TextLabel + 0 - TextLabel + diff --git a/src/rpc.cpp b/src/rpc.cpp index 7ff0ba6..0cef631 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -326,6 +326,8 @@ 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()); } diff --git a/src/sendtab.cpp b/src/sendtab.cpp index fde3309..12b6970 100644 --- a/src/sendtab.cpp +++ b/src/sendtab.cpp @@ -56,29 +56,30 @@ void MainWindow::setupSendTab() { AddressBook::open(this, ui->Address1); }); - // The first Amount button QObject::connect(ui->Amount1, &QLineEdit::textChanged, [=] (auto text) { this->amountChanged(1, text); }); - // Font for the first Memo label - QFont f = ui->Address1->font(); - f.setPointSize(f.pointSize() - 1); - ui->MemoTxt1->setFont(f); + // Fee amount changed + QObject::connect(ui->minerFeeAmt, &QLineEdit::textChanged, [=](auto txt) { + ui->lblMinerFeeUSD->setText(Settings::getUSDFormat(txt.toDouble())); + }); + ui->minerFeeAmt->setText(Settings::getDecimalString(Settings::getMinerFee())); - // Set up focus enter to set fees + // Set up focus enter to set fees QObject::connect(ui->tabWidget, &QTabWidget::currentChanged, [=] (int pos) { if (pos == 1) { - // Set the fees - ui->lblMinerFee->setText(QString::number(Settings::getMinerFee(), 'g', 8) % - " " % Settings::getTokenName()); - ui->lblMinerFeeUSD->setText(Settings::getUSDFormat(Settings::getMinerFee())); - - // Set focus to the first address box - ui->Address1->setFocus(); + QString txt = ui->minerFeeAmt->text(); + ui->lblMinerFeeUSD->setText(Settings::getUSDFormat(txt.toDouble())); } }); + + // Font for the first Memo label + QFont f = ui->Address1->font(); + f.setPointSize(f.pointSize() - 1); + ui->MemoTxt1->setFont(f); + } void MainWindow::updateLabelsAutoComplete() { @@ -318,6 +319,9 @@ void MainWindow::removeExtraAddresses() { // Disable first memo btn setMemoEnabled(1, false); + // Reset the fee + ui->minerFeeAmt->setText(Settings::getDecimalString(Settings::getMinerFee())); + // Start the deletion after the first item, since we want to keep 1 send field there all there for (int i=1; i < totalItems; i++) { auto addressGroupBox = ui->sendToWidgets->findChild(QString("AddressGroupBox") % QString::number(i+1)); @@ -374,7 +378,7 @@ Tx MainWindow::createTxFromSendPage() { tx.toAddrs.push_back( ToFields{addr, amt, memo, memo.toUtf8().toHex()} ); } - tx.fee = Settings::getMinerFee(); + tx.fee = ui->minerFeeAmt->text().toDouble(); return tx; } diff --git a/src/settings.cpp b/src/settings.cpp index 73aa97d..806639a 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -109,14 +109,18 @@ QString Settings::getUSDFormat(double bal) { return QString(); } -QString Settings::getZECDisplayFormat(double bal) { - // This is idiotic. Why doesn't QString have a way to do this? - QString f = QString::number(bal, 'f', 8); +QString Settings::getDecimalString(double amt) { + QString f = QString::number(amt, 'f', 8); while (f.contains(".") && (f.right(1) == "0" || f.right(1) == ".")) { f = f.left(f.length() - 1); } - return f % " " % Settings::getTokenName(); + return f; +} + +QString Settings::getZECDisplayFormat(double bal) { + // This is idiotic. Why doesn't QString have a way to do this? + return getDecimalString(bal) % " " % Settings::getTokenName(); } QString Settings::getZECUSDDisplayFormat(double bal) { diff --git a/src/settings.h b/src/settings.h index 5bcf0c1..6a450ad 100644 --- a/src/settings.h +++ b/src/settings.h @@ -57,6 +57,7 @@ public: // Static stuff static const QString txidStatusMessage; + static QString getDecimalString(double amt); static QString getUSDFormat(double bal); static QString getZECDisplayFormat(double bal); static QString getZECUSDDisplayFormat(double bal);