Browse Source

Cleanup labels code

import_zecw
adityapk00 5 years ago
parent
commit
5eb2a14aec
  1. 2
      src/addressbook.cpp
  2. 58
      src/mainwindow.cpp
  3. 4
      src/mainwindow.h

2
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 // 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 there is a target then make it the addr for the "Add to" button
if (target != nullptr && Settings::isValidAddress(target->text())) { if (target != nullptr && Settings::isValidAddress(target->text())) {

58
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 // Connect t-addr radio button
QObject::connect(ui->rdioTAddr, &QRadioButton::toggled, [=] (bool checked) { QObject::connect(ui->rdioTAddr, &QRadioButton::toggled, [=] (bool checked) {
// Whenever the t-address is selected, we generate a new address, because we don't // Whenever the t-address is selected, we generate a new address, because we don't
// want to reuse t-addrs // want to reuse t-addrs
if (checked && this->rpc->getUTXOs() != nullptr) { if (checked && this->rpc->getUTXOs() != nullptr) {
fnUpdateTAddrCombo(checked); updateTAddrCombo(checked);
addNewTAddr(); addNewTAddr();
} }
}); });
@ -1368,16 +1353,8 @@ void MainWindow::setupRecieveTab() {
AddressBook::getInstance()->addAddressLabel(label, addr); AddressBook::getInstance()->addAddressLabel(label, addr);
} }
// Update the UI // Update labels everywhere on the UI
if (ui->rdioTAddr->isChecked()) { updateLabels();
fnUpdateTAddrCombo(true);
}
else {
addZAddrsToComboList(ui->rdioZSAddr->isChecked())(true);
}
// Update the autocomplete
updateLabelsAutoComplete();
// Show the user feedback // Show the user feedback
if (!info.isEmpty()) { 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() MainWindow::~MainWindow()
{ {
delete ui; delete ui;

4
src/mainwindow.h

@ -50,6 +50,10 @@ public:
void createWebsocket(QString wormholecode); void createWebsocket(QString wormholecode);
void stopWebsocket(); void stopWebsocket();
void updateLabels();
void updateTAddrCombo(bool checked);
Ui::MainWindow* ui; Ui::MainWindow* ui;
QLabel* statusLabel; QLabel* statusLabel;

Loading…
Cancel
Save