Browse Source

History: set correct fiat currency

1.0.0
tobtoht 1 month ago
parent
commit
130733ad98
Signed by: tobtoht GPG Key ID: 1CADD27F41F45C3C
  1. 1
      src/HistoryWidget.cpp
  2. 2
      src/MainWindow.cpp
  3. 3
      src/SettingsDialog.cpp
  4. 18
      src/appcontext.cpp
  5. 2
      src/appcontext.h
  6. 18
      src/model/TransactionHistoryModel.cpp
  7. 3
      src/model/TransactionHistoryModel.h

1
src/HistoryWidget.cpp

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

2
src/MainWindow.cpp

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

3
src/SettingsDialog.cpp

@ -79,8 +79,9 @@ Settings::Settings(QSharedPointer<AppContext> ctx, QWidget *parent)
// Preferred fiat currency combobox
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);
}
auto preferredFiatCurrency = config()->get(Config::preferredFiatCurrency).toString();
if(!preferredFiatCurrency.isEmpty())

18
src/appcontext.cpp

@ -55,9 +55,6 @@ AppContext::AppContext(Wallet *wallet)
this->updateBalance();
// force trigger preferredFiat signal for history model
this->onPreferredFiatCurrencyChanged(config()->get(Config::preferredFiatCurrency).toString());
connect(this->wallet->history(), &TransactionHistory::txNoteChanged, [this]{
this->wallet->history()->refresh(this->wallet->currentSubaddressAccount());
});
@ -167,21 +164,6 @@ QString AppContext::getCacheTransaction(const QString &txid) const {
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 ##################
void AppContext::onDeviceButtonRequest(quint64 code) {

2
src/appcontext.h

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

18
src/model/TransactionHistoryModel.cpp

@ -158,7 +158,7 @@ QVariant TransactionHistoryModel::parseTransactionInfo(const TransactionInfo &tI
if (role == Qt::UserRole) {
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;
return amount;
}
@ -168,23 +168,27 @@ QVariant TransactionHistoryModel::parseTransactionInfo(const TransactionInfo &tI
case Column::FiatAmount:
{
double usd_price = appData()->txFiatHistory->get(tInfo.timestamp().toString("yyyyMMdd"));
if (usd_price == 0.0)
return QVariant("?");
if (usd_price == 0.0) {
return QString("?");
}
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) {
return usd_amount;
}
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:
{
qCritical() << "Unimplemented role";
return QVariant();
return {};
}
}
}

3
src/model/TransactionHistoryModel.h

@ -35,9 +35,6 @@ public:
TransactionHistory * transactionHistory() const;
TransactionInfo* entryFromIndex(const QModelIndex& index) const;
QString preferredFiatSymbol = "USD";
int amountPrecision = 4;
int rowCount(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;

Loading…
Cancel
Save