diff --git a/src/HistoryWidget.cpp b/src/HistoryWidget.cpp index 62d18d1..e6e66d5 100644 --- a/src/HistoryWidget.cpp +++ b/src/HistoryWidget.cpp @@ -53,7 +53,6 @@ HistoryWidget::HistoryWidget(QSharedPointer 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()); diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 20b1f8a..14eab45 100644 --- a/src/MainWindow.cpp +++ b/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();}); diff --git a/src/SettingsDialog.cpp b/src/SettingsDialog.cpp index d948f96..5084db5 100644 --- a/src/SettingsDialog.cpp +++ b/src/SettingsDialog.cpp @@ -79,8 +79,9 @@ Settings::Settings(QSharedPointer 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()) diff --git a/src/appcontext.cpp b/src/appcontext.cpp index 2714b12..cadf15d 100644 --- a/src/appcontext.cpp +++ b/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) { diff --git a/src/appcontext.h b/src/appcontext.h index ac4db6f..d3e4d23 100644 --- a/src/appcontext.h +++ b/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(); diff --git a/src/model/TransactionHistoryModel.cpp b/src/model/TransactionHistoryModel.cpp index 2265a3e..3bec012 100644 --- a/src/model/TransactionHistoryModel.cpp +++ b/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 {}; } } } diff --git a/src/model/TransactionHistoryModel.h b/src/model/TransactionHistoryModel.h index 4df7dbd..d61da79 100644 --- a/src/model/TransactionHistoryModel.h +++ b/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;