mirror of
https://github.com/feather-wallet/feather.git
synced 2024-11-17 09:47:36 +00:00
MorphToken: Add Qr code for deposit address
This commit is contained in:
parent
ca5b1df7df
commit
a11dd576e4
3 changed files with 97 additions and 9 deletions
|
@ -4,6 +4,8 @@
|
||||||
#include "MorphTokenWidget.h"
|
#include "MorphTokenWidget.h"
|
||||||
#include "ui_MorphTokenWidget.h"
|
#include "ui_MorphTokenWidget.h"
|
||||||
#include "mainwindow.h"
|
#include "mainwindow.h"
|
||||||
|
#include "qrcode/QrCode.h"
|
||||||
|
#include "dialog/qrcodedialog.h"
|
||||||
|
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
|
@ -54,6 +56,10 @@ MorphTokenWidget::MorphTokenWidget(QWidget *parent) :
|
||||||
ui->label_rate->setVisible(false);
|
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);
|
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));
|
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) {
|
if (resp.endpoint == MorphTokenApi::Endpoint::CREATE_TRADE || resp.endpoint == MorphTokenApi::Endpoint::GET_TRADE) {
|
||||||
ui->tabWidget->setCurrentIndex(1);
|
ui->tabWidget->setCurrentIndex(1);
|
||||||
ui->line_Id->setText(resp.obj.value("id").toString());
|
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()),
|
statusText += QString(" Maximum amount accepted: %1 %2\n").arg(formatAmount(input["asset"].toString(), input["limits"].toObject()["max"].toDouble()),
|
||||||
input["asset"].toString());
|
input["asset"].toString());
|
||||||
statusText += QString("\nSend a single deposit. If the amount is outside the limits, a refund will happen.");
|
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") {
|
} else if (state == "PROCESSING" || state == "TRADING" || state == "CONFIRMING") {
|
||||||
if (state == "CONFIRMING") {
|
if (state == "CONFIRMING") {
|
||||||
statusText += QString("Waiting for confirmations\n");
|
statusText += QString("Waiting for confirmations\n");
|
||||||
|
@ -180,6 +198,13 @@ void MorphTokenWidget::displayRate() {
|
||||||
ui->label_rate->setText(rateStr);
|
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) {
|
QString MorphTokenWidget::formatAmount(const QString &asset, double amount) {
|
||||||
double displayAmount;
|
double displayAmount;
|
||||||
double div;
|
double div;
|
||||||
|
|
|
@ -28,6 +28,7 @@ private:
|
||||||
|
|
||||||
void onCountdown();
|
void onCountdown();
|
||||||
void displayRate();
|
void displayRate();
|
||||||
|
void showQrCodeDialog();
|
||||||
|
|
||||||
QString formatAmount(const QString &asset, double amount);
|
QString formatAmount(const QString &asset, double amount);
|
||||||
|
|
||||||
|
@ -40,6 +41,7 @@ private:
|
||||||
int m_countdown = 30;
|
int m_countdown = 30;
|
||||||
QJsonObject m_rates;
|
QJsonObject m_rates;
|
||||||
QTimer m_ratesTimer;
|
QTimer m_ratesTimer;
|
||||||
|
QString m_depositAddress;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //FEATHER_MORPHTOKENWIDGET_H
|
#endif //FEATHER_MORPHTOKENWIDGET_H
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTabWidget" name="tabWidget">
|
<widget class="QTabWidget" name="tabWidget">
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>0</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="tabCreateTrade">
|
<widget class="QWidget" name="tabCreateTrade">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
|
@ -305,6 +305,8 @@
|
||||||
<string>Trade</string>
|
<string>Trade</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_5">
|
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label_status">
|
<widget class="QLabel" name="label_status">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
@ -315,6 +317,58 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_4">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="ClickableLabel" name="qrCode">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>qrcode</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_depositAddress">
|
||||||
|
<property name="text">
|
||||||
|
<string>Deposit address</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer_3">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>0</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="verticalSpacer">
|
<spacer name="verticalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
@ -357,6 +411,13 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<customwidgets>
|
||||||
|
<customwidget>
|
||||||
|
<class>ClickableLabel</class>
|
||||||
|
<extends>QLabel</extends>
|
||||||
|
<header>components.h</header>
|
||||||
|
</customwidget>
|
||||||
|
</customwidgets>
|
||||||
<resources/>
|
<resources/>
|
||||||
<connections/>
|
<connections/>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
Loading…
Reference in a new issue