#156 Prevent duplicate labels
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -37,3 +37,4 @@ workspace.code-workspace
|
|||||||
zcashd
|
zcashd
|
||||||
IDEWorkspaceChecks.plist
|
IDEWorkspaceChecks.plist
|
||||||
*.sln
|
*.sln
|
||||||
|
node_modules
|
||||||
|
|||||||
@@ -122,14 +122,32 @@ void AddressBook::open(MainWindow* parent, QLineEdit* target) {
|
|||||||
// Add new address button
|
// Add new address button
|
||||||
QObject::connect(ab.addNew, &QPushButton::clicked, [&] () {
|
QObject::connect(ab.addNew, &QPushButton::clicked, [&] () {
|
||||||
auto addr = ab.addr->text().trimmed();
|
auto addr = ab.addr->text().trimmed();
|
||||||
if (!addr.isEmpty() && !ab.label->text().isEmpty()) {
|
QString newLabel = ab.label->text();
|
||||||
// Test if address is valid.
|
|
||||||
if (!Settings::isValidAddress(addr)) {
|
if (addr.isEmpty() || newLabel.isEmpty()) {
|
||||||
QMessageBox::critical(parent, QObject::tr("Address Format Error"), addr + QObject::tr(" doesn't seem to be a valid Zcash address."), QMessageBox::Ok);
|
QMessageBox::critical(parent, QObject::tr("Address or Label Error"),
|
||||||
} else {
|
QObject::tr("Address or Label cannot be empty"), QMessageBox::Ok);
|
||||||
model.addNewLabel(ab.label->text(), ab.addr->text());
|
return;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
// Test if address is valid.
|
||||||
|
if (!Settings::isValidAddress(addr)) {
|
||||||
|
QMessageBox::critical(parent, QObject::tr("Address Format Error"),
|
||||||
|
QObject::tr("%1 doesn't seem to be a valid Zcash address.")
|
||||||
|
.arg(addr),
|
||||||
|
QMessageBox::Ok);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't allow duplicate address labels.
|
||||||
|
if (!getInstance()->getAddressForLabel(newLabel).isEmpty()) {
|
||||||
|
QMessageBox::critical(parent, QObject::tr("Label Error"),
|
||||||
|
QObject::tr("The label '%1' already exists. Please remove the existing label.")
|
||||||
|
.arg(newLabel),
|
||||||
|
QMessageBox::Ok);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
model.addNewLabel(newLabel, ab.addr->text());
|
||||||
});
|
});
|
||||||
|
|
||||||
// Import Button
|
// Import Button
|
||||||
@@ -344,6 +362,16 @@ QString AddressBook::getLabelForAddress(QString addr) {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get the address for a label
|
||||||
|
QString AddressBook::getAddressForLabel(QString label) {
|
||||||
|
for (auto i: allLabels) {
|
||||||
|
if (i.first == label)
|
||||||
|
return i.second;
|
||||||
|
}
|
||||||
|
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
QString AddressBook::addLabelToAddress(QString addr) {
|
QString AddressBook::addLabelToAddress(QString addr) {
|
||||||
QString label = AddressBook::getInstance()->getLabelForAddress(addr);
|
QString label = AddressBook::getInstance()->getLabelForAddress(addr);
|
||||||
if (!label.isEmpty())
|
if (!label.isEmpty())
|
||||||
|
|||||||
@@ -52,6 +52,8 @@ public:
|
|||||||
|
|
||||||
// Get an address's first label
|
// Get an address's first label
|
||||||
QString getLabelForAddress(QString address);
|
QString getLabelForAddress(QString address);
|
||||||
|
// Get a Label's address
|
||||||
|
QString getAddressForLabel(QString label);
|
||||||
private:
|
private:
|
||||||
AddressBook();
|
AddressBook();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user