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
99102void ColdStakingWidget::loadWalletModel (){
@@ -124,8 +127,10 @@ void ColdStakingWidget::loadWalletModel(){
124127void 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
147152void 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
158223void ColdStakingWidget::onCoinControlClicked (){
159224 if (ui->pushRight ->isChecked ()) {
0 commit comments