Skip to content

Commit

Permalink
[GUI] Display actual recipient amount with sffa in confirmation dlg
Browse files Browse the repository at this point in the history
  • Loading branch information
random-zebra committed Jul 12, 2021
1 parent 3f45e09 commit 3e860c5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
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);
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

0 comments on commit 3e860c5

Please sign in to comment.