From 5eb2a14aec8ec74676d35ef26109f4da22b8dbf2 Mon Sep 17 00:00:00 2001 From: adityapk00 Date: Sat, 23 Feb 2019 09:42:14 -0800 Subject: [PATCH] Cleanup labels code --- src/addressbook.cpp | 2 +- src/mainwindow.cpp | 58 +++++++++++++++++++++++++-------------------- src/mainwindow.h | 4 ++++ 3 files changed, 37 insertions(+), 27 deletions(-) diff --git a/src/addressbook.cpp b/src/addressbook.cpp index 762bea6..82d99a5 100644 --- a/src/addressbook.cpp +++ b/src/addressbook.cpp @@ -111,7 +111,7 @@ void AddressBook::open(MainWindow* parent, QLineEdit* target) { } // Connect the dialog's closing to updating the label address completor - QObject::connect(&d, &QDialog::finished, [=] (auto) { parent->updateLabelsAutoComplete(); }); + QObject::connect(&d, &QDialog::finished, [=] (auto) { parent->updateLabels(); }); // If there is a target then make it the addr for the "Add to" button if (target != nullptr && Settings::isValidAddress(target->text())) { diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 8fadfb0..3f448b3 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1223,27 +1223,12 @@ void MainWindow::setupRecieveTab() { }); }; - auto fnUpdateTAddrCombo = [=] (bool checked) { - if (checked) { - auto utxos = this->rpc->getUTXOs(); - ui->listRecieveAddresses->clear(); - - std::for_each(utxos->begin(), utxos->end(), [=](auto& utxo) { - auto addr = utxo.address; - if (addr.startsWith("t") && ui->listRecieveAddresses->findText(addr) < 0) { - auto bal = rpc->getAllBalances()->value(addr); - ui->listRecieveAddresses->addItem(addr, bal); - } - }); - } - }; - // 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 && this->rpc->getUTXOs() != nullptr) { - fnUpdateTAddrCombo(checked); + updateTAddrCombo(checked); addNewTAddr(); } }); @@ -1368,16 +1353,8 @@ void MainWindow::setupRecieveTab() { AddressBook::getInstance()->addAddressLabel(label, addr); } - // Update the UI - if (ui->rdioTAddr->isChecked()) { - fnUpdateTAddrCombo(true); - } - else { - addZAddrsToComboList(ui->rdioZSAddr->isChecked())(true); - } - - // Update the autocomplete - updateLabelsAutoComplete(); + // Update labels everywhere on the UI + updateLabels(); // Show the user feedback if (!info.isEmpty()) { @@ -1395,6 +1372,35 @@ void MainWindow::setupRecieveTab() { }); } +void MainWindow::updateTAddrCombo(bool checked) { + if (checked) { + auto utxos = this->rpc->getUTXOs(); + ui->listRecieveAddresses->clear(); + + std::for_each(utxos->begin(), utxos->end(), [=](auto& utxo) { + auto addr = utxo.address; + if (addr.startsWith("t") && ui->listRecieveAddresses->findText(addr) < 0) { + auto bal = rpc->getAllBalances()->value(addr); + ui->listRecieveAddresses->addItem(addr, bal); + } + }); + } +}; + +// 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); + } + + // Update the autocomplete + updateLabelsAutoComplete(); +} + MainWindow::~MainWindow() { delete ui; diff --git a/src/mainwindow.h b/src/mainwindow.h index c24d402..0b68f9d 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -50,6 +50,10 @@ public: void createWebsocket(QString wormholecode); void stopWebsocket(); + void updateLabels(); + void updateTAddrCombo(bool checked); + + Ui::MainWindow* ui; QLabel* statusLabel;