Removing taddr on receive tab

Left zaddr radio button for now as it's used to update dropdown of zaddrs
This commit is contained in:
fekt
2022-11-01 22:12:04 -04:00
parent e179e723f5
commit 364c775d6d
2 changed files with 19 additions and 140 deletions

View File

@@ -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<void(bool)> 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<void(bool)> MainWindow::addZAddrsToComboList(bool sapling) {
if (addrs.isEmpty()) {
addNewZaddr(sapling);
}
}
}
};
}
void MainWindow::setupReceiveTab() {
auto addNewTAddr = [=] () {
rpc->createNewTaddr([=] (json reply) {
QString addr = QString::fromStdString(reply.get<json::array_t>()[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<QString> allAddresses;
if (ui->rdioTAddr->isChecked()) {
allAddresses = getRPC()->getModel()->getAllTAddresses();
} else {
allAddresses = getRPC()->getModel()->getAllZAddresses();
}
QList<QString> 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<QString> 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<QString> 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<QStandardItemModel*>(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();