From fd9d668a4428d2bc71a2db79de9ee43273e0d1b7 Mon Sep 17 00:00:00 2001 From: Aditya Kulkarni Date: Sun, 27 Oct 2019 10:32:58 -0700 Subject: [PATCH] Remove "from" fields --- src/camount.h | 4 ++ src/controller.cpp | 34 ++++++----- src/datamodel.h | 6 +- src/mainwindow.cpp | 51 ---------------- src/mainwindow.h | 3 - src/mainwindow.ui | 142 +++++++++++++++++++++++++++------------------ src/sendtab.cpp | 34 ++--------- 7 files changed, 120 insertions(+), 154 deletions(-) diff --git a/src/camount.h b/src/camount.h index 6487720..7831e7b 100644 --- a/src/camount.h +++ b/src/camount.h @@ -43,6 +43,10 @@ public: return this->amount < other.amount; } + bool operator< (const qint64& other) const { + return this->amount < other; + } + bool operator> (const CAmount& other) const { return this->amount > other.amount; } diff --git a/src/controller.cpp b/src/controller.cpp index a09919f..bc820a1 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -127,9 +127,6 @@ void Controller::noConnection() { ui->balSheilded->setToolTip(""); ui->balTransparent->setToolTip(""); ui->balTotal->setToolTip(""); - - // Clear send tab from address - ui->inputsCombo->clear(); } /// This will refresh all the balance data from zcashd @@ -243,9 +240,6 @@ void Controller::updateUI(bool anyUnconfirmed) { // Update balances model data, which will update the table too balancesTableModel->setNewData(model->getAllZAddresses(), model->getAllTAddresses(), model->getAllBalances(), model->getUTXOs()); - - // Update from address - main->updateFromCombo(); }; // Function to process reply of the listunspent and z_listunspent API calls, used below. @@ -280,19 +274,33 @@ void Controller::refreshBalances() { // 1. Get the Balances zrpc->fetchBalance([=] (json reply) { - CAmount balT = CAmount::fromqint64(reply["tbalance"].get()); - CAmount balZ = CAmount::fromqint64(reply["zbalance"].get()); - CAmount balTotal = balT + balZ; - + CAmount balT = CAmount::fromqint64(reply["tbalance"].get()); + CAmount balZ = CAmount::fromqint64(reply["zbalance"].get()); + CAmount balVerified = CAmount::fromqint64(reply["verified_zbalance"].get()); + + CAmount balTotal = balT + balZ; + CAmount balAvailable = balT + balVerified; + + // This is for the websockets AppDataModel::getInstance()->setBalances(balT, balZ); + + // This is for the datamodel + model->setAvailableBalance(balAvailable); + // Balances table ui->balSheilded ->setText(balZ.toDecimalZECString()); + ui->balVerified ->setText(balVerified.toDecimalZECString()); ui->balTransparent->setText(balT.toDecimalZECString()); ui->balTotal ->setText(balTotal.toDecimalZECString()); - ui->balSheilded ->setToolTip(balZ.toDecimalZECUSDString()); - ui->balTransparent->setToolTip(balT.toDecimalZECUSDString()); - ui->balTotal ->setToolTip(balTotal.toDecimalZECUSDString()); + ui->balSheilded ->setToolTip(balZ.toDecimalUSDString()); + ui->balVerified ->setToolTip(balVerified.toDecimalUSDString()); + ui->balTransparent->setToolTip(balT.toDecimalUSDString()); + ui->balTotal ->setToolTip(balTotal.toDecimalUSDString()); + + // Send tab + ui->txtAvailableZEC->setText(balAvailable.toDecimalZECString()); + ui->txtAvailableUSD->setText(balAvailable.toDecimalUSDString()); }); // 2. Get the UTXOs diff --git a/src/datamodel.h b/src/datamodel.h index 1068d41..2e1764f 100644 --- a/src/datamodel.h +++ b/src/datamodel.h @@ -33,7 +33,9 @@ public: const QList getUTXOs() { QReadLocker locker(lock); return *utxos; } const QMap getAllBalances() { QReadLocker locker(lock); return *balances; } const QMap getUsedAddresses() { QReadLocker locker(lock); return *usedAddresses; } - + + CAmount getAvailableBalance() { return availableBalance; } + void setAvailableBalance(CAmount a) { this->availableBalance = a; } DataModel(); ~DataModel(); @@ -46,6 +48,8 @@ private: QList* zaddresses = nullptr; QList* taddresses = nullptr; + CAmount availableBalance; + QReadWriteLock* lock; }; diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index ed72f9e..fa7e50c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -430,10 +430,6 @@ void MainWindow::payZcashURI(QString uri, QString myAddr) { // Now, set the fields on the send tab clearSendForm(); - if (!myAddr.isEmpty()) { - ui->inputsCombo->setCurrentText(myAddr); - } - ui->Address1->setText(paymentInfo.addr); ui->Address1->setCursorPosition(0); ui->Amount1->setText(paymentInfo.amt); @@ -631,40 +627,6 @@ void MainWindow::setupBalancesTab() { ui->lblSyncWarning->setVisible(false); ui->lblSyncWarningReceive->setVisible(false); - // Double click on balances table - auto fnDoSendFrom = [=](const QString& addr, const QString& to = QString(), bool sendMax = false) { - // Find the inputs combo - for (int i = 0; i < ui->inputsCombo->count(); i++) { - auto inputComboAddress = ui->inputsCombo->itemText(i); - if (inputComboAddress.startsWith(addr)) { - ui->inputsCombo->setCurrentIndex(i); - break; - } - } - - // If there's a to address, add that as well - if (!to.isEmpty()) { - // Remember to clear any existing address fields, because we are creating a new transaction. - this->clearSendForm(); - ui->Address1->setText(to); - } - - // See if max button has to be checked - if (sendMax) { - ui->Max1->setChecked(true); - } - - // And switch to the send tab. - ui->tabWidget->setCurrentIndex(1); - }; - - // Double click opens up memo if one exists - QObject::connect(ui->balancesTable, &QTableView::doubleClicked, [=](auto index) { - index = index.sibling(index.row(), 0); - auto addr = AddressBook::addressFromAddressLabel(ui->balancesTable->model()->data(index).toString()); - - fnDoSendFrom(addr); - }); // Setup context menu on balances tab ui->balancesTable->setContextMenuPolicy(Qt::CustomContextMenu); @@ -688,18 +650,8 @@ void MainWindow::setupBalancesTab() { this->exportKeys(addr); }); - menu.addAction("Send from " % addr.left(40) % (addr.size() > 40 ? "..." : ""), [=]() { - fnDoSendFrom(addr); - }); if (Settings::isTAddress(addr)) { - auto defaultSapling = rpc->getDefaultSaplingAddress(); - if (!defaultSapling.isEmpty()) { - menu.addAction(tr("Shield balance to Sapling"), [=] () { - fnDoSendFrom(addr, defaultSapling, true); - }); - } - menu.addAction(tr("View on block explorer"), [=] () { Settings::openAddressInExplorer(addr); }); @@ -1118,9 +1070,6 @@ void MainWindow::updateLabels() { addZAddrsToComboList(ui->rdioZSAddr->isChecked())(true); } - // Update the Send Tab - updateFromCombo(); - // Update the autocomplete updateLabelsAutoComplete(); } diff --git a/src/mainwindow.h b/src/mainwindow.h index 6b1aafd..54dc309 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -47,7 +47,6 @@ public: QRegExpValidator* getAmountValidator() { return amtValidator; } QString doSendTxValidations(Tx tx); - void setDefaultPayFrom(); void replaceWormholeClient(WormholeClient* newClient); bool isWebsocketListening(); @@ -59,7 +58,6 @@ public: void updateLabels(); void updateTAddrCombo(bool checked); - void updateFromCombo(); // Disable recurring on mainnet void disableRecurring(); @@ -100,7 +98,6 @@ private: void cancelButton(); void sendButton(); - void inputComboTextChanged(int index); void addAddressSection(); void maxAmountChecked(int checked); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 0b03762..b44dce6 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -22,7 +22,7 @@ - 0 + 1 @@ -75,6 +75,37 @@ + + + + + + + 10 + + + + Verified + + + + + + + + 10 + + + + + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + @@ -270,60 +301,59 @@ false - + - - - - - + + + Qt::Horizontal + + + + 40 + 20 + + + - - - - - Address Balance - - - - - - - - 0 - 0 - - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - true - - - - - - - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + + + + 75 + true + + + + Total verified funds available: + + + + + + + + + + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + @@ -362,8 +392,8 @@ 0 0 - 1162 - 344 + 1226 + 504 @@ -1055,7 +1085,7 @@ 0 0 1274 - 39 + 22 @@ -1201,7 +1231,6 @@ tabWidget - inputsCombo Address1 Amount1 Max1 @@ -1220,7 +1249,6 @@ transactionsTable balancesTable minerFeeAmt - sendAddressBalance sendToScrollArea diff --git a/src/sendtab.cpp b/src/sendtab.cpp index 2e0de49..730a234 100644 --- a/src/sendtab.cpp +++ b/src/sendtab.cpp @@ -22,10 +22,6 @@ void MainWindow::setupSendTab() { // Cancel Button QObject::connect(ui->cancelSendButton, &QPushButton::clicked, this, &MainWindow::cancelButton); - // Input Combobox current text changed - QObject::connect(ui->inputsCombo, QOverload::of(&QComboBox::currentIndexChanged), - this, &MainWindow::inputComboTextChanged); - // Hook up add address button click QObject::connect(ui->addAddressButton, &QPushButton::clicked, this, &MainWindow::addAddressSection); @@ -168,18 +164,6 @@ void MainWindow::updateLabelsAutoComplete() { } } -void MainWindow::setDefaultPayFrom() { - -}; - -void MainWindow::updateFromCombo() { - // delete -} - -void MainWindow::inputComboTextChanged(int) { - // delete -} - void MainWindow::addAddressSection() { int itemNumber = ui->sendToWidgets->children().size() - 1; @@ -336,12 +320,9 @@ void MainWindow::memoButtonClicked(int number, bool includeReplyTo) { memoDialog.memoTxt->setAcceptButton(memoDialog.buttonBox->button(QDialogButtonBox::Ok)); auto fnAddReplyTo = [=, &dialog]() { - QString replyTo = ui->inputsCombo->currentText(); - if (!Settings::isZAddress(replyTo)) { - replyTo = rpc->getDefaultSaplingAddress(); - if (replyTo.isEmpty()) - return; - } + auto replyTo = rpc->getDefaultSaplingAddress(); + if (replyTo.isEmpty()) + return; memoDialog.memoTxt->includeReplyTo(replyTo); @@ -424,10 +405,8 @@ void MainWindow::maxAmountChecked(int checked) { sumAllAmounts = sumAllAmounts + Settings::getMinerFee(); - auto addr = ui->inputsCombo->currentText(); - - auto maxamount = rpc->getModel()->getAllBalances().value(addr) - sumAllAmounts; - maxamount = (maxamount.toqint64() < 0) ? CAmount::fromqint64(0) : maxamount; + auto maxamount = rpc->getModel()->getAvailableBalance() - sumAllAmounts; + maxamount = (maxamount < 0) ? CAmount::fromqint64(0): maxamount; ui->Amount1->setText(maxamount.toDecimalString()); } else if (checked == Qt::Unchecked) { @@ -440,9 +419,6 @@ void MainWindow::maxAmountChecked(int checked) { Tx MainWindow::createTxFromSendPage() { Tx tx; - // Gather the from / to addresses - tx.fromAddr = ui->inputsCombo->currentText(); - // For each addr/amt in the sendTo tab int totalItems = ui->sendToWidgets->children().size() - 2; // The last one is a spacer, so ignore that CAmount totalAmt;