Fixed credits display in statistic charts.

This commit is contained in:
23rd 2025-06-30 11:57:16 +03:00 committed by John Preston
parent a665d7cc3c
commit 96951576c1
9 changed files with 22 additions and 16 deletions

View file

@ -765,7 +765,6 @@ void EarnStatistics::requestHistory(
_requestId = 0;
const auto nextToken = result.data().vnext_offset().value_or_empty();
qDebug() << "next" << nextToken;
const auto &tlTransactions
= result.data().vhistory().value_or_empty();

View file

@ -93,7 +93,7 @@ CreditsAmount Credits::balanceCurrency(PeerId peerId) const {
const auto it = _cachedPeerCurrencyBalances.find(peerId);
return (it != _cachedPeerCurrencyBalances.end())
? it->second
: CreditsAmount();
: CreditsAmount(0, 0, CreditsType::Ton);
}
rpl::producer<CreditsAmount> Credits::balanceValue() const {

View file

@ -1475,7 +1475,9 @@ void ApplyChannelUpdate(
currencyLoadLifetime->destroy();
};
currencyLoad->request() | rpl::start_with_error_done(
[=](const QString &error) { apply({}); },
[=](const QString &error) {
apply(CreditsAmount(0, CreditsType::Ton));
},
[=] { apply(currencyLoad->data().currentBalance); },
*currencyLoadLifetime);
base::timer_once(kTimeout) | rpl::start_with_next([=] {

View file

@ -797,7 +797,9 @@ void ApplyUserUpdate(not_null<UserData*> user, const MTPDuserFull &update) {
currencyLoadLifetime->destroy();
};
currencyLoad->request() | rpl::start_with_error_done(
[=](const QString &error) { apply({}); },
[=](const QString &error) {
apply(CreditsAmount(0, CreditsType::Ton));
},
[=] { apply(currencyLoad->data().currentBalance); },
*currencyLoadLifetime);
base::timer_once(kTimeout) | rpl::start_with_next([=] {

View file

@ -436,9 +436,7 @@ void InnerWidget::fill() {
value
) | rpl::start_with_next([=](CreditsAmount v) {
label->setMarkedText(
base::duplicate(prepended)
.append(icon)
.append(QString::number(v.whole())),
base::duplicate(prepended).append(icon).append(MajorPart(v)),
Core::TextContext({ .session = session }));
}, label->lifetime());
};

View file

@ -897,7 +897,9 @@ rpl::producer<CreditsAmount> AddCurrencyAction(
}
};
currencyLoad->request() | rpl::start_with_error_done(
[=](const QString &error) { done({}); },
[=](const QString &error) {
done(CreditsAmount(0, CreditsType::Ton));
},
[=] { done(currencyLoad->data().currentBalance); },
*currencyLoadLifetime);
}

View file

@ -11,7 +11,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "api/api_statistics.h"
#include "boxes/peer_list_controllers.h"
#include "boxes/peer_list_widgets.h"
#include "info/channel_statistics/earn/earn_format.h"
#include "info/channel_statistics/earn/earn_icons.h"
#include "info/channel_statistics/earn/earn_format.h"
#include "chat_helpers/stickers_gift_box_pack.h"

View file

@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "statistics/view/chart_rulers_view.h"
#include "data/data_channel_earn.h" // Data::kEarnMultiplier.
#include "info/channel_statistics/earn/earn_format.h"
#include "lang/lang_keys.h"
#include "statistics/chart_lines_filter_controller.h"
@ -42,9 +41,15 @@ void ChartRulersView::setChartData(
|| chartData.currencyRate;
if (chartData.currencyRate) {
_currencyIcon = ChartCurrencyIcon(chartData, {});
_leftCustomCaption = [=](float64 value) {
return FormatF(value / float64(Data::kEarnMultiplier));
};
if (chartData.currency == Data::StatisticalCurrency::Ton) {
_leftCustomCaption = [=](float64 value) {
return FormatF(value / float64(kOneStarInNano));
};
} else {
_leftCustomCaption = [=](float64 value) {
return FormatF(value);
};
}
_rightCustomCaption = [=, rate = chartData.currencyRate](float64 v) {
return Info::ChannelEarn::ToUsd(v, rate, 0);
};

View file

@ -7,7 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "statistics/widgets/point_details_widget.h"
#include "data/data_channel_earn.h" // Data::kEarnMultiplier.
#include "info/channel_statistics/earn/earn_format.h"
#include "lang/lang_keys.h"
#include "statistics/statistics_common.h"
@ -179,7 +178,7 @@ PointDetailsWidget::PointDetailsWidget(
const auto maxValueTextWidth = [&] {
if (hasUsdLine) {
auto maxValueWidth = 0;
const auto multiplier = float64(Data::kEarnMultiplier);
const auto multiplier = float64(kOneStarInNano);
for (const auto &value : _chartData.lines.front().y) {
const auto valueText = Ui::Text::String(
_textStyle,
@ -325,7 +324,7 @@ void PointDetailsWidget::setXIndex(int xIndex) {
nullptr,
{ float64(xIndex), float64(xIndex) }).parts
: std::vector<PiePartData::Part>();
const auto multiplier = float64(Data::kEarnMultiplier);
const auto multiplier = float64(kOneStarInNano);
const auto isCredits
= _chartData.currency == Data::StatisticalCurrency::Credits;
for (auto i = 0; i < _chartData.lines.size(); i++) {