diff --git a/src/addressbook.cpp b/src/addressbook.cpp index 2504317..cd9a490 100644 --- a/src/addressbook.cpp +++ b/src/addressbook.cpp @@ -259,6 +259,17 @@ void AddressBook::removeAddressLabel(QString label, QString address) { } } +void AddressBook::updateLabel(QString oldlabel, QString address, QString newlabel) { + // Iterate over the list and update the label/address + for (int i = 0; i < allLabels.size(); i++) { + if (allLabels[i].first == oldlabel && allLabels[i].second == address) { + allLabels[i].first = newlabel; + writeToStorage(); + return; + } + } +} + // Read all addresses const QList>& AddressBook::getAllAddressLabels() { return allLabels; diff --git a/src/addressbook.h b/src/addressbook.h index e8b8f10..a55c2b6 100644 --- a/src/addressbook.h +++ b/src/addressbook.h @@ -44,6 +44,9 @@ public: // Remove a new address/label from the database void removeAddressLabel(QString label, QString address); + // Update a label/address + void AddressBook::updateLabel(QString oldlabel, QString address, QString newlabel); + // Read all addresses const QList>& getAllAddressLabels(); diff --git a/src/connection.cpp b/src/connection.cpp index a825acc..83cd626 100644 --- a/src/connection.cpp +++ b/src/connection.cpp @@ -322,7 +322,7 @@ bool ConnectionLoader::startEmbeddedZcashd() { #elif defined(Q_OS_DARWIN) ezcashd->start(zcashdProgram); #else - ezcashd->setWorkingDirectory(fi.dir().absolutePath()); + ezcashd->setWorkingDirectory(appPath.absolutePath()); ezcashd->start("zcashd.exe"); #endif // Q_OS_LINUX diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 500e903..2f8dbde 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -962,22 +962,27 @@ void MainWindow::setupRecieveTab() { }); }; - // 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) { + auto fnUpdateTAddrCombo = [=] (bool checked) { + if (checked) { auto utxos = this->rpc->getUTXOs(); ui->listRecieveAddresses->clear(); - std::for_each(utxos->begin(), utxos->end(), [=] (auto& utxo) { + 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); addNewTAddr(); } }); @@ -1036,15 +1041,66 @@ void MainWindow::setupRecieveTab() { if (addr.isEmpty()) { // Draw empty stuff + ui->rcvLabel->clear(); + ui->rcvBal->clear(); ui->txtRecieve->clear(); ui->qrcodeDisplay->clear(); return; } + auto label = AddressBook::getInstance()->getLabelForAddress(addr); + if (label.isEmpty()) { + ui->rcvUpdateLabel->setText("Add Label"); + } + else { + ui->rcvUpdateLabel->setText("Update Label"); + } + + ui->rcvLabel->setText(label); + ui->rcvBal->setText(Settings::getZECUSDDisplayFormat(rpc->getAllBalances()->value(addr))); ui->txtRecieve->setPlainText(addr); ui->qrcodeDisplay->setAddress(addr); }); + // Recieve tab add/update label + QObject::connect(ui->rcvUpdateLabel, &QPushButton::clicked, [=]() { + QString addr = ui->listRecieveAddresses->currentText(); + if (addr.isEmpty()) + return; + + auto curLabel = AddressBook::getInstance()->getLabelForAddress(addr); + auto label = ui->rcvLabel->text(); + + QString info; + + if (!curLabel.isEmpty() && label.isEmpty()) { + info = "Removed Label"; + AddressBook::getInstance()->removeAddressLabel(curLabel, addr); + } + else if (!curLabel.isEmpty() && !label.isEmpty()) { + info = "Updated Label"; + AddressBook::getInstance()->updateLabel(curLabel, addr, label); + } + else if (curLabel.isEmpty() && !label.isEmpty()) { + info = "Added Label"; + AddressBook::getInstance()->addAddressLabel(label, addr); + } + + if (info.isEmpty()) + return; + + // Update the UI + if (ui->rdioTAddr->isChecked()) { + fnUpdateTAddrCombo(true); + } + else { + addZAddrsToComboList(ui->rdioZSAddr->isChecked())(true); + } + + // Show the user feedback + QMessageBox::information(this, "Label", info, QMessageBox::Ok); + }); + } MainWindow::~MainWindow() diff --git a/src/mainwindow.ui b/src/mainwindow.ui index b9aa53d..4c103a9 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -316,8 +316,8 @@ 0 0 - 920 - 334 + 928 + 380 @@ -655,11 +655,73 @@ - - - true - - + + + + + + 0 + 0 + + + + true + + + + + + + + + Label + + + + + + + 40 + + + + + + + Update Label + + + + + + + Address Balance + + + + + + + TextLabel + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + @@ -849,7 +911,7 @@ 0 0 968 - 22 + 19 @@ -991,7 +1053,6 @@ rdioTAddr listRecieveAddresses btnRecieveNewAddr - txtRecieve transactionsTable