From 364c775d6d9a4f73ca5b98e9d278db3d576ee4b0 Mon Sep 17 00:00:00 2001 From: fekt Date: Tue, 1 Nov 2022 22:12:04 -0400 Subject: [PATCH] Removing taddr on receive tab Left zaddr radio button for now as it's used to update dropdown of zaddrs --- src/mainwindow.cpp | 129 ++++----------------------------------------- src/mainwindow.ui | 30 ++++------- 2 files changed, 19 insertions(+), 140 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 0e9e27b..5c7982c 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -2437,7 +2437,7 @@ void MainWindow::addNewZaddr(bool sapling) { // Just double make sure the z-address is still checked if ( sapling && ui->rdioZSAddr->isChecked() ) { - ui->listReceiveAddresses->insertItem(0, addr); + ui->listReceiveAddresses->insertItem(0, addr); ui->listReceiveAddresses->setCurrentIndex(0); ui->statusBar->showMessage(QString::fromStdString("Created new zaddr") % @@ -2451,8 +2451,8 @@ void MainWindow::addNewZaddr(bool sapling) { // Adds sapling z-addresses to the combo box. Technically, returns a // lambda, which can be connected to the appropriate signal std::function MainWindow::addZAddrsToComboList(bool sapling) { - return [=] (bool checked) { - if (checked) { + return [=] (bool checked) { + if (checked) { auto addrs = this->rpc->getModel()->getAllZAddresses(); // Save the current address, so we can update it later @@ -2475,38 +2475,11 @@ std::function MainWindow::addZAddrsToComboList(bool sapling) { if (addrs.isEmpty()) { addNewZaddr(sapling); } - } + } }; } void MainWindow::setupReceiveTab() { - auto addNewTAddr = [=] () { - rpc->createNewTaddr([=] (json reply) { - QString addr = QString::fromStdString(reply.get()[0]); - // Make sure the RPC class reloads the t-addrs for future use - rpc->refreshAddresses(); - - // Just double make sure the t-address is still checked - if (ui->rdioTAddr->isChecked()) { - ui->listReceiveAddresses->insertItem(0, addr); - ui->listReceiveAddresses->setCurrentIndex(0); - - ui->statusBar->showMessage(tr("Created new t-Addr"), 10 * 1000); - } - }); - }; - - // Connect t-addr radio button - QObject::connect(ui->rdioTAddr, &QRadioButton::toggled, [=] (bool checked) { - // Whenever the t-address is selected, we generate a new address, because we don't - // want to reuse t-addrs - if (checked) { - updateTAddrCombo(checked); - } - - - }); - // View all addresses goes to "View all private keys" QObject::connect(ui->btnViewAllAddresses, &QPushButton::clicked, [=] () { // If there's no RPC, return @@ -2520,12 +2493,8 @@ void MainWindow::setupReceiveTab() { Settings::saveRestoreTableHeader(viewaddrs.tblAddresses, &d, "viewalladdressestable"); viewaddrs.tblAddresses->horizontalHeader()->setStretchLastSection(true); - QList allAddresses; - if (ui->rdioTAddr->isChecked()) { - allAddresses = getRPC()->getModel()->getAllTAddresses(); - } else { - allAddresses = getRPC()->getModel()->getAllZAddresses(); - } + QList allAddresses; + allAddresses = getRPC()->getModel()->getAllZAddresses(); ViewAllAddressesModel model(viewaddrs.tblAddresses, allAddresses, getRPC()); viewaddrs.tblAddresses->setModel(&model); @@ -2579,18 +2548,16 @@ void MainWindow::setupReceiveTab() { if (ui->rdioZSAddr->isChecked()) { addNewZaddr(true); - } else if (ui->rdioTAddr->isChecked()) { - addNewTAddr(); } }); // Focus enter for the Receive Tab QObject::connect(ui->tabWidget, &QTabWidget::currentChanged, [=] (int tab) { - if (tab == 2) { + if (tab == 3) { // Switched to receive tab, select the z-addr radio button ui->rdioZSAddr->setChecked(true); - - + + // And then select the first one ui->listReceiveAddresses->setCurrentIndex(0); } @@ -2704,86 +2671,10 @@ void MainWindow::setupReceiveTab() { }); } -void MainWindow::updateTAddrCombo(bool checked) { - if (checked) { - auto utxos = this->rpc->getModel()->getUTXOs(); - - // Save the current address so we can restore it later - auto currentTaddr = ui->listReceiveAddresses->currentText(); - - ui->listReceiveAddresses->clear(); - - // Maintain a set of addresses so we don't duplicate any, because we'll be adding - // t addresses multiple times - QSet addrs; - - // 1. Add all t addresses that have a balance - std::for_each(utxos.begin(), utxos.end(), [=, &addrs](auto& utxo) { - auto addr = utxo.address; - if (Settings::isTAddress(addr) && !addrs.contains(addr)) { - auto bal = rpc->getModel()->getAllBalances().value(addr); - ui->listReceiveAddresses->addItem(addr, bal); - - addrs.insert(addr); - } - }); - - // 2. Add all t addresses that have a label - auto allTaddrs = this->rpc->getModel()->getAllTAddresses(); - QSet labels; - for (auto p : AddressBook::getInstance()->getAllAddressLabels()) { - labels.insert(p.getPartnerAddress()); - } - std::for_each(allTaddrs.begin(), allTaddrs.end(), [=, &addrs] (auto& taddr) { - // If the address is in the address book, add it. - if (labels.contains(taddr) && !addrs.contains(taddr)) { - addrs.insert(taddr); - ui->listReceiveAddresses->addItem(taddr, CAmount::fromqint64(0)); - } - }); - - // 3. Add all t-addresses. We won't add more than 20 total t-addresses, - // since it will overwhelm the dropdown - for (int i=0; addrs.size() < 20 && i < allTaddrs.size(); i++) { - auto addr = allTaddrs.at(i); - if (!addrs.contains(addr)) { - addrs.insert(addr); - // Balance is zero since it has not been previously added - ui->listReceiveAddresses->addItem(addr, CAmount::fromqint64(0)); - } - } - - // 4. Add the previously selected t-address - if (!currentTaddr.isEmpty() && Settings::isTAddress(currentTaddr)) { - // Make sure the current taddr is in the list - if (!addrs.contains(currentTaddr)) { - auto bal = rpc->getModel()->getAllBalances().value(currentTaddr); - ui->listReceiveAddresses->addItem(currentTaddr, bal); - } - ui->listReceiveAddresses->setCurrentText(currentTaddr); - } - - // 5. Add a last, disabled item if there are remaining items - if (allTaddrs.size() > addrs.size()) { - auto num = QString::number(allTaddrs.size() - addrs.size()); - ui->listReceiveAddresses->addItem("-- " + num + " more --", CAmount::fromqint64(0)); - - QStandardItemModel* model = qobject_cast(ui->listReceiveAddresses->model()); - QStandardItem* item = model->findItems("--", Qt::MatchStartsWith)[0]; - item->setFlags(item->flags() & ~Qt::ItemIsEnabled); - } - } -}; - // Updates the labels everywhere on the UI. Call this after the labels have been updated void MainWindow::updateLabels() { // Update the Receive tab - if (ui->rdioTAddr->isChecked()) { - updateTAddrCombo(true); - } - else { - addZAddrsToComboList(ui->rdioZSAddr->isChecked())(true); - } + addZAddrsToComboList(ui->rdioZSAddr->isChecked())(true); // Update the autocomplete updateLabelsAutoComplete(); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 5f7c1ae..7db1cd8 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -59,7 +59,7 @@ - 1 + 3 @@ -956,8 +956,8 @@ 0 0 - 1260 - 509 + 1268 + 519 @@ -1262,21 +1262,14 @@ + + true + z-Addr - - - - - - - 0 - 0 - - - - t-Addr + + false @@ -1682,7 +1675,6 @@ - @@ -1690,7 +1682,6 @@ - @@ -1712,7 +1703,6 @@ - @@ -1734,7 +1724,6 @@ - @@ -1921,7 +1910,7 @@ 0 0 1308 - 22 + 30 @@ -2118,7 +2107,6 @@ sendTransactionButton cancelSendButton rdioZSAddr - rdioTAddr listReceiveAddresses txtReceive rcvLabel