diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index aff366c..2c41619 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1,5 +1,6 @@ #include "mainwindow.h" #include "ui_mainwindow.h" +#include "ui_zboard.h" #include "ui_privkey.h" #include "ui_about.h" #include "ui_settings.h" @@ -46,6 +47,9 @@ MainWindow::MainWindow(QWidget *parent) : // Export All Private Keys QObject::connect(ui->actionExport_All_Private_Keys, &QAction::triggered, this, &MainWindow::exportAllKeys); + // z-Board.net + QObject::connect(ui->actionz_board_net, &QAction::triggered, this, &MainWindow::postToZBoard); + // Set up about action QObject::connect(ui->actionAbout, &QAction::triggered, [=] () { QDialog aboutDialog(this); @@ -417,6 +421,59 @@ void MainWindow::donate() { ui->tabWidget->setCurrentIndex(1); } +void MainWindow::postToZBoard() { + QDialog d(this); + Ui_zboard zb; + zb.setupUi(&d); + + // Fill the from field with sapling addresses. + for (auto i = rpc->getAllBalances()->keyBegin(); i != rpc->getAllBalances()->keyEnd(); i++) { + if (Settings::getInstance()->isSaplingAddress(*i) && rpc->getAllBalances()->value(*i) > 0) { + zb.fromAddr->addItem(*i); + } + } + + // Testnet warning + if (Settings::getInstance()->isTestnet()) { + zb.testnetWarning->setText("You are on testnet, your post won't actually appear on z-board.net"); + } + else { + zb.testnetWarning->setText(""); + } + + zb.feeAmount->setText(Settings::getInstance()->getZECUSDDisplayFormat(Utils::getZboardAmount() + Utils::getMinerFee())); + if (d.exec() == QDialog::Accepted) { + // Create a transaction. + Tx tx; + + // Send from your first sapling address that has a balance. + tx.fromAddr = zb.fromAddr->currentText(); + if (tx.fromAddr.isEmpty()) { + QMessageBox::critical(this, "Error Posting Message", "You need a sapling address with available balance to post", QMessageBox::Ok); + } + + auto memo = zb.memoTxt->toPlainText().trimmed(); + if (!zb.postAs->text().trimmed().isEmpty()) + memo = "Name::" + zb.postAs->text().trimmed() + " " + memo; + + tx.toAddrs.push_back(ToFields{ Utils::getZboardAddr(), Utils::getZboardAmount(), memo, memo.toUtf8().toHex() }); + tx.fee = Utils::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()); + ui->statusBar->showMessage("Computing Tx: " % opid); + + // And then start monitoring the transaction + rpc->addNewTxToWatch(tx, opid); + }); + } +} + void MainWindow::doImport(QList* keys) { qDebug() << keys->size(); if (keys->isEmpty()) { diff --git a/src/mainwindow.h b/src/mainwindow.h index a7a6871..d1abc5d 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -81,6 +81,7 @@ private: QString doSendTxValidations(Tx tx); void donate(); + void postToZBoard(); void importPrivKey(); void exportAllKeys(); void doImport(QList* keys); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index cda1018..2febbd1 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -316,8 +316,8 @@ 0 0 - 841 - 321 + 843 + 363 @@ -718,7 +718,7 @@ 0 0 889 - 22 + 21 @@ -727,7 +727,6 @@ - @@ -740,7 +739,15 @@ + + + Apps + + + + + @@ -787,6 +794,11 @@ Export All Private Keys + + + z-board.net + + diff --git a/src/memodialog.ui b/src/memodialog.ui index e659854..f34dc6a 100644 --- a/src/memodialog.ui +++ b/src/memodialog.ui @@ -11,7 +11,7 @@ - Dialog + Memo diff --git a/src/sendtab.cpp b/src/sendtab.cpp index 0471d12..61ceabd 100644 --- a/src/sendtab.cpp +++ b/src/sendtab.cpp @@ -245,7 +245,17 @@ void MainWindow::memoButtonClicked(int number) { QString txt = memoDialog.memoTxt->toPlainText(); memoDialog.memoSize->setText(QString::number(txt.toUtf8().size()) + "/512"); - memoDialog.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(txt.toUtf8().size() <= 512); + if (txt.toUtf8().size() <= 512) { + // Everything is fine + memoDialog.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true); + memoDialog.memoSize->setStyleSheet(""); + } + else { + // Overweight + memoDialog.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); + memoDialog.memoSize->setStyleSheet("color: red;"); + } + }); memoDialog.memoTxt->setPlainText(currentMemo); diff --git a/src/utils.cpp b/src/utils.cpp index 25234aa..55380af 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -67,6 +67,19 @@ const QString Utils::getDevAddr(Tx tx) { double Utils::getMinerFee() { return 0.0001; } + +double Utils::getZboardAmount() { + return 0.0001; +} + +QString Utils::getZboardAddr() { + if (Settings::getInstance()->isTestnet()) { + return getDonationAddr(true); + } + else { + return "zs10m00rvkhfm4f7n23e4sxsx275r7ptnggx39ygl0vy46j9mdll5c97gl6dxgpk0njuptg2mn9w5s"; + } +} double Utils::getDevFee() { if (Settings::getInstance()->isTestnet()) { return 0.0001; diff --git a/src/utils.h b/src/utils.h index cbe841b..19d1ed5 100644 --- a/src/utils.h +++ b/src/utils.h @@ -17,6 +17,8 @@ public: static const QString getDonationAddr(bool sapling); static double getMinerFee(); + static double getZboardAmount(); + static QString getZboardAddr(); static double getDevFee(); static double getTotalFee(); diff --git a/src/zboard.ui b/src/zboard.ui new file mode 100644 index 0000000..ccacbe7 --- /dev/null +++ b/src/zboard.ui @@ -0,0 +1,155 @@ + + + zboard + + + + 0 + 0 + 520 + 376 + + + + Post to z-board.net + + + + + + + + + Send From + + + + + + + Qt::Horizontal + + + + + + + (optional) + + + + + + + Memo + + + + + + + 0 / 512 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + Post As: + + + + + + + Total Fee + + + + + + + + + + feeamount + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + <html><head/><body><p>ZBoard is Fully anonymous and untraceable chat messages based on the ZCash blockchain. <a href="http://www.z-board.net/"><span style=" text-decoration: underline; color:#0000ff;">http://www.z-board.net/</span></a></p><p>Posting to ZBoard: #Main_Area</p></body></html> + + + true + + + true + + + + + + + color:red; + + + TextLabel + + + + + + + + + buttonBox + accepted() + zboard + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + zboard + reject() + + + 316 + 260 + + + 286 + 274 + + + + + diff --git a/zec-qt-wallet.pro b/zec-qt-wallet.pro index 2ece2d0..3f7bcc5 100644 --- a/zec-qt-wallet.pro +++ b/zec-qt-wallet.pro @@ -82,7 +82,8 @@ FORMS += \ src/turnstileprogress.ui \ src/privkey.ui \ src/memodialog.ui \ - src/connection.ui + src/connection.ui \ + src/zboard.ui win32: RC_ICONS = res/icon.ico