Fixed update of currency balance on error receiving.

This commit is contained in:
23rd 2025-05-07 11:17:33 +03:00
parent 54825dc66f
commit f4658728e8
3 changed files with 26 additions and 27 deletions

View file

@ -1371,8 +1371,8 @@ void ApplyChannelUpdate(
creditsLoad->request({}, [=](Data::CreditsStatusSlice slice) { creditsLoad->request({}, [=](Data::CreditsStatusSlice slice) {
if (const auto strong = weak.get()) { if (const auto strong = weak.get()) {
strong->credits().apply(id, slice.balance); strong->credits().apply(id, slice.balance);
creditsLoadLifetime->destroy();
} }
creditsLoadLifetime->destroy();
}); });
base::timer_once(kTimeout) | rpl::start_with_next([=] { base::timer_once(kTimeout) | rpl::start_with_next([=] {
creditsLoadLifetime->destroy(); creditsLoadLifetime->destroy();
@ -1380,17 +1380,16 @@ void ApplyChannelUpdate(
const auto currencyLoadLifetime = std::make_shared<rpl::lifetime>(); const auto currencyLoadLifetime = std::make_shared<rpl::lifetime>();
const auto currencyLoad const auto currencyLoad
= currencyLoadLifetime->make_state<Api::EarnStatistics>(channel); = currencyLoadLifetime->make_state<Api::EarnStatistics>(channel);
currencyLoad->request( const auto apply = [=](Data::EarnInt balance) {
) | rpl::start_with_error_done([=](const QString &error) {
currencyLoadLifetime->destroy();
}, [=] {
if (const auto strong = weak.get()) { if (const auto strong = weak.get()) {
strong->credits().applyCurrency( strong->credits().applyCurrency(id, balance);
id,
currencyLoad->data().currentBalance);
currencyLoadLifetime->destroy();
} }
}, *currencyLoadLifetime); currencyLoadLifetime->destroy();
};
currencyLoad->request() | rpl::start_with_error_done(
[=](const QString &error) { apply(0); },
[=] { apply(currencyLoad->data().currentBalance); },
*currencyLoadLifetime);
base::timer_once(kTimeout) | rpl::start_with_next([=] { base::timer_once(kTimeout) | rpl::start_with_next([=] {
currencyLoadLifetime->destroy(); currencyLoadLifetime->destroy();
}, *currencyLoadLifetime); }, *currencyLoadLifetime);

View file

@ -778,8 +778,8 @@ void ApplyUserUpdate(not_null<UserData*> user, const MTPDuserFull &update) {
creditsLoad->request({}, [=](Data::CreditsStatusSlice slice) { creditsLoad->request({}, [=](Data::CreditsStatusSlice slice) {
if (const auto strong = weak.get()) { if (const auto strong = weak.get()) {
strong->credits().apply(id, slice.balance); strong->credits().apply(id, slice.balance);
creditsLoadLifetime->destroy();
} }
creditsLoadLifetime->destroy();
}); });
base::timer_once(kTimeout) | rpl::start_with_next([=] { base::timer_once(kTimeout) | rpl::start_with_next([=] {
creditsLoadLifetime->destroy(); creditsLoadLifetime->destroy();
@ -788,17 +788,16 @@ void ApplyUserUpdate(not_null<UserData*> user, const MTPDuserFull &update) {
= std::make_shared<rpl::lifetime>(); = std::make_shared<rpl::lifetime>();
const auto currencyLoad const auto currencyLoad
= currencyLoadLifetime->make_state<Api::EarnStatistics>(user); = currencyLoadLifetime->make_state<Api::EarnStatistics>(user);
currencyLoad->request( const auto apply = [=](Data::EarnInt balance) {
) | rpl::start_with_error_done([=](const QString &error) {
currencyLoadLifetime->destroy();
}, [=] {
if (const auto strong = weak.get()) { if (const auto strong = weak.get()) {
strong->credits().applyCurrency( strong->credits().applyCurrency(id, balance);
id,
currencyLoad->data().currentBalance);
currencyLoadLifetime->destroy();
} }
}, *currencyLoadLifetime); currencyLoadLifetime->destroy();
};
currencyLoad->request() | rpl::start_with_error_done(
[=](const QString &error) { apply(0); },
[=] { apply(currencyLoad->data().currentBalance); },
*currencyLoadLifetime);
base::timer_once(kTimeout) | rpl::start_with_next([=] { base::timer_once(kTimeout) | rpl::start_with_next([=] {
currencyLoadLifetime->destroy(); currencyLoadLifetime->destroy();
}, *currencyLoadLifetime); }, *currencyLoadLifetime);

View file

@ -887,15 +887,16 @@ rpl::producer<uint64> AddCurrencyAction(
= std::make_shared<rpl::lifetime>(); = std::make_shared<rpl::lifetime>();
const auto currencyLoad const auto currencyLoad
= currencyLoadLifetime->make_state<Api::EarnStatistics>(user); = currencyLoadLifetime->make_state<Api::EarnStatistics>(user);
currencyLoad->request( const auto done = [=](Data::EarnInt balance) {
) | rpl::start_with_error_done([=](const QString &error) {
currencyLoadLifetime->destroy();
}, [=] {
if ([[maybe_unused]] const auto strong = weak.data()) { if ([[maybe_unused]] const auto strong = weak.data()) {
state->balance = currencyLoad->data().currentBalance; state->balance = balance;
currencyLoadLifetime->destroy(); currencyLoadLifetime->destroy();
} }
}, *currencyLoadLifetime); };
currencyLoad->request() | rpl::start_with_error_done(
[=](const QString &error) { done(0); },
[=] { done(currencyLoad->data().currentBalance); },
*currencyLoadLifetime);
} }
const auto &st = st::infoSharedMediaButton; const auto &st = st::infoSharedMediaButton;
const auto button = wrapButton->entity(); const auto button = wrapButton->entity();
@ -915,7 +916,7 @@ rpl::producer<uint64> AddCurrencyAction(
) | rpl::start_with_next([=, &st]( ) | rpl::start_with_next([=, &st](
int width, int width,
const QString &button, const QString &button,
uint64 balance) { Data::EarnInt balance) {
const auto available = width const auto available = width
- rect::m::sum::h(st.padding) - rect::m::sum::h(st.padding)
- st.style.font->width(button) - st.style.font->width(button)