Skip to content

Commit bd70562

Browse files
author
Philip Kaufmann
committed
[Qt] add messages when handling local payment request files
- important for the open URI dialog to give users feedback when a file is invalid etc.
1 parent fb96e28 commit bd70562

File tree

2 files changed

+37
-17
lines changed

2 files changed

+37
-17
lines changed

src/qt/paymentserver.cpp

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -373,40 +373,52 @@ void PaymentServer::handleURIOrFile(const QString& s)
373373
#else
374374
QUrlQuery uri((QUrl(s)));
375375
#endif
376-
if (uri.hasQueryItem("r"))
376+
if (uri.hasQueryItem("r")) // payment request URI
377377
{
378378
QByteArray temp;
379379
temp.append(uri.queryItemValue("r"));
380380
QString decoded = QUrl::fromPercentEncoding(temp);
381381
QUrl fetchUrl(decoded, QUrl::StrictMode);
382382

383-
qDebug() << "PaymentServer::handleURIOrFile : fetchRequest(" << fetchUrl << ")";
384-
385383
if (fetchUrl.isValid())
384+
{
385+
qDebug() << "PaymentServer::handleURIOrFile : fetchRequest(" << fetchUrl << ")";
386386
fetchRequest(fetchUrl);
387+
}
387388
else
389+
{
388390
qDebug() << "PaymentServer::handleURIOrFile : Invalid URL: " << fetchUrl;
391+
emit message(tr("URI handling"),
392+
tr("Payment request fetch URL is invalid: %1").arg(fetchUrl.toString()),
393+
CClientUIInterface::ICON_WARNING);
394+
}
389395

390396
return;
391397
}
398+
else // normal URI
399+
{
400+
SendCoinsRecipient recipient;
401+
if (GUIUtil::parseBitcoinURI(s, &recipient))
402+
emit receivedPaymentRequest(recipient);
403+
else
404+
emit message(tr("URI handling"),
405+
tr("URI can not be parsed! This can be caused by an invalid Bitcoin address or malformed URI parameters."),
406+
CClientUIInterface::ICON_WARNING);
392407

393-
SendCoinsRecipient recipient;
394-
if (GUIUtil::parseBitcoinURI(s, &recipient))
395-
emit receivedPaymentRequest(recipient);
396-
else
397-
emit message(tr("URI handling"),
398-
tr("URI can not be parsed! This can be caused by an invalid Bitcoin address or malformed URI parameters."),
399-
CClientUIInterface::ICON_WARNING);
400-
401-
return;
408+
return;
409+
}
402410
}
403411

404-
if (QFile::exists(s))
412+
if (QFile::exists(s)) // payment request file
405413
{
406414
PaymentRequestPlus request;
407415
SendCoinsRecipient recipient;
408416
if (readPaymentRequest(s, request) && processPaymentRequest(request, recipient))
409417
emit receivedPaymentRequest(recipient);
418+
else
419+
emit message(tr("Payment request file handling"),
420+
tr("Payment request file can not be read or processed! This can be caused by an invalid payment request file."),
421+
CClientUIInterface::ICON_WARNING);
410422

411423
return;
412424
}
@@ -584,7 +596,7 @@ void PaymentServer::netRequestFinished(QNetworkReply* reply)
584596
.arg(reply->errorString());
585597

586598
qDebug() << "PaymentServer::netRequestFinished : " << msg;
587-
emit message(tr("Network request error"), msg, CClientUIInterface::MSG_ERROR);
599+
emit message(tr("Payment request error"), msg, CClientUIInterface::MSG_ERROR);
588600
return;
589601
}
590602

@@ -596,9 +608,16 @@ void PaymentServer::netRequestFinished(QNetworkReply* reply)
596608
PaymentRequestPlus request;
597609
SendCoinsRecipient recipient;
598610
if (request.parse(data) && processPaymentRequest(request, recipient))
611+
{
599612
emit receivedPaymentRequest(recipient);
613+
}
600614
else
615+
{
601616
qDebug() << "PaymentServer::netRequestFinished : Error processing payment request";
617+
emit message(tr("Payment request error"),
618+
tr("Payment request can not be parsed or processed!"),
619+
CClientUIInterface::MSG_ERROR);
620+
}
602621

603622
return;
604623
}
@@ -611,9 +630,10 @@ void PaymentServer::netRequestFinished(QNetworkReply* reply)
611630
.arg(reply->request().url().toString());
612631

613632
qDebug() << "PaymentServer::netRequestFinished : " << msg;
614-
emit message(tr("Network request error"), msg, CClientUIInterface::MSG_ERROR);
633+
emit message(tr("Payment request error"), msg, CClientUIInterface::MSG_ERROR);
615634
}
616-
else {
635+
else
636+
{
617637
emit receivedPaymentACK(GUIUtil::HtmlEscape(paymentACK.memo()));
618638
}
619639
}

src/qt/paymentserver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public slots:
9898
// Submit Payment message to a merchant, get back PaymentACK:
9999
void fetchPaymentACK(CWallet* wallet, SendCoinsRecipient recipient, QByteArray transaction);
100100

101-
// Handle an incoming URI or file
101+
// Handle an incoming URI, URI with local file scheme or file
102102
void handleURIOrFile(const QString& s);
103103

104104
private slots:

0 commit comments

Comments
 (0)