mirror of
				https://git.wownero.com/wowlet/wowlet.git
				synced 2024-08-15 01:03:14 +00:00 
			
		
		
		
	Send: show fiat conversion when XMR is selected
This commit is contained in:
		
							parent
							
								
									a325883b62
								
							
						
					
					
						commit
						98db512164
					
				
					 4 changed files with 29 additions and 15 deletions
				
			
		| 
						 | 
					@ -256,6 +256,7 @@ MainWindow::MainWindow(AppContext *ctx, QWidget *parent) :
 | 
				
			||||||
        connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, tickerWidget, &TickerWidget::init);
 | 
					        connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, tickerWidget, &TickerWidget::init);
 | 
				
			||||||
    connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, m_balanceWidget, &TickerWidget::init);
 | 
					    connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, m_balanceWidget, &TickerWidget::init);
 | 
				
			||||||
    connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, m_ctx, &AppContext::onPreferredFiatCurrencyChanged);
 | 
					    connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, m_ctx, &AppContext::onPreferredFiatCurrencyChanged);
 | 
				
			||||||
 | 
					    connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, ui->sendWidget, QOverload<>::of(&SendWidget::onPreferredFiatCurrencyChanged));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // CCS/Reddit widget
 | 
					    // CCS/Reddit widget
 | 
				
			||||||
    connect(m_windowSettings, &Settings::homeWidgetChanged, this, &MainWindow::homeWidgetChanged);
 | 
					    connect(m_windowSettings, &Settings::homeWidgetChanged, this, &MainWindow::homeWidgetChanged);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -27,8 +27,8 @@ SendWidget::SendWidget(QWidget *parent) :
 | 
				
			||||||
    connect(ui->lineAmount, &QLineEdit::textEdited, this, &SendWidget::amountEdited);
 | 
					    connect(ui->lineAmount, &QLineEdit::textEdited, this, &SendWidget::amountEdited);
 | 
				
			||||||
    connect(ui->lineAddress, &QLineEdit::textEdited, this, &SendWidget::addressEdited);
 | 
					    connect(ui->lineAddress, &QLineEdit::textEdited, this, &SendWidget::addressEdited);
 | 
				
			||||||
    connect(ui->btn_openAlias, &QPushButton::clicked, this, &SendWidget::aliasClicked);
 | 
					    connect(ui->btn_openAlias, &QPushButton::clicked, this, &SendWidget::aliasClicked);
 | 
				
			||||||
    ui->label_xmrAmount->setText("");
 | 
					    ui->label_conversionAmount->setText("");
 | 
				
			||||||
    ui->label_xmrAmount->hide();
 | 
					    ui->label_conversionAmount->hide();
 | 
				
			||||||
    ui->btn_openAlias->hide();
 | 
					    ui->btn_openAlias->hide();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -120,18 +120,26 @@ void SendWidget::btnMaxClicked() {
 | 
				
			||||||
void SendWidget::updateConversionLabel() {
 | 
					void SendWidget::updateConversionLabel() {
 | 
				
			||||||
    auto amount = this->amount();
 | 
					    auto amount = this->amount();
 | 
				
			||||||
    if(amount == -1) return;
 | 
					    if(amount == -1) return;
 | 
				
			||||||
    ui->label_xmrAmount->setText("");
 | 
					    ui->label_conversionAmount->setText("");
 | 
				
			||||||
    if(amount <= 0) {
 | 
					    if(amount <= 0) {
 | 
				
			||||||
        ui->label_xmrAmount->hide();
 | 
					        ui->label_conversionAmount->hide();
 | 
				
			||||||
        return;
 | 
					        return;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    QString conversionAmountStr = [this]{
 | 
				
			||||||
        QString currency = ui->comboCurrencySelection->currentText();
 | 
					        QString currency = ui->comboCurrencySelection->currentText();
 | 
				
			||||||
        if (currency != "XMR") {
 | 
					        if (currency != "XMR") {
 | 
				
			||||||
        QString xmr_str = QString("%1 XMR").arg(QString::number(this->conversionAmount()));
 | 
					            return QString("~%1 XMR").arg(QString::number(this->conversionAmount(), 'f'));
 | 
				
			||||||
        ui->label_xmrAmount->setText(xmr_str);
 | 
					
 | 
				
			||||||
        ui->label_xmrAmount->show();
 | 
					        } else {
 | 
				
			||||||
    }
 | 
					            auto preferredFiatCurrency = config()->get(Config::preferredFiatCurrency).toString();
 | 
				
			||||||
 | 
					            double conversionAmount = AppContext::prices->convert("XMR", preferredFiatCurrency, this->amount());
 | 
				
			||||||
 | 
					            return QString("~%1 %2").arg(QString::number(conversionAmount, 'f', 2), preferredFiatCurrency);
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					    }();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    ui->label_conversionAmount->setText(conversionAmountStr);
 | 
				
			||||||
 | 
					    ui->label_conversionAmount->show();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
double SendWidget::conversionAmount() {
 | 
					double SendWidget::conversionAmount() {
 | 
				
			||||||
| 
						 | 
					@ -163,7 +171,7 @@ void SendWidget::clearFields() {
 | 
				
			||||||
    ui->lineAddress->clear();
 | 
					    ui->lineAddress->clear();
 | 
				
			||||||
    ui->lineAmount->clear();
 | 
					    ui->lineAmount->clear();
 | 
				
			||||||
    ui->lineDescription->clear();
 | 
					    ui->lineDescription->clear();
 | 
				
			||||||
    ui->label_xmrAmount->clear();
 | 
					    ui->label_conversionAmount->clear();
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void SendWidget::onWalletClosed() {
 | 
					void SendWidget::onWalletClosed() {
 | 
				
			||||||
| 
						 | 
					@ -178,6 +186,10 @@ void SendWidget::onEndTransaction() {
 | 
				
			||||||
    ui->btnSend->setEnabled(true);
 | 
					    ui->btnSend->setEnabled(true);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					void SendWidget::onPreferredFiatCurrencyChanged() {
 | 
				
			||||||
 | 
					    this->updateConversionLabel();
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
SendWidget::~SendWidget() {
 | 
					SendWidget::~SendWidget() {
 | 
				
			||||||
    delete ui;
 | 
					    delete ui;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -38,6 +38,7 @@ public slots:
 | 
				
			||||||
    void onOpenAliasResolveError(const QString &err);
 | 
					    void onOpenAliasResolveError(const QString &err);
 | 
				
			||||||
    void onOpenAliasResolved(const QString &address, const QString &openAlias);
 | 
					    void onOpenAliasResolved(const QString &address, const QString &openAlias);
 | 
				
			||||||
    void onWalletClosed();
 | 
					    void onWalletClosed();
 | 
				
			||||||
 | 
					    void onPreferredFiatCurrencyChanged();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    void onInitiateTransaction();
 | 
					    void onInitiateTransaction();
 | 
				
			||||||
    void onEndTransaction();
 | 
					    void onEndTransaction();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,8 +6,8 @@
 | 
				
			||||||
   <rect>
 | 
					   <rect>
 | 
				
			||||||
    <x>0</x>
 | 
					    <x>0</x>
 | 
				
			||||||
    <y>0</y>
 | 
					    <y>0</y>
 | 
				
			||||||
    <width>500</width>
 | 
					    <width>603</width>
 | 
				
			||||||
    <height>148</height>
 | 
					    <height>175</height>
 | 
				
			||||||
   </rect>
 | 
					   </rect>
 | 
				
			||||||
  </property>
 | 
					  </property>
 | 
				
			||||||
  <property name="windowTitle">
 | 
					  <property name="windowTitle">
 | 
				
			||||||
| 
						 | 
					@ -153,12 +153,12 @@
 | 
				
			||||||
      </widget>
 | 
					      </widget>
 | 
				
			||||||
     </item>
 | 
					     </item>
 | 
				
			||||||
     <item>
 | 
					     <item>
 | 
				
			||||||
      <widget class="QLabel" name="label_xmrAmount">
 | 
					      <widget class="QLabel" name="label_conversionAmount">
 | 
				
			||||||
       <property name="enabled">
 | 
					       <property name="enabled">
 | 
				
			||||||
        <bool>true</bool>
 | 
					        <bool>true</bool>
 | 
				
			||||||
       </property>
 | 
					       </property>
 | 
				
			||||||
       <property name="text">
 | 
					       <property name="text">
 | 
				
			||||||
        <string>xmrAmount</string>
 | 
					        <string>conversionAmount</string>
 | 
				
			||||||
       </property>
 | 
					       </property>
 | 
				
			||||||
      </widget>
 | 
					      </widget>
 | 
				
			||||||
     </item>
 | 
					     </item>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue