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
#include "base/algorithm.h"
#include "base/basic_types.h"
class MTPstarsAmount;
@ -77,6 +78,17 @@ public:
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) {
_whole += other._whole;
_nano += other._nano;

View file

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

View file

@ -177,7 +177,9 @@ QSize TodoList::countOptimalSize() {
}
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()->Has<HistoryMessageForwarded>();
}

View file

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

View file

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