diff --git a/src/qt/pivx/forms/sendmultirow.ui b/src/qt/pivx/forms/sendmultirow.ui index 55807066364e60..83272fe04631d8 100644 --- a/src/qt/pivx/forms/sendmultirow.ui +++ b/src/qt/pivx/forms/sendmultirow.ui @@ -347,6 +347,16 @@ padding:0px; 0 + + + + The fee will be deducted from the amount being sent. The recipient will receive less PIV than you enter in the amount field. If multiple recipients are selected, the fee is split equally. + + + Subtract fee from amount + + + diff --git a/src/qt/pivx/sendconfirmdialog.cpp b/src/qt/pivx/sendconfirmdialog.cpp index 984a9b6e6fb5d3..dfe6c02582f66d 100644 --- a/src/qt/pivx/sendconfirmdialog.cpp +++ b/src/qt/pivx/sendconfirmdialog.cpp @@ -183,14 +183,26 @@ void TxDetailDialog::setData(WalletModel *_model, WalletModelTransaction* _tx) this->model = _model; this->tx = _tx; CAmount txFee = tx->getTransactionFee(); - CAmount totalAmount = tx->getTotalTransactionAmount() + txFee; // inputs label CTransactionRef walletTx = tx->getTransaction(); setInputsType(walletTx); + bool fSubtractFee = false; + const QList& recipients = tx->getRecipients(); + for (const SendCoinsRecipient& rec : recipients) { + if (rec.fSubtractFee) { + fSubtractFee = true; + break; + } + } + + CAmount totalAmount = tx->getTotalTransactionAmount(); + if (!fSubtractFee) totalAmount += txFee; + ui->textAmount->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, totalAmount, false, BitcoinUnits::separatorAlways) + " (Fee included)"); - int nRecipients = tx->getRecipients().size(); + + int nRecipients = recipients.size(); if (nRecipients == 1) { const SendCoinsRecipient& recipient = tx->getRecipients().at(0); if (recipient.isP2CS) { diff --git a/src/qt/pivx/sendmultirow.cpp b/src/qt/pivx/sendmultirow.cpp index a95cd6ce3b9bbe..a91f472b3b67c0 100644 --- a/src/qt/pivx/sendmultirow.cpp +++ b/src/qt/pivx/sendmultirow.cpp @@ -225,6 +225,7 @@ SendCoinsRecipient SendMultiRow::getValue() recipient.amount = getAmountValue(); auto dest = Standard::DecodeDestination(recipient.address.toStdString()); recipient.isShieldedAddr = boost::get(&dest); + recipient.fSubtractFee = getSubtractFeeFromAmount(); return recipient; } @@ -263,6 +264,11 @@ int SendMultiRow::getNumber() return number; } +bool SendMultiRow::getSubtractFeeFromAmount() const +{ + return ui->checkboxSubtractFeeFromAmount->isChecked(); +} + void SendMultiRow::setAddress(const QString& address) { ui->lineEditAddress->setText(address); @@ -274,6 +280,12 @@ void SendMultiRow::setAmount(const QString& amount) ui->lineEditAmount->setText(amount); } +void SendMultiRow::toggleSubtractFeeFromAmount() +{ + bool old = ui->checkboxSubtractFeeFromAmount->isChecked(); + ui->checkboxSubtractFeeFromAmount->setChecked(!old); +} + void SendMultiRow::setAddressAndLabelOrDescription(const QString& address, const QString& message) { QString label = walletModel->getAddressTableModel()->labelForAddress(address); diff --git a/src/qt/pivx/sendmultirow.h b/src/qt/pivx/sendmultirow.h index 5a6f5ad0f55b3d..9bb34c5d3fbf58 100644 --- a/src/qt/pivx/sendmultirow.h +++ b/src/qt/pivx/sendmultirow.h @@ -50,11 +50,13 @@ class SendMultiRow : public PWidget void setAmount(const QString& amount); void setAddressAndLabelOrDescription(const QString& address, const QString& message); void setFocus(); + void toggleSubtractFeeFromAmount(); QRect getEditLineRect(); int getEditHeight(); int getEditWidth(); int getMenuBtnWidth(); + bool getSubtractFeeFromAmount() const; // Return true if memo was set and false if it was cleared. bool launchMemoDialog(); diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 567ccf24b6801f..d5edb32f6f6d19 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -488,7 +488,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact // Regular P2PK or P2PKH scriptPubKey = GetScriptForDestination(out); } - vecSend.emplace_back(scriptPubKey, rcp.amount, false); + vecSend.emplace_back(scriptPubKey, rcp.amount, rcp.fSubtractFee); total += rcp.amount; } @@ -598,9 +598,9 @@ OperationResult WalletModel::PrepareShieldedTransaction(WalletModelTransaction* const CCoinControl* coinControl) { // Load shieldedAddrRecipients. - bool fSubtractFeeFromAmount{false}; std::vector recipients; for (const auto& recipient : modelTransaction->getRecipients()) { + bool fSubtractFeeFromAmount = recipient.fSubtractFee; if (recipient.isShieldedAddr) { auto pa = KeyIO::DecodeSaplingPaymentAddress(recipient.address.toStdString()); if (!pa) return errorOut("Error, invalid shielded address"); diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 2cdcec7575d201..d06220648fd57b 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -70,6 +70,9 @@ class SendCoinsRecipient // Quick flag to not have to check the address type more than once. bool isShieldedAddr{false}; + // Whether to subtract the tx fee from this recipient + bool fSubtractFee{false}; + // Amount CAmount amount{0}; // If from a payment request, this is used for storing the memo