Skip to content

Commit

Permalink
new display currencies
Browse files Browse the repository at this point in the history
  • Loading branch information
flo071 committed Apr 12, 2020
1 parent cb893b6 commit 737802c
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 9 deletions.
30 changes: 30 additions & 0 deletions src/qt/optionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,33 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
if(configs.value("Currency").toInt() == 0){
ui->currency->addItem("USD");
ui->currency->addItem("EUR");
ui->currency->addItem("GBP");
ui->currency->addItem("LTC");
ui->currency->addItem("JPY");
} else if(configs.value("Currency").toInt() == 1){
ui->currency->addItem("EUR");
ui->currency->addItem("USD");
ui->currency->addItem("GBP");
ui->currency->addItem("LTC");
ui->currency->addItem("JPY");
} else if(configs.value("Currency").toInt() == 2){
ui->currency->addItem("GBP");
ui->currency->addItem("USD");
ui->currency->addItem("EUR");
ui->currency->addItem("LTC");
ui->currency->addItem("JPY");
} else if(configs.value("Currency").toInt() == 3){
ui->currency->addItem("LTC");
ui->currency->addItem("USD");
ui->currency->addItem("EUR");
ui->currency->addItem("GBP");
ui->currency->addItem("JPY");
} else if(configs.value("Currency").toInt() == 4){
ui->currency->addItem("JPY");
ui->currency->addItem("USD");
ui->currency->addItem("EUR");
ui->currency->addItem("GBP");
ui->currency->addItem("LTC");
}

