From 6e1d621b8710782db17471d7843fe398d1f8c091 Mon Sep 17 00:00:00 2001 From: adityapk00 Date: Mon, 5 Nov 2018 23:12:21 -0800 Subject: [PATCH] fix z-board memo size/other validations --- src/main.cpp | 2 +- src/mainwindow.cpp | 26 +++++++++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 36febd2..eb518f3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -18,7 +18,7 @@ int main(int argc, char *argv[]) qApp->setFont(QFont("Ubuntu", 11, QFont::Normal, false)); #endif - std::srand(std::time(nullptr)); + std::srand(static_cast(std::time(nullptr))); Settings::init(); QCoreApplication::setOrganizationName("zec-qt-wallet-org"); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 20afdb9..c0f9740 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -445,6 +445,9 @@ void MainWindow::postToZBoard() { Ui_zboard zb; zb.setupUi(&d); + if (rpc->getConnection() == nullptr) + return; + // 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) { @@ -460,10 +463,20 @@ void MainWindow::postToZBoard() { zb.testnetWarning->setText(""); } + QRegExpValidator v(QRegExp("^[a-zA-Z0-9_]{3,20}$"), zb.postAs); + zb.postAs->setValidator(&v); + zb.feeAmount->setText(Settings::getInstance()->getZECUSDDisplayFormat(Utils::getZboardAmount() + Utils::getMinerFee())); - QObject::connect(zb.memoTxt, &QPlainTextEdit::textChanged, [=] () { - QString txt = zb.memoTxt->toPlainText(); + auto fnBuildNameMemo = [=]() -> QString { + auto memo = zb.memoTxt->toPlainText().trimmed(); + if (!zb.postAs->text().trimmed().isEmpty()) + memo = zb.postAs->text().trimmed() + ":: " + memo; + return memo; + }; + + auto fnUpdateMemoSize = [=]() { + QString txt = fnBuildNameMemo(); zb.memoSize->setText(QString::number(txt.toUtf8().size()) + "/512"); if (txt.toUtf8().size() <= 512) { @@ -472,12 +485,15 @@ void MainWindow::postToZBoard() { zb.memoSize->setStyleSheet(""); } else { - // Overweight + // Overweight zb.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false); zb.memoSize->setStyleSheet("color: red;"); } - - }); + }; + + // Memo text changed + QObject::connect(zb.memoTxt, &QPlainTextEdit::textChanged, fnUpdateMemoSize); + QObject::connect(zb.postAs, &QLineEdit::textChanged, fnUpdateMemoSize); zb.memoTxt->setFocus();