Cleanup labels code
This commit is contained in:
@@ -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())) {
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
Reference in New Issue
Block a user