update sendTab

This commit is contained in:
DenioD
2019-10-28 10:26:04 +01:00
6 changed files with 71 additions and 37 deletions

View File

@@ -144,8 +144,6 @@ void Controller::getInfoThenRefresh(bool force) {
static bool prevCallSucceeded = false;
zrpc->fetchInfo([=] (const json& reply) {
qDebug() << "Info updated";
prevCallSucceeded = true;
// Testnet?
@@ -159,11 +157,13 @@ void Controller::getInfoThenRefresh(bool force) {
if (!Settings::getInstance()->isTestnet())
main->disableRecurring();
static int lastBlock = 0;
int curBlock = reply["latest_block_height"].get<json::number_integer_t>();
bool doUpdate = force || (model->getLatestBlock() != curBlock);
model->setLatestBlock(curBlock);
ui->blockHeight->setText(QString::number(curBlock));
qDebug() << "Refreshing. Full update: " << doUpdate;
// Connected, so display checkmark.
auto tooltip = Settings::getInstance()->getSettings().server + "\n" + QString::fromStdString(reply.dump());
QIcon i(":/icons/res/connected.gif");
@@ -185,10 +185,8 @@ void Controller::getInfoThenRefresh(bool force) {
// See if recurring payments needs anything
Recurring::getInstance()->processPending(main);
if ( force || (curBlock != lastBlock) ) {
if ( doUpdate ) {
// Something changed, so refresh everything.
lastBlock = curBlock;
refreshBalances();
refreshAddresses(); // This calls refreshZSentTransactions() and refreshReceivedZTrans()
refreshTransactions();
@@ -347,6 +345,16 @@ void Controller::refreshTransactions() {
CAmount total_amount;
QList<TransactionItemDetail> items;
long confirmations;
if (it.find("unconfirmed") != it.end() && it["unconfirmed"].get<json::boolean_t>()) {
confirmations = 0;
} else {
confirmations = model->getLatestBlock() - it["block_height"].get<json::number_integer_t>() + 1;
}
auto txid = QString::fromStdString(it["txid"]);
auto datetime = it["datetime"].get<json::number_integer_t>();
// First, check if there's outgoing metadata
if (!it["outgoing_metadata"].is_null()) {
@@ -375,12 +383,7 @@ void Controller::refreshTransactions() {
}
txdata.push_back(TransactionItem{
"Sent",
it["datetime"].get<json::number_integer_t>(),
address,
QString::fromStdString(it["txid"]),
model->getLatestBlock() - it["block_height"].get<json::number_integer_t>(),
items
"Sent", datetime, address, txid,confirmations, items
});
} else {
// Incoming Transaction
@@ -400,12 +403,7 @@ void Controller::refreshTransactions() {
TransactionItem tx{
"Receive",
it["datetime"].get<json::number_integer_t>(),
address,
QString::fromStdString(it["txid"]),
model->getLatestBlock() - it["block_height"].get<json::number_integer_t>() + 1,
items
"Receive", datetime, address, txid,confirmations, items
};
txdata.push_back(tx);

View File

@@ -179,13 +179,19 @@ void MainWindow::restoreSavedStates() {
QSettings s;
restoreGeometry(s.value("geometry").toByteArray());
ui->balancesTable->horizontalHeader()->restoreState(s.value("baltablegeometry").toByteArray());
ui->transactionsTable->horizontalHeader()->restoreState(s.value("tratablegeometry").toByteArray());
auto balance_geom = s.value("baltablegeom");
if (balance_geom == QVariant()) {
ui->balancesTable->setColumnWidth(0, 500);
} else {
ui->balancesTable->horizontalHeader()->restoreState(balance_geom.toByteArray());
}
// Explicitly set the tx table resize headers, since some previous values may have made them
// non-expandable.
ui->transactionsTable->horizontalHeader()->setSectionResizeMode(3, QHeaderView::Interactive);
ui->transactionsTable->horizontalHeader()->setSectionResizeMode(4, QHeaderView::Interactive);
auto tx_geom = s.value("tratablegeom");
if (tx_geom == QVariant()) {
ui->transactionsTable->setColumnWidth(1, 500);
} else {
ui->transactionsTable->horizontalHeader()->restoreState(tx_geom.toByteArray());
}
}
void MainWindow::doClose() {
@@ -196,8 +202,8 @@ void MainWindow::closeEvent(QCloseEvent* event) {
QSettings s;
s.setValue("geometry", saveGeometry());
s.setValue("baltablegeometry", ui->balancesTable->horizontalHeader()->saveState());
s.setValue("tratablegeometry", ui->transactionsTable->horizontalHeader()->saveState());
s.setValue("baltablegeom", ui->balancesTable->horizontalHeader()->saveState());
s.setValue("tratablegeom", ui->transactionsTable->horizontalHeader()->saveState());
s.sync();

View File

@@ -22,7 +22,7 @@
<item row="0" column="0">
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>1</number>
<number>3</number>
</property>
<widget class="QWidget" name="tab">
<attribute name="title">
@@ -392,8 +392,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>1226</width>
<height>504</height>
<width>1162</width>
<height>344</height>
</rect>
</property>
<layout class="QVBoxLayout" name="sendToLayout">
@@ -932,6 +932,9 @@
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
</widget>
</item>
</layout>
@@ -1085,7 +1088,7 @@
<x>0</x>
<y>0</y>
<width>1274</width>
<height>22</height>
<height>39</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">

View File

@@ -489,8 +489,6 @@ bool MainWindow::confirmTx(Tx tx, RecurringPaymentInfo* rpi) {
confirm.setupUi(&d);
Settings::saveRestore(&d);
const QFont fixedFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
// Remove all existing address/amt qlabels on the confirm dialog.
int totalConfirmAddrItems = confirm.sendToAddrs->children().size();
for (int i = 0; i < totalConfirmAddrItems / 3; i++) {
@@ -526,7 +524,6 @@ bool MainWindow::confirmTx(Tx tx, RecurringPaymentInfo* rpi) {
Addr->setObjectName(QString("Addr") % QString::number(i + 1));
Addr->setWordWrap(true);
Addr->setText(fnSplitAddressForWrap(toAddr.addr));
Addr->setFont(fixedFont);
confirm.gridLayout->addWidget(Addr, row, 0, 1, 1);
// Amount (hush)
@@ -646,11 +643,36 @@ void MainWindow::sendButton() {
// Then delete the additional fields from the sendTo tab
clearSendForm();
// Create a new Dialog to show that we are computing/sending the Tx
auto d = new QDialog(this);
auto connD = new Ui_ConnectionDialog();
connD->setupUi(d);
QPixmap logo(":/img/res/logobig.gif");
connD->topIcon->setBasePixmap(logo.scaled(256, 256, Qt::KeepAspectRatio, Qt::SmoothTransformation));
connD->status->setText(tr("Please wait..."));
connD->statusDetail->setText(tr("Computing your transaction"));
d->show();
// And send the Tx
rpc->executeTransaction(tx,
[=] (QString txid) {
ui->statusBar->showMessage(Settings::txidStatusMessage + " " + txid);
connD->status->setText(tr("Done!"));
connD->statusDetail->setText(txid);
QTimer::singleShot(1000, [=]() {
d->accept();
d->close();
delete connD;
delete d;
});
// Force a UI update so we get the unconfirmed Tx
rpc->refresh(true);
// If this was a recurring payment, update the payment with the info
if (!recurringPaymentHash.isEmpty()) {
// Since this is the send button payment, this is the first payment
@@ -661,6 +683,11 @@ void MainWindow::sendButton() {
// Errored out
[=] (QString opid, QString errStr) {
ui->statusBar->showMessage(QObject::tr(" Tx ") % opid % QObject::tr(" failed"), 15 * 1000);
d->accept();
d->close();
delete connD;
delete d;
if (!opid.isEmpty())
errStr = QObject::tr("The transaction with id ") % opid % QObject::tr(" failed. The error was") + ":\n\n" + errStr;