Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GUI] Add GUI controls for subtract-fee-from-amount #2347

Merged
merged 5 commits into from
Jul 18, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions src/qt/pivx/sendconfirmdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,23 +188,15 @@ void TxDetailDialog::setData(WalletModel *_model, WalletModelTransaction* _tx)
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;
if (tx->subtractFeeFromRecipents() == 0) totalAmount += txFee;

ui->textAmount->setText(BitcoinUnits::formatWithUnit(nDisplayUnit, totalAmount, false, BitcoinUnits::separatorAlways) + " (Fee included)");

const QList<SendCoinsRecipient>& recipients = tx->getRecipients();
int nRecipients = recipients.size();
if (nRecipients == 1) {
const SendCoinsRecipient& recipient = tx->getRecipients().at(0);
const SendCoinsRecipient& recipient = recipients.at(0);
if (recipient.isP2CS) {
ui->labelSend->setText(tr("Delegating to"));
}
Expand Down Expand Up @@ -337,11 +329,14 @@ void TxDetailDialog::onOutputsClicked()
// If the there is a model tx, then this is a confirmation dialog
if (tx) {
const QList<SendCoinsRecipient>& recipients = tx->getRecipients();
unsigned int sffa = tx->subtractFeeFromRecipents();
CAmount rcp_fee = (sffa > 0) ? (tx->getTransactionFee() / sffa) : 0;
for (int i = 0; i < recipients.size(); ++i) {
const auto& recipient = recipients[i];
CAmount rcp_amt = recipient.amount - (recipient.fSubtractFee ? rcp_fee : 0);
random-zebra marked this conversation as resolved.
Show resolved Hide resolved
int charsSize = recipient.isShieldedAddr ? 18 : 16;
QString labelRes = recipient.address.left(charsSize) + "..." + recipient.address.right(charsSize);
appendOutput(layoutGrid, i, labelRes, recipient.amount, nDisplayUnit);
appendOutput(layoutGrid, i, labelRes, rcp_amt, nDisplayUnit);
}
} else {
// Tx detail dialog
Expand Down
9 changes: 9 additions & 0 deletions src/qt/walletmodeltransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ void WalletModelTransaction::setTransactionFee(const CAmount& newFee)
fee = newFee;
}

unsigned int WalletModelTransaction::subtractFeeFromRecipents() const
{
unsigned int count = 0;
for (const SendCoinsRecipient& rcp : recipients) {
if (rcp.fSubtractFee) count++;
}
return count;
}

CAmount WalletModelTransaction::getTotalTransactionAmount()
{
CAmount totalTransactionAmount = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/qt/walletmodeltransaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class WalletModelTransaction

CTransactionRef& getTransaction();

// return the number of recipients with subtract-fee-from-amount
unsigned int subtractFeeFromRecipents() const;

// Whether should create a +v2 tx or go simple and create a v1.
bool useV2{false};
bool fIsStakeDelegationVoided{false};
Expand Down