From d0f406d37375eeb192336cc594bef5f2e1998a61 Mon Sep 17 00:00:00 2001 From: DenioD <41270280+DenioD@users.noreply.github.com> Date: Wed, 27 May 2020 13:47:22 +0200 Subject: [PATCH] add hushrequest and delete contact --- silentdragon-lite.pro | 1 + src/contactmodel.cpp | 102 +++++++++++++++-- src/contactmodel.h | 1 + src/hushrequest.ui | 208 +++++++++++++++++++++++----------- src/mainwindow.cpp | 48 ++++++-- src/requestdialog.ui | 252 +++++++++++++++++++++--------------------- 6 files changed, 406 insertions(+), 206 deletions(-) diff --git a/silentdragon-lite.pro b/silentdragon-lite.pro index 4d07b4d..90b261b 100644 --- a/silentdragon-lite.pro +++ b/silentdragon-lite.pro @@ -122,6 +122,7 @@ HEADERS += \ FORMS += \ src/contactrequest.ui \ src/encryption.ui \ + src/hushrequest.ui \ src/mainwindow.ui \ src/migration.ui \ src/newseed.ui \ diff --git a/src/contactmodel.cpp b/src/contactmodel.cpp index 691c65e..7f9d097 100644 --- a/src/contactmodel.cpp +++ b/src/contactmodel.cpp @@ -7,6 +7,7 @@ #include "chatmodel.h" #include "requestdialog.h" #include "ui_requestdialog.h" +#include "ui_hushrequest.h" #include "settings.h" #include "controller.h" @@ -39,17 +40,104 @@ void ContactModel::renderContactList(QListView* view) void MainWindow::showRequesthush() { - Ui_RequestDialog req; + Ui_hushrequest req; QDialog d(this); req.setupUi(&d); Settings::saveRestore(&d); - // setupDialog(main, &d, &req); + QString label = ui->contactNameMemo->text(); + for(auto &p : AddressBook::getInstance()->getAllAddressLabels()) + { + + if (p.getName() == label) + + { + + QString addr = p.getPartnerAddress(); + QString myzaddr = p.getMyAddress(); + + req.txtFrom->setText(addr); + req.lblAddressInfo->setText(myzaddr); + // Amount textbox + req.txtAmount->setValidator(this->getAmountValidator()); + QObject::connect(req.txtAmount, &QLineEdit::textChanged, [=] (auto text) { + CAmount amount = CAmount::fromDecimalString(text); + if (Settings::getInstance()->get_currency_name() == "USD") { + req.txtAmountUSD->setText(amount.toDecimalUSDString()); + } else if (Settings::getInstance()->get_currency_name() == "EUR") { + req.txtAmountUSD->setText(amount.toDecimalEURString()); + } else if (Settings::getInstance()->get_currency_name() == "BTC") { + req.txtAmountUSD->setText(amount.toDecimalBTCString()); + } else if (Settings::getInstance()->get_currency_name() == "CNY") { + req.txtAmountUSD->setText(amount.toDecimalCNYString()); + } else if (Settings::getInstance()->get_currency_name() == "RUB") { + req.txtAmountUSD->setText(amount.toDecimalRUBString()); + } else if (Settings::getInstance()->get_currency_name() == "CAD") { + req.txtAmountUSD->setText(amount.toDecimalCADString()); + } else if (Settings::getInstance()->get_currency_name() == "SGD") { + req.txtAmountUSD->setText(amount.toDecimalSGDString()); + } else if (Settings::getInstance()->get_currency_name() == "CHF") { + req.txtAmountUSD->setText(amount.toDecimalCHFString()); + } else if (Settings::getInstance()->get_currency_name() == "INR") { + req.txtAmountUSD->setText(amount.toDecimalINRString()); + } else if (Settings::getInstance()->get_currency_name() == "GBP") { + req.txtAmountUSD->setText(amount.toDecimalGBPString()); + } else if (Settings::getInstance()->get_currency_name() == "AUD") { + req.txtAmountUSD->setText(amount.toDecimalBTCString()); + } + }); + CAmount amount = CAmount::fromDecimalString(req.txtAmount->text()); + if (Settings::getInstance()->get_currency_name() == "USD") { + req.txtAmountUSD->setText(amount.toDecimalUSDString()); + } else if (Settings::getInstance()->get_currency_name() == "EUR") { + req.txtAmountUSD->setText(amount.toDecimalEURString()); + } else if (Settings::getInstance()->get_currency_name() == "BTC") { + req.txtAmountUSD->setText(amount.toDecimalBTCString()); + } else if (Settings::getInstance()->get_currency_name() == "CNY") { + req.txtAmountUSD->setText(amount.toDecimalCNYString()); + } else if (Settings::getInstance()->get_currency_name() == "RUB") { + req.txtAmountUSD->setText(amount.toDecimalRUBString()); + } else if (Settings::getInstance()->get_currency_name() == "CAD") { + req.txtAmountUSD->setText(amount.toDecimalCADString()); + } else if (Settings::getInstance()->get_currency_name() == "SGD") { + req.txtAmountUSD->setText(amount.toDecimalSGDString()); + } else if (Settings::getInstance()->get_currency_name() == "CHF") { + req.txtAmountUSD->setText(amount.toDecimalCHFString()); + } else if (Settings::getInstance()->get_currency_name() == "INR") { + req.txtAmountUSD->setText(amount.toDecimalINRString()); + } else if (Settings::getInstance()->get_currency_name() == "GBP") { + req.txtAmountUSD->setText(amount.toDecimalGBPString()); + } else if (Settings::getInstance()->get_currency_name() == "AUD") { + req.txtAmountUSD->setText(amount.toDecimalBTCString()); + } + req.txtMemo->setAcceptButton(req.buttonBox->button(QDialogButtonBox::Ok)); + req.txtMemo->setLenDisplayLabel(req.lblMemoLen); + req.txtMemo->setMaxLen(400); + + req.txtFrom->setFocus(); + + + } + } + if (d.exec() == QDialog::Accepted) { + // Construct a hush Payment URI with the data and pay it immediately. + CAmount amount = CAmount::fromDecimalString(req.txtAmount->text()); + QString memoURI = "hush:" + req.lblAddressInfo->text() + + "?amt=" + amount.toDecimalString() + + "&memo=" + QUrl::toPercentEncoding(req.txtMemo->toPlainText()); + + QString sendURI = "hush:" + AddressBook::addressFromAddressLabel(req.txtFrom->text()) + + "?amt=0.0001" + + "&memo=" + QUrl::toPercentEncoding(memoURI); + + // If the disclosed address in the memo doesn't have a balance, it will automatically fallback to the default + // sapling address + this->payhushURI(sendURI, req.lblAddressInfo->text()); + + + + } - // Setup the Label completer for the Address - - - d.exec(); - } + diff --git a/src/contactmodel.h b/src/contactmodel.h index 095fe99..f361ceb 100644 --- a/src/contactmodel.h +++ b/src/contactmodel.h @@ -16,6 +16,7 @@ class ContactModel ContactModel() {} void renderContactList(QListView* view); + }; #endif \ No newline at end of file diff --git a/src/hushrequest.ui b/src/hushrequest.ui index fb923db..d0b0ca7 100644 --- a/src/hushrequest.ui +++ b/src/hushrequest.ui @@ -1,72 +1,156 @@ - - - - - Dialog - - + + + hushrequest + + 0 0 - 400 - 300 + 663 + 529 - + Dialog - - - - 30 - 240 - 341 - 32 - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - + + + + + TextLabel + + + Qt::AlignCenter + + + + + + + Request payment from a Sapling address. You'll send a hush 0.0001 transaction to the address with a hush payment URI. The memo will be included in the transaction when the address pays you. + + + true + + + + + + + Request From + + + + + + + Qt::Horizontal + + + + 541 + 20 + + + + + + + + zaddr + + + + + + + Amount in + + + + + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + Amount + + + + + + + Amount USD + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + + + + + Memo + + + + + + + 0 / 512 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + + 0 + 0 + + + + + + + + My Address + + + + + + + The recipient will see this address in the "to" field when they pay your request. + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + - + + + MemoEdit + QPlainTextEdit +
memoedit.h
+
+
- - - buttonBox - accepted() - Dialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - Dialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - +
- diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 24f9b7c..cad3ca9 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1338,9 +1338,6 @@ void MainWindow::setupchatTab() { ui->memoTxtChat->setTextColor("Black"); } - - - QObject::connect(ui->sendChatButton, &QPushButton::clicked, this, &MainWindow::sendChat); QObject::connect(ui->safeContactRequest, &QPushButton::clicked, this, &MainWindow::addContact); QObject::connect(ui->pushContact, &QPushButton::clicked, this , &MainWindow::renderContactRequest); @@ -1355,17 +1352,13 @@ void MainWindow::setupchatTab() { for(auto &p : AddressBook::getInstance()->getAllAddressLabels()) if (label_contact == p.getName()) { - // ui->ContactZaddr->setText(p.getPartnerAddress()); - // ui->MyZaddr->setText(p.getMyAddress()); - ui->contactNameMemo->setText(p.getName()); - // ui->memoTxtChat->clear(); - - rpc->refresh(true); - // updateChat(); + ui->contactNameMemo->setText(p.getName()); + rpc->refresh(true); + } }); - + QMenu* contextMenu; QAction* requestAction; QAction* editAction; @@ -1382,9 +1375,42 @@ void MainWindow::setupchatTab() { ui->listContactWidget->addAction(HushAction); ui->listContactWidget->addAction(requestHushAction); QObject::connect(requestHushAction, &QAction::triggered, [=]() { + QModelIndex index = ui->listContactWidget->currentIndex(); + QString label_contact = index.data(Qt::DisplayRole).toString(); + + for(auto &p : AddressBook::getInstance()->getAllAddressLabels()) + if (label_contact == p.getName()) { + ui->contactNameMemo->setText(p.getName()); + rpc->refresh(true); + + } + MainWindow::showRequesthush(); }); + QObject::connect(editAction, &QAction::triggered, [=]() { + QModelIndex index = ui->listContactWidget->currentIndex(); + QString label_contact = index.data(Qt::DisplayRole).toString(); + + for(auto &p : AddressBook::getInstance()->getAllAddressLabels()) + if (label_contact == p.getName()) { + + + QString label1 = p.getName(); + QString addr = p.getPartnerAddress(); + QString myzaddr = p.getMyAddress(); + QString cid = p.getCid(); + QString avatar = p.getAvatar(); + + + AddressBook::getInstance()->removeAddressLabel(label1, addr, myzaddr, cid,avatar); + // QList labels = AddressBook::getInstance()->getAllAddressLabels(); + rpc->refreshContacts( + ui->listContactWidget); + rpc->refresh(true); + } + }); + ui->memoTxtChat->setLenDisplayLabelChat(ui->memoSizeChat); } diff --git a/src/requestdialog.ui b/src/requestdialog.ui index 952f780..e52c475 100644 --- a/src/requestdialog.ui +++ b/src/requestdialog.ui @@ -14,37 +14,10 @@ Payment Request
- - - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - AddressBook - - - - - - - - - Qt::Horizontal + + + + @@ -55,171 +28,198 @@ - - + + - My Address + The recipient will see this address in the "to" field when they pay your request. + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - - color: red; - - - + + + + + 0 + 0 + - - + + - Amount in + TextLabel + + + Qt::AlignCenter - - + + + + + - - - - Qt::Horizontal + + + + color: red; - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + - - + + - + Memo - - - - - 0 - 0 - + + + + Qt::Vertical - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + 20 + 40 + - - z address + + + + + + 0 / 512 + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - + + Qt::Horizontal - - - - - 0 - 0 - + + + + Amount USD - - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter - - Amount - - - + + Qt::Horizontal - - + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + AddressBook + + + + + + + - The recipient will see this address in the "to" field when they pay your request. + Request payment from a Sapling address. You'll send a hush 0.0001 transaction to the address with a hush payment URI. The memo will be included in the transaction when the address pays you. - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + true - - - - 0 / 512 + + + + + 0 + 0 + - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + z address - - + + - Amount USD - - - Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + My Address - - + + - Qt::Vertical - - - - 20 - 40 - + Qt::Horizontal - - - - - - Memo + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - - - TextLabel - + + - Qt::AlignCenter + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter + + + Amount - - + + - Request payment from a Sapling address. You'll send a hush 0.0001 transaction to the address with a hush payment URI. The memo will be included in the transaction when the address pays you. + Amount in - - true + + + + + + Qt::Horizontal