From be7d790f3d9460deee1a60e4cb07235206a4b7cd Mon Sep 17 00:00:00 2001 From: 0x2830 <0x2830@tuta.io> Date: Wed, 14 Oct 2020 14:52:43 +0200 Subject: [PATCH] SWAP and other GUI changes --- configure.ac | 4 +- doc/Doxyfile | 2 +- src/Makefile.qt.include | 6 + src/clientversion.h | 4 +- src/qt/forms/getaddresstoreceive.ui | 29 +-- src/qt/forms/overviewpage.ui | 42 ++-- src/qt/forms/sendcoinsentry.ui | 48 ++-- src/qt/getaddresstoreceive.cpp | 33 ++- src/qt/getaddresstoreceive.h | 3 +- src/qt/navcoin.qrc | 6 +- src/qt/navcoinamountfield.cpp | 7 +- src/qt/navcoinamountfield.h | 2 +- src/qt/overviewpage.cpp | 12 + src/qt/overviewpage.h | 4 + src/qt/res/icons/mininav.png | Bin 0 -> 4327 bytes src/qt/res/icons/minixnav.png | Bin 0 -> 5029 bytes src/qt/res/icons/swap.png | Bin 0 -> 2009 bytes src/qt/sendcoinsdialog.cpp | 2 +- src/qt/sendcoinsentry.cpp | 37 ++- src/qt/sendcoinsentry.h | 3 +- src/qt/swapxnav.cpp | 342 ++++++++++++++++++++++++++++ src/qt/swapxnav.h | 67 ++++++ src/qt/walletview.cpp | 3 +- 23 files changed, 548 insertions(+), 108 deletions(-) create mode 100644 src/qt/res/icons/mininav.png create mode 100644 src/qt/res/icons/minixnav.png create mode 100644 src/qt/res/icons/swap.png create mode 100644 src/qt/swapxnav.cpp create mode 100644 src/qt/swapxnav.h diff --git a/configure.ac b/configure.ac index 090a31fd3..0d22e4b9f 100644 --- a/configure.ac +++ b/configure.ac @@ -1,8 +1,8 @@ dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N) AC_PREREQ([2.60]) -define(_CLIENT_VERSION_MAJOR, 5) +define(_CLIENT_VERSION_MAJOR, 6) define(_CLIENT_VERSION_MINOR, 0) -define(_CLIENT_VERSION_REVISION, 1) +define(_CLIENT_VERSION_REVISION, 0) define(_CLIENT_VERSION_BUILD, 0) define(_CLIENT_VERSION_IS_RELEASE, true) define(_CLIENT_BUILD_IS_TEST_RELEASE, false) diff --git a/doc/Doxyfile b/doc/Doxyfile index 0734beb53..ee680c287 100755 --- a/doc/Doxyfile +++ b/doc/Doxyfile @@ -34,7 +34,7 @@ PROJECT_NAME = NavCoin # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = 5.0.1 +PROJECT_NUMBER = 6.0.0 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer diff --git a/src/Makefile.qt.include b/src/Makefile.qt.include index f39a3b481..ee5d8edec 100755 --- a/src/Makefile.qt.include +++ b/src/Makefile.qt.include @@ -203,6 +203,7 @@ QT_MOC_CPP = \ qt/moc_daopage.cpp \ qt/moc_daoconsultationvote.cpp \ qt/moc_daoconsultationcreate.cpp \ + qt/moc_swapxnav.cpp \ qt/moc_navcoinlistwidget.cpp \ qt/moc_navcoinpushbutton.cpp \ qt/moc_daoproposeanswer.cpp \ @@ -315,6 +316,7 @@ NAVCOIN_QT_H = \ qt/walletview.h \ qt/winshutdownmonitor.h \ qt/daopage.h \ + qt/swapxnav.h \ qt/daoconsultationvote.h \ qt/daoconsultationcreate.h \ qt/navcoinlistwidget.h \ @@ -328,6 +330,9 @@ RES_ICONS = \ qt/res/icons/navcoin.icns \ qt/res/icons/navcoin.ico \ qt/res/icons/navcoin.png \ + qt/res/icons/mininav.png \ + qt/res/icons/swap.png \ + qt/res/icons/minixnav.png \ qt/res/icons/navcoin_full.png # Vector Icons @@ -551,6 +556,7 @@ NAVCOIN_QT_CPP += \ qt/walletmodeltransaction.cpp \ qt/walletview.cpp \ qt/daopage.cpp \ + qt/swapxnav.cpp \ qt/daoconsultationvote.cpp \ qt/daoconsultationcreate.cpp \ qt/daoproposeanswer.cpp \ diff --git a/src/clientversion.h b/src/clientversion.h index d83736eac..e1ed0210b 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -14,9 +14,9 @@ */ //! These need to be macros, as clientversion.cpp's and navcoin*-res.rc's voodoo requires it -#define CLIENT_VERSION_MAJOR 5 +#define CLIENT_VERSION_MAJOR 6 #define CLIENT_VERSION_MINOR 0 -#define CLIENT_VERSION_REVISION 1 +#define CLIENT_VERSION_REVISION 0 #define CLIENT_VERSION_BUILD 0 //! Set to true for release, false for prerelease or test build diff --git a/src/qt/forms/getaddresstoreceive.ui b/src/qt/forms/getaddresstoreceive.ui index e485cc49d..57b16d7da 100644 --- a/src/qt/forms/getaddresstoreceive.ui +++ b/src/qt/forms/getaddresstoreceive.ui @@ -45,9 +45,9 @@ - + - + Qt::Horizontal @@ -60,19 +60,10 @@ - - - - 11 - - - - Use the following address to receive NavCoins: - - + - + Qt::Horizontal @@ -151,10 +142,7 @@ - - - Qt::AlignCenter - + true @@ -278,13 +266,6 @@ - - - - Show private address - - - diff --git a/src/qt/forms/overviewpage.ui b/src/qt/forms/overviewpage.ui index 834612185..44976e32b 100644 --- a/src/qt/forms/overviewpage.ui +++ b/src/qt/forms/overviewpage.ui @@ -49,14 +49,14 @@ Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - + Available Public - + 1 000.00000000 NAV @@ -66,14 +66,14 @@ - + - Pending - + 1 000.00000000 NAV @@ -83,14 +83,14 @@ - + Available Private - + 1 000.00000000 NAV @@ -100,14 +100,14 @@ - + - Pending - + 1 000.00000000 NAV @@ -117,14 +117,14 @@ - + Cold Staking - + 1 000.00000000 NAV @@ -134,14 +134,14 @@ - + Immature - + 1 000.00000000 NAV @@ -151,14 +151,14 @@ - + Watched - + 1 000.00000000 NAV @@ -168,14 +168,14 @@ - + Total - + 1 000.00000000 NAV @@ -185,9 +185,19 @@ + + + + + + + Swap NAV/xNAV + + + diff --git a/src/qt/forms/sendcoinsentry.ui b/src/qt/forms/sendcoinsentry.ui index 1caa905e5..745aca648 100644 --- a/src/qt/forms/sendcoinsentry.ui +++ b/src/qt/forms/sendcoinsentry.ui @@ -255,30 +255,24 @@ - - - - 0 - 0 - - - - - 0 - 0 - - - - Public coins - - - - - - - Private coins - - + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + @@ -311,6 +305,12 @@ + + + 0 + 0 + + 10 diff --git a/src/qt/getaddresstoreceive.cpp b/src/qt/getaddresstoreceive.cpp index 683f42a88..c58a3e632 100644 --- a/src/qt/getaddresstoreceive.cpp +++ b/src/qt/getaddresstoreceive.cpp @@ -36,13 +36,30 @@ getAddressToReceive::getAddressToReceive(QWidget *parent) : } } - ui->lblAddress->setMinimumWidth(360 * GUIUtil::scale()); + ui->textAddress->setMinimumWidth(260 * GUIUtil::scale()); + + QPixmap p1(":/icons/mininav"); + QPixmap p2(":/icons/minixnav"); + + ui->typeBox->insertItem(0,"Public NAV"); + ui->typeBox->insertItem(1,"Private xNAV"); + ui->typeBox->setItemData(0,p1,Qt::DecorationRole); + ui->typeBox->setItemData(1,p2,Qt::DecorationRole); + ui->typeBox->setIconSize(QSize(32,32)); connect(ui->copyClipboardButton,SIGNAL(clicked()),this,SLOT(copyToClipboard())); connect(ui->newAddressButton,SIGNAL(clicked()),this,SLOT(getNewAddress())); connect(ui->coldStakingButton,SIGNAL(clicked()),this,SLOT(getColdStakingAddress())); connect(ui->requestNewAddressButton,SIGNAL(clicked()),this,SLOT(showAddressHistory())); - connect(ui->privateAddressButton,SIGNAL(clicked()),this,SLOT(showPrivateAddress())); + connect(ui->typeBox,SIGNAL(currentIndexChanged(int)),this,SLOT(showPrivateAddress(int))); + + ui->textAddress->setFont(GUIUtil::fixedPitchFont()); + + ui->textAddress->setText(address); + + QSize size = ui->textAddress->document()->size().toSize(); + ui->textAddress->setFixedHeight( size.height() + 3 ); + ui->textAddress->setAlignment(Qt::AlignCenter); } getAddressToReceive::~getAddressToReceive() @@ -50,9 +67,9 @@ getAddressToReceive::~getAddressToReceive() delete ui; } -void getAddressToReceive::showPrivateAddress() +void getAddressToReceive::showPrivateAddress(int what) { - if (address.length() > 65) + if (!ui->typeBox->currentIndex()) { LOCK(pwalletMain->cs_wallet); for(const PAIRTYPE(CTxDestination, CAddressBookData)& item: pwalletMain->mapAddressBook) @@ -65,7 +82,6 @@ void getAddressToReceive::showPrivateAddress() break; } } - ui->privateAddressButton->setText(QString(tr("Show private address"))); ui->requestNewAddressButton->show(); ui->coldStakingButton->show(); ui->newAddressButton->show(); @@ -80,11 +96,11 @@ void getAddressToReceive::showPrivateAddress() else address = "Unavailable"; - ui->privateAddressButton->setText(QString(tr("Show public address"))); ui->requestNewAddressButton->hide(); ui->coldStakingButton->hide(); ui->newAddressButton->hide(); } + showQR(); } @@ -164,8 +180,11 @@ void getAddressToReceive::showQR() ui->lblQRCode->setMinimumSize(qrSize, qrSize); // Add the address to the label - ui->lblAddress->setText(address); + ui->textAddress->setText(address); } } #endif + QSize size = ui->textAddress->document()->size().toSize(); + ui->textAddress->setFixedHeight( std::max(size.height() + 3, 22) ); + ui->textAddress->setAlignment(Qt::AlignCenter); } diff --git a/src/qt/getaddresstoreceive.h b/src/qt/getaddresstoreceive.h index 3aaa1f960..0141153a7 100644 --- a/src/qt/getaddresstoreceive.h +++ b/src/qt/getaddresstoreceive.h @@ -1,6 +1,7 @@ #ifndef GETADDRESSTORECEIVE_H #define GETADDRESSTORECEIVE_H +#include #include #include @@ -18,7 +19,7 @@ class getAddressToReceive : public QWidget void setModel(WalletModel *model); public Q_SLOTS: - void showPrivateAddress(); + void showPrivateAddress(int); void getNewAddress(); void getColdStakingAddress(); void showQR(); diff --git a/src/qt/navcoin.qrc b/src/qt/navcoin.qrc index cde7401b5..d27e580da 100755 --- a/src/qt/navcoin.qrc +++ b/src/qt/navcoin.qrc @@ -3,7 +3,6 @@ res/icons/navcoin.png res/icons/navcoin_full.png res/icons/logo_n.png - res/icons/about.svg res/icons/about_qt.svg res/icons/add.svg @@ -59,13 +58,15 @@ res/icons/tx_output.svg res/icons/verify.svg res/icons/warning.svg - res/fonts/roboto.ttf res/fonts/roboto-black.ttf res/fonts/roboto-bold.ttf res/fonts/roboto-medium.ttf res/fonts/roboto-regular.ttf res/fonts/source.ttf + res/icons/mininav.png + res/icons/minixnav.png + res/icons/swap.png res/movies/spinner-000.png @@ -108,7 +109,6 @@ res/themes/app.qss res/themes/shared.qss - res/themes/dark/styles.qss res/themes/light/styles.qss diff --git a/src/qt/navcoinamountfield.cpp b/src/qt/navcoinamountfield.cpp index d6bf68395..7e955b8a1 100644 --- a/src/qt/navcoinamountfield.cpp +++ b/src/qt/navcoinamountfield.cpp @@ -178,7 +178,7 @@ class AmountSpinBox: public QAbstractSpinBox #include -NavCoinAmountField::NavCoinAmountField(QWidget *parent) : +NavCoinAmountField::NavCoinAmountField(QWidget *parent, bool fUnit) : QWidget(parent), amount(0) { @@ -188,8 +188,9 @@ NavCoinAmountField::NavCoinAmountField(QWidget *parent) : QHBoxLayout *layout = new QHBoxLayout(this); layout->addWidget(amount); - unit = new QLabel(this); - layout->addWidget(unit); + unit = new QLabel(fUnit?this:0); + if (fUnit) + layout->addWidget(unit); layout->setContentsMargins(0,0,0,0); setLayout(layout); diff --git a/src/qt/navcoinamountfield.h b/src/qt/navcoinamountfield.h index 93cdd4ed2..c4658392a 100644 --- a/src/qt/navcoinamountfield.h +++ b/src/qt/navcoinamountfield.h @@ -27,7 +27,7 @@ class NavCoinAmountField: public QWidget Q_PROPERTY(qint64 value READ value WRITE setValue NOTIFY valueChanged USER true) public: - explicit NavCoinAmountField(QWidget *parent = 0); + explicit NavCoinAmountField(QWidget *parent = 0, bool fUnit = false); CAmount value(bool *value=0) const; diff --git a/src/qt/overviewpage.cpp b/src/qt/overviewpage.cpp index e282dca3a..c02dbb815 100644 --- a/src/qt/overviewpage.cpp +++ b/src/qt/overviewpage.cpp @@ -139,6 +139,9 @@ OverviewPage::OverviewPage(const PlatformStyle *platformStyle, QWidget *parent) ui->listTransactions->setAttribute(Qt::WA_MacShowFocusRect, false); connect(ui->listTransactions, SIGNAL(clicked(QModelIndex)), this, SLOT(handleTransactionClicked(QModelIndex))); + connect(ui->swapButton, SIGNAL(clicked()), this, SLOT(ShowSwapDialog())); + + swapDialog = new SwapXNAVDialog(this); // start with displaying the "out of sync" warnings updateStakeReportNow(); @@ -200,6 +203,9 @@ void OverviewPage::setBalance( updateStakeReportNow(); + swapDialog->SetPublicBalance(balance); + swapDialog->SetPrivateBalance(privateBalance); + uiInterface.SetBalance(currentBalance, currentUnconfirmedBalance, currentImmatureBalance, currentPrivateBalance, currentPrivateBalancePending, currentPrivateBalanceLocked); } @@ -212,11 +218,13 @@ void OverviewPage::updateWatchOnlyLabels(bool showWatchOnly) void OverviewPage::setClientModel(ClientModel *model) { this->clientModel = model; + this->swapDialog->setClientModel(model); } void OverviewPage::setWalletModel(WalletModel *model) { this->walletModel = model; + this->swapDialog->setModel(model); if(model && model->getOptionsModel()) { // Set up transaction list @@ -265,6 +273,10 @@ void OverviewPage::updateDisplayUnit() } } +void OverviewPage::ShowSwapDialog() +{ + this->swapDialog->exec(); +} using namespace boost; using namespace std; diff --git a/src/qt/overviewpage.h b/src/qt/overviewpage.h index 69b4c6c75..561e9d388 100644 --- a/src/qt/overviewpage.h +++ b/src/qt/overviewpage.h @@ -7,6 +7,7 @@ #include #include +#include #include #include @@ -76,10 +77,13 @@ public Q_SLOTS: qint64 nLastReportUpdate; void updateStakeReport(bool fImmediate); + SwapXNAVDialog* swapDialog; + private Q_SLOTS: void updateDisplayUnit(); void handleTransactionClicked(const QModelIndex &index); void updateWatchOnlyLabels(bool showWatchOnly); + void ShowSwapDialog(); }; #endif // NAVCOIN_QT_OVERVIEWPAGE_H diff --git a/src/qt/res/icons/mininav.png b/src/qt/res/icons/mininav.png new file mode 100644 index 0000000000000000000000000000000000000000..c93630a16d29d3a70a67319dd3edaa83e26439e7 GIT binary patch literal 4327 zcmVKLZ*U+0o1BVCgO^&5lY?fml!x!HPyi6pThdVnHm}f?)3#B&bAV zuwX;welUsN%-p$i&&)ILnKSdA_nqg{58#AK+V1ytD2EilvgeIX!7!#I+9U&$> z2!A4!h#=yLL_$Vn6M4h}Vi{3JR1np~4x*m;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(NBO*$O&Q9?g2vpz{!+K|(^sB8P76m(nq!7nw_u)!#;cq~pzf#~D1 zD=|3}8lh}o8t=qaY!(vLpXOv4$;SB=F~LJ<1cI_ z#B|Lr?JG*P@BVWE zrE}4Z*K>%2e~|kMuTue!CTyGJ`mB4lr+`OLKAQ8k0_E0cV~K#5nC-^k-H+wNk2Tw^ z(Lo4;5pnfpGW{e%2;~JdzdVy&iFt?#dL83rw|S$QkHUN`Cxjpplk%Gh!NamxCa#v% zvxC<0PP2L4clF{NkCF?ar*G1{fTWOEc$M->0msJmO0Tr9+=@RfP6`B(%Pd8c*|68` zYCW^Grx*jLS?wQuteJ-6;RMCy&3JBYHZ>n!EX*PgF*VgJ?JH{AfN+|e07xNmuT5`^{akqPnq_60wt$#MeXF$J>URx71)DbQ}Lvwfvi(-4A> z=0uMOS}DM^A8g6LY%PyePH_p{`EQC-H%hduC!xn%Di4-6p|g z96d+oga|}sX?Zj5WoS*^uAFp~>zhBXpHiTw}EZDNN22&SrMFe7?9cnH=31@6?YnziNV-oBt5AV;MZOzrJ(3_vgTF4e9%JB zqjIXo!G~I_t_`!9F>ub0TGfjl8e7cKI1xf}D!8~Vd-ZBvvnt1(uA;k#83Y*9>Ur;Y zr{P!+NJ=p6G_;dl#Wp4&<_MgW0-v8-+>oOl?;`}$uA-Or71!o*C*`c-cB651bN_ax z?o>`X)v^jFA?64^;r5eyaYJ@&;`-2R8qVcOw_bVR4Gv@4xV$;|Sc}SjUgTVTFQq`K z^^bpT8oG_9&It(t7sYnqGtC*x$CjFWLPPR7YN87JdpoQ#uke%YMA4*-n) V+S7#s5R?D_002ovPDHLkV1mhZY5f2I literal 0 HcmV?d00001 diff --git a/src/qt/res/icons/minixnav.png b/src/qt/res/icons/minixnav.png new file mode 100644 index 0000000000000000000000000000000000000000..e2129fcf6474703a32de27e3fde4639205b392ae GIT binary patch literal 5029 zcmZ`*XEa>z*S$oUXb~-l-bJrLv@pm_n1~V4J7EyLmyqa02_w4bgo$Wj)aV(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zqQ0>+3>b|AGP zU{&xrn59sYD~jZK7R3(S&s?ac$oE=oyvNhn0iHxsbKlsMSL{q5oi-_o9o%tOA^PyZ z5Ho4d1al&zC(|k#F2BMv*rpSer!@MjEYa?%{tD?8=Ssi7Vw-&NIZD)KiHf?+IR1st zTWd2mu5@ccitSWZEJYI+v|mHVO&KgqE#(cNE94X~nuQw4l>g%u=GebK{2GBJm_^bP z)8zjl8jAJcpEmT%yg|cXqr(_1y%MoT;{Zh$!2jrW72$5&!SDfn(SZoc#BO3&Gj8aN*>Z5 z!1cuW4wSLH@*4Y*AHDdhLlC98ErLaZX<*}8o`Cuawh%$4WTdFHZB5pe)C$qMhOJsR z!)JfP3lZS5V$4R5{T_p`=6#Q-YvcG=E+^EHC+&A#78HNl`3ZMpVo4;uU1=xC%bvg@ zr258s&asMfq$R85D=*jSEgiSlb>{_10dwcr#r4 z8&QO;f3*7l3jR&k|Bd>AK!-Wgk2#evB9zUs)frJi^nKx{kDV_mdLQGYQ{i1|5;Rk##!|@iRb#q+payTo_is->setFont(GUIUtil::fixedPitchFont()); + QPixmap p1(":/icons/mininav"); + QPixmap p2(":/icons/minixnav"); + + ui->fromBox->insertItem(0,"Public NAV"); + ui->fromBox->insertItem(1,"Private xNAV"); + ui->fromBox->setItemData(0,p1,Qt::DecorationRole); + ui->fromBox->setItemData(1,p2,Qt::DecorationRole); + ui->fromBox->setIconSize(QSize(32,32)); + // Connect signals connect(ui->payAmount, SIGNAL(valueChanged()), this, SIGNAL(payAmountChanged())); connect(ui->checkboxSubtractFeeFromAmount, SIGNAL(toggled(bool)), this, SIGNAL(subtractFeeFromAmountChanged())); @@ -51,15 +60,13 @@ SendCoinsEntry::SendCoinsEntry(const PlatformStyle *platformStyle, QWidget *pare connect(ui->addressBookCheckBox, SIGNAL(clicked()), this, SLOT(updateAddressBook())); connect(ui->checkboxUseFullAmount, SIGNAL(clicked()), this, SLOT(useFullAmount())); connect(ui->checkboxCoinControl, SIGNAL(toggled(bool)), this, SLOT(_coinControlFeaturesChanged(bool))); - connect(ui->sendPublic, SIGNAL(clicked()), this, SLOT(sendPublicChanged())); - connect(ui->sendPrivate, SIGNAL(clicked()), this, SLOT(sendPrivateChanged())); + connect(ui->fromBox, SIGNAL(currentIndexChanged(int)), this, SLOT(fromChanged(int))); QSettings settings; bool fDefaultPrivate = settings.value("defaultprivate", false).toBool(); - ui->sendPublic->setChecked(!fDefaultPrivate); - ui->sendPrivate->setChecked(fDefaultPrivate); + ui->fromBox->setCurrentIndex(fDefaultPrivate); ui->amountLabel->setText(fDefaultPrivate ? "A&mount (xNAV):" : "A&mount (NAV):"); ui->memo->setVisible(false); ui->memoLabel->setVisible(false); @@ -74,22 +81,13 @@ SendCoinsEntry::~SendCoinsEntry() delete ui; } -void SendCoinsEntry::sendPublicChanged() -{ - fPrivate = !((bool)ui->sendPublic->isChecked() && ui->sendPublic->isCheckable()); - QSettings settings; - settings.setValue("defaultprivate", !ui->sendPublic->isChecked()); - ui->amountLabel->setText(fPrivate ? "A&mount (xNAV):" : "A&mount (NAV):"); - Q_EMIT privateOrPublicChanged(false); -} - -void SendCoinsEntry::sendPrivateChanged() +void SendCoinsEntry::fromChanged(int index) { - fPrivate = (bool)ui->sendPrivate->isChecked() && ui->sendPrivate->isCheckable(); + fPrivate = index; QSettings settings; - settings.setValue("defaultprivate", ui->sendPrivate->isChecked()); + settings.setValue("defaultprivate", index); ui->amountLabel->setText(fPrivate ? "A&mount (xNAV):" : "A&mount (NAV):"); - Q_EMIT privateOrPublicChanged(true); + Q_EMIT privateOrPublicChanged(index); } void SendCoinsEntry::setTotalPrivateAmount(const CAmount& amount) @@ -110,8 +108,7 @@ void SendCoinsEntry::useFullAmount() { ui->payAmount->setValue(totalAmount); ui->payAmount->setDisabled(ui->checkboxUseFullAmount->isChecked()); - ui->sendPublic->setChecked(true); - ui->sendPrivate->setChecked(false); + ui->fromBox->setCurrentIndex(0); fPrivate = false; } @@ -263,7 +260,7 @@ SendCoinsRecipient SendCoinsEntry::getValue() recipient.label = ui->addAsLabel->text(); recipient.amount = ui->payAmount->value(); recipient.message = ui->memo->text(); - recipient.isanon = ui->sendPrivate->isChecked(); + recipient.isanon = ui->fromBox->currentIndex(); recipient.fSubtractFeeFromAmount = (ui->checkboxSubtractFeeFromAmount->checkState() == Qt::Checked); return recipient; diff --git a/src/qt/sendcoinsentry.h b/src/qt/sendcoinsentry.h index 94931b847..04f757c91 100644 --- a/src/qt/sendcoinsentry.h +++ b/src/qt/sendcoinsentry.h @@ -69,8 +69,7 @@ private Q_SLOTS: void on_addressBookButton_clicked(); void updateDisplayUnit(); void updateAddressBook(); - void sendPrivateChanged(); - void sendPublicChanged(); + void fromChanged(int); void useFullAmount(); void coinControlFeaturesChanged(bool enabled); void _coinControlFeaturesChanged(bool enabled); diff --git a/src/qt/swapxnav.cpp b/src/qt/swapxnav.cpp new file mode 100644 index 000000000..faa8bdfa9 --- /dev/null +++ b/src/qt/swapxnav.cpp @@ -0,0 +1,342 @@ +// Copyright (c) 2020 The NavCoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#include "swapxnav.h" + +SwapXNAVDialog::SwapXNAVDialog(QWidget *parent) : + layout(new QVBoxLayout) +{ + this->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Expanding); + this->resize(600,250); + this->setLayout(layout); + + QFont amountFont("Sans Serif", 8, QFont::Bold); + QFont titleFont("Sans Serif", 16, QFont::Bold); + label1 = new QLabel(""); + label1->setFont(amountFont); + label2 = new QLabel(""); + label2->setFont(amountFont); + + toplabel1 = new QLabel(""); + toplabel1->setFont(titleFont); + toplabel2 = new QLabel(""); + toplabel2->setFont(titleFont); + + icon1 = new QLabel(""); + icon2 = new QLabel(""); + + amount = new NavCoinAmountField(0, 0); + + QPixmap pixmap(":/icons/swap"); + QIcon ButtonIcon(pixmap); + swapButton = new QPushButton(); + swapButton->setIcon(ButtonIcon); + swapButton->setIconSize(QSize(65, 65)); + swapButton->setFixedSize(QSize(65, 65)); + swapButton->setFlat(true); + + connect(swapButton, SIGNAL(clicked()), this, SLOT(Swap())); + + fMode = false; + + QHBoxLayout *iconsLayout = new QHBoxLayout(); + QVBoxLayout *icon1Layout = new QVBoxLayout(); + QVBoxLayout *icon2Layout = new QVBoxLayout(); + + icon1Layout->addWidget(toplabel1); + icon1Layout->addWidget(icon1); + icon1Layout->addWidget(label1); + icon1Layout->setAlignment(icon1, Qt::AlignCenter); + icon1Layout->setAlignment(label1, Qt::AlignCenter); + icon1Layout->setAlignment(toplabel1, Qt::AlignCenter); + + icon2Layout->addWidget(toplabel2); + icon2Layout->addWidget(icon2); + icon2Layout->addWidget(label2); + icon2Layout->setAlignment(icon2, Qt::AlignCenter); + icon2Layout->setAlignment(label2, Qt::AlignCenter); + icon2Layout->setAlignment(toplabel2, Qt::AlignCenter); + + iconsLayout->addLayout(icon1Layout); + iconsLayout->addWidget(swapButton); + iconsLayout->addLayout(icon2Layout); + + QLabel *amountLabel = new QLabel(tr("Swap amount: ")); + amountLabel->setFont(titleFont); + + QPushButton* okButton = new QPushButton(tr("SWAP!")); + + connect(okButton, SIGNAL(clicked()), this, SLOT(Ok())); + + layout->addSpacing(10); + layout->addWidget(amountLabel); + layout->addWidget(amount); + layout->addSpacing(20); + layout->addLayout(iconsLayout); + layout->addSpacing(20); + layout->addWidget(okButton); + layout->addSpacing(10); + + layout->setAlignment(amountLabel, Qt::AlignCenter); + layout->setAlignment(amount, Qt::AlignCenter); + + Swap(); +} + +void SwapXNAVDialog::setModel(WalletModel *model) +{ + this->model = model; +} + +void SwapXNAVDialog::setClientModel(ClientModel *model) +{ + this->clientModel = model; +} + +void SwapXNAVDialog::SetPublicBalance(CAmount a) +{ + int unit = 0; + + this->publicBalance = a; + if (fMode) + label1->setText(QString::fromStdString(_("Available: ")) + NavCoinUnits::formatWithUnit(unit, a, false, NavCoinUnits::separatorAlways, false)); + else + label2->setText(QString::fromStdString(_("Available: ")) + NavCoinUnits::formatWithUnit(unit, a, false, NavCoinUnits::separatorAlways, false)); +} + +void SwapXNAVDialog::SetPrivateBalance(CAmount a) +{ + int unit = 0; + + this->privateBalance = a; + if (fMode) + label2->setText(QString::fromStdString(_("Available: ")) + NavCoinUnits::formatWithUnit(unit, a, false, NavCoinUnits::separatorAlways, true)); + else + label1->setText(QString::fromStdString(_("Available: ")) + NavCoinUnits::formatWithUnit(unit, a, false, NavCoinUnits::separatorAlways, true)); +} + +void SwapXNAVDialog::Swap() +{ + fMode = !fMode; + + QPixmap pix(":/icons/mininav"); + QPixmap scaled = pix.scaled(50,50,Qt::KeepAspectRatio,Qt::SmoothTransformation); + + QBitmap map(50,50); + map.fill(Qt::color0); + QPainter painter( &map ); + painter.setBrush(Qt::color1); + painter.drawRoundedRect( 0, 0, 50, 50,15,15); + scaled.setMask(map); + + QPixmap pix2(":/icons/minixnav"); + QPixmap scaled2 = pix2.scaled(50,50,Qt::KeepAspectRatio,Qt::SmoothTransformation); + + QBitmap map2(50,50); + map2.fill(Qt::color0); + QPainter painter2( &map2 ); + painter2.setBrush(Qt::color1); + painter2.drawRoundedRect( 0, 0, 50, 50,15,15); + scaled2.setMask(map2); + + if (fMode) + { + toplabel1->setText(tr("From: NAV")); + icon1->setPixmap(scaled); + toplabel2->setText(tr("To: xNAV")); + icon2->setPixmap(scaled2); + } + else + { + toplabel1->setText(tr("From: xNAV")); + icon1->setPixmap(scaled2); + toplabel2->setText(tr("To: NAV")); + icon2->setPixmap(scaled); + } + + SetPublicBalance(this->publicBalance); + SetPrivateBalance(this->privateBalance); +} + +void SwapXNAVDialog::Ok() +{ + CAmount nAmount = amount->value(); + + if ((fMode ? publicBalance : privateBalance) < nAmount) + + { + QMessageBox msgBox(this); + std::string str = tr("You don't have that many coins to swap!\n\nAvailable:\n%1").arg(NavCoinUnits::formatWithUnit(0, fMode ? publicBalance : privateBalance, false, NavCoinUnits::separatorAlways, !fMode)).toStdString(); + msgBox.setText(tr(str.c_str())); + msgBox.addButton(tr("Ok"), QMessageBox::AcceptRole); + msgBox.setIcon(QMessageBox::Warning); + msgBox.setWindowTitle("Insufficient NAV"); + msgBox.exec(); + return; + } + + CWalletTx wtx; + + // Ensure wallet is unlocked + WalletModel::UnlockContext ctx(model->requestUnlock()); + if(!ctx.isValid()) + { + // Unlock wallet was cancelled + return; + } + + CNavCoinAddress address; + + if (fMode) + { + blsctDoublePublicKey k; + if (pwalletMain->GetBLSCTSubAddressPublicKeys(std::make_pair(0, 0), k)) + address = CNavCoinAddress(k); + else + { + QMessageBox msgBox(this); + msgBox.setText(tr("Swap failed: your wallet does not support receiving xNAV")); + msgBox.addButton(tr("Ok"), QMessageBox::AcceptRole); + msgBox.setIcon(QMessageBox::Warning); + msgBox.setWindowTitle("Error"); + msgBox.exec(); + + QWidget::close(); + return; + } + } + else + { + if (!pwalletMain->IsLocked()) + pwalletMain->TopUpKeyPool(); + + // Generate a new key that is added to wallet + CPubKey newKey; + if (!pwalletMain->GetKeyFromPool(newKey)) + { + QMessageBox msgBox(this); + msgBox.setText(tr("Swap failed: keypool run out!")); + msgBox.addButton(tr("Ok"), QMessageBox::AcceptRole); + msgBox.setIcon(QMessageBox::Warning); + msgBox.setWindowTitle("Error"); + msgBox.exec(); + + QWidget::close(); + return; + } + CKeyID keyID = newKey.GetID(); + + address = CNavCoinAddress(keyID); + } + + CScript scriptPubKey = GetScriptForDestination(address.Get()); + + // Create and send the transaction + CReserveKey reservekey(pwalletMain); + CAmount nFeeRequired; + std::string strError; + vector vecSend; + int nChangePosRet = -1; + CRecipient recipient = {scriptPubKey, nAmount, true, fMode}; + if (fMode) + { + bls::G1Element vk, sk; + blsctDoublePublicKey dk = boost::get(address.Get()); + + if (!dk.GetSpendKey(sk) || !dk.GetViewKey(vk)) + { + QMessageBox msgBox(this); + msgBox.setText(tr("Swap failed: invalid address")); + msgBox.addButton(tr("Ok"), QMessageBox::AcceptRole); + msgBox.setIcon(QMessageBox::Warning); + msgBox.setWindowTitle("Error"); + msgBox.exec(); + + QWidget::close(); + return; + } + recipient.sk = sk.Serialize(); + recipient.vk = vk.Serialize(); + recipient.sMemo = "Swap"; + } + vecSend.push_back(recipient); + + std::vector> reserveBLSCTKey; + + for (unsigned int i = 0; i < vecSend.size()+2; i++) + { + shared_ptr rk(new CReserveBLSCTBlindingKey(pwalletMain)); + reserveBLSCTKey.insert(reserveBLSCTKey.begin(), std::move(rk)); + } + + CandidateTransaction selectedCoins; + + if (!fMode) + { + AggregationSessionDialog msd(0); + msd.setWalletModel(model); + msd.setClientModel(clientModel); + if (!msd.exec()) + QMessageBox::critical(this, tr("Something failed"), tr("The mixing process failed, if you continue, the transaction would be sent with limited privacy and the source could be easily identified by an observer. Please, review your connection to the network.")); + else + { + selectedCoins = msd.GetSelectedCoins(); + if (selectedCoins.tx.vout.size() == 0) + QMessageBox::critical(this, tr("No coins for mixing"), tr("We could not find any candidate coin, if you continue, the transaction would be sent with limited privacy and the source could be easily identified by an observer. Please, review your connection to the network.")); + } + } + + if (pwalletMain->CreateTransaction(vecSend, wtx, reservekey, reserveBLSCTKey, nFeeRequired, nChangePosRet, strError, !fMode, NULL, true, &selectedCoins)) { + if (QMessageBox::No == QMessageBox(QMessageBox::Information, + tr("Swap!"), + tr("In order to swap %1 to %2, you will have to pay a fee of %3.").arg( + NavCoinUnits::formatWithUnit(0, nAmount, false, NavCoinUnits::separatorAlways, !fMode), + fMode ? "xNAV" : "NAV", + NavCoinUnits::formatWithUnit(0, nFeeRequired, false, NavCoinUnits::separatorAlways, !fMode)) + +"

