From 3b43a57f3575c9d507aa77be07b22f0315b633aa Mon Sep 17 00:00:00 2001 From: adityapk00 Date: Sat, 10 Nov 2018 11:51:30 -0800 Subject: [PATCH] - Show no connection if zcashd connection fails - Double click on balances table --- src/mainwindow.cpp | 33 +++++++++++++++++++++++---------- src/rpc.cpp | 11 ++++++++--- 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 0765751..d6b6fbc 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -671,6 +671,28 @@ void MainWindow::exportAllKeys() { void MainWindow::setupBalancesTab() { ui->unconfirmedWarning->setVisible(false); + // Double click on balances table + auto fnDoSendFrom = [=](const QString& addr) { + // Find the inputs combo + for (int i = 0; i < ui->inputsCombo->count(); i++) { + if (ui->inputsCombo->itemText(i).startsWith(addr)) { + ui->inputsCombo->setCurrentIndex(i); + break; + } + } + + // And switch to the send tab. + ui->tabWidget->setCurrentIndex(1); + }; + + // Double click opens up memo if one exists + QObject::connect(ui->balancesTable, &QTableView::doubleClicked, [=](auto index) { + index = index.sibling(index.row(), 0); + auto addr = ui->balancesTable->model()->data(index).toString(); + + fnDoSendFrom(addr); + }); + // Setup context menu on balances tab ui->balancesTable->setContextMenuPolicy(Qt::CustomContextMenu); QObject::connect(ui->balancesTable, &QTableView::customContextMenuRequested, [=] (QPoint pos) { @@ -712,16 +734,7 @@ void MainWindow::setupBalancesTab() { }); menu.addAction("Send from " % addr.left(40) % (addr.size() > 40 ? "..." : ""), [=]() { - // Find the inputs combo - for (int i = 0; i < ui->inputsCombo->count(); i++) { - if (ui->inputsCombo->itemText(i).startsWith(addr)) { - ui->inputsCombo->setCurrentIndex(i); - break; - } - } - - // And switch to the send tab. - ui->tabWidget->setCurrentIndex(1); + fnDoSendFrom(addr); }); if (addr.startsWith("t")) { diff --git a/src/rpc.cpp b/src/rpc.cpp index b664b6d..b89bc47 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -10,7 +10,7 @@ RPC::RPC(MainWindow* main) { auto cl = new ConnectionLoader(main, this); // Execute the load connection async, so we can set up the rest of RPC properly. - QTimer::singleShot(1, [=]() {cl->loadConnection(); }); + QTimer::singleShot(1, [=]() { cl->loadConnection(); }); this->main = main; this->ui = main->ui; @@ -463,7 +463,7 @@ void RPC::getInfoThenRefresh(bool force) { {"method", "getinfo"} }; - conn->doRPCIgnoreError(payload, [=] (const json& reply) { + conn->doRPC(payload, [=] (const json& reply) { // Testnet? if (!reply["testnet"].is_null()) { Settings::getInstance()->setTestnet(reply["testnet"].get()); @@ -549,7 +549,12 @@ void RPC::getInfoThenRefresh(bool force) { main->statusIcon->setToolTip(tooltip); }); - }); + }, [=](QNetworkReply* reply, const json& replyJson) { + // zcashd has probably disappeared. + this->noConnection(); + QMessageBox::critical(main, "Connection Error", "There was an error connecting to zcashd. The error was: \n\n" + + reply->errorString(), QMessageBox::StandardButton::Ok); + }); } void RPC::refreshAddresses() {