Requst payment dialog
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#include "turnstile.h"
|
||||
#include "senttxstore.h"
|
||||
#include "connection.h"
|
||||
#include "requestdialog.h"
|
||||
#include "websockets.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
@@ -45,6 +46,11 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
rpc->checkForUpdate(false);
|
||||
});
|
||||
|
||||
// Request zcash
|
||||
QObject::connect(ui->actionRequest_zcash, &QAction::triggered, [=]() {
|
||||
RequestDialog::showRequestZcash(this);
|
||||
});
|
||||
|
||||
// Pay Zcash URI
|
||||
QObject::connect(ui->actionPay_URI, &QAction::triggered, [=] () {
|
||||
payZcashURI();
|
||||
@@ -1505,6 +1511,9 @@ MainWindow::~MainWindow()
|
||||
delete rpc;
|
||||
delete labelCompleter;
|
||||
|
||||
delete amtValidator;
|
||||
delete feesValidator;
|
||||
|
||||
delete loadingMovie;
|
||||
delete logger;
|
||||
|
||||
|
||||
@@ -42,6 +42,9 @@ public:
|
||||
void updateLabelsAutoComplete();
|
||||
RPC* getRPC() { return rpc; }
|
||||
|
||||
QCompleter* getLabelCompleter() { return labelCompleter; }
|
||||
QRegExpValidator* getAmountValidator() { return amtValidator; }
|
||||
|
||||
QString doSendTxValidations(Tx tx);
|
||||
void setDefaultPayFrom();
|
||||
|
||||
@@ -126,8 +129,10 @@ private:
|
||||
WSServer* wsserver = nullptr;
|
||||
WormholeClient* wormhole = nullptr;
|
||||
|
||||
RPC* rpc = nullptr;
|
||||
QCompleter* labelCompleter = nullptr;
|
||||
RPC* rpc = nullptr;
|
||||
QCompleter* labelCompleter = nullptr;
|
||||
QRegExpValidator* amtValidator = nullptr;
|
||||
QRegExpValidator* feesValidator = nullptr;
|
||||
|
||||
QMovie* loadingMovie;
|
||||
};
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
<item row="0" column="0">
|
||||
<widget class="QTabWidget" name="tabWidget">
|
||||
<property name="currentIndex">
|
||||
<number>2</number>
|
||||
<number>1</number>
|
||||
</property>
|
||||
<widget class="QWidget" name="tab">
|
||||
<attribute name="title">
|
||||
@@ -1058,6 +1058,7 @@
|
||||
<property name="title">
|
||||
<string>&File</string>
|
||||
</property>
|
||||
<addaction name="actionRequest_zcash"/>
|
||||
<addaction name="actionPay_URI"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionImport_Private_Key"/>
|
||||
@@ -1183,19 +1184,24 @@
|
||||
<string>Ctrl+M</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionRequest_zcash">
|
||||
<property name="text">
|
||||
<string>Request zcash...</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>QRCodeLabel</class>
|
||||
<extends>QLabel</extends>
|
||||
<header>qrcodelabel.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>AddressCombo</class>
|
||||
<extends>QComboBox</extends>
|
||||
<header>addresscombo.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>QRCodeLabel</class>
|
||||
<extends>QLabel</extends>
|
||||
<header>qrcodelabel.h</header>
|
||||
</customwidget>
|
||||
<customwidget>
|
||||
<class>FilledIconLabel</class>
|
||||
<extends>QLabel</extends>
|
||||
|
||||
@@ -1,27 +1,35 @@
|
||||
#include "memoedit.h"
|
||||
|
||||
MemoEdit::MemoEdit(QWidget* parent) : QPlainTextEdit(parent) {
|
||||
QObject::connect(this, &QPlainTextEdit::textChanged, [=]() {
|
||||
QString txt = this->toPlainText();
|
||||
if (lenDisplayLabel)
|
||||
lenDisplayLabel->setText(QString::number(txt.toUtf8().size()) + "/" + QString::number(maxlen));
|
||||
QObject::connect(this, &QPlainTextEdit::textChanged, this, &MemoEdit::updateDisplay);
|
||||
}
|
||||
|
||||
if (txt.toUtf8().size() <= maxlen) {
|
||||
// Everything is fine
|
||||
void MemoEdit::updateDisplay() {
|
||||
QString txt = this->toPlainText();
|
||||
if (lenDisplayLabel)
|
||||
lenDisplayLabel->setText(QString::number(txt.toUtf8().size()) + "/" + QString::number(maxlen));
|
||||
|
||||
if (txt.toUtf8().size() <= maxlen) {
|
||||
// Everything is fine
|
||||
if (acceptButton)
|
||||
acceptButton->setEnabled(true);
|
||||
|
||||
if (lenDisplayLabel)
|
||||
lenDisplayLabel->setStyleSheet("");
|
||||
}
|
||||
else {
|
||||
// Overweight
|
||||
}
|
||||
else {
|
||||
// Overweight
|
||||
if (acceptButton)
|
||||
acceptButton->setEnabled(false);
|
||||
|
||||
if (lenDisplayLabel)
|
||||
lenDisplayLabel->setStyleSheet("color: red;");
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void MemoEdit::setMaxLen(int len) {
|
||||
this->maxlen = len;
|
||||
updateDisplay();
|
||||
}
|
||||
|
||||
void MemoEdit::setLenDisplayLabel(QLabel* label) {
|
||||
|
||||
@@ -12,6 +12,7 @@ public:
|
||||
void setLenDisplayLabel(QLabel* label);
|
||||
void setAcceptButton(QPushButton* button);
|
||||
void includeReplyTo(QString replyToAddress);
|
||||
void updateDisplay();
|
||||
|
||||
private:
|
||||
int maxlen = 512;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
#include "requestdialog.h"
|
||||
#include "ui_requestdialog.h"
|
||||
#include "settings.h"
|
||||
#include "addressbook.h"
|
||||
|
||||
RequestDialog::RequestDialog(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
@@ -12,3 +14,50 @@ RequestDialog::~RequestDialog()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
|
||||
// Static method that shows the request dialog
|
||||
void RequestDialog::showRequestZcash(MainWindow* main) {
|
||||
QDialog d(main);
|
||||
Ui_RequestDialog req;
|
||||
req.setupUi(&d);
|
||||
Settings::saveRestore(&d);
|
||||
|
||||
// Setup the Label completer for the Address
|
||||
req.txtFrom->setCompleter(main->getLabelCompleter());
|
||||
QObject::connect(req.txtFrom, &QLineEdit::textChanged, [=] (auto text) {
|
||||
auto addr = AddressBook::addressFromAddressLabel(text);
|
||||
if (!Settings::getInstance()->isSaplingAddress(addr)) {
|
||||
req.lblSaplingWarning->setText(tr("Can only request from Sapling addresses"));
|
||||
req.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
|
||||
} else {
|
||||
req.lblSaplingWarning->setText("");
|
||||
req.buttonBox->button(QDialogButtonBox::Ok)->setEnabled(true);
|
||||
}
|
||||
});
|
||||
|
||||
// Wire up AddressBook button
|
||||
QObject::connect(req.btnAddressBook, &QPushButton::clicked, [=] () {
|
||||
AddressBook::open(main, req.txtFrom);
|
||||
});
|
||||
|
||||
// Amount textbox
|
||||
req.txtAmount->setValidator(main->getAmountValidator());
|
||||
QObject::connect(req.txtAmount, &QLineEdit::textChanged, [=] (auto text) {
|
||||
req.txtAmountUSD->setText(Settings::getUSDFormat(text.toDouble()));
|
||||
});
|
||||
req.txtAmountUSD->setText(Settings::getUSDFormat(req.txtAmount->text().toDouble()));
|
||||
|
||||
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 zcash Payment URI with the data and pay it immediately.
|
||||
QString paymentURI = "zcash:" + AddressBook::addressFromAddressLabel(req.txtFrom->text())
|
||||
+ "?amt=" + Settings::getDecimalString(req.txtAmount->text().toDouble())
|
||||
+ "&memo=" + QUrl::toPercentEncoding(req.txtMemo->toPlainText());
|
||||
main->payZcashURI(paymentURI);
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
#define REQUESTDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include "mainwindow.h"
|
||||
|
||||
namespace Ui {
|
||||
class RequestDialog;
|
||||
@@ -15,6 +16,8 @@ public:
|
||||
explicit RequestDialog(QWidget *parent = nullptr);
|
||||
~RequestDialog();
|
||||
|
||||
static void showRequestZcash(MainWindow* main);
|
||||
|
||||
private:
|
||||
Ui::RequestDialog *ui;
|
||||
};
|
||||
|
||||
@@ -6,45 +6,92 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>544</width>
|
||||
<height>450</height>
|
||||
<width>714</width>
|
||||
<height>524</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Dialog</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<item row="1" column="1" colspan="3">
|
||||
<item row="8" column="1" colspan="3">
|
||||
<widget class="MemoEdit" name="txtMemo"/>
|
||||
</item>
|
||||
<item row="5" column="1" colspan="3">
|
||||
<widget class="QLineEdit" name="txtAmount">
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>amount in ZEC</string>
|
||||
<string>Amount</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1" colspan="3">
|
||||
<widget class="QLabel" name="txtAmountUSD">
|
||||
<item row="0" column="2" colspan="2">
|
||||
<widget class="QLabel" name="lblSaplingWarning">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">color: red;</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Amount USD</string>
|
||||
<string/>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Amount</string>
|
||||
<item row="11" column="2" colspan="2">
|
||||
<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>
|
||||
<item row="3" column="1" colspan="3">
|
||||
<widget class="QTextEdit" name="txtMemo"/>
|
||||
<item row="9" column="2" colspan="2">
|
||||
<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="0" column="1" colspan="3">
|
||||
<item row="8" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Memo</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" 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="1" column="1" colspan="3">
|
||||
<widget class="QLineEdit" name="txtFrom">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
|
||||
@@ -60,32 +107,46 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_3">
|
||||
<property name="text">
|
||||
<string>Memo</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Request From</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="4" column="2" colspan="2">
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<item row="6" column="1" colspan="3">
|
||||
<widget class="QLabel" name="txtAmountUSD">
|
||||
<property name="text">
|
||||
<string>Amount USD</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Amount in ZEC</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="10" column="0" colspan="4">
|
||||
<widget class="Line" name="line">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>MemoEdit</class>
|
||||
<extends>QPlainTextEdit</extends>
|
||||
<header>memoedit.h</header>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<resources/>
|
||||
<connections>
|
||||
<connection>
|
||||
|
||||
@@ -12,7 +12,8 @@ using json = nlohmann::json;
|
||||
|
||||
void MainWindow::setupSendTab() {
|
||||
// Create the validator for send to/amount fields
|
||||
auto amtValidator = new QRegExpValidator(QRegExp("[0-9]{0,8}\\.?[0-9]{0,8}"));
|
||||
amtValidator = new QRegExpValidator(QRegExp("[0-9]{0,8}\\.?[0-9]{0,8}"));
|
||||
|
||||
ui->Amount1->setValidator(amtValidator);
|
||||
|
||||
// Send button
|
||||
@@ -72,8 +73,9 @@ void MainWindow::setupSendTab() {
|
||||
ui->lblMinerFeeUSD->setText(Settings::getUSDFormat(txt.toDouble()));
|
||||
}
|
||||
});
|
||||
|
||||
//Fees validator
|
||||
auto feesValidator = new QRegExpValidator(QRegExp("[0-9]{0,8}\\.?[0-9]{0,8}"));
|
||||
feesValidator = new QRegExpValidator(QRegExp("[0-9]{0,8}\\.?[0-9]{0,8}"));
|
||||
ui->minerFeeAmt->setValidator(feesValidator);
|
||||
|
||||
// Font for the first Memo label
|
||||
@@ -243,8 +245,8 @@ void MainWindow::addAddressSection() {
|
||||
Amount1->setObjectName(QString("Amount") % QString::number(itemNumber));
|
||||
Amount1->setBaseSize(QSize(200, 0));
|
||||
Amount1->setAlignment(Qt::AlignRight);
|
||||
|
||||
// Create the validator for send to/amount fields
|
||||
auto amtValidator = new QRegExpValidator(QRegExp("[0-9]{0,8}\\.?[0-9]{0,8}"));
|
||||
Amount1->setValidator(amtValidator);
|
||||
QObject::connect(Amount1, &QLineEdit::textChanged, [=] (auto text) {
|
||||
this->amountChanged(itemNumber, text);
|
||||
|
||||
Reference in New Issue
Block a user