mirror of
				https://git.wownero.com/wowlet/wowlet.git
				synced 2024-08-15 01:03:14 +00:00 
			
		
		
		
	Merge pull request 'MorphToken: Add Qr code for deposit address' (#178) from tobtoht/feather:morphtoken_qr into master
Reviewed-on: https://git.wownero.com/feather/feather/pulls/178
This commit is contained in:
		
						commit
						1a6024c697
					
				
					 3 changed files with 97 additions and 9 deletions
				
			
		| 
						 | 
				
			
			@ -4,6 +4,8 @@
 | 
			
		|||
#include "MorphTokenWidget.h"
 | 
			
		||||
#include "ui_MorphTokenWidget.h"
 | 
			
		||||
#include "mainwindow.h"
 | 
			
		||||
#include "qrcode/QrCode.h"
 | 
			
		||||
#include "dialog/qrcodedialog.h"
 | 
			
		||||
 | 
			
		||||
#include <QMessageBox>
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -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;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -29,7 +29,7 @@
 | 
			
		|||
   <item>
 | 
			
		||||
    <widget class="QTabWidget" name="tabWidget">
 | 
			
		||||
     <property name="currentIndex">
 | 
			
		||||
      <number>0</number>
 | 
			
		||||
      <number>1</number>
 | 
			
		||||
     </property>
 | 
			
		||||
     <widget class="QWidget" name="tabCreateTrade">
 | 
			
		||||
      <attribute name="title">
 | 
			
		||||
| 
						 | 
				
			
			@ -306,14 +306,68 @@
 | 
			
		|||
         </property>
 | 
			
		||||
         <layout class="QVBoxLayout" name="verticalLayout_5">
 | 
			
		||||
          <item>
 | 
			
		||||
           <widget class="QLabel" name="label_status">
 | 
			
		||||
            <property name="text">
 | 
			
		||||
             <string>No trade loaded.</string>
 | 
			
		||||
            </property>
 | 
			
		||||
            <property name="textInteractionFlags">
 | 
			
		||||
             <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
 | 
			
		||||
            </property>
 | 
			
		||||
           </widget>
 | 
			
		||||
           <layout class="QHBoxLayout" name="horizontalLayout_4">
 | 
			
		||||
            <item>
 | 
			
		||||
             <widget class="QLabel" name="label_status">
 | 
			
		||||
              <property name="text">
 | 
			
		||||
               <string>No trade loaded.</string>
 | 
			
		||||
              </property>
 | 
			
		||||
              <property name="textInteractionFlags">
 | 
			
		||||
               <set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
 | 
			
		||||
              </property>
 | 
			
		||||
             </widget>
 | 
			
		||||
            </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>
 | 
			
		||||
           <spacer name="verticalSpacer">
 | 
			
		||||
| 
						 | 
				
			
			@ -357,6 +411,13 @@
 | 
			
		|||
   </item>
 | 
			
		||||
  </layout>
 | 
			
		||||
 </widget>
 | 
			
		||||
 <customwidgets>
 | 
			
		||||
  <customwidget>
 | 
			
		||||
   <class>ClickableLabel</class>
 | 
			
		||||
   <extends>QLabel</extends>
 | 
			
		||||
   <header>components.h</header>
 | 
			
		||||
  </customwidget>
 | 
			
		||||
 </customwidgets>
 | 
			
		||||
 <resources/>
 | 
			
		||||
 <connections/>
 | 
			
		||||
</ui>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue