diff --git a/src/MorphTokenWidget.cpp b/src/MorphTokenWidget.cpp index 67f70ae..5459487 100644 --- a/src/MorphTokenWidget.cpp +++ b/src/MorphTokenWidget.cpp @@ -4,6 +4,8 @@ #include "MorphTokenWidget.h" #include "ui_MorphTokenWidget.h" #include "mainwindow.h" +#include "qrcode/QrCode.h" +#include "dialog/qrcodedialog.h" #include @@ -54,6 +56,10 @@ MorphTokenWidget::MorphTokenWidget(QWidget *parent) : ui->label_rate->setVisible(false); }); + ui->qrCode->setVisible(false); + ui->label_depositAddress->setVisible(false); + connect(ui->qrCode, &ClickableLabel::clicked, this, &MorphTokenWidget::showQrCodeDialog); + ui->tabWidget->setTabVisible(2, false); } @@ -86,6 +92,10 @@ void MorphTokenWidget::onApiResponse(const MorphTokenApi::MorphTokenResponse &re ui->debugInfo->setPlainText(QJsonDocument(resp.obj).toJson(QJsonDocument::Indented)); + bool shouldShowQr = (resp.endpoint == MorphTokenApi::Endpoint::CREATE_TRADE || resp.endpoint == MorphTokenApi::Endpoint::GET_TRADE); + ui->qrCode->setVisible(shouldShowQr); + ui->label_depositAddress->setVisible(shouldShowQr); + if (resp.endpoint == MorphTokenApi::Endpoint::CREATE_TRADE || resp.endpoint == MorphTokenApi::Endpoint::GET_TRADE) { ui->tabWidget->setCurrentIndex(1); ui->line_Id->setText(resp.obj.value("id").toString()); @@ -112,6 +122,14 @@ void MorphTokenWidget::onApiResponse(const MorphTokenApi::MorphTokenResponse &re statusText += QString(" Maximum amount accepted: %1 %2\n").arg(formatAmount(input["asset"].toString(), input["limits"].toObject()["max"].toDouble()), input["asset"].toString()); statusText += QString("\nSend a single deposit. If the amount is outside the limits, a refund will happen."); + + m_depositAddress = input["deposit_address"].toString(); + + const QrCode qrc(m_depositAddress, QrCode::Version::AUTO, QrCode::ErrorCorrectionLevel::MEDIUM); + int width = ui->qrCode->width(); + if (qrc.isValid()) { + ui->qrCode->setPixmap(qrc.toPixmap(1).scaled(width, width, Qt::KeepAspectRatio)); + } } else if (state == "PROCESSING" || state == "TRADING" || state == "CONFIRMING") { if (state == "CONFIRMING") { statusText += QString("Waiting for confirmations\n"); @@ -180,6 +198,13 @@ void MorphTokenWidget::displayRate() { ui->label_rate->setText(rateStr); } +void MorphTokenWidget::showQrCodeDialog() { + QrCode qr(m_depositAddress, QrCode::Version::AUTO, QrCode::ErrorCorrectionLevel::HIGH); + auto *dialog = new QrCodeDialog(this, qr, "Deposit address"); + dialog->exec(); + dialog->deleteLater(); +} + QString MorphTokenWidget::formatAmount(const QString &asset, double amount) { double displayAmount; double div; diff --git a/src/MorphTokenWidget.h b/src/MorphTokenWidget.h index e9d5128..0f0961f 100644 --- a/src/MorphTokenWidget.h +++ b/src/MorphTokenWidget.h @@ -28,6 +28,7 @@ private: void onCountdown(); void displayRate(); + void showQrCodeDialog(); QString formatAmount(const QString &asset, double amount); @@ -40,6 +41,7 @@ private: int m_countdown = 30; QJsonObject m_rates; QTimer m_ratesTimer; + QString m_depositAddress; }; #endif //FEATHER_MORPHTOKENWIDGET_H diff --git a/src/MorphTokenWidget.ui b/src/MorphTokenWidget.ui index 8790ab7..fcdbff7 100644 --- a/src/MorphTokenWidget.ui +++ b/src/MorphTokenWidget.ui @@ -29,7 +29,7 @@ - 0 + 1 @@ -306,14 +306,68 @@ - - - No trade loaded. - - - Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse - - + + + + + No trade loaded. + + + Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse + + + + + + + Qt::Horizontal + + + + 0 + 20 + + + + + + + + + + + 0 + 0 + + + + qrcode + + + + + + + Deposit address + + + + + + + Qt::Vertical + + + + 20 + 0 + + + + + + + @@ -357,6 +411,13 @@ + + + ClickableLabel + QLabel +
components.h
+
+