Merge branch 'recurring'
This commit is contained in:
@@ -616,17 +616,20 @@ void MainWindow::postToZBoard() {
|
||||
tx.toAddrs.push_back(ToFields{ toAddr, Settings::getZboardAmount(), memo, memo.toUtf8().toHex() });
|
||||
tx.fee = Settings::getMinerFee();
|
||||
|
||||
json params = json::array();
|
||||
rpc->fillTxJsonParams(params, tx);
|
||||
std::cout << std::setw(2) << params << std::endl;
|
||||
|
||||
// And send the Tx
|
||||
rpc->sendZTransaction(params, [=](const json& reply) {
|
||||
QString opid = QString::fromStdString(reply.get<json::string_t>());
|
||||
rpc->executeTransaction(tx, [=] (QString opid) {
|
||||
ui->statusBar->showMessage(tr("Computing Tx: ") % opid);
|
||||
},
|
||||
[=] (QString opid, QString txid) {
|
||||
ui->statusBar->showMessage(Settings::txidStatusMessage + " " + txid);
|
||||
},
|
||||
[=] (QString opid, QString errStr) {
|
||||
ui->statusBar->showMessage(QObject::tr(" Tx ") % opid % QObject::tr(" failed"), 15 * 1000);
|
||||
|
||||
// And then start monitoring the transaction
|
||||
rpc->addNewTxToWatch(tx, opid);
|
||||
if (!opid.isEmpty())
|
||||
errStr = QObject::tr("The transaction with id ") % opid % QObject::tr(" failed. The error was") + ":\n\n" + errStr;
|
||||
|
||||
QMessageBox::critical(this, QObject::tr("Transaction Error"), errStr, QMessageBox::Ok);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ public:
|
||||
~MainWindow();
|
||||
|
||||
void updateLabelsAutoComplete();
|
||||
RPC* getRPC() { return rpc; }
|
||||
|
||||
void setDefaultPayFrom();
|
||||
|
||||
@@ -76,6 +77,8 @@ private:
|
||||
void addAddressSection();
|
||||
void maxAmountChecked(int checked);
|
||||
|
||||
void editSchedule();
|
||||
|
||||
void addressChanged(int number, const QString& text);
|
||||
void amountChanged (int number, const QString& text);
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<item row="0" column="0">
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>2</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
@@ -346,8 +346,8 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>928</width>
|
||||
<height>380</height>
|
||||
<width>920</width>
|
||||
<height>301</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="sendToLayout">
|
||||
@@ -530,6 +530,50 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_17">
|
||||
<item>
|
||||
<widget class="QCheckBox" name="chkRecurring">
|
||||
<property name="text">
|
||||
<string>Recurring payment</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="lblRecurDesc">
|
||||
<property name="text">
|
||||
<string>Every month, starting 12-May-2012, for 6 payments</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="btnRecurSchedule">
|
||||
<property name="text">
|
||||
<string>Edit Schedule</string>
|
||||
</property>
|
||||
<property name="checkable">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="checked">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_7">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||
<item>
|
||||
@@ -559,6 +603,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_17">
|
||||
<property name="text">
|
||||
<string notr="true"/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
|
||||
245
src/newrecurring.ui
Normal file
245
src/newrecurring.ui
Normal file
@@ -0,0 +1,245 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>newRecurringDialog</class>
|
||||
<widget class="QDialog" name="newRecurringDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>740</width>
|
||||
<height>403</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Edit Schedule</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="5" column="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||
<item>
|
||||
<widget class="QComboBox" name="cmbSchedule"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="10" column="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="1">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Schedule</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLabel" name="label_7">
|
||||
<property name="text">
|
||||
<string>Payment Description</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="2">
|
||||
<widget class="QLabel" name="lblNextPayment">
|
||||
<property name="text">
|
||||
<string>TextLabel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="7" column="1" colspan="2">
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="txtAmt">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QComboBox" name="cmbCurrency"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_3">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLineEdit" name="txtDesc"/>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>From</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="6" column="1">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Number of payments</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLabel" name="label_6">
|
||||
<property name="text">
|
||||
<string>Amount</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="9" column="1">
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="1" column="2">
|
||||
<widget class="AddressCombo" name="cmbFromAddress"/>
|
||||
</item>
|
||||
<item row="6" column="2">
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
<item>
|
||||
<widget class="QLineEdit" name="txtNumPayments"/>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="8" column="1">
|
||||
<widget class="QLabel" name="label_8">
|
||||
<property name="text">
|
||||
<string>Next Payment</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QLineEdit" name="txtToAddr"/>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>To</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2">
|
||||
<widget class="QPlainTextEdit" name="txtMemo"/>
|
||||
</item>
|
||||
<item row="4" column="1">
|
||||
<widget class="QLabel" name="label_4">
|
||||
<property name="text">
|
||||
<string>Memo</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>AddressCombo</class>
|
||||
<extends>QComboBox</extends>
|
||||
<header>addresscombo.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>txtDesc</tabstop>
|
||||
<tabstop>cmbFromAddress</tabstop>
|
||||
<tabstop>txtToAddr</tabstop>
|
||||
<tabstop>txtAmt</tabstop>
|
||||
<tabstop>cmbCurrency</tabstop>
|
||||
<tabstop>cmbSchedule</tabstop>
|
||||
<tabstop>txtNumPayments</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>newRecurringDialog</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>newRecurringDialog</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>
|
||||
48
src/recurring.cpp
Normal file
48
src/recurring.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include "recurring.h"
|
||||
|
||||
#include "mainwindow.h"
|
||||
#include "rpc.h"
|
||||
#include "settings.h"
|
||||
#include "ui_newrecurring.h"
|
||||
|
||||
void Recurring::showEditDialog(QWidget* parent, MainWindow* main, Tx tx) {
|
||||
Ui_newRecurringDialog ui;
|
||||
QDialog d(parent);
|
||||
ui.setupUi(&d);
|
||||
Settings::saveRestore(&d);
|
||||
|
||||
// Add all the from addresses
|
||||
auto allBalances = main->getRPC()->getAllBalances();
|
||||
for (QString addr : allBalances->keys()) {
|
||||
ui.cmbFromAddress->addItem(addr, allBalances->value(addr));
|
||||
}
|
||||
|
||||
if (!tx.fromAddr.isEmpty()) {
|
||||
ui.cmbFromAddress->setCurrentText(tx.fromAddr);
|
||||
ui.cmbFromAddress->setEnabled(false);
|
||||
}
|
||||
|
||||
ui.cmbCurrency->addItem(Settings::getTokenName());
|
||||
ui.cmbCurrency->addItem("USD");
|
||||
|
||||
if (tx.toAddrs.length() > 0) {
|
||||
ui.txtToAddr->setText(tx.toAddrs[0].addr);
|
||||
ui.txtToAddr->setEnabled(false);
|
||||
|
||||
ui.txtAmt->setText(Settings::getDecimalString(tx.toAddrs[0].amount));
|
||||
ui.txtAmt->setEnabled(false);
|
||||
|
||||
ui.txtMemo->setPlainText(tx.toAddrs[0].txtMemo);
|
||||
ui.txtMemo->setEnabled(false);
|
||||
}
|
||||
|
||||
ui.cmbSchedule->addItem("Every Day", QVariant(Schedule::DAY));
|
||||
ui.cmbSchedule->addItem("Every Week", QVariant(Schedule::WEEK));
|
||||
ui.cmbSchedule->addItem("Every Month", QVariant(Schedule::MONTH));
|
||||
ui.cmbSchedule->addItem("Every Year", QVariant(Schedule::YEAR));
|
||||
|
||||
ui.txtNumPayments->setText("10");
|
||||
|
||||
ui.txtDesc->setFocus();
|
||||
d.exec();
|
||||
}
|
||||
36
src/recurring.h
Normal file
36
src/recurring.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef RECURRING_H
|
||||
#define RECURRING_H
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "mainwindow.h"
|
||||
|
||||
enum Schedule {
|
||||
DAY = 1,
|
||||
WEEK,
|
||||
MONTH,
|
||||
YEAR
|
||||
};
|
||||
|
||||
struct RecurringPaymentInfo {
|
||||
QString desc;
|
||||
QString fromAddr;
|
||||
QString toAddr;
|
||||
double amt;
|
||||
QString currency;
|
||||
Schedule schedule;
|
||||
int numPayments;
|
||||
|
||||
long startBlock;
|
||||
int completedPayments;
|
||||
};
|
||||
|
||||
class Recurring
|
||||
{
|
||||
public:
|
||||
Recurring();
|
||||
|
||||
static void showEditDialog(QWidget* parent, MainWindow* main, Tx tx);
|
||||
};
|
||||
|
||||
#endif // RECURRING_H
|
||||
92
src/recurringdialog.ui
Normal file
92
src/recurringdialog.ui
Normal file
@@ -0,0 +1,92 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>RecurringDialog</class>
|
||||
<widget class="QDialog" name="RecurringDialog">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>601</width>
|
||||
<height>438</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QTableView" name="tableView"/>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton">
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_2">
|
||||
<property name="text">
|
||||
<string>Edit</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_3">
|
||||
<property name="text">
|
||||
<string>Delete</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
<sender>buttonBox</sender>
|
||||
<signal>accepted()</signal>
|
||||
<receiver>RecurringDialog</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>RecurringDialog</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>
|
||||
74
src/rpc.cpp
74
src/rpc.cpp
@@ -213,7 +213,8 @@ void RPC::getTransactions(const std::function<void(json)>& cb) {
|
||||
conn->doRPCWithDefaultErrorHandling(payload, cb);
|
||||
}
|
||||
|
||||
void RPC::sendZTransaction(json params, const std::function<void(json)>& cb) {
|
||||
void RPC::sendZTransaction(json params, const std::function<void(json)>& cb,
|
||||
const std::function<void(QString)>& err) {
|
||||
json payload = {
|
||||
{"jsonrpc", "1.0"},
|
||||
{"id", "someid"},
|
||||
@@ -221,7 +222,13 @@ void RPC::sendZTransaction(json params, const std::function<void(json)>& cb) {
|
||||
{"params", params}
|
||||
};
|
||||
|
||||
conn->doRPCWithDefaultErrorHandling(payload, cb);
|
||||
conn->doRPC(payload, cb, [=] (auto reply, auto parsed) {
|
||||
if (!parsed.is_discarded() && !parsed["error"]["message"].is_null()) {
|
||||
err(QString::fromStdString(parsed["error"]["message"]));
|
||||
} else {
|
||||
err(reply->errorString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -529,6 +536,9 @@ void RPC::getInfoThenRefresh(bool force) {
|
||||
// Something changed, so refresh everything.
|
||||
lastBlock = curBlock;
|
||||
|
||||
// See if the turnstile migration has any steps that need to be done.
|
||||
turnstile->executeMigrationStep();
|
||||
|
||||
refreshBalances();
|
||||
refreshAddresses(); // This calls refreshZSentTransactions() and refreshReceivedZTrans()
|
||||
refreshTransactions();
|
||||
@@ -662,10 +672,7 @@ void RPC::refreshAddresses() {
|
||||
}
|
||||
|
||||
// Function to create the data model and update the views, used below.
|
||||
void RPC::updateUI(bool anyUnconfirmed) {
|
||||
// See if the turnstile migration has any steps that need to be done.
|
||||
turnstile->executeMigrationStep();
|
||||
|
||||
void RPC::updateUI(bool anyUnconfirmed) {
|
||||
ui->unconfirmedWarning->setVisible(anyUnconfirmed);
|
||||
|
||||
// Update balances model data, which will update the table too
|
||||
@@ -833,12 +840,36 @@ void RPC::refreshSentZTrans() {
|
||||
);
|
||||
}
|
||||
|
||||
void RPC::addNewTxToWatch(Tx tx, const QString& newOpid) {
|
||||
watchingOps.insert(newOpid, tx);
|
||||
void RPC::addNewTxToWatch(const QString& newOpid, WatchedTx wtx) {
|
||||
watchingOps.insert(newOpid, wtx);
|
||||
|
||||
watchTxStatus();
|
||||
}
|
||||
|
||||
|
||||
// Execute a transaction!
|
||||
void RPC::executeTransaction(Tx tx,
|
||||
const std::function<void(QString opid)> submitted,
|
||||
const std::function<void(QString opid, QString txid)> computed,
|
||||
const std::function<void(QString opid, QString errStr)> error) {
|
||||
// First, create the json params
|
||||
json params = json::array();
|
||||
fillTxJsonParams(params, tx);
|
||||
std::cout << std::setw(2) << params << std::endl;
|
||||
|
||||
sendZTransaction(params, [=](const json& reply) {
|
||||
QString opid = QString::fromStdString(reply.get<json::string_t>());
|
||||
|
||||
// And then start monitoring the transaction
|
||||
addNewTxToWatch( opid, WatchedTx { opid, tx, computed, error} );
|
||||
submitted(opid);
|
||||
},
|
||||
[=](QString errStr) {
|
||||
error("", errStr);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
void RPC::watchTxStatus() {
|
||||
if (conn == nullptr)
|
||||
return noConnection();
|
||||
@@ -858,35 +889,26 @@ void RPC::watchTxStatus() {
|
||||
if (watchingOps.contains(id)) {
|
||||
// And if it ended up successful
|
||||
QString status = QString::fromStdString(it["status"]);
|
||||
main->loadingLabel->setVisible(false);
|
||||
|
||||
if (status == "success") {
|
||||
auto txid = QString::fromStdString(it["result"]["txid"]);
|
||||
|
||||
SentTxStore::addToSentTx(watchingOps.value(id), txid);
|
||||
|
||||
main->ui->statusBar->showMessage(Settings::txidStatusMessage + " " + txid);
|
||||
main->loadingLabel->setVisible(false);
|
||||
SentTxStore::addToSentTx(watchingOps[id].tx, txid);
|
||||
|
||||
auto wtx = watchingOps[id];
|
||||
watchingOps.remove(id);
|
||||
wtx.completed(id, txid);
|
||||
|
||||
// Refresh balances to show unconfirmed balances
|
||||
refresh(true);
|
||||
refresh(true);
|
||||
} else if (status == "failed") {
|
||||
// If it failed, then we'll actually show a warning.
|
||||
auto errorMsg = QString::fromStdString(it["error"]["message"]);
|
||||
QMessageBox msg(
|
||||
QMessageBox::Critical,
|
||||
QObject::tr("Transaction Error"),
|
||||
QObject::tr("The transaction with id ") % id % QObject::tr(" failed. The error was") + ":\n\n" + errorMsg,
|
||||
QMessageBox::Ok,
|
||||
main
|
||||
);
|
||||
|
||||
watchingOps.remove(id);
|
||||
|
||||
main->ui->statusBar->showMessage(QObject::tr(" Tx ") % id % QObject::tr(" failed"), 15 * 1000);
|
||||
main->loadingLabel->setVisible(false);
|
||||
|
||||
msg.exec();
|
||||
auto wtx = watchingOps[id];
|
||||
watchingOps.remove(id);
|
||||
wtx.error(id, errorMsg);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
18
src/rpc.h
18
src/rpc.h
@@ -24,6 +24,13 @@ struct TransactionItem {
|
||||
QString memo;
|
||||
};
|
||||
|
||||
struct WatchedTx {
|
||||
QString opid;
|
||||
Tx tx;
|
||||
std::function<void(QString, QString)> completed;
|
||||
std::function<void(QString, QString)> error;
|
||||
};
|
||||
|
||||
class RPC
|
||||
{
|
||||
public:
|
||||
@@ -42,10 +49,15 @@ public:
|
||||
void refreshZECPrice();
|
||||
void getZboardTopics(std::function<void(QMap<QString, QString>)> cb);
|
||||
|
||||
void executeTransaction(Tx tx,
|
||||
const std::function<void(QString opid)> submitted,
|
||||
const std::function<void(QString opid, QString txid)> computed,
|
||||
const std::function<void(QString opid, QString errStr)> error);
|
||||
|
||||
void fillTxJsonParams(json& params, Tx tx);
|
||||
void sendZTransaction (json params, const std::function<void(json)>& cb);
|
||||
void sendZTransaction(json params, const std::function<void(json)>& cb, const std::function<void(QString)>& err);
|
||||
void watchTxStatus();
|
||||
void addNewTxToWatch(Tx tx, const QString& newOpid);
|
||||
void addNewTxToWatch(const QString& newOpid, WatchedTx wtx);
|
||||
|
||||
const TxTableModel* getTransactionsModel() { return transactionsTableModel; }
|
||||
const QList<QString>* getAllZAddresses() { return zaddresses; }
|
||||
@@ -98,7 +110,7 @@ private:
|
||||
QMap<QString, bool>* usedAddresses = nullptr;
|
||||
QList<QString>* zaddresses = nullptr;
|
||||
|
||||
QMap<QString, Tx> watchingOps;
|
||||
QMap<QString, WatchedTx> watchingOps;
|
||||
|
||||
TxTableModel* transactionsTableModel = nullptr;
|
||||
BalancesTableModel* balancesTableModel = nullptr;
|
||||
|
||||
@@ -3,8 +3,10 @@
|
||||
#include "addressbook.h"
|
||||
#include "ui_confirm.h"
|
||||
#include "ui_memodialog.h"
|
||||
#include "ui_newrecurring.h"
|
||||
#include "settings.h"
|
||||
#include "rpc.h"
|
||||
#include "recurring.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
@@ -80,6 +82,29 @@ void MainWindow::setupSendTab() {
|
||||
QFont f = ui->Address1->font();
|
||||
f.setPointSize(f.pointSize() - 1);
|
||||
ui->MemoTxt1->setFont(f);
|
||||
|
||||
// Recurring button
|
||||
QObject::connect(ui->chkRecurring, &QCheckBox::stateChanged, [=] (int checked) {
|
||||
if (checked) {
|
||||
ui->btnRecurSchedule->setEnabled(true);
|
||||
} else {
|
||||
ui->btnRecurSchedule->setEnabled(false);
|
||||
ui->lblRecurDesc->setText("");
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// Recurring schedule button
|
||||
QObject::connect(ui->btnRecurSchedule, &QPushButton::clicked, this, &MainWindow::editSchedule);
|
||||
|
||||
// Set the default state for the whole page
|
||||
removeExtraAddresses();
|
||||
}
|
||||
|
||||
void MainWindow::editSchedule() {
|
||||
// Open the edit schedule dialog
|
||||
Recurring::showEditDialog(this, this, createTxFromSendPage());
|
||||
|
||||
}
|
||||
|
||||
void MainWindow::updateLabelsAutoComplete() {
|
||||
@@ -354,6 +379,11 @@ void MainWindow::removeExtraAddresses() {
|
||||
|
||||
delete addressGroupBox;
|
||||
}
|
||||
|
||||
// Reset the recurring button
|
||||
ui->chkRecurring->setCheckState(Qt::Unchecked);
|
||||
ui->btnRecurSchedule->setEnabled(false);
|
||||
ui->lblRecurDesc->setText("");
|
||||
}
|
||||
|
||||
void MainWindow::maxAmountChecked(int checked) {
|
||||
@@ -620,18 +650,23 @@ void MainWindow::sendButton() {
|
||||
|
||||
// Show a dialog to confirm the Tx
|
||||
if (confirmTx(tx)) {
|
||||
json params = json::array();
|
||||
rpc->fillTxJsonParams(params, tx);
|
||||
std::cout << std::setw(2) << params << std::endl;
|
||||
|
||||
// And send the Tx
|
||||
rpc->sendZTransaction(params, [=](const json& reply) {
|
||||
QString opid = QString::fromStdString(reply.get<json::string_t>());
|
||||
ui->statusBar->showMessage(tr("Computing Tx: ") % opid);
|
||||
rpc->executeTransaction(tx,
|
||||
[=] (QString opid) {
|
||||
ui->statusBar->showMessage(tr("Computing Tx: ") % opid);
|
||||
},
|
||||
[=] (QString opid, QString txid) {
|
||||
ui->statusBar->showMessage(Settings::txidStatusMessage + " " + txid);
|
||||
},
|
||||
[=] (QString opid, QString errStr) {
|
||||
ui->statusBar->showMessage(QObject::tr(" Tx ") % opid % QObject::tr(" failed"), 15 * 1000);
|
||||
|
||||
// And then start monitoring the transaction
|
||||
rpc->addNewTxToWatch(tx, opid);
|
||||
});
|
||||
if (!opid.isEmpty())
|
||||
errStr = QObject::tr("The transaction with id ") % opid % QObject::tr(" failed. The error was") + ":\n\n" + errStr;
|
||||
|
||||
QMessageBox::critical(this, QObject::tr("Transaction Error"), errStr, QMessageBox::Ok);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -351,17 +351,19 @@ void Turnstile::executeMigrationStep() {
|
||||
}
|
||||
|
||||
void Turnstile::doSendTx(Tx tx, std::function<void(void)> cb) {
|
||||
json params = json::array();
|
||||
rpc->fillTxJsonParams(params, tx);
|
||||
std::cout << std::setw(2) << params << std::endl;
|
||||
rpc->sendZTransaction(params, [=] (const json& reply) {
|
||||
QString opid = QString::fromStdString(reply.get<json::string_t>());
|
||||
//qDebug() << opid;
|
||||
mainwindow->ui->statusBar->showMessage(QObject::tr("Computing Tx: ") % opid);
|
||||
rpc->executeTransaction(tx, [=] (QString opid) {
|
||||
mainwindow->ui->statusBar->showMessage(QObject::tr("Computing Tx: ") % opid);
|
||||
},
|
||||
[=] (QString opid, QString txid) {
|
||||
mainwindow->ui->statusBar->showMessage(Settings::txidStatusMessage + " " + txid);
|
||||
},
|
||||
[=] (QString opid, QString errStr) {
|
||||
mainwindow->ui->statusBar->showMessage(QObject::tr(" Tx ") % opid % QObject::tr(" failed"), 15 * 1000);
|
||||
|
||||
// And then start monitoring the transaction
|
||||
rpc->addNewTxToWatch(tx, opid);
|
||||
if (!opid.isEmpty())
|
||||
errStr = QObject::tr("The transaction with id ") % opid % QObject::tr(" failed. The error was") + ":\n\n" + errStr;
|
||||
|
||||
cb();
|
||||
});
|
||||
QMessageBox::critical(mainwindow, QObject::tr("Transaction Error"), errStr, QMessageBox::Ok);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@@ -51,7 +51,8 @@ SOURCES += \
|
||||
src/fillediconlabel.cpp \
|
||||
src/addressbook.cpp \
|
||||
src/logger.cpp \
|
||||
src/addresscombo.cpp
|
||||
src/addresscombo.cpp \
|
||||
src/recurring.cpp
|
||||
|
||||
HEADERS += \
|
||||
src/mainwindow.h \
|
||||
@@ -71,7 +72,8 @@ HEADERS += \
|
||||
src/fillediconlabel.h \
|
||||
src/addressbook.h \
|
||||
src/logger.h \
|
||||
src/addresscombo.h
|
||||
src/addresscombo.h \
|
||||
src/recurring.h
|
||||
|
||||
FORMS += \
|
||||
src/mainwindow.ui \
|
||||
@@ -85,7 +87,9 @@ FORMS += \
|
||||
src/connection.ui \
|
||||
src/zboard.ui \
|
||||
src/addressbook.ui \
|
||||
src/createzcashconfdialog.ui
|
||||
src/createzcashconfdialog.ui \
|
||||
src/recurringdialog.ui \
|
||||
src/newrecurring.ui
|
||||
|
||||
|
||||
TRANSLATIONS = res/zec_qt_wallet_es.ts \
|
||||
|
||||
Reference in New Issue
Block a user