Skip to content

Commit

Permalink
Add memo field in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
levoncrypto committed Nov 3, 2024
1 parent 9fecae3 commit b72db01
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 14 deletions.
13 changes: 5 additions & 8 deletions src/qt/forms/sendcoinsentry.ui
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
</item>
</layout>
</item>
<item row="4" column="0">
<item row="6" column="0">
<widget class="QLabel" name="messageLabel">
<property name="text">
<string>Message:</string>
Expand All @@ -231,15 +231,12 @@
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLabel" name="messageTextLabel">
<item row="6" column="1">
<widget class="QLineEdit" name="messageTextLabel">
<property name="toolTip">
<string>A message that was attached to the firo: URI which will be stored with the transaction for your reference. Note: This message will not be sent over the Firo network.</string>
<string>Optional message for this transaction</string>
</property>
<property name="textFormat">
<enum>Qt::PlainText</enum>
</property>
</widget>
</widget>
</item>
<item row="5" column="0" colspan="2">
<widget class="Line" name="line">
Expand Down
8 changes: 8 additions & 0 deletions src/qt/sendcoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ void SendCoinsDialog::on_sendButton_clicked()
}
ctx = dialog->getUnlockContext();
}
recipient.message = entry->getValue().message;
recipients.append(recipient);
}
else
Expand Down Expand Up @@ -532,6 +533,13 @@ void SendCoinsDialog::on_sendButton_clicked()
QString questionString = tr("Are you sure you want to send?");
questionString.append(warningMessage);
questionString.append("<br /><br />%1");
questionString.append("\n\nMessage: ");
for (auto rec : recipients)
{
questionString.append(rec.message);
questionString.append("\n");
}

double txSize;
if ((fAnonymousMode == false) && (recipients.size() == sparkAddressCount) && spark::IsSparkAllowed())
{
Expand Down
7 changes: 7 additions & 0 deletions src/qt/sendcoinsentry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ SendCoinsEntry::SendCoinsEntry(const PlatformStyle *_platformStyle, QWidget *par
connect(ui->deleteButton, &QToolButton::clicked, this, &SendCoinsEntry::deleteClicked);
connect(ui->deleteButton_is, &QToolButton::clicked, this, &SendCoinsEntry::deleteClicked);
connect(ui->deleteButton_s, &QToolButton::clicked, this, &SendCoinsEntry::deleteClicked);

ui->messageLabel->setVisible(false);
ui->messageTextLabel->setVisible(false);
}

SendCoinsEntry::~SendCoinsEntry()
Expand Down Expand Up @@ -85,6 +88,10 @@ void SendCoinsEntry::on_payTo_textChanged(const QString &address)
{
updateLabel(address);
setWarning(fAnonymousMode);

bool isSparkAddress = model && model->validateSparkAddress(address);
ui->messageLabel->setVisible(isSparkAddress);
ui->messageTextLabel->setVisible(isSparkAddress);
}

void SendCoinsEntry::setModel(WalletModel *_model)
Expand Down
12 changes: 8 additions & 4 deletions src/qt/transactiondesc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,14 @@ QString TransactionDesc::toHTML(CWallet *wallet, CWalletTx &wtx, TransactionReco
strHTML += "<b>" + tr("Transaction total size") + ":</b> " + QString::number(wtx.tx->GetTotalSize()) + " bytes<br>";
strHTML += "<b>" + tr("Output index") + ":</b> " + QString::number(rec->getOutputIndex()) + "<br>";

// Message from normal firo:URI (firo:123...?message=example)
for (const PAIRTYPE(std::string, std::string)& r : wtx.vOrderForm)
if (r.first == "Message")
strHTML += "<br><b>" + tr("Message") + ":</b><br>" + GUIUtil::HtmlEscape(r.second, true) + "<br>";
uint256 selectedTxID = rec->hash;
std::unordered_map<uint256, CSparkMintMeta> coins = wallet->sparkWallet->getMintMap();

for (const auto& [id, meta] : coins) {
if (meta.txid == selectedTxID && !meta.memo.empty()) {
strHTML += "<b>" + tr("Message") + ":</b> " + GUIUtil::HtmlEscape(meta.memo, true) + "<br>\n";
}
}

if (wtx.IsCoinBase())
{
Expand Down
4 changes: 2 additions & 2 deletions src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareMintSparkTransaction(std::vecto
address.decode(rcp.address.toStdString());
spark::MintedCoinData data;
data.address = address;
data.memo = "";
data.memo = rcp.message.toStdString();
data.v = rcp.amount;
outputs.push_back(data);
total += rcp.amount;
Expand Down Expand Up @@ -1481,7 +1481,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareSpendSparkTransaction(WalletMod
address.decode(rcp.address.toStdString());
spark::OutputCoinData data;
data.address = address;
data.memo = "";
data.memo = rcp.message.toStdString();
data.v = rcp.amount;
privateRecipients.push_back(std::make_pair(data, rcp.fSubtractFeeFromAmount));
} else {
Expand Down

0 comments on commit b72db01

Please sign in to comment.