Browse Source

add hushrequest and delete contact

pull/130/head
DenioD 4 years ago
parent
commit
d0f406d373
  1. 1
      silentdragon-lite.pro
  2. 102
      src/contactmodel.cpp
  3. 1
      src/contactmodel.h
  4. 208
      src/hushrequest.ui
  5. 48
      src/mainwindow.cpp
  6. 252
      src/requestdialog.ui

1
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 \

102
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();
}

1
src/contactmodel.h

@ -16,6 +16,7 @@ class ContactModel
ContactModel() {}
void renderContactList(QListView* view);
};
#endif

208
src/hushrequest.ui

@ -1,72 +1,156 @@
<ui version="4.0" >
<author></author>
<comment></comment>
<exportmacro></exportmacro>
<class>Dialog</class>
<widget class="QDialog" name="Dialog" >
<property name="geometry" >
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>hushrequest</class>
<widget class="QDialog" name="hushrequest">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>663</width>
<height>529</height>
</rect>
</property>
<property name="windowTitle" >
<property name="windowTitle">
<string>Dialog</string>
</property>
<widget class="QDialogButtonBox" name="buttonBox" >
<property name="geometry" >
<rect>
<x>30</x>
<y>240</y>
<width>341</width>
<height>32</height>
</rect>
</property>
<property name="orientation" >
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons" >
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="lblPixmap">
<property name="text">
<string>TextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="lblHeader">
<property name="text">
<string>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.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="lblAddress">
<property name="text">
<string>Request From</string>
</property>
</widget>
</item>
<item row="1" column="1">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>541</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="txtFrom">
<property name="text">
<string>zaddr</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QLabel" name="lblAmount">
<property name="text">
<string>Amount in </string>
</property>
</widget>
</item>
<item row="4" column="0" colspan="2">
<widget class="QLineEdit" name="txtAmount">
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="placeholderText">
<string>Amount</string>
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="txtAmountUSD">
<property name="text">
<string>Amount USD</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Memo</string>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLabel" name="lblMemoLen">
<property name="text">
<string notr="true">0 / 512</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="7" column="0" colspan="2">
<widget class="MemoEdit" name="txtMemo">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="8" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>My Address</string>
</property>
</widget>
</item>
<item row="8" column="1">
<widget class="QLabel" name="lblAddressInfo">
<property name="text">
<string>The recipient will see this address in the &quot;to&quot; field when they pay your request.</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="9" column="1">
<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>
</layout>
</widget>
<pixmapfunction></pixmapfunction>
<customwidgets>
<customwidget>
<class>MemoEdit</class>
<extends>QPlainTextEdit</extends>
<header>memoedit.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>Dialog</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>Dialog</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>
<connections/>
</ui>

48
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<ContactItem> labels = AddressBook::getInstance()->getAllAddressLabels();
rpc->refreshContacts(
ui->listContactWidget);
rpc->refresh(true);
}
});
ui->memoTxtChat->setLenDisplayLabelChat(ui->memoSizeChat);
}

252
src/requestdialog.ui

