Prevent negative z balances,Hide 0-balance addresses from the balances table,Rename new address to next address
This commit is contained in:
@@ -20,24 +20,29 @@ void BalancesTableModel::setNewData(const QList<QString> zaddrs, const QList<QSt
|
||||
// This is a QList deep copy.
|
||||
*unspentOutputs = outputs;
|
||||
|
||||
// Are there any z or t addresses with balance in the balances table?
|
||||
bool anyz = false;
|
||||
bool anyt = false;
|
||||
|
||||
// Process the address balances into a list
|
||||
delete modeldata;
|
||||
modeldata = new QList<std::tuple<QString, CAmount>>();
|
||||
std::for_each(balances.keyBegin(), balances.keyEnd(), [=] (auto keyIt) {
|
||||
std::for_each(balances.keyBegin(), balances.keyEnd(), [=, &anyz, &anyt] (auto keyIt) {
|
||||
modeldata->push_back(std::make_tuple(keyIt, balances.value(keyIt)));
|
||||
if (Settings::isZAddress(keyIt)) {
|
||||
anyz = true;
|
||||
} else if (Settings::isTAddress(keyIt)) {
|
||||
anyt = true;
|
||||
}
|
||||
});
|
||||
|
||||
// Add all addresses that have no balances as well
|
||||
for (auto zaddr: zaddrs) {
|
||||
if (!balances.contains(zaddr)) {
|
||||
modeldata->push_back(std::make_tuple(zaddr, CAmount::fromqint64(0)));
|
||||
}
|
||||
// Add all addresses that have no balances, if there are no existing addresses
|
||||
if (!anyz && zaddrs.length() > 0) {
|
||||
modeldata->push_back(std::make_tuple(zaddrs[0], CAmount::fromqint64(0)));
|
||||
}
|
||||
|
||||
for (auto taddr: taddrs) {
|
||||
if (!balances.contains(taddr)) {
|
||||
modeldata->push_back(std::make_tuple(taddr, CAmount::fromqint64(0)));
|
||||
}
|
||||
if (!anyt && taddrs.length() > 0) {
|
||||
modeldata->push_back(std::make_tuple(taddrs[0], CAmount::fromqint64(0)));
|
||||
}
|
||||
|
||||
// And then update the data
|
||||
|
||||
@@ -71,6 +71,9 @@ public:
|
||||
bool operator> (const CAmount& other) const {
|
||||
return this->amount > other.amount;
|
||||
}
|
||||
bool operator== (const qint64 other) const {
|
||||
return this->amount == other;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // CAMOUNT_H
|
||||
|
||||
@@ -353,6 +353,9 @@ void Controller::updateUIBalances() {
|
||||
|
||||
CAmount balTotal = balT + balZ;
|
||||
CAmount balAvailable = balT + balVerified;
|
||||
if (balZ < 0) {
|
||||
balZ = CAmount::fromqint64(0);
|
||||
}
|
||||
|
||||
// Balances table
|
||||
ui->balSheilded ->setText(balZ.toDecimalhushString());
|
||||
|
||||
@@ -1048,8 +1048,7 @@ void MainWindow::setupReceiveTab() {
|
||||
updateTAddrCombo(checked);
|
||||
}
|
||||
|
||||
// Toggle the "View all addresses" button as well
|
||||
ui->btnViewAllAddresses->setVisible(checked);
|
||||
|
||||
});
|
||||
|
||||
// View all addresses goes to "View all private keys"
|
||||
@@ -1065,7 +1064,14 @@ void MainWindow::setupReceiveTab() {
|
||||
Settings::saveRestoreTableHeader(viewaddrs.tblAddresses, &d, "viewalladdressestable");
|
||||
viewaddrs.tblAddresses->horizontalHeader()->setStretchLastSection(true);
|
||||
|
||||
ViewAllAddressesModel model(viewaddrs.tblAddresses, getRPC()->getModel()->getAllTAddresses(), getRPC());
|
||||
QList<QString> allAddresses;
|
||||
if (ui->rdioTAddr->isChecked()) {
|
||||
allAddresses = getRPC()->getModel()->getAllTAddresses();
|
||||
} else {
|
||||
allAddresses = getRPC()->getModel()->getAllZAddresses();
|
||||
}
|
||||
|
||||
ViewAllAddressesModel model(viewaddrs.tblAddresses, allAddresses, getRPC());
|
||||
viewaddrs.tblAddresses->setModel(&model);
|
||||
|
||||
QObject::connect(viewaddrs.btnExportAll, &QPushButton::clicked, this, &MainWindow::exportAllKeys);
|
||||
@@ -1100,6 +1106,20 @@ void MainWindow::setupReceiveTab() {
|
||||
QObject::connect(ui->btnReceiveNewAddr, &QPushButton::clicked, [=] () {
|
||||
if (!rpc->getConnection())
|
||||
return;
|
||||
|
||||
// Go over the dropdown and just select the next address that has:
|
||||
// 0 balance and has no labels
|
||||
for (int i=ui->listReceiveAddresses->currentIndex()+1; i < ui->listReceiveAddresses->count(); i++) {
|
||||
QString item = ui->listReceiveAddresses->itemText(i);
|
||||
CAmount bal = getRPC()->getModel()->getAllBalances().value(item, CAmount());
|
||||
if (bal == 0 && AddressBook::getInstance()->getLabelForAddress(item).isEmpty()) {
|
||||
// Pick this one, since it has no balance and no label
|
||||
ui->listReceiveAddresses->setCurrentIndex(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// If none of the existing items were eligible, create a new one.
|
||||
|
||||
if (ui->rdioZSAddr->isChecked()) {
|
||||
addNewZaddr(true);
|
||||
@@ -1113,7 +1133,7 @@ void MainWindow::setupReceiveTab() {
|
||||
if (tab == 2) {
|
||||
// Switched to receive tab, select the z-addr radio button
|
||||
ui->rdioZSAddr->setChecked(true);
|
||||
ui->btnViewAllAddresses->setVisible(false);
|
||||
|
||||
|
||||
// And then select the first one
|
||||
ui->listReceiveAddresses->setCurrentIndex(0);
|
||||
|
||||
@@ -770,7 +770,7 @@
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnReceiveNewAddr">
|
||||
<property name="text">
|
||||
<string>New Address</string>
|
||||
<string>Next Address</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
Reference in New Issue
Block a user