Skip to content

Commit

Permalink
Composed txComments for gui-wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
ace committed Feb 26, 2021
1 parent d350504 commit 5207557
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 61 deletions.
144 changes: 87 additions & 57 deletions src/qt/forms/sendcoinsentry.ui
Expand Up @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>729</width>
<height>150</height>
<height>172</height>
</rect>
</property>
<property name="focusPolicy">
Expand Down Expand Up @@ -36,47 +36,6 @@
<property name="verticalSpacing">
<number>8</number>
</property>
<item row="2" column="2">
<layout class="QHBoxLayout" name="horizontalLayoutAmount" stretch="0,1,0">
<item>
<widget class="EarthcoinAmountField" name="payAmount"/>
</item>
<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 earthcoins than you enter in the amount field. If multiple recipients are selected, the fee is split equally.</string>
</property>
<property name="text">
<string>S&amp;ubtract fee from amount</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="useAvailableBalanceButton">
<property name="text">
<string>Use available balance</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="3" column="0">
<widget class="QLabel" name="messageLabel">
<property name="text">
<string>Message:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="4" column="0" colspan="3">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="payToLabel">
<property name="text">
Expand All @@ -90,25 +49,18 @@
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labellLabel">
<item row="6" column="0">
<widget class="QLabel" name="messageLabel">
<property name="text">
<string>&amp;Label:</string>
<string>Message:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>addAsLabel</cstring>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="addAsLabel">
<property name="toolTip">
<string>Enter a label for this address to add it to the list of used addresses</string>
</property>
</widget>
<item row="6" column="2">
<widget class="QLineEdit" name="messageTextLabel"/>
</item>
<item row="0" column="2">
<layout class="QHBoxLayout" name="payToLayout">
Expand Down Expand Up @@ -190,7 +142,7 @@
</item>
</layout>
</item>
<item row="2" column="0">
<item row="3" column="0">
<widget class="QLabel" name="amountLabel">
<property name="text">
<string>A&amp;mount:</string>
Expand All @@ -204,7 +156,86 @@
</widget>
</item>
<item row="3" column="2">
<widget class="QLineEdit" name="messageTextLabel"/>
<layout class="QHBoxLayout" name="horizontalLayoutAmount" stretch="0,1,0">
<item>
<widget class="EarthcoinAmountField" name="payAmount"/>
</item>
<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 earthcoins than you enter in the amount field. If multiple recipients are selected, the fee is split equally.</string>
</property>
<property name="text">
<string>S&amp;ubtract fee from amount</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="useAvailableBalanceButton">
<property name="text">
<string>Use available balance</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="7" column="0">
<widget class="QLabel" name="cidLabel">
<property name="text">
<string>IPFS CID:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item row="9" column="0" colspan="3">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="labellLabel">
<property name="text">
<string>&amp;Label:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>addAsLabel</cstring>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLineEdit" name="addAsLabel">
<property name="toolTip">
<string>Enter a label for this address to add it to the list of used addresses</string>
</property>
</widget>
</item>
<item row="7" column="2">
<layout class="QHBoxLayout" name="horizontalLayoutMessageCID">
<item>
<widget class="QLineEdit" name="cidTextLabel">
<property name="enabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxCID">
<property name="text">
<string/>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
Expand Down Expand Up @@ -1262,7 +1293,6 @@
<tabstop>addressBookButton</tabstop>
<tabstop>pasteButton</tabstop>
<tabstop>deleteButton</tabstop>
<tabstop>addAsLabel</tabstop>
<tabstop>payAmount</tabstop>
<tabstop>payAmount_is</tabstop>
<tabstop>deleteButton_is</tabstop>
Expand Down
18 changes: 17 additions & 1 deletion src/qt/sendcoinsentry.cpp
Expand Up @@ -46,6 +46,7 @@ SendCoinsEntry::SendCoinsEntry(const PlatformStyle *_platformStyle, QWidget *par
connect(ui->deleteButton_is, SIGNAL(clicked()), this, SLOT(deleteClicked()));
connect(ui->deleteButton_s, SIGNAL(clicked()), this, SLOT(deleteClicked()));
connect(ui->useAvailableBalanceButton, SIGNAL(clicked()), this, SLOT(useAvailableBalanceClicked()));
connect(ui->checkBoxCID, SIGNAL(stateChanged(int)), this, SLOT(useCID(int)));
}

