Allow labels on recieve tab
This commit is contained in:
@@ -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<QPair<QString, QString>>& AddressBook::getAllAddressLabels() {
|
||||
return allLabels;
|
||||
|
||||
@@ -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<QPair<QString, QString>>& getAllAddressLabels();
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -316,8 +316,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>920</width>
|
||||
<height>334</height>
|
||||
<width>928</width>
|
||||
<height>380</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="sendToLayout">
|
||||
@@ -655,11 +655,73 @@
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_11">
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="txtRecieve">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
<layout class="QVBoxLayout" name="verticalLayout_10">
|
||||
<item>
|
||||
<widget class="QPlainTextEdit" name="txtRecieve">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Label</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="rcvLabel">
|
||||
<property name="maxLength">
|
||||
<number>40</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QPushButton" name="rcvUpdateLabel">
|
||||
<property name="text">
|
||||
<string>Update Label</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_21">
|
||||
<property name="text">
|
||||
<string>Address Balance</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1" colspan="2">
|
||||
<widget class="QLabel" name="rcvBal">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QRCodeLabel" name="qrcodeDisplay">
|
||||
@@ -849,7 +911,7 @@
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>968</width>
|
||||
<height>22</height>
|
||||
<height>19</height>
|
||||
</rect>
|
||||
</property>
|
||||
<widget class="QMenu" name="menuFile">
|
||||
@@ -991,7 +1053,6 @@
|
||||
<tabstop>rdioTAddr</tabstop>
|
||||
<tabstop>listRecieveAddresses</tabstop>
|
||||
<tabstop>btnRecieveNewAddr</tabstop>
|
||||
<tabstop>txtRecieve</tabstop>
|
||||
<tabstop>transactionsTable</tabstop>
|
||||
</tabstops>
|
||||
<resources>
|
||||
|
||||
Reference in New Issue
Block a user