"+tr("You will receive a total of %1.").arg( + NavCoinUnits::formatWithUnit(0, nAmount - nFeeRequired, false, NavCoinUnits::separatorAlways, !fMode)) + +"

"+tr("Do you want to continue?"), + QMessageBox::Yes|QMessageBox::No).exec()) + { + QWidget::close(); + return; + } + } + else + { + // Display something went wrong UI + QMessageBox msgBox(this); + msgBox.setText(tr("Swap failed: %1").arg(QString::fromStdString(strError))); + msgBox.addButton(tr("Ok"), QMessageBox::AcceptRole); + msgBox.setIcon(QMessageBox::Warning); + msgBox.setWindowTitle("Error"); + msgBox.exec(); + + QWidget::close(); + return; + } + + if (!pwalletMain->CommitTransaction(wtx, reservekey, reserveBLSCTKey)) { + // Display something went wrong UI + QMessageBox msgBox(this); + msgBox.setText(tr("Swap failed")); + msgBox.addButton(tr("Ok"), QMessageBox::AcceptRole); + msgBox.setIcon(QMessageBox::Warning); + msgBox.setWindowTitle("Error"); + msgBox.exec(); + } + else + { + // Display something went wrong UI + QMessageBox msgBox(this); + msgBox.setText(tr("Swap succeded")); + msgBox.addButton(tr("Ok"), QMessageBox::AcceptRole); + msgBox.setIcon(QMessageBox::Information); + msgBox.setWindowTitle("Ok!"); + msgBox.exec(); + } + + QWidget::close(); + return; +} diff --git a/src/qt/swapxnav.h b/src/qt/swapxnav.h new file mode 100644 index 000000000..352d22280 --- /dev/null +++ b/src/qt/swapxnav.h @@ -0,0 +1,67 @@ +// Copyright (c) 2020 The NavCoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef SWAPXNAV_H +#define SWAPXNAV_H + +#include "aggregationsession.h" +#include "navcoinunits.h" +#include "optionsmodel.h" +#include "navcoinamountfield.h" +#include "blsct/key.h" +#include "wallet/wallet.h" +#include "clientmodel.h" +#include "walletmodel.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define DEFAULT_UNIT 0 + +class SwapXNAVDialog : public QDialog +{ + Q_OBJECT + +public: + SwapXNAVDialog(QWidget *parent); + + void setModel(WalletModel *model); + void setClientModel(ClientModel *model); + void SetPublicBalance(CAmount a); + void SetPrivateBalance(CAmount a); + +private: + CAmount publicBalance; + CAmount privateBalance; + + bool fMode; + + WalletModel *model; + ClientModel *clientModel; + QVBoxLayout* layout; + QLabel *label1; + QLabel *label2; + QLabel *toplabel1; + QLabel *toplabel2; + QPushButton *swapButton; + NavCoinAmountField *amount; + + QLabel *icon1; + QLabel *icon2; + +private Q_SLOTS: + void Swap(); + void Ok(); +}; + +#endif // SWAPXNAV_H diff --git a/src/qt/walletview.cpp b/src/qt/walletview.cpp index 9da7e5bcd..d35d9771e 100644 --- a/src/qt/walletview.cpp +++ b/src/qt/walletview.cpp @@ -147,7 +147,7 @@ void WalletView::setWalletModel(WalletModel *walletModel) daoPage->setWalletModel(walletModel); receiveCoinsPage->setModel(walletModel); requestPaymentPage->setModel(walletModel); - requestPaymentPage->showQR(); + requestPaymentPage->showPrivateAddress(0); sendCoinsPage->setModel(walletModel); usedReceivingAddressesPage->setModel(walletModel->getAddressTableModel()); usedSendingAddressesPage->setModel(walletModel->getAddressTableModel()); @@ -231,6 +231,7 @@ void WalletView::gotoReceiveCoinsPage() } void WalletView::gotoRequestPaymentPage(){ + requestPaymentPage->showPrivateAddress(0); setCurrentWidget(requestPaymentPage); daoPage->setActive(false); }