Browse Source

Removing taddr on receive tab

Left zaddr radio button for now as it's used to update dropdown of zaddrs
pull/94/head
fekt 2 years ago
parent
commit
364c775d6d
  1. 129
      src/mainwindow.cpp
  2. 30
      src/mainwindow.ui

129
src/mainwindow.cpp

@ -2437,7 +2437,7 @@ void MainWindow::addNewZaddr(bool sapling) {
// Just double make sure the z-address is still checked // Just double make sure the z-address is still checked
if ( sapling && ui->rdioZSAddr->isChecked() ) { if ( sapling && ui->rdioZSAddr->isChecked() ) {
ui->listReceiveAddresses->insertItem(0, addr); ui->listReceiveAddresses->insertItem(0, addr);
ui->listReceiveAddresses->setCurrentIndex(0); ui->listReceiveAddresses->setCurrentIndex(0);
ui->statusBar->showMessage(QString::fromStdString("Created new zaddr") % ui->statusBar->showMessage(QString::fromStdString("Created new zaddr") %
@ -2451,8 +2451,8 @@ void MainWindow::addNewZaddr(bool sapling) {
// Adds sapling z-addresses to the combo box. Technically, returns a // Adds sapling z-addresses to the combo box. Technically, returns a
// lambda, which can be connected to the appropriate signal // lambda, which can be connected to the appropriate signal
std::function<void(bool)> MainWindow::addZAddrsToComboList(bool sapling) { std::function<void(bool)> MainWindow::addZAddrsToComboList(bool sapling) {
return [=] (bool checked) { return [=] (bool checked) {
if (checked) { if (checked) {
auto addrs = this->rpc->getModel()->getAllZAddresses(); auto addrs = this->rpc->getModel()->getAllZAddresses();
// Save the current address, so we can update it later // Save the current address, so we can update it later
@ -2475,38 +2475,11 @@ std::function<void(bool)> MainWindow::addZAddrsToComboList(bool sapling) {
if (addrs.isEmpty()) { if (addrs.isEmpty()) {
addNewZaddr(sapling); addNewZaddr(sapling);
} }
} }
}; };
} }
void MainWindow::setupReceiveTab() { void MainWindow::setupReceiveTab() {
auto addNewTAddr = [=] () {
rpc->createNewTaddr([=] (json reply) {
QString addr = QString::fromStdString(reply.get<json::array_t>()[0]);
// Make sure the RPC class reloads the t-addrs for future use
rpc->refreshAddresses();
// Just double make sure the t-address is still checked
if (ui->rdioTAddr->isChecked()) {
ui->listReceiveAddresses->insertItem(0, addr);
ui->listReceiveAddresses->setCurrentIndex(0);
ui->statusBar->showMessage(tr("Created new t-Addr"), 10 * 1000);
}
});
};
// 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) {
updateTAddrCombo(checked);
}
});
// View all addresses goes to "View all private keys" // View all addresses goes to "View all private keys"
QObject::connect(ui->btnViewAllAddresses, &QPushButton::clicked, [=] () { QObject::connect(ui->btnViewAllAddresses, &QPushButton::clicked, [=] () {
// If there's no RPC, return // If there's no RPC, return
@ -2520,12 +2493,8 @@ void MainWindow::setupReceiveTab() {
Settings::saveRestoreTableHeader(viewaddrs.tblAddresses, &d, "viewalladdressestable"); Settings::saveRestoreTableHeader(viewaddrs.tblAddresses, &d, "viewalladdressestable");
viewaddrs.tblAddresses->horizontalHeader()->setStretchLastSection(true); viewaddrs.tblAddresses->horizontalHeader()->setStretchLastSection(true);
QList<QString> allAddresses; QList<QString> allAddresses;
if (ui->rdioTAddr->isChecked()) { allAddresses = getRPC()->getModel()->getAllZAddresses();
allAddresses = getRPC()->getModel()->getAllTAddresses();
} else {
allAddresses = getRPC()->getModel()->getAllZAddresses();
}
ViewAllAddressesModel model(viewaddrs.tblAddresses, allAddresses, getRPC()); ViewAllAddressesModel model(viewaddrs.tblAddresses, allAddresses, getRPC());
viewaddrs.tblAddresses->setModel(&model); viewaddrs.tblAddresses->setModel(&model);
@ -2579,18 +2548,16 @@ void MainWindow::setupReceiveTab() {
if (ui->rdioZSAddr->isChecked()) { if (ui->rdioZSAddr->isChecked()) {
addNewZaddr(true); addNewZaddr(true);
} else if (ui->rdioTAddr->isChecked()) {
addNewTAddr();
} }
}); });
// Focus enter for the Receive Tab // Focus enter for the Receive Tab
QObject::connect(ui->tabWidget, &QTabWidget::currentChanged, [=] (int tab) { QObject::connect(ui->tabWidget, &QTabWidget::currentChanged, [=] (int tab) {
if (tab == 2) { if (tab == 3) {
// Switched to receive tab, select the z-addr radio button // Switched to receive tab, select the z-addr radio button
ui->rdioZSAddr->setChecked(true); ui->rdioZSAddr->setChecked(true);
// And then select the first one // And then select the first one
ui->listReceiveAddresses->setCurrentIndex(0); ui->listReceiveAddresses->setCurrentIndex(0);
} }
@ -2704,86 +2671,10 @@ void MainWindow::setupReceiveTab() {
}); });
} }
void MainWindow::updateTAddrCombo(bool checked) {
if (checked) {
auto utxos = this->rpc->getModel()->getUTXOs();
// Save the current address so we can restore it later
auto currentTaddr = ui->listReceiveAddresses->currentText();
ui->listReceiveAddresses->clear();
// Maintain a set of addresses so we don't duplicate any, because we'll be adding
// t addresses multiple times
QSet<QString> addrs;
// 1. Add all t addresses that have a balance
std::for_each(utxos.begin(), utxos.end(), [=, &addrs](auto& utxo) {
auto addr = utxo.address;
if (Settings::isTAddress(addr) && !addrs.contains(addr)) {
auto bal = rpc->getModel()->getAllBalances().value(addr);
ui->listReceiveAddresses->addItem(addr, bal);
addrs.insert(addr);
}
});
// 2. Add all t addresses that have a label
auto allTaddrs = this->rpc->getModel()->getAllTAddresses();
QSet<QString> labels;
for (auto p : AddressBook::getInstance()->getAllAddressLabels()) {
labels.insert(p.getPartnerAddress());
}
std::for_each(allTaddrs.begin(), allTaddrs.end(), [=, &addrs] (auto& taddr) {
// If the address is in the address book, add it.
if (labels.contains(taddr) && !addrs.contains(taddr)) {
addrs.insert(taddr);
ui->listReceiveAddresses->addItem(taddr, CAmount::fromqint64(0));
}
});
// 3. Add all t-addresses. We won't add more than 20 total t-addresses,
// since it will overwhelm the dropdown
for (int i=0; addrs.size() < 20 && i < allTaddrs.size(); i++) {
auto addr = allTaddrs.at(i);
if (!addrs.contains(addr)) {
addrs.insert(addr);
// Balance is zero since it has not been previously added
ui->listReceiveAddresses->addItem(addr, CAmount::fromqint64(0));
}
}
// 4. Add the previously selected t-address
if (!currentTaddr.isEmpty() && Settings::isTAddress(currentTaddr)) {
// Make sure the current taddr is in the list
if (!addrs.contains(currentTaddr)) {
auto bal = rpc->getModel()->getAllBalances().value(currentTaddr);
ui->listReceiveAddresses->addItem(currentTaddr, bal);
}
ui->listReceiveAddresses->setCurrentText(currentTaddr);
}
// 5. Add a last, disabled item if there are remaining items
if (allTaddrs.size() > addrs.size()) {
auto num = QString::number(allTaddrs.size() - addrs.size());
ui->listReceiveAddresses->addItem("-- " + num + " more --", CAmount::fromqint64(0));
QStandardItemModel* model = qobject_cast<QStandardItemModel*>(ui->listReceiveAddresses->model());
QStandardItem* item = model->findItems("--", Qt::MatchStartsWith)[0];
item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
}
}
};
// Updates the labels everywhere on the UI. Call this after the labels have been updated // Updates the labels everywhere on the UI. Call this after the labels have been updated
void MainWindow::updateLabels() { void MainWindow::updateLabels() {
// Update the Receive tab // Update the Receive tab
if (ui->rdioTAddr->isChecked()) { addZAddrsToComboList(ui->rdioZSAddr->isChecked())(true);
updateTAddrCombo(true);
}
else {
addZAddrsToComboList(ui->rdioZSAddr->isChecked())(true);
}
// Update the autocomplete // Update the autocomplete
updateLabelsAutoComplete(); updateLabelsAutoComplete();

30
src/mainwindow.ui

@ -59,7 +59,7 @@
<item row="0" column="0" colspan="2"> <item row="0" column="0" colspan="2">
<widget class="QTabWidget" name="tabWidget"> <widget class="QTabWidget" name="tabWidget">
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>3</number>
</property> </property>
<widget class="QWidget" name="tab_6"> <widget class="QWidget" name="tab_6">
<attribute name="title"> <attribute name="title">
@ -956,8 +956,8 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1260</width> <width>1268</width>
<height>509</height> <height>519</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="sendToLayout"> <layout class="QVBoxLayout" name="sendToLayout">
@ -1262,21 +1262,14 @@
<layout class="QHBoxLayout" name="horizontalLayout_9"> <layout class="QHBoxLayout" name="horizontalLayout_9">
<item> <item>
<widget class="QRadioButton" name="rdioZSAddr"> <widget class="QRadioButton" name="rdioZSAddr">
<property name="enabled">
<bool>true</bool>
</property>
<property name="text"> <property name="text">
<string>z-Addr</string> <string>z-Addr</string>
</property> </property>
</widget> <property name="checked">
</item> <bool>false</bool>
<item>
<widget class="QRadioButton" name="rdioTAddr">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>t-Addr</string>
</property> </property>
</widget> </widget>
</item> </item>
@ -1682,7 +1675,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="9" column="0"> <item row="9" column="0">
<widget class="QLabel" name="label_37"> <widget class="QLabel" name="label_37">
<property name="text"> <property name="text">
@ -1690,7 +1682,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="10" column="0"> <item row="10" column="0">
<widget class="QLabel" name="current_server_label"> <widget class="QLabel" name="current_server_label">
<property name="text"> <property name="text">
@ -1712,7 +1703,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="11" column="0"> <item row="11" column="0">
<widget class="QLabel" name="sticky_server_label"> <widget class="QLabel" name="sticky_server_label">
<property name="text"> <property name="text">
@ -1734,7 +1724,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="1"> <item row="3" column="1">
<widget class="QLabel" name="label_13"> <widget class="QLabel" name="label_13">
<property name="text"> <property name="text">
@ -1921,7 +1910,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>1308</width> <width>1308</width>
<height>22</height> <height>30</height>
</rect> </rect>
</property> </property>
<widget class="QMenu" name="menuFile"> <widget class="QMenu" name="menuFile">
@ -2118,7 +2107,6 @@
<tabstop>sendTransactionButton</tabstop> <tabstop>sendTransactionButton</tabstop>
<tabstop>cancelSendButton</tabstop> <tabstop>cancelSendButton</tabstop>
<tabstop>rdioZSAddr</tabstop> <tabstop>rdioZSAddr</tabstop>
<tabstop>rdioTAddr</tabstop>
<tabstop>listReceiveAddresses</tabstop> <tabstop>listReceiveAddresses</tabstop>
<tabstop>txtReceive</tabstop> <tabstop>txtReceive</tabstop>
<tabstop>rcvLabel</tabstop> <tabstop>rcvLabel</tabstop>

Loading…
Cancel
Save