Fix usd values in stats.

This commit is contained in:
John Preston 2025-07-02 10:07:54 +04:00
parent 5121f04d66
commit 4571302642
5 changed files with 29 additions and 15 deletions

View file

@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/ */
#pragma once #pragma once
#include "base/algorithm.h"
#include "base/basic_types.h" #include "base/basic_types.h"
class MTPstarsAmount; class MTPstarsAmount;
@ -77,6 +78,17 @@ public:
return !empty(); return !empty();
} }
[[nodiscard]] CreditsAmount multiplied(float64 rate) const {
const auto result = value() * rate;
const auto abs = std::abs(result);
const auto whole = std::floor(abs);
const auto nano = base::SafeRound((abs - whole) * kOneStarInNano);
return CreditsAmount(
(result < 0) ? -whole : whole,
(result < 0) ? -nano : nano,
type());
}
inline CreditsAmount &operator+=(CreditsAmount other) { inline CreditsAmount &operator+=(CreditsAmount other) {
_whole += other._whole; _whole += other._whole;
_nano += other._nano; _nano += other._nano;

View file

@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history.h" #include "history/history.h"
#include "history/history_item.h" #include "history/history_item.h"
#include "history/history_item_components.h" #include "history/history_item_components.h"
#include "info/channel_statistics/earn/earn_format.h"
#include "info/channel_statistics/earn/earn_icons.h" #include "info/channel_statistics/earn/earn_icons.h"
#include "lang/lang_keys.h" #include "lang/lang_keys.h"
#include "lottie/lottie_icon.h" #include "lottie/lottie_icon.h"
@ -93,8 +94,7 @@ void AddApproximateUsd(
const auto rate = amount.ton() const auto rate = amount.ton()
? appConfig->currencyWithdrawRate() ? appConfig->currencyWithdrawRate()
: (appConfig->starsWithdrawRate() / 100.); : (appConfig->starsWithdrawRate() / 100.);
const auto precise = amount.value() * rate; return Info::ChannelEarn::ToUsd(amount, rate, 2);
return u"~$"_q + QString::number(precise, 'f', 2);
}); });
const auto usd = Ui::CreateChild<Ui::FlatLabel>( const auto usd = Ui::CreateChild<Ui::FlatLabel>(
field, field,
@ -677,13 +677,10 @@ CreditsAmount PriceAfterCommission(
const auto mul = price.stars() const auto mul = price.stars()
? appConfig->suggestedPostCommissionStars() ? appConfig->suggestedPostCommissionStars()
: appConfig->suggestedPostCommissionTon(); : appConfig->suggestedPostCommissionTon();
const auto exact = price.multiplied(mul / 1000.);
const auto value = (price.value() * mul / 1000.); return price.stars()
const auto whole = int(std::floor(value)); ? CreditsAmount(exact.whole(), 0, CreditsType::Stars)
const auto nano = price.stars() : exact;
? 0
: int(base::SafeRound((value - whole) * Ui::kNanosInOne));
return CreditsAmount(whole, nano, price.type());
} }
QString FormatAfterCommissionPercent( QString FormatAfterCommissionPercent(

View file

@ -177,7 +177,9 @@ QSize TodoList::countOptimalSize() {
} }
bool TodoList::canComplete() const { bool TodoList::canComplete() const {
return (_parent->data()->out() || _todolist->othersCanComplete()) return (_parent->data()->out()
|| _parent->history()->peer->isSelf()
|| _todolist->othersCanComplete())
&& _parent->data()->isRegular() && _parent->data()->isRegular()
&& !_parent->data()->Has<HistoryMessageForwarded>(); && !_parent->data()->Has<HistoryMessageForwarded>();
} }

View file

@ -45,14 +45,17 @@ void ChartRulersView::setChartData(
_leftCustomCaption = [=](float64 value) { _leftCustomCaption = [=](float64 value) {
return FormatF(value / float64(kOneStarInNano)); return FormatF(value / float64(kOneStarInNano));
}; };
_rightCustomCaption = [=, rate = chartData.currencyRate](float64 v) {
return Info::ChannelEarn::ToUsd(v / float64(kOneStarInNano), rate, 0);
};
} else { } else {
_leftCustomCaption = [=](float64 value) { _leftCustomCaption = [=](float64 value) {
return FormatF(value); return FormatF(value);
}; };
}
_rightCustomCaption = [=, rate = chartData.currencyRate](float64 v) { _rightCustomCaption = [=, rate = chartData.currencyRate](float64 v) {
return Info::ChannelEarn::ToUsd(v, rate, 0); return Info::ChannelEarn::ToUsd(v, rate, 0);
}; };
}
_rightPen = QPen(st::windowSubTextFg); _rightPen = QPen(st::windowSubTextFg);
} }
if (_isDouble && (chartData.lines.size() == 2)) { if (_isDouble && (chartData.lines.size() == 2)) {

View file

@ -186,7 +186,7 @@ PointDetailsWidget::PointDetailsWidget(
const auto usdText = Ui::Text::String( const auto usdText = Ui::Text::String(
_textStyle, _textStyle,
Info::ChannelEarn::ToUsd( Info::ChannelEarn::ToUsd(
value, value / multiplier,
_chartData.currencyRate, _chartData.currencyRate,
0)); 0));
const auto width = std::max( const auto width = std::max(
@ -361,7 +361,7 @@ void PointDetailsWidget::setXIndex(int xIndex) {
textLine.value.setText( textLine.value.setText(
_textStyle, _textStyle,
Info::ChannelEarn::ToUsd( Info::ChannelEarn::ToUsd(
dataLine.y[xIndex], dataLine.y[xIndex] / multiplier,
_chartData.currencyRate, 0)); _chartData.currencyRate, 0));
} }
_lines.push_back(std::move(textLine)); _lines.push_back(std::move(textLine));