From ce2621abdfce855d89050f673c0522cf67393d64 Mon Sep 17 00:00:00 2001 From: adityapk00 Date: Sat, 23 Mar 2019 10:42:42 -0700 Subject: [PATCH] Pick from address for request payments --- .gitignore | 1 + src/mainwindow.cpp | 9 ++- src/mainwindow.h | 2 +- src/requestdialog.cpp | 28 ++++++-- src/requestdialog.h | 2 +- src/requestdialog.ui | 156 ++++++++++++++++++++++++------------------ src/settings.ui | 17 ----- 7 files changed, 120 insertions(+), 95 deletions(-) diff --git a/.gitignore b/.gitignore index 0194a5a..a1efcce 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,4 @@ workspace.code-workspace *.mak zcashd IDEWorkspaceChecks.plist +*.sln diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 82ba03c..df635d2 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -795,8 +795,9 @@ bool MainWindow::eventFilter(QObject *object, QEvent *event) { // Pay the Zcash URI by showing a confirmation window. If the URI parameter is empty, the UI -// will prompt for one. -void MainWindow::payZcashURI(QString uri) { +// will prompt for one. If the myAddr is empty, then the default from address is used to send +// the transaction. +void MainWindow::payZcashURI(QString uri, QString myAddr) { // If the Payments UI is not ready (i.e, all balances have not loaded), defer the payment URI if (!uiPaymentsReady) { qDebug() << "Payment UI not ready, waiting for UI to pay URI"; @@ -825,6 +826,10 @@ void MainWindow::payZcashURI(QString uri) { // Now, set the fields on the send tab removeExtraAddresses(); + if (!myAddr.isEmpty()) { + ui->inputsCombo->setCurrentText(myAddr); + } + ui->Address1->setText(paymentInfo.addr); ui->Address1->setCursorPosition(0); ui->Amount1->setText(Settings::getDecimalString(paymentInfo.amt.toDouble())); diff --git a/src/mainwindow.h b/src/mainwindow.h index 6a5e179..692e746 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -54,7 +54,7 @@ public: void stopWebsocket(); void balancesReady(); - void payZcashURI(QString uri = ""); + void payZcashURI(QString uri = "", QString myAddr = ""); void updateLabels(); void updateTAddrCombo(bool checked); diff --git a/src/requestdialog.cpp b/src/requestdialog.cpp index da95c3d..1adcb75 100644 --- a/src/requestdialog.cpp +++ b/src/requestdialog.cpp @@ -6,6 +6,7 @@ #include "rpc.h" #include "settings.h" +#include "precompiled.h" RequestDialog::RequestDialog(QWidget *parent) : QDialog(parent), @@ -19,13 +20,26 @@ RequestDialog::~RequestDialog() delete ui; } -void RequestDialog::setupDialog(QDialog* d, Ui_RequestDialog* req) { +void RequestDialog::setupDialog(MainWindow* main, QDialog* d, Ui_RequestDialog* req) { req->setupUi(d); Settings::saveRestore(d); // Setup req->txtMemo->setLenDisplayLabel(req->lblMemoLen); req->lblAmount->setText(req->lblAmount->text() + Settings::getTokenName()); + + if (!main || !main->getRPC() || !main->getRPC()->getAllZAddresses() || !main->getRPC()->getAllBalances()) + return; + + for (auto addr : *main->getRPC()->getAllZAddresses()) { + auto bal = main->getRPC()->getAllBalances()->value(addr); + if (bal == 0) + continue; + if (Settings::getInstance()->isSaplingAddress(addr)) { + req->cmbMyAddress->addItem(addr, bal); + } + } + req->cmbMyAddress->setCurrentText(main->getRPC()->getDefaultSaplingAddress()); } // Static method that shows an incoming payment request and prompts the user to pay it @@ -39,7 +53,7 @@ void RequestDialog::showPaymentConfirmation(MainWindow* main, QString paymentURI QDialog d(main); Ui_RequestDialog req; - setupDialog(&d, &req); + setupDialog(main, &d, &req); // In the view mode, all fields are read-only req.txtAmount->setReadOnly(true); @@ -60,7 +74,7 @@ void RequestDialog::showPaymentConfirmation(MainWindow* main, QString paymentURI req.buttonBox->button(QDialogButtonBox::Ok)->setText(tr("Pay")); if (d.exec() == QDialog::Accepted) { - main->payZcashURI(paymentURI); + main->payZcashURI(paymentURI, req.cmbMyAddress->currentText()); } } @@ -68,8 +82,8 @@ void RequestDialog::showPaymentConfirmation(MainWindow* main, QString paymentURI void RequestDialog::showRequestZcash(MainWindow* main) { QDialog d(main); Ui_RequestDialog req; - req.setupUi(&d); - Settings::saveRestore(&d); + + setupDialog(main, &d, &req); // Setup the Label completer for the Address req.txtFrom->setCompleter(main->getLabelCompleter()); @@ -104,7 +118,7 @@ void RequestDialog::showRequestZcash(MainWindow* main) { if (d.exec() == QDialog::Accepted) { // Construct a zcash Payment URI with the data and pay it immediately. - QString memoURI = "zcash:" + main->getRPC()->getDefaultSaplingAddress() + QString memoURI = "zcash:" + req.cmbMyAddress->currentText() + "?amt=" + Settings::getDecimalString(req.txtAmount->text().toDouble()) + "&memo=" + QUrl::toPercentEncoding(req.txtMemo->toPlainText()); @@ -113,6 +127,6 @@ void RequestDialog::showRequestZcash(MainWindow* main) { + "&memo=" + QUrl::toPercentEncoding(memoURI); qDebug() << "Paying " << sendURI; - main->payZcashURI(sendURI); + main->payZcashURI(sendURI, req.cmbMyAddress->currentText()); } } diff --git a/src/requestdialog.h b/src/requestdialog.h index a05b3c7..6e53234 100644 --- a/src/requestdialog.h +++ b/src/requestdialog.h @@ -19,7 +19,7 @@ public: static void showRequestZcash(MainWindow* main); static void showPaymentConfirmation(MainWindow* main, QString paymentURI); - static void setupDialog(QDialog* d, Ui_RequestDialog* req); + static void setupDialog(MainWindow* main, QDialog* d, Ui_RequestDialog* req); private: Ui::RequestDialog *ui; }; diff --git a/src/requestdialog.ui b/src/requestdialog.ui index f188f8b..db1a3cc 100644 --- a/src/requestdialog.ui +++ b/src/requestdialog.ui @@ -6,29 +6,23 @@ 0 0 - 1052 - 509 + 588 + 384 Payment Request - - - - - + + - Qt::Vertical + Qt::Horizontal - - - 20 - 40 - + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok - + @@ -40,16 +34,58 @@ - - + + + + + + + + + Qt::Horizontal - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + z address + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + @@ -60,6 +96,26 @@ + + + + color: red; + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Qt::Horizontal + + + @@ -67,19 +123,10 @@ - - - - - 0 - 0 - - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - z address + + + + Qt::Horizontal @@ -114,26 +161,6 @@ - - - - color: red; - - - - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - - - - - - - - - @@ -151,25 +178,15 @@ - - - - Qt::Horizontal + + + + My Address - - - - Qt::Horizontal - - - - 40 - 20 - - - + + @@ -179,6 +196,11 @@ QPlainTextEdit
memoedit.h
+ + AddressCombo + QComboBox +
addresscombo.h
+
txtFrom diff --git a/src/settings.ui b/src/settings.ui index d026952..f107bd4 100644 --- a/src/settings.ui +++ b/src/settings.ui @@ -325,16 +325,6 @@
- - - - Rescan the blockchain for any missing wallet transactions and to correct your wallet balance. This will take several hours. You need to restart ZecWallet for this to take effect - - - true - - - @@ -345,13 +335,6 @@ - - - - Rescan - - -