Fix T-addresses not showing up in dropdown (#169)
* Add upto 20 addresses to the taddr dropdown * View All Addresses dialog box * Add balances to view all addresses * Add export all keys * Add translations + copy address
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
#include "addressbook.h"
|
#include "addressbook.h"
|
||||||
|
#include "viewalladdresses.h"
|
||||||
#include "ui_mainwindow.h"
|
#include "ui_mainwindow.h"
|
||||||
#include "ui_mobileappconnector.h"
|
#include "ui_mobileappconnector.h"
|
||||||
#include "ui_addressbook.h"
|
#include "ui_addressbook.h"
|
||||||
@@ -9,6 +10,7 @@
|
|||||||
#include "ui_settings.h"
|
#include "ui_settings.h"
|
||||||
#include "ui_turnstile.h"
|
#include "ui_turnstile.h"
|
||||||
#include "ui_turnstileprogress.h"
|
#include "ui_turnstileprogress.h"
|
||||||
|
#include "ui_viewalladdresses.h"
|
||||||
#include "rpc.h"
|
#include "rpc.h"
|
||||||
#include "balancestablemodel.h"
|
#include "balancestablemodel.h"
|
||||||
#include "settings.h"
|
#include "settings.h"
|
||||||
@@ -425,15 +427,15 @@ void MainWindow::setupStatusBar() {
|
|||||||
|
|
||||||
if (!msg.isEmpty() && msg.startsWith(Settings::txidStatusMessage)) {
|
if (!msg.isEmpty() && msg.startsWith(Settings::txidStatusMessage)) {
|
||||||
auto txid = msg.split(":")[1].trimmed();
|
auto txid = msg.split(":")[1].trimmed();
|
||||||
menu.addAction("Copy txid", [=]() {
|
menu.addAction(tr("Copy txid"), [=]() {
|
||||||
QGuiApplication::clipboard()->setText(txid);
|
QGuiApplication::clipboard()->setText(txid);
|
||||||
});
|
});
|
||||||
menu.addAction("View tx on block explorer", [=]() {
|
menu.addAction(tr("View tx on block explorer"), [=]() {
|
||||||
Settings::openTxInExplorer(txid);
|
Settings::openTxInExplorer(txid);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
menu.addAction("Refresh", [=]() {
|
menu.addAction(tr("Refresh"), [=]() {
|
||||||
rpc->refresh(true);
|
rpc->refresh(true);
|
||||||
});
|
});
|
||||||
QPoint gpos(mapToGlobal(pos).x(), mapToGlobal(pos).y() + this->height() - ui->statusBar->height());
|
QPoint gpos(mapToGlobal(pos).x(), mapToGlobal(pos).y() + this->height() - ui->statusBar->height());
|
||||||
@@ -980,7 +982,7 @@ void MainWindow::exportKeys(QString addr) {
|
|||||||
|
|
||||||
Settings::saveRestore(&d);
|
Settings::saveRestore(&d);
|
||||||
|
|
||||||
pui.privKeyTxt->setPlainText(tr("Loading..."));
|
pui.privKeyTxt->setPlainText(tr("This might take several minutes. Loading..."));
|
||||||
pui.privKeyTxt->setReadOnly(true);
|
pui.privKeyTxt->setReadOnly(true);
|
||||||
pui.privKeyTxt->setLineWrapMode(QPlainTextEdit::LineWrapMode::NoWrap);
|
pui.privKeyTxt->setLineWrapMode(QPlainTextEdit::LineWrapMode::NoWrap);
|
||||||
|
|
||||||
@@ -1306,7 +1308,45 @@ void MainWindow::setupReceiveTab() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// View all addresses goes to "View all private keys"
|
// View all addresses goes to "View all private keys"
|
||||||
QObject::connect(ui->btnViewAllAddresses, &QPushButton::clicked, this, &MainWindow::exportAllKeys);
|
QObject::connect(ui->btnViewAllAddresses, &QPushButton::clicked, [=] () {
|
||||||
|
// If there's no RPC, return
|
||||||
|
if (!getRPC())
|
||||||
|
return;
|
||||||
|
|
||||||
|
QDialog d(this);
|
||||||
|
Ui_ViewAddressesDialog viewaddrs;
|
||||||
|
viewaddrs.setupUi(&d);
|
||||||
|
Settings::saveRestore(&d);
|
||||||
|
Settings::saveRestoreTableHeader(viewaddrs.tblAddresses, &d, "viewalladdressestable");
|
||||||
|
|
||||||
|
ViewAllAddressesModel model(viewaddrs.tblAddresses, *getRPC()->getAllTAddresses(), getRPC());
|
||||||
|
viewaddrs.tblAddresses->setModel(&model);
|
||||||
|
|
||||||
|
QObject::connect(viewaddrs.btnExportAll, &QPushButton::clicked, this, &MainWindow::exportAllKeys);
|
||||||
|
|
||||||
|
viewaddrs.tblAddresses->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||||
|
QObject::connect(viewaddrs.tblAddresses, &QTableView::customContextMenuRequested, [=] (QPoint pos) {
|
||||||
|
QModelIndex index = viewaddrs.tblAddresses->indexAt(pos);
|
||||||
|
if (index.row() < 0) return;
|
||||||
|
|
||||||
|
index = index.sibling(index.row(), 0);
|
||||||
|
QString addr = viewaddrs.tblAddresses->model()->data(index).toString();
|
||||||
|
|
||||||
|
QMenu menu(this);
|
||||||
|
menu.addAction(tr("Export Private Key"), [=] () {
|
||||||
|
if (addr.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
this->exportKeys(addr);
|
||||||
|
});
|
||||||
|
menu.addAction(tr("Copy Address"), [=]() {
|
||||||
|
QGuiApplication::clipboard()->setText(addr);
|
||||||
|
});
|
||||||
|
menu.exec(viewaddrs.tblAddresses->viewport()->mapToGlobal(pos));
|
||||||
|
});
|
||||||
|
|
||||||
|
d.exec();
|
||||||
|
});
|
||||||
|
|
||||||
QObject::connect(ui->rdioZSAddr, &QRadioButton::toggled, addZAddrsToComboList(true));
|
QObject::connect(ui->rdioZSAddr, &QRadioButton::toggled, addZAddrsToComboList(true));
|
||||||
|
|
||||||
@@ -1423,9 +1463,11 @@ void MainWindow::updateTAddrCombo(bool checked) {
|
|||||||
auto utxos = this->rpc->getUTXOs();
|
auto utxos = this->rpc->getUTXOs();
|
||||||
ui->listReceiveAddresses->clear();
|
ui->listReceiveAddresses->clear();
|
||||||
|
|
||||||
// Maintain a set of addresses so we don't duplicate any.
|
// Maintain a set of addresses so we don't duplicate any, because we'll be adding
|
||||||
|
// t addresses multiple times
|
||||||
QSet<QString> addrs;
|
QSet<QString> addrs;
|
||||||
|
|
||||||
|
// 1. Add all t addresses that have a balance
|
||||||
std::for_each(utxos->begin(), utxos->end(), [=, &addrs](auto& utxo) {
|
std::for_each(utxos->begin(), utxos->end(), [=, &addrs](auto& utxo) {
|
||||||
auto addr = utxo.address;
|
auto addr = utxo.address;
|
||||||
if (Settings::isTAddress(addr) && !addrs.contains(addr)) {
|
if (Settings::isTAddress(addr) && !addrs.contains(addr)) {
|
||||||
@@ -1436,17 +1478,30 @@ void MainWindow::updateTAddrCombo(bool checked) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 2. Add all t addresses that have a label
|
||||||
auto allTaddrs = this->rpc->getAllTAddresses();
|
auto allTaddrs = this->rpc->getAllTAddresses();
|
||||||
QSet<QString> labels;
|
QSet<QString> labels;
|
||||||
for (auto p : AddressBook::getInstance()->getAllAddressLabels()) {
|
for (auto p : AddressBook::getInstance()->getAllAddressLabels()) {
|
||||||
labels.insert(p.second);
|
labels.insert(p.second);
|
||||||
}
|
}
|
||||||
std::for_each(allTaddrs->begin(), allTaddrs->end(), [=] (auto& taddr) {
|
std::for_each(allTaddrs->begin(), allTaddrs->end(), [=, &addrs] (auto& taddr) {
|
||||||
// If the address is in the address book, add it.
|
// If the address is in the address book, add it.
|
||||||
if (labels.contains(taddr) && !addrs.contains(taddr)) {
|
if (labels.contains(taddr) && !addrs.contains(taddr)) {
|
||||||
|
addrs.insert(taddr);
|
||||||
ui->listReceiveAddresses->addItem(taddr, 0);
|
ui->listReceiveAddresses->addItem(taddr, 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, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -176,6 +176,14 @@ void Settings::saveRestore(QDialog* d) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Settings::saveRestoreTableHeader(QTableView* table, QDialog* d, QString tablename) {
|
||||||
|
table->horizontalHeader()->restoreState(QSettings().value(tablename).toByteArray());
|
||||||
|
|
||||||
|
QObject::connect(d, &QDialog::finished, [=](auto) {
|
||||||
|
QSettings().setValue(tablename, table->horizontalHeader()->saveState());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void Settings::openAddressInExplorer(QString address) {
|
void Settings::openAddressInExplorer(QString address) {
|
||||||
QString url;
|
QString url;
|
||||||
if (Settings::getInstance()->isTestnet()) {
|
if (Settings::getInstance()->isTestnet()) {
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ public:
|
|||||||
static const QString txidStatusMessage;
|
static const QString txidStatusMessage;
|
||||||
|
|
||||||
static void saveRestore(QDialog* d);
|
static void saveRestore(QDialog* d);
|
||||||
|
static void saveRestoreTableHeader(QTableView* table, QDialog* d, QString tablename) ;
|
||||||
|
|
||||||
static void openAddressInExplorer(QString address);
|
static void openAddressInExplorer(QString address);
|
||||||
static void openTxInExplorer(QString txid);
|
static void openTxInExplorer(QString txid);
|
||||||
|
|||||||
38
src/viewalladdresses.cpp
Normal file
38
src/viewalladdresses.cpp
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
#include "viewalladdresses.h"
|
||||||
|
#include "settings.h"
|
||||||
|
|
||||||
|
ViewAllAddressesModel::ViewAllAddressesModel(QTableView *parent, QList<QString> taddrs, RPC* rpc)
|
||||||
|
: QAbstractTableModel(parent) {
|
||||||
|
headers << tr("Address") << tr("Balance (%1)").arg(Settings::getTokenName());
|
||||||
|
addresses = taddrs;
|
||||||
|
this->rpc = rpc;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int ViewAllAddressesModel::rowCount(const QModelIndex&) const {
|
||||||
|
return addresses.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
int ViewAllAddressesModel::columnCount(const QModelIndex&) const {
|
||||||
|
return headers.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant ViewAllAddressesModel::data(const QModelIndex &index, int role) const {
|
||||||
|
QString address = addresses.at(index.row());
|
||||||
|
if (role == Qt::DisplayRole) {
|
||||||
|
switch(index.column()) {
|
||||||
|
case 0: return address;
|
||||||
|
case 1: return rpc->getAllBalances()->value(address, 0.0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
QVariant ViewAllAddressesModel::headerData(int section, Qt::Orientation orientation, int role) const {
|
||||||
|
if (role == Qt::DisplayRole && orientation == Qt::Horizontal) {
|
||||||
|
return headers.at(section);
|
||||||
|
}
|
||||||
|
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
24
src/viewalladdresses.h
Normal file
24
src/viewalladdresses.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#ifndef VIEWALLADDRESSES_H
|
||||||
|
#define VIEWALLADDRESSES_H
|
||||||
|
|
||||||
|
#include "precompiled.h"
|
||||||
|
#include "rpc.h"
|
||||||
|
|
||||||
|
class ViewAllAddressesModel : public QAbstractTableModel {
|
||||||
|
|
||||||
|
public:
|
||||||
|
ViewAllAddressesModel(QTableView* parent, QList<QString> taddrs, RPC* rpc);
|
||||||
|
~ViewAllAddressesModel() = default;
|
||||||
|
|
||||||
|
int rowCount(const QModelIndex &parent) const;
|
||||||
|
int columnCount(const QModelIndex &parent) const;
|
||||||
|
QVariant data(const QModelIndex &index, int role) const;
|
||||||
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<QString> addresses;
|
||||||
|
QStringList headers;
|
||||||
|
RPC* rpc;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
81
src/viewalladdresses.ui
Normal file
81
src/viewalladdresses.ui
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>ViewAddressesDialog</class>
|
||||||
|
<widget class="QDialog" name="ViewAddressesDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>400</width>
|
||||||
|
<height>300</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>All Addresses</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QPushButton" name="btnExportAll">
|
||||||
|
<property name="text">
|
||||||
|
<string>Export All Keys</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="0" colspan="2">
|
||||||
|
<widget class="QTableView" name="tblAddresses">
|
||||||
|
<property name="selectionMode">
|
||||||
|
<enum>QAbstractItemView::SingleSelection</enum>
|
||||||
|
</property>
|
||||||
|
<attribute name="horizontalHeaderStretchLastSection">
|
||||||
|
<bool>true</bool>
|
||||||
|
</attribute>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>ViewAddressesDialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>248</x>
|
||||||
|
<y>254</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>157</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>ViewAddressesDialog</receiver>
|
||||||
|
<slot>reject()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>316</x>
|
||||||
|
<y>260</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>286</x>
|
||||||
|
<y>274</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
||||||
@@ -57,7 +57,8 @@ SOURCES += \
|
|||||||
src/mobileappconnector.cpp \
|
src/mobileappconnector.cpp \
|
||||||
src/recurring.cpp \
|
src/recurring.cpp \
|
||||||
src/requestdialog.cpp \
|
src/requestdialog.cpp \
|
||||||
src/memoedit.cpp
|
src/memoedit.cpp \
|
||||||
|
src/viewalladdresses.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
src/mainwindow.h \
|
src/mainwindow.h \
|
||||||
@@ -82,7 +83,8 @@ HEADERS += \
|
|||||||
src/mobileappconnector.h \
|
src/mobileappconnector.h \
|
||||||
src/recurring.h \
|
src/recurring.h \
|
||||||
src/requestdialog.h \
|
src/requestdialog.h \
|
||||||
src/memoedit.h
|
src/memoedit.h \
|
||||||
|
src/viewalladdresses.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
src/mainwindow.ui \
|
src/mainwindow.ui \
|
||||||
@@ -95,6 +97,7 @@ FORMS += \
|
|||||||
src/turnstileprogress.ui \
|
src/turnstileprogress.ui \
|
||||||
src/privkey.ui \
|
src/privkey.ui \
|
||||||
src/memodialog.ui \
|
src/memodialog.ui \
|
||||||
|
src/viewalladdresses.ui \
|
||||||
src/connection.ui \
|
src/connection.ui \
|
||||||
src/zboard.ui \
|
src/zboard.ui \
|
||||||
src/addressbook.ui \
|
src/addressbook.ui \
|
||||||
|
|||||||
Reference in New Issue
Block a user