History: set correct fiat currency

This commit is contained in:
tobtoht 2021-10-21 21:38:39 +02:00
parent 9b22aa25a5
commit 130733ad98
No known key found for this signature in database
GPG key ID: 1CADD27F41F45C3C
7 changed files with 13 additions and 34 deletions

View file

@ -53,7 +53,6 @@ HistoryWidget::HistoryWidget(QSharedPointer<AppContext> ctx, QWidget *parent)
ui->syncNotice->setVisible(config()->get(Config::showHistorySyncNotice).toBool()); ui->syncNotice->setVisible(config()->get(Config::showHistorySyncNotice).toBool());
ui->history->setHistoryModel(m_model); ui->history->setHistoryModel(m_model);
m_ctx->wallet->transactionHistoryModel()->amountPrecision = config()->get(Config::amountPrecision).toInt();
// Load view state // Load view state
QByteArray historyViewState = QByteArray::fromBase64(config()->get(Config::GUI_HistoryViewState).toByteArray()); QByteArray historyViewState = QByteArray::fromBase64(config()->get(Config::GUI_HistoryViewState).toByteArray());

View file

@ -72,9 +72,7 @@ MainWindow::MainWindow(WindowManager *windowManager, Wallet *wallet, QWidget *pa
for (const auto &widget: m_priceTickerWidgets) for (const auto &widget: m_priceTickerWidgets)
connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, widget, &PriceTickerWidget::updateDisplay); connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, widget, &PriceTickerWidget::updateDisplay);
connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, m_balanceTickerWidget, &BalanceTickerWidget::updateDisplay); connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, m_balanceTickerWidget, &BalanceTickerWidget::updateDisplay);
connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, m_ctx.get(), &AppContext::onPreferredFiatCurrencyChanged);
connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, m_sendWidget, QOverload<>::of(&SendWidget::onPreferredFiatCurrencyChanged)); connect(m_windowSettings, &Settings::preferredFiatCurrencyChanged, m_sendWidget, QOverload<>::of(&SendWidget::onPreferredFiatCurrencyChanged));
connect(m_windowSettings, &Settings::amountPrecisionChanged, m_ctx.get(), &AppContext::onAmountPrecisionChanged);
connect(m_windowSettings, &Settings::skinChanged, this, &MainWindow::skinChanged); connect(m_windowSettings, &Settings::skinChanged, this, &MainWindow::skinChanged);
QTimer::singleShot(1, [this]{this->updateWidgetIcons();}); QTimer::singleShot(1, [this]{this->updateWidgetIcons();});

View file

@ -79,8 +79,9 @@ Settings::Settings(QSharedPointer<AppContext> ctx, QWidget *parent)
// Preferred fiat currency combobox // Preferred fiat currency combobox
QStringList fiatCurrencies; QStringList fiatCurrencies;
for (int index = 0; index < ui->comboBox_fiatCurrency->count(); index++) for (int index = 0; index < ui->comboBox_fiatCurrency->count(); index++) {
fiatCurrencies << ui->comboBox_fiatCurrency->itemText(index); fiatCurrencies << ui->comboBox_fiatCurrency->itemText(index);
}
auto preferredFiatCurrency = config()->get(Config::preferredFiatCurrency).toString(); auto preferredFiatCurrency = config()->get(Config::preferredFiatCurrency).toString();
if(!preferredFiatCurrency.isEmpty()) if(!preferredFiatCurrency.isEmpty())

View file