if(configs.value("Design").toInt() == 0){
Expand Down Expand Up @@ -371,6 +395,12 @@ void OptionsDialog::changeCurrency(){
configs.setValue("Currency", 0);
if(ui->currency->currentText().toStdString() == "EUR")
configs.setValue("Currency", 1);
if(ui->currency->currentText().toStdString() == "GBP")
configs.setValue("Currency", 2);
if(ui->currency->currentText().toStdString() == "LTC")
configs.setValue("Currency", 3);
if(ui->currency->currentText().toStdString() == "JPY")
configs.setValue("Currency", 4);
std::cout << "CURRENT CURR: " << configs.value("Currency").toInt() << std::endl;
}

Expand Down
22 changes: 20 additions & 2 deletions src/qt/sendcoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,19 @@ SendCoinsDialog::SendCoinsDialog(const PlatformStyle *platformStyle, QWidget *pa
ui->coinControl->setVisible(true);
ui->transactionFees->setVisible(true);
}

QString usdValue = ui->priceUSD->text().mid(1, ui->priceUSD->text().length());
if(settings.value("Currency").toInt() == 0){
ui->sendAmount->setText("Sending: " + ui->PayAmount->text() + " NOR (" + QString::number(ui->PayAmount->value() * usdValue.toDouble()) + " $)");
} else if(settings.value("Currency").toInt() == 1){
ui->sendAmount->setText("Sending: " + ui->PayAmount->text() + " NOR (" + QString::number(ui->PayAmount->value() * usdValue.toDouble()) + " €)");
} else if(settings.value("Currency").toInt() == 2){
ui->sendAmount->setText("Sending: " + ui->PayAmount->text() + " NOR (" + QString::number(ui->PayAmount->value() * usdValue.toDouble()) + " £)");
} else if(settings.value("Currency").toInt() == 3){
ui->sendAmount->setText("Sending: " + ui->PayAmount->text() + " NOR (" + QString::number(ui->PayAmount->value() * usdValue.toDouble()) + " Ł)");
} else if(settings.value("Currency").toInt() == 4){
ui->sendAmount->setText("Sending: " + ui->PayAmount->text() + " NOR (" + QString::number(ui->PayAmount->value() * usdValue.toDouble()) + " ¥)");
}


/*
Expand All @@ -171,9 +184,14 @@ void SendCoinsDialog::txtChanged(){
QSettings configs;
if(configs.value("Currency").toInt() == 0){
ui->sendAmount->setText("Sending: " + ui->PayAmount->text() + " NOR (" + QString::number(ui->PayAmount->value() * usdValue.toDouble()) + " $)");
}
else if(configs.value("Currency").toInt() == 1){
} else if(configs.value("Currency").toInt() == 1){
ui->sendAmount->setText("Sending: " + ui->PayAmount->text() + " NOR (" + QString::number(ui->PayAmount->value() * usdValue.toDouble()) + " €)");
} else if(configs.value("Currency").toInt() == 2){
ui->sendAmount->setText("Sending: " + ui->PayAmount->text() + " NOR (" + QString::number(ui->PayAmount->value() * usdValue.toDouble()) + " £)");
} else if(configs.value("Currency").toInt() == 3){
ui->sendAmount->setText("Sending: " + ui->PayAmount->text() + " NOR (" + QString::number(ui->PayAmount->value() * usdValue.toDouble()) + " Ł)");
} else if(configs.value("Currency").toInt() == 4){
ui->sendAmount->setText("Sending: " + ui->PayAmount->text() + " NOR (" + QString::number(ui->PayAmount->value() * usdValue.toDouble()) + " ¥)");
}
}

Expand Down
34 changes: 27 additions & 7 deletions src/qt/walletview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,7 @@ void WalletView::fetchPrice()
QSslConfiguration config = QSslConfiguration::defaultConfiguration();
config.setProtocol(QSsl::TlsV1_2);
request.setSslConfiguration(config);
if(configs.value("Currency").toInt() == 0)
request.setUrl(QUrl("https://api.coingecko.com/api/v3/coins/bring?localization=false&tickers=false&market_data=true&community_data=false&developer_data=false&sparkline=false"));
else if(configs.value("Currency").toInt() == 1)
request.setUrl(QUrl("https://api.coingecko.com/api/v3/coins/bring?localization=false&tickers=false&market_data=true&community_data=false&developer_data=false&sparkline=false"));
request.setUrl(QUrl("https://api.coingecko.com/api/v3/coins/bring?localization=false&tickers=false&market_data=true&community_data=false&developer_data=false&sparkline=false"));

request.setHeader(QNetworkRequest::ServerHeader, "application/json");
//url.setPort(8850);
Expand All @@ -520,11 +517,19 @@ void WalletView::replyFinished(QNetworkReply *reply)
if(configs.value("Currency").toInt() == 0){
s = str.toStdString().find("\"usd\":");
newPriceUSD = "$";
}
else if(configs.value("Currency").toInt() == 1){
} else if(configs.value("Currency").toInt() == 1){
s = str.toStdString().find("\"eur\":");
newPriceUSD = "";
}
} else if(configs.value("Currency").toInt() == 2){
s = str.toStdString().find("\"gbp\":");
newPriceUSD = "£";
} else if(configs.value("Currency").toInt() == 3){
s = str.toStdString().find("\"ltc\":");
newPriceUSD = "Ł";
} else if(configs.value("Currency").toInt() == 4){
s = str.toStdString().find("\"jpy\":");
newPriceUSD = "¥";
}
size_t e = str.toStdString().find(",", s);
string priceUSD = str.toStdString().substr(s + 6, e - s - 6);
QString priceUSDq = QString::fromStdString(priceUSD);
Expand Down Expand Up @@ -556,6 +561,21 @@ void WalletView::replyFinished(QNetworkReply *reply)
overviewPage->labelBalanceUSD->setText(QString::number(priceBTCq.toDouble() * walletAmountConfirmed.toDouble(), 'f', 4) + " BTC " + "(€" + QString::number(priceUSDq.toDouble() * walletAmountConfirmed.toDouble(), 'f', 2) + ")");
overviewPage->labelUnconfirmedUSD->setText(QString::number(priceBTCq.toDouble() * walletAmountUnconfirmed.toDouble(), 'f', 4) + " BTC " + "(€" + QString::number(priceUSDq.toDouble() * walletAmountUnconfirmed.toDouble(), 'f', 2) + ")");
}
if(configs.value("Currency").toInt() == 2){
newPriceUSD = "£"+ QString::number(priceUSDq.toDouble(), 'f', 2).toStdString();
overviewPage->labelBalanceUSD->setText(QString::number(priceBTCq.toDouble() * walletAmountConfirmed.toDouble(), 'f', 4) + " BTC " + "" + QString::number(priceUSDq.toDouble() * walletAmountConfirmed.toDouble(), 'f', 2) + ")");
overviewPage->labelUnconfirmedUSD->setText(QString::number(priceBTCq.toDouble() * walletAmountUnconfirmed.toDouble(), 'f', 4) + " BTC " + "" + QString::number(priceUSDq.toDouble() * walletAmountUnconfirmed.toDouble(), 'f', 2) + ")");
}
if(configs.value("Currency").toInt() == 3){
newPriceUSD = "Ł"+ QString::number(priceUSDq.toDouble(), 'f', 6).toStdString();
overviewPage->labelBalanceUSD->setText(QString::number(priceBTCq.toDouble() * walletAmountConfirmed.toDouble(), 'f', 4) + " BTC " + "" + QString::number(priceUSDq.toDouble() * walletAmountConfirmed.toDouble(), 'f', 2) + ")");
overviewPage->labelUnconfirmedUSD->setText(QString::number(priceBTCq.toDouble() * walletAmountUnconfirmed.toDouble(), 'f', 4) + " BTC " + "" + QString::number(priceUSDq.toDouble() * walletAmountUnconfirmed.toDouble(), 'f', 2) + ")");
}
if(configs.value("Currency").toInt() == 4){
newPriceUSD = "¥"+ QString::number(priceUSDq.toDouble(), 'f', 2).toStdString();
overviewPage->labelBalanceUSD->setText(QString::number(priceBTCq.toDouble() * walletAmountConfirmed.toDouble(), 'f', 4) + " BTC " + "" + QString::number(priceUSDq.toDouble() * walletAmountConfirmed.toDouble(), 'f', 2) + ")");
overviewPage->labelUnconfirmedUSD->setText(QString::number(priceBTCq.toDouble() * walletAmountUnconfirmed.toDouble(), 'f', 4) + " BTC " + "" + QString::number(priceUSDq.toDouble() * walletAmountUnconfirmed.toDouble(), 'f', 2) + ")");
}
overviewPage->priceUSD->setText(QString::fromStdString(newPriceUSD));
overviewPage->priceBTC->setText(QString::number(priceBTCq.toDouble(), 'f', 8) + " BTC");
sendCoinsPage->priceUSD->setText(QString::fromStdString(newPriceUSD));
Expand Down

0 comments on commit 737802c

Please sign in to comment.