@ -14,37 +14,10 @@
<string>Payment Request</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="18" column="1" colspan="3">
<widget class="AddressCombo" name="cmbMyAddress"/>
</item>
<item row="2" column="3">
<layout class="QHBoxLayout" name="horizontalLayout">
<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>
<item>
<widget class="QPushButton" name="btnAddressBook">
<property name="text">
<string>AddressBook</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="21" column="0" colspan="4">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<item row="10" column="1">
<widget class="QLabel" name="label">
<property name="text">
<string/>
</property>
</widget>
</item>
@ -55,171 +28,198 @@
</property>
</widget>
</item>
<item row="15" column="1">
<widget class="QLabel" name="label_2">
<item row="15" column="3">
<widget class="QLabel" name="lblAddressInfo">
<property name="text">
<string>My Address</string>
<string>The recipient will see this address in the &quot;to&quot; field when they pay your request.</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="5" column="1" colspan="3">
<widget class="QLabel" name="lblSaplingWarning">
<property name="styleSheet">
<string notr="true">color: red;</string>
</property>
<property name="text">
<string/>
<item row="12" column="1" colspan="3">
<widget class="MemoEdit" name="txtMemo">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item row="6" column="1">
<widget class="QLabel" name="lblAmount">
<item row="0" column="1">
<widget class="QLabel" name="lblPixmap">
<property name="text">
<string>Amount in </string>
<string>TextLabel</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item row="10" column="1">
<widget class="QLabel" name="label">
<item row="18" column="1" colspan="3">
<widget class="AddressCombo" name="cmbMyAddress"/>
</item>
<item row="14" column="1">
<widget class="QLabel" name="label_4">
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="24" column="2" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<item row="5" column="1" colspan="3">
<widget class="QLabel" name="lblSaplingWarning">
<property name="styleSheet">
<string notr="true">color: red;</string>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="14" column="1">
<widget class="QLabel" name="label_4">
<item row="11" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string/>
<string>Memo</string>
</property>
</widget>
</item>
<item row="4" column="1" colspan="3">
<widget class="QLineEdit" name="txtFrom">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<item row="20" column="1">
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
<property name="placeholderText">
<string>z address</string>
</spacer>
</item>
<item row="11" column="3">
<widget class="QLabel" name="lblMemoLen">
<property name="text">
<string notr="true">0 / 512</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="1" column="1" colspan="3">
<widget class="Line" name="line_3">
<item row="13" column="1" colspan="3">
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="12" column="1" colspan="3">
<widget class="MemoEdit" name="txtMemo">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
<item row="9" column="1">
<widget class="QLabel" name="txtAmountUSD">
<property name="text">
<string>Amount USD</string>
</property>
</widget>
</item>
<item row="7" column="1" colspan="3">
<widget class="QLineEdit" name="txtAmount">
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="placeholderText">
<string>Amount</string>
</property>
</widget>
</item>
<item row="13" column="1" colspan="3">
<widget class="Line" name="line_2">
<item row="21" column="0" colspan="4">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="15" column="3">
<widget class="QLabel" name="lblAddressInfo">
<item row="2" column="3">
<layout class="QHBoxLayout" name="horizontalLayout">
<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>
<item>
<widget class="QPushButton" name="btnAddressBook">
<property name="text">
<string>AddressBook</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="0" column="2" colspan="2">
<widget class="QLabel" name="lblHeader">
<property name="text">
<string>The recipient will see this address in the &quot;to&quot; field when they pay your request.</string>
<string>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.</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="11" column="3">
<widget class="QLabel" name="lblMemoLen">
<property name="text">
<string notr="true">0 / 512</string>
<item row="4" column="1" colspan="3">
<widget class="QLineEdit" name="txtFrom">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="placeholderText">
<string>z address</string>
</property>
</widget>
</item>
<item row="9" column="1">
<widget class="QLabel" name="txtAmountUSD">
<item row="15" column="1">
<widget class="QLabel" name="label_2">
<property name="text">
<string>Amount USD</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
<string>My Address</string>
</property>
</widget>
</item>
<item row="20" column="1">
<spacer name="verticalSpacer">
<item row="24" column="2" colspan="2">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
<enum>Qt::Horizontal</enum>
</property>
</spacer>
</item>
<item row="11" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Memo</string>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLabel" name="lblPixmap">
<property name="text">
<string>TextLabel</string>
</property>
<item row="7" column="1" colspan="3">
<widget class="QLineEdit" name="txtAmount">
<property name="alignment">
<set>Qt::AlignCenter</set>
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<property name="placeholderText">
<string>Amount</string>
</property>
</widget>
</item>
<item row="0" column="2" colspan="2">
<widget class="QLabel" name="lblHeader">
<item row="6" column="1">
<widget class="QLabel" name="lblAmount">
<property name="text">
<string>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.</string>
<string>Amount in </string>
</property>
<property name="wordWrap">
<bool>true</bool>
</widget>
</item>
<item row="1" column="1" colspan="3">
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>

Loading…
Cancel
Save