mirror of
https://github.com/feather-wallet/feather.git
synced 2024-11-16 17:27:38 +00:00
History: set correct fiat currency
This commit is contained in:
parent
9b22aa25a5
commit
130733ad98
7 changed files with 13 additions and 34 deletions
|
@ -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());
|
||||
|
|
|
@ -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();});
|
||||
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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 {};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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…
Reference in a new issue