SendCoinsEntry::~SendCoinsEntry()
Expand Down Expand Up @@ -94,10 +95,15 @@ void SendCoinsEntry::clear(bool showMessage)
ui->addAsLabel->clear();
ui->payAmount->clear();
ui->checkboxSubtractFeeFromAmount->setCheckState(Qt::Unchecked);
ui->checkBoxCID->setCheckState(Qt::Unchecked);
ui->cidTextLabel->setEnabled(false);
ui->messageTextLabel->clear();
if (!showMessage) {
ui->messageTextLabel->hide();
ui->messageLabel->hide();
ui->cidLabel->hide();
ui->cidTextLabel->hide();
ui->checkBoxCID->hide();
}
// clear UI elements for unauthenticated payment request
ui->payTo_is->clear();
Expand All @@ -117,6 +123,11 @@ void SendCoinsEntry::checkSubtractFeeFromAmount()
ui->checkboxSubtractFeeFromAmount->setChecked(true);
}

void SendCoinsEntry::useCID(int a)
{
ui->cidTextLabel->setEnabled(ui->checkBoxCID->isChecked());
}

void SendCoinsEntry::deleteClicked()
{
Q_EMIT removeEntry(this);
Expand Down Expand Up @@ -176,7 +187,12 @@ SendCoinsRecipient SendCoinsEntry::getValue()
recipient.address = ui->payTo->text();
recipient.label = ui->addAsLabel->text();
recipient.amount = ui->payAmount->value();
recipient.message = ui->messageTextLabel->text();
// SANDO - composed txComment set
QString cid = ui->cidTextLabel->text();
QString spr("\n");
QString msg = ui->messageTextLabel->text();
bool cmp = ui->checkBoxCID->isChecked();
recipient.message = cmp ? (cid + spr + msg) : msg;
recipient.fSubtractFeeFromAmount = (ui->checkboxSubtractFeeFromAmount->checkState() == Qt::Checked);

return recipient;
Expand Down
1 change: 1 addition & 0 deletions src/qt/sendcoinsentry.h
Expand Up @@ -50,6 +50,7 @@ class SendCoinsEntry : public QStackedWidget
public Q_SLOTS:
void clear(bool showMessage = true);
void checkSubtractFeeFromAmount();
void useCID(int);

Q_SIGNALS:
void removeEntry(SendCoinsEntry *entry);
Expand Down
13 changes: 11 additions & 2 deletions src/qt/transactiondesc.cpp
Expand Up @@ -251,8 +251,17 @@ QString TransactionDesc::toHTML(interfaces::Node& node, interfaces::Wallet& wall
strHTML += "<b>" + tr("Transaction total size") + ":</b> " + QString::number(wtx.tx->GetTotalSize()) + " bytes<br>";
strHTML += "<b>" + tr("Transaction virtual size") + ":</b> " + QString::number(GetVirtualTransactionSize(*wtx.tx)) + " bytes<br>";
strHTML += "<b>" + tr("Output index") + ":</b> " + QString::number(rec->getOutputIndex()) + "<br>";
if (wtx.tx->nVersion == 2)
strHTML += "<b>" + tr("Transaction comment") + ":</b> " + GUIUtil::HtmlEscape(wtx.tx->strTxComment); + "<br>";
if (wtx.tx->nVersion == 2)
{
std::string sMsg = wtx.tx->strTxComment;
size_t pos = FindIpfsIdseparator(sMsg);
if (pos) {
strHTML += "<b>" + tr("IPFS_CID") + ":</b> " + GUIUtil::HtmlEscape(sMsg.substr(0, pos)) + "<br>";
strHTML += "<b>" + tr("Transaction comment") + ":</b> " + GUIUtil::HtmlEscape(sMsg.substr(pos+1)) + "<br>";
}
else
strHTML += "<b>" + tr("Transaction comment") + ":</b> " + GUIUtil::HtmlEscape(sMsg) + "<br>";
}

// Message from normal earthcoin:URI (earthcoin:123...?message=example)
for (const std::pair<std::string, std::string>& r : orderForm)
Expand Down
2 changes: 1 addition & 1 deletion src/utilstrencodings.cpp
Expand Up @@ -565,7 +565,7 @@ size_t FindIpfsIdseparator(const std::string& s)
int n = s.length();
if (n < 1)
return 0;
size_t pos = s.find(':');
size_t pos = s.find(0x0a);
if (pos == std::string::npos)
return 0;
return (IsBase58(s.substr(0, pos))) ? pos : 0;
Expand Down

0 comments on commit 5207557

Please sign in to comment.