Skip to content

Commit

Permalink
[GUI] Add checkboxSubtractFeeFromAmount checkbox in sendmultirow
Browse files Browse the repository at this point in the history
Visible when single recipient. Its checked state returns whether or not
to subtract the fee from the recipient amount.

SendMultiRow::toggleSubtractFeeFromAmount is not connected for now.
It will be connected with the contextual menu, to set per-recipient
subtract-fee-from-amount, when there are multiple rows.
  • Loading branch information
random-zebra committed Jun 14, 2021
1 parent 3a19d0b commit e3410cf
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 4 deletions.
10 changes: 10 additions & 0 deletions src/qt/pivx/forms/sendmultirow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,16 @@ padding:0px;</string>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QCheckBox" name="checkboxSubtractFeeFromAmount">
<property name="toolTip">
<string>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.</string>
</property>
<property name="text">
<string>Subtract fee from amount</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
Expand Down
16 changes: 14 additions & 2 deletions src/qt/pivx/sendconfirmdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<SendCoinsRecipient>& 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) {
Expand Down
12 changes: 12 additions & 0 deletions src/qt/pivx/sendmultirow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ SendCoinsRecipient SendMultiRow::getValue()
recipient.amount = getAmountValue();
auto dest = Standard::DecodeDestination(recipient.address.toStdString());
recipient.isShieldedAddr = boost::get<libzcash::SaplingPaymentAddress>(&dest);
recipient.fSubtractFee = getSubtractFeeFromAmount();
return recipient;
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/qt/pivx/sendmultirow.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -598,9 +598,9 @@ OperationResult WalletModel::PrepareShieldedTransaction(WalletModelTransaction*
const CCoinControl* coinControl)
{
// Load shieldedAddrRecipients.
bool fSubtractFeeFromAmount{false};
std::vector<SendManyRecipient> 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");
Expand Down
3 changes: 3 additions & 0 deletions src/qt/walletmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e3410cf

Please sign in to comment.