Skip to content

Commit b43e813

Browse files
committed
[GUI] Cold Staking, P2CS delegation flow created.
1 parent fa25b18 commit b43e813

File tree

6 files changed

+223
-67
lines changed

6 files changed

+223
-67
lines changed

src/qt/pivx/coldstakingwidget.cpp

Lines changed: 72 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
#include "qt/pivx/forms/ui_coldstakingwidget.h"
77
#include "qt/pivx/qtutils.h"
88
#include "guiutil.h"
9-
#include "qt/pivx/denomgenerationdialog.h"
109
#include "qt/pivx/txviewholder.h"
10+
#include "qt/pivx/sendconfirmdialog.h"
11+
#include "qt/pivx/guitransactionsutils.h"
1112
#include "walletmodel.h"
1213
#include "optionsmodel.h"
1314
#include "coincontroldialog.h"
1415
#include "coincontrol.h"
15-
#include "zpiv/accumulators.h"
1616

1717
#define DECORATION_SIZE 65
1818
#define NUM_ITEMS 3
@@ -52,11 +52,12 @@ ColdStakingWidget::ColdStakingWidget(PIVXGUI* parent) :
5252
ui->labelSubtitle2->setText(tr("Delegate or Accept PIV delegation"));
5353
setCssSubtitleScreen(ui->labelSubtitle2);
5454
ui->labelSubtitle2->setContentsMargins(0,2,0,0);
55+
setCssBtnPrimary(ui->pushButtonSend);
5556

5657
ui->labelEditTitle->setText(tr("Add the delegator address"));
5758
setCssProperty(ui->labelEditTitle, "text-title");
5859
sendMultiRow = new SendMultiRow(this);
59-
ui->containerSend->layout()->addWidget(sendMultiRow);
60+
((QVBoxLayout*)ui->containerSend->layout())->insertWidget(1, sendMultiRow);
6061
//connect(sendMultiRow, &SendMultiRow::onContactsClicked, this, &SendWidget::onContactsClicked);
6162
//connect(sendMultiRow, &SendMultiRow::onMenuClicked, this, &SendWidget::onMenuClicked);
6263
//connect(sendMultiRow, &SendMultiRow::onValueChanged, this, &SendWidget::onValueChanged);
@@ -94,6 +95,8 @@ ColdStakingWidget::ColdStakingWidget(PIVXGUI* parent) :
9495
ui->listView->setMinimumHeight(NUM_ITEMS * (DECORATION_SIZE + 2));
9596
ui->listView->setAttribute(Qt::WA_MacShowFocusRect, false);
9697
ui->listView->setSelectionBehavior(QAbstractItemView::SelectRows);
98+
99+
connect(ui->pushButtonSend, &QPushButton::clicked, this, &ColdStakingWidget::onSendClicked);
97100
}
98101