@ -55,9 +55,6 @@ AppContext::AppContext(Wallet *wallet)
this->updateBalance(); this->updateBalance();
// force trigger preferredFiat signal for history model
this->onPreferredFiatCurrencyChanged(config()->get(Config::preferredFiatCurrency).toString());
connect(this->wallet->history(), &TransactionHistory::txNoteChanged, [this]{ connect(this->wallet->history(), &TransactionHistory::txNoteChanged, [this]{
this->wallet->history()->refresh(this->wallet->currentSubaddressAccount()); this->wallet->history()->refresh(this->wallet->currentSubaddressAccount());
}); });
@ -167,21 +164,6 @@ QString AppContext::getCacheTransaction(const QString &txid) const {
return txHex; return txHex;
} }
// ################## Models ##################
void AppContext::onPreferredFiatCurrencyChanged(const QString &symbol) {
auto *model = this->wallet->transactionHistoryModel();
if (model != nullptr) {
model->preferredFiatSymbol = symbol;
}
}
void AppContext::onAmountPrecisionChanged(int precision) {
auto *model = this->wallet->transactionHistoryModel();
if (!model) return;
model->amountPrecision = precision;
}
// ################## Device ################## // ################## Device ##################
void AppContext::onDeviceButtonRequest(quint64 code) { void AppContext::onDeviceButtonRequest(quint64 code) {

View file

@ -57,8 +57,6 @@ public slots:
void onCreateTransactionError(const QString &msg); void onCreateTransactionError(const QString &msg);
void onOpenAliasResolve(const QString &openAlias); void onOpenAliasResolve(const QString &openAlias);
void onSetRestoreHeight(quint64 height); void onSetRestoreHeight(quint64 height);
void onPreferredFiatCurrencyChanged(const QString &symbol);
void onAmountPrecisionChanged(int precision);
void onMultiBroadcast(PendingTransaction *tx); void onMultiBroadcast(PendingTransaction *tx);
void onDeviceButtonRequest(quint64 code); void onDeviceButtonRequest(quint64 code);
void onDeviceButtonPressed(); void onDeviceButtonPressed();

View file

@ -158,7 +158,7 @@ QVariant TransactionHistoryModel::parseTransactionInfo(const TransactionInfo &tI
if (role == Qt::UserRole) { if (role == Qt::UserRole) {
return tInfo.balanceDelta(); return tInfo.balanceDelta();
} }
QString amount = QString::number(tInfo.balanceDelta() / constants::cdiv, 'f', this->amountPrecision); QString amount = QString::number(tInfo.balanceDelta() / constants::cdiv, 'f', config()->get(Config::amountPrecision).toInt());
amount = (tInfo.direction() == TransactionInfo::Direction_Out) ? "-" + amount : "+" + amount; amount = (tInfo.direction() == TransactionInfo::Direction_Out) ? "-" + amount : "+" + amount;
return amount; return amount;
} }
@ -168,23 +168,27 @@ QVariant TransactionHistoryModel::parseTransactionInfo(const TransactionInfo &tI
case Column::FiatAmount: case Column::FiatAmount:
{ {
double usd_price = appData()->txFiatHistory->get(tInfo.timestamp().toString("yyyyMMdd")); double usd_price = appData()->txFiatHistory->get(tInfo.timestamp().toString("yyyyMMdd"));
if (usd_price == 0.0) if (usd_price == 0.0) {
return QVariant("?"); return QString("?");
}
double usd_amount = usd_price * (tInfo.balanceDelta() / constants::cdiv); double usd_amount = usd_price * (tInfo.balanceDelta() / constants::cdiv);
if(this->preferredFiatSymbol != "USD")
usd_amount = appData()->prices.convert("USD", this->preferredFiatSymbol, usd_amount); QString preferredFiatCurrency = config()->get(Config::preferredFiatCurrency).toString();
if (preferredFiatCurrency != "USD") {
usd_amount = appData()->prices.convert("USD", preferredFiatCurrency, usd_amount);
}
if (role == Qt::UserRole) { if (role == Qt::UserRole) {
return usd_amount; return usd_amount;
} }
double fiat_rounded = ceil(Utils::roundSignificant(usd_amount, 3) * 100.0) / 100.0; double fiat_rounded = ceil(Utils::roundSignificant(usd_amount, 3) * 100.0) / 100.0;
return QString("%1").arg(Utils::amountToCurrencyString(fiat_rounded, this->preferredFiatSymbol)); return QString("%1").arg(Utils::amountToCurrencyString(fiat_rounded, preferredFiatCurrency));
} }
default: default:
{ {
qCritical() << "Unimplemented role"; qCritical() << "Unimplemented role";
return QVariant(); return {};
} }
} }
} }

View file

@ -35,9 +35,6 @@ public:
TransactionHistory * transactionHistory() const; TransactionHistory * transactionHistory() const;
TransactionInfo* entryFromIndex(const QModelIndex& index) const; TransactionInfo* entryFromIndex(const QModelIndex& index) const;
QString preferredFiatSymbol = "USD";
int amountPrecision = 4;
int rowCount(const QModelIndex & parent = QModelIndex()) const override; int rowCount(const QModelIndex & parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override; int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override; QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) const override;