6 #include "ui_coldstakingwidget.h"
23 #define DECORATION_SIZE 70
25 #define LOAD_MIN_TIME_INTERVAL 15
26 #define REQUEST_LOAD_TASK 1
42 void init(QWidget* holder,
const QModelIndex &index,
bool isHovered,
bool isSelected)
const override
47 QString address = index.data(Qt::DisplayRole).toString();
49 if (label.isEmpty()) {
50 label = QObject::tr(
"Address with no label");
55 row->
updateView(address, label, isWhitelisted, isReceivedDelegation, amountStr);
59 QColor
rectColor(
bool isHovered,
bool isSelected)
override
81 this->setStyleSheet(parent->styleSheet());
85 ui->left->setContentsMargins(0,20,0,0);
87 ui->right->setContentsMargins(0,10,0,20);
91 fontLight.setWeight(QFont::Light);
95 ui->labelTitle->setFont(fontLight);
103 spacerDiv =
new QSpacerItem(40, 20, QSizePolicy::Maximum, QSizePolicy::Expanding);
106 btnOwnerContact =
ui->lineEditOwnerAddress->addAction(QIcon(
"://ic-contact-arrow-down"), QLineEdit::TrailingPosition);
108 ui->lineEditOwnerAddress->setAttribute(Qt::WA_MacShowFocusRect, 0);
113 ui->labelSubtitle2->setContentsMargins(0,2,0,0);
123 ((QVBoxLayout*)
ui->containerSend->layout())->insertWidget(1,
sendMultiRow);
132 ui->btnCoinControl->setTitleClassAndText(
"btn-title-grey", tr(
"Coin Control"));
133 ui->btnCoinControl->setSubTitleClassAndText(
"text-subtitle", tr(
"Select %1 outputs to delegate.").arg(
CURRENCY_UNIT.c_str()));
135 ui->btnColdStaking->setTitleClassAndText(
"btn-title-grey", tr(
"Create Cold Staking Address"));
136 ui->btnColdStaking->setSubTitleClassAndText(
"text-subtitle", tr(
"Creates an address to receive delegated coins\nand stake them on their owner's behalf."));
137 ui->btnColdStaking->layout()->setMargin(0);
143 ui->pushRight->setChecked(
true);
144 connect(
ui->pushLeft, &QPushButton::clicked, [
this](){onDelegateSelected(false);});
145 connect(
ui->pushRight, &QPushButton::clicked, [
this](){onDelegateSelected(true);});
166 ui->listView->setAttribute(Qt::WA_MacShowFocusRect,
false);
167 ui->listView->setSelectionBehavior(QAbstractItemView::SelectRows);
169 ui->btnMyStakingAddresses->setChecked(
true);
170 ui->listViewStakingAddress->setVisible(
false);
174 ui->lineEditFilter->setStyleSheet(
"font: 14px;");
176 ui->btnMyStakingAddresses->setTitleClassAndText(
"btn-title-grey", tr(
"My Cold Staking Addresses"));
177 ui->btnMyStakingAddresses->setSubTitleClassAndText(
"text-subtitle", tr(
"List your own cold staking addresses."));
178 ui->btnMyStakingAddresses->layout()->setMargin(0);
179 ui->btnMyStakingAddresses->setRightIconClass(
"ic-arrow");
186 ui->listViewStakingAddress->setAttribute(Qt::WA_MacShowFocusRect,
false);
187 ui->listViewStakingAddress->setSelectionBehavior(QAbstractItemView::SelectRows);
188 ui->listViewStakingAddress->setUniformItemSizes(
true);
198 ui->sortWidget->setVisible(
false);
230 ui->containerHistoryLabel->setVisible(
false);
231 ui->emptyContainer->setVisible(
false);
232 ui->listView->setVisible(
false);
259 if (!isVisible())
return;
285 ui->labelStakingTotal->setVisible(hasDel);
293 QMetaObject::invokeMethod(
this,
"onDelegationsRefreshed", Qt::QueuedConnection);
299 inform(tr(
"Error loading delegations: %1").arg(
error));
315 if (contactsSize == 0) {
317 tr(
"No receive addresses available, you can go to the receive screen and create some there!") :
318 tr(
"No contacts available, you can go to the contacts screen and add some there!")
328 height =
ui->lineEditOwnerAddress->height();
329 width =
ui->lineEditOwnerAddress->width();
330 pos =
ui->containerSend->rect().bottomLeft();
331 pos.setY((pos.y() + (height - 12) * 3));
336 pos.setY((pos.y() + (height - 14) * 4));
339 int margin1, margin2;
340 ui->verticalLayoutTop->getContentsMargins(&margin1,
nullptr,
nullptr,
nullptr);
341 ui->vContainerOwner->getContentsMargins(&margin2,
nullptr,
nullptr,
nullptr);
342 pos.setX(pos.x() + margin1 + margin2);
344 height = (contactsSize <= 2) ? height * ( 2 * (contactsSize + 1 )) : height * 6;
354 ui->lineEditOwnerAddress->setText(address);
387 ui->btnCoinControl->setVisible(
true);
388 ui->containerSend->setVisible(
true);
389 ui->containerBtn->setVisible(
true);
390 ui->emptyContainer->setVisible(
false);
391 ui->listView->setVisible(
false);
392 ui->containerHistoryLabel->setVisible(
false);
393 ui->btnColdStaking->setVisible(
false);
394 ui->btnMyStakingAddresses->setVisible(
false);
395 ui->listViewStakingAddress->setVisible(
false);
396 ui->sortWidget->setVisible(
false);
399 ui->btnCoinControl->setVisible(
false);
400 ui->containerSend->setVisible(
false);
401 ui->containerBtn->setVisible(
false);
402 ui->btnColdStaking->setVisible(
true);
404 ui->btnMyStakingAddresses->setVisible(
true);
419 ui->emptyContainer->setVisible(!show);
420 ui->listView->setVisible(show);
421 ui->containerHistoryLabel->setVisible(show);
430 inform(tr(
"Cold staking is networkely disabled"));
435 inform(tr(
"Invalid entry"));
444 if (dest.
amount < minColdStakingAmount) {
445 inform(tr(
"Invalid entry, minimum delegable amount is ") +
450 QString inputOwner =
ui->lineEditOwnerAddress->text();
451 bool isOwnerEmpty = inputOwner.isEmpty();
453 inform(tr(
"Owner address invalid"));
459 bool isOwnerAddressFromThisWallet = isOwnerEmpty ||
walletModel->
isMine(inputOwner);
462 if (!isOwnerAddressFromThisWallet && !
ask(tr(
"ALERT!"),
463 tr(
"Delegating to an external owner address!\n\n"
464 "The delegated coins will NOT be spendable by this wallet.\nSpending these coins will need to be done from the wallet or\ndevice containing the owner address.\n\n"
465 "Do you wish to proceed?"))) {
470 if (isStakingAddressFromThisWallet && isOwnerAddressFromThisWallet) {
471 inform(tr(
"Staking address corresponds to this wallet, change it to an external node"));
479 inform(tr(
"Cannot send delegation, wallet locked"));
484 QList<SendCoinsRecipient> recipients;
485 recipients.append(dest);
501 inform(tr(
"Cannot create transaction."));
509 dialog->adjustSize();
524 inform(tr(
"Coins delegated"));
528 dialog->deleteLater();
534 ui->lineEditOwnerAddress->clear();
537 ui->btnCoinControl->setActive(
false);
574 inform(tr(
"Cannot perform operation, wallet locked"));
583 if (dialog->
res == 1) {
584 inform(tr(
"URI copied to clipboard"));
585 }
else if (dialog->
res == 2) {
586 inform(tr(
"Address copied to clipboard"));
588 dialog->deleteLater();
595 ui->listViewStakingAddress->setCurrentIndex(_index);
597 QRect rect =
ui->listViewStakingAddress->visualRect(_index);
598 QPoint pos = rect.topRight();
627 ui->listView->setCurrentIndex(rIndex);
628 QRect rect =
ui->listView->visualRect(rIndex);
629 QPoint pos = rect.topRight();
640 this->
menu->setMinimumHeight(157);
641 this->
menu->setFixedHeight(157);
642 this->
menu->setMinimumWidth(125);
652 this->
index = rIndex;
654 if (isReceivedDelegation) {
656 Qt::DisplayRole).toBool();
660 this->
menu->setMinimumHeight(157);
666 this->
menu->setMinimumHeight(60);
669 this->
menu->adjustSize();
678 inform(tr(
"Address copied"));
684 tr(
"Edit Cold Address Label"),
694 inform(tr(
"Whitelist failed, please check the logs"));
698 if (label.isEmpty()) {
699 label =
index.data(Qt::DisplayRole).toString();
702 inform(label + tr(
" staking!"));
709 inform(tr(
"Blacklist failed, please check the logs"));
713 if (label.isEmpty()) {
714 label =
index.data(Qt::DisplayRole).toString();
717 inform(label + tr(
" blacklisted from staking"));
727 QString owner =
index.data(Qt::DisplayRole).toString();
729 inform(tr(
"Owner address copied"));
735 tr(
"Edit Owner Address Label"),
748 QString qAddress =
index.data(Qt::DisplayRole).toString();
752 std::string stdString = qAddress.toStdString();
757 label.toUtf8().constData(),
760 if (isMyColdStakingAddresses) {
764 inform(tr(
"Address label saved"));
766 inform(tr(
"Error storing address label"));
777 "btn-dropdown" :
"ic-arrow"),
true);
780 ui->sortWidget->setVisible(
true);
782 ui->listViewStakingAddress->update();
784 ui->sortWidget->setVisible(
false);
791 const bool isValid =
ui->lineEditOwnerAddress->text().isEmpty() || (
794 setCssProperty(
ui->lineEditOwnerAddress, isValid ?
"edit-primary-multi-book" :
"edit-primary-multi-book-error",
true);
801 ui->listView->update();
807 ui->labelStakingTotal->setText(tr(
"Total Staking: %1").arg(
820 sortOrder = (Qt::SortOrder)
ui->comboBoxSortOrder->itemData(idx).toInt();
int64_t CAmount
Amount in PIV (Can be negative)
static const QString ColdStakingSend
Specifies send cold staking addresses (simil 'contacts')
@ Address
Bitcoin address.
std::string purposeForAddress(const std::string &address) const
void notifyChange(const QModelIndex &index)
static const QString Receive
Specifies receive address.
static const QString ColdStaking
Specifies cold staking own addresses.
QString labelForAddress(const QString &address) const
static QString formatWithUnit(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string (with unit)
QColor rectColor(bool isHovered, bool isSelected) override
CSDelegationHolder(bool _isLightTheme)
~CSDelegationHolder() override
CSRow * createHolder(int pos) override
void init(QWidget *holder, const QModelIndex &index, bool isHovered, bool isSelected) const override
void updateState(bool isLightTheme, bool isHovered, bool isSelected)
void updateView(const QString &address, const QString &label, bool isStaking, bool isReceivedDelegation, const QString &amount)
void showMenuButton(bool show)
void setModel(WalletModel *model)
CCoinControl * coinControl
void addPayAmount(const CAmount &amount, bool isShieldedRecipient)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
CAmount getTotalAmount() const
bool whitelist(const QModelIndex &modelIndex)
bool blacklist(const QModelIndex &index)
@ TOTAL_STACKEABLE_AMOUNT_STR
FurListRow * getRowFactory()
void setWalletModel(WalletModel *model)
void setPaymentRequest(bool _isPaymentRequest)
SendCoinsRecipient getValue()
void setLabel(const QString &label)
void onContactsClicked(SendMultiRow *entry)
void setOnlyStakingAddressAccepted(bool onlyStakingAddress)
void setAddress(const QString &address)
void txArrived(const QString &hash, const bool isCoinStake, const bool isMNReward, const bool isCSAnyType)
WalletModel::SendCoinsReturn getStatus()
void setDisplayUnit(int unit)
void setData(WalletModel *model, WalletModelTransaction *tx)
bool validateAddress(const QString &address)
bool isMine(const CWDestination &address)
bool updateAddressBookLabels(const CWDestination &address, const std::string &strName, const std::string &strPurpose)
CAmount getMinColdStakingAmount() const
AddressTableModel * getAddressTableModel()
OptionsModel * getOptionsModel()
SendCoinsReturn prepareTransaction(WalletModelTransaction *transaction, const CCoinControl *coinControl=nullptr, bool fIncludeDelegations=true)
bool isColdStakingNetworkelyEnabled() const
Whether cold staking is enabled or disabled in the network.
CAmount getBalance(const CCoinControl *coinControl=nullptr, bool fIncludeDelegated=true, bool fUnlockedOnly=false, bool fIncludeShielded=true) const
UnlockContext requestUnlock()
TransactionTableModel * getTransactionTableModel()
Data model for a walletmodel transaction.
CAmount getTransactionFee()
const std::string CURRENCY_UNIT
QString formatBalance(CAmount amount, int nDisplayUnit, bool isZpiv)
void setClipboard(const QString &str)
void ProcessSendCoinsReturnAndInform(PWidget *parent, const WalletModel::SendCoinsReturn &sendCoinsReturn, WalletModel *walletModel, const QString &msgArg, bool fPrepare)
CWDestination DecodeDestination(const std::string &strAddress)
bool openDialogWithOpaqueBackgroundY(QDialog *widget, PIVXGUI *gui, double posX, int posY, bool hideOpaqueBackground)
void setCssTitleScreen(QLabel *label)
void initCssEditLine(QLineEdit *edit, bool isDialog)
void setShadow(QWidget *edit)
void setCssProperty(std::initializer_list< QWidget * > args, const QString &value)
QColor getRowColor(bool isLightTheme, bool isHovered, bool isSelected)
void setCssSubtitleScreen(QWidget *wid)
void setCssBtnPrimary(QPushButton *btn, bool forceUpdate)
void setCssBtnSecondary(QPushButton *btn, bool forceUpdate)
void fillAddressSortControls(SortEdit *seType, SortEdit *seOrder, QComboBox *boxType, QComboBox *boxOrder)
boost::variant< CNoDestination, CKeyID, CScriptID, CExchangeKeyID > CTxDestination
A txout script template with a specific destination.
bool error(const char *fmt, const Args &... args)
int64_t GetTime()
DEPRECATED Use either GetSystemTimeInSeconds (not mockable) or GetTime<T> (mockable)