[UI] Add Instantsend parameter to URI/QR-code (#1042)

This commit is contained in:
crowning- 2016-09-27 09:48:52 +02:00 committed by UdjinM6
parent b9bd11610d
commit 93cd3693c2
5 changed files with 61 additions and 3 deletions

View File

@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>776</width> <width>776</width>
<height>364</height> <height>387</height>
</rect> </rect>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,1"> <layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,1">
@ -127,7 +127,7 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="8" column="2"> <item row="9" column="2">
<layout class="QHBoxLayout" name="horizontalLayout"> <layout class="QHBoxLayout" name="horizontalLayout">
<item> <item>
<widget class="QPushButton" name="receiveButton"> <widget class="QPushButton" name="receiveButton">
@ -176,13 +176,23 @@
</item> </item>
</layout> </layout>
</item> </item>
<item row="8" column="0"> <item row="9" column="0">
<widget class="QLabel" name="label_7"> <widget class="QLabel" name="label_7">
<property name="text"> <property name="text">
<string/> <string/>
</property> </property>
</widget> </widget>
</item> </item>
<item row="8" column="2">
<widget class="QCheckBox" name="checkUseInstantSend">
<property name="text">
<string>Request InstantSend</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout> </layout>
</item> </item>
</layout> </layout>

View File

@ -151,6 +151,8 @@ bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out)
QUrlQuery uriQuery(uri); QUrlQuery uriQuery(uri);
QList<QPair<QString, QString> > items = uriQuery.queryItems(); QList<QPair<QString, QString> > items = uriQuery.queryItems();
#endif #endif
rv.fUseInstantSend = false;
for (QList<QPair<QString, QString> >::iterator i = items.begin(); i != items.end(); i++) for (QList<QPair<QString, QString> >::iterator i = items.begin(); i != items.end(); i++)
{ {
bool fShouldReturnFalse = false; bool fShouldReturnFalse = false;
@ -165,6 +167,13 @@ bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out)
rv.label = i->second; rv.label = i->second;
fShouldReturnFalse = false; fShouldReturnFalse = false;
} }
if (i->first == "IS")
{
if(i->second.compare(QString("1")) == 0)
rv.fUseInstantSend = true;
fShouldReturnFalse = false;
}
if (i->first == "message") if (i->first == "message")
{ {
rv.message = i->second; rv.message = i->second;
@ -230,6 +239,12 @@ QString formatBitcoinURI(const SendCoinsRecipient &info)
ret += QString("%1message=%2").arg(paramCount == 0 ? "?" : "&").arg(msg); ret += QString("%1message=%2").arg(paramCount == 0 ? "?" : "&").arg(msg);
paramCount++; paramCount++;
} }
if(info.fUseInstantSend)
{
ret += QString("%1IS=1").arg(paramCount == 0 ? "?" : "&");
paramCount++;
}
return ret; return ret;
} }

View File

@ -152,6 +152,7 @@ void ReceiveCoinsDialog::on_receiveButton_clicked()
} }
SendCoinsRecipient info(address, label, SendCoinsRecipient info(address, label,
ui->reqAmount->value(), ui->reqMessage->text()); ui->reqAmount->value(), ui->reqMessage->text());
info.fUseInstantSend = ui->checkUseInstantSend->isChecked();
ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this); ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);
dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setModel(model->getOptionsModel()); dialog->setModel(model->getOptionsModel());

View File

@ -149,6 +149,10 @@ void ReceiveRequestDialog::update()
html += "<b>"+tr("Label")+"</b>: " + GUIUtil::HtmlEscape(info.label) + "<br>"; html += "<b>"+tr("Label")+"</b>: " + GUIUtil::HtmlEscape(info.label) + "<br>";
if(!info.message.isEmpty()) if(!info.message.isEmpty())
html += "<b>"+tr("Message")+"</b>: " + GUIUtil::HtmlEscape(info.message) + "<br>"; html += "<b>"+tr("Message")+"</b>: " + GUIUtil::HtmlEscape(info.message) + "<br>";
if(info.fUseInstantSend)
html += "<b>"+tr("InstantSend")+"</b>: Yes<br>";
else
html += "<b>"+tr("InstantSend")+"</b>: No<br>";
ui->outUri->setText(html); ui->outUri->setText(html);
#ifdef USE_QRCODE #ifdef USE_QRCODE

View File

@ -63,4 +63,32 @@ void URITests::uriTests()
uri.setUrl(QString("dash:XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg?amount=1,000.0&label=Some Example")); uri.setUrl(QString("dash:XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg?amount=1,000.0&label=Some Example"));
QVERIFY(!GUIUtil::parseBitcoinURI(uri, &rv)); QVERIFY(!GUIUtil::parseBitcoinURI(uri, &rv));
uri.setUrl(QString("dash:XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg?amount=100&label=Some Example&message=Some Example Message&IS=1"));
QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv));
QVERIFY(rv.address == QString("XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg"));
QVERIFY(rv.amount == 10000000000LL);
QVERIFY(rv.label == QString("Some Example"));
QVERIFY(rv.message == QString("Some Example Message"));
QVERIFY(rv.fUseInstantSend == 1);
uri.setUrl(QString("dash:XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg?amount=100&label=Some Example&message=Some Example Message&IS=Something Invalid"));
QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv));
QVERIFY(rv.address == QString("XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg"));
QVERIFY(rv.amount == 10000000000LL);
QVERIFY(rv.label == QString("Some Example"));
QVERIFY(rv.message == QString("Some Example Message"));
QVERIFY(rv.fUseInstantSend != 1);
uri.setUrl(QString("dash:XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg?IS=1"));
QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv));
QVERIFY(rv.fUseInstantSend == 1);
uri.setUrl(QString("dash:XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg?IS=0"));
QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv));
QVERIFY(rv.fUseInstantSend != 1);
uri.setUrl(QString("dash:XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg"));
QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv));
QVERIFY(rv.fUseInstantSend != 1);
} }