99102
void ColdStakingWidget::loadWalletModel(){
@@ -124,8 +127,10 @@ void ColdStakingWidget::loadWalletModel(){
124127
void ColdStakingWidget::onDelegateSelected(bool delegate){
125128
if(delegate){
126129
ui->btnCoinControl->setVisible(true);
130+
ui->containerSend->setVisible(true);
127131
}else{
128132
ui->btnCoinControl->setVisible(false);
133+
ui->containerSend->setVisible(false);
129134
// change list row for the whitelisted addresses
130135
}
131136
}
@@ -145,15 +150,75 @@ void ColdStakingWidget::showList(bool show){
145150
}
146151

147152
void ColdStakingWidget::onSendClicked(){
148-
if (!walletModel || !walletModel->getOptionsModel())
153+
if (!walletModel || !walletModel->getOptionsModel() || !verifyWalletUnlocked())
149154
return;
150155

151-
}
156+
if (!sendMultiRow->validate()) {
157+
inform(tr("Invalid Entry"));
158+
return;
159+
}
160+
161+
SendCoinsRecipient dest = sendMultiRow->getValue();
162+
dest.isP2CS = true;
163+
164+
// TODO: Add field for owner address. Meanwhile will create one here
165+
CBitcoinAddress address;
166+
if (!walletModel->getNewAddress(address).result) {
167+
inform(tr("Error generating address"));
168+
return;
169+
}
170+
dest.ownerAddress = QString::fromStdString(address.ToString());
171+
QList<SendCoinsRecipient> recipients;
172+
recipients.append(dest);
173+
174+
// Prepare transaction for getting txFee earlier
175+
WalletModelTransaction currentTransaction(recipients);
176+
WalletModel::SendCoinsReturn prepareStatus = walletModel->prepareTransaction(currentTransaction, CoinControlDialog::coinControl);
177+
178+
// process prepareStatus and on error generate message shown to user
179+
GuiTransactionsUtils::ProcessSendCoinsReturn(
180+
this,
181+
prepareStatus,
182+
walletModel,
183+
BitcoinUnits::formatWithUnit(walletModel->getOptionsModel()->getDisplayUnit(),
184+
currentTransaction.getTransactionFee()),
185+
true
186+
);
187+
188+
if (prepareStatus.status != WalletModel::OK) {
189+
inform(tr("Cannot create transaction."));
190+
return;
191+
}
152192

153-
void ColdStakingWidget::delegateBalance(CAmount value, QString address, QString label){
154-
inform(tr("Complete me.. delegation."));
193+
showHideOp(true);
194+
TxDetailDialog* dialog = new TxDetailDialog(window);
195+
dialog->setDisplayUnit(walletModel->getOptionsModel()->getDisplayUnit());
196+
dialog->setData(walletModel, currentTransaction);
197+
dialog->adjustSize();
198+
openDialogWithOpaqueBackgroundY(dialog, window, 3, 5);
199+
200+
if(dialog->isConfirm()){
201+
// now send the prepared transaction
202+
WalletModel::SendCoinsReturn sendStatus = dialog->getStatus();
203+
// process sendStatus and on error generate message shown to user
204+
GuiTransactionsUtils::ProcessSendCoinsReturn(
205+
this,
206+
sendStatus,
207+
walletModel
208+
);
209+
210+
if (sendStatus.status == WalletModel::OK) {
211+
clearAll();
212+
inform(tr("Coins delegated"));
213+
}
214+
}
215+
216+
dialog->deleteLater();
155217
}
156218

219+
void ColdStakingWidget::clearAll() {
220+
if (sendMultiRow) sendMultiRow->clear();
221+
}
157222

158223
void ColdStakingWidget::onCoinControlClicked(){
159224
if(ui->pushRight->isChecked()) {

src/qt/pivx/coldstakingwidget.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private slots:
5555
SendMultiRow *sendMultiRow = nullptr;
5656

5757
int nDisplayUnit;
58-
void delegateBalance(CAmount value, QString address, QString label);
58+
void clearAll();
5959
};
6060

6161
#endif // COLDSTAKINGWIDGET_H

src/qt/pivx/forms/coldstakingwidget.ui

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,44 @@
271271
</property>
272272
</widget>
273273
</item>
274+
<item>
275+
<widget class="QWidget" name="containerBtn" native="true">
276+
<property name="minimumSize">
277+
<size>
278+
<width>0</width>
279+
<height>50</height>
280+
</size>
281+
</property>
282+
<layout class="QHBoxLayout" name="horizontalLayout">
283+
<item>
284+
<spacer name="horizontalSpacer_2">
285+
<property name="orientation">
286+
<enum>Qt::Horizontal</enum>
287+
</property>
288+
<property name="sizeHint" stdset="0">
289+
<size>
290+
<width>200</width>
291+
<height>20</height>
292+
</size>
293+
</property>
294+
</spacer>
295+
</item>
296+
<item>
297+
<widget class="QPushButton" name="pushButtonSend">
298+
<property name="minimumSize">
299+
<size>
300+
<width>150</width>
301+
<height>40</height>
302+
</size>
303+
</property>
304+
<property name="text">
305+
<string>Delegate</string>
306+
</property>
307+
</widget>
308+
</item>
309+
</layout>
310+
</widget>
311+
</item>
274312
</layout>
275313
</widget>
276314
</item>

src/qt/pivx/res/css/style_dark.css

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,49 @@ QPushButton[cssClass="img-nav-logo"] {
100100
color: #B088FF;
101101
}
102102

103+
/*HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
104+
!############# Cold staking
105+
################################*/
106+
107+
*[cssClass="btn-nav-cold-staking"] {
108+
qproperty-icon: url("://ic-nav-cold-staking") off,
109+
url("://ic-nav-cold-staking-active") on;
110+
qproperty-iconSize: 24px 40px;
111+
background-color:transparent;
112+
font-size:14px;
113+
color: #938da5;
114+
}
115+
116+
*[cssClass="btn-nav-cold-staking"]:checked {
117+
background-color: qlineargradient(x1:0, x2: 1, stop: 0 #3c2559, stop: 1 #1f162b);
118+
font-size:14px;
119+
color: #B088FF;
120+
}
121+
122+
*[cssClass="btn-nav-cold-staking"]:checked:hover {
123+
background-color: #0f0b16;
124+
color: #B088FF;
125+
}
126+
127+
*[cssClass="btn-nav-cold-staking"]:hover {
128+
qproperty-icon: url("://ic-nav-cold-staking-hover");
129+
qproperty-iconSize: 24px 40px;
130+
background-color: #1A000000;
131+
color: #938da5;
132+
}
133+
134+
*[cssClass="btn-nav-cold-staking-active"] {
135+
qproperty-icon:url("://ic-nav-cold-staking-active") ;
136+
qproperty-iconSize: 24px 40px;
137+
background-color: #0f0b16;
138+
font-size:14px;
139+
color: #B088FF;
140+
}
141+
142+
/*HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH
143+
!#############
144+
################################*/
145+
103146
*[cssClass="btn-nav-settings"] {
104147
qproperty-icon: url("://ic-nav-settings") off,
105148
url("://ic-nav-settings-active") on;

src/qt/pivx/res/img/ic-transaction-cs-contract-inactive.svg

Lines changed: 29 additions & 27 deletions
Loading

0 commit comments

Comments
 (0)