mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-07 15:43:55 +02:00
Fixed update of currency balance on error receiving.
This commit is contained in:
parent
54825dc66f
commit
f4658728e8
3 changed files with 26 additions and 27 deletions
|
@ -1371,8 +1371,8 @@ void ApplyChannelUpdate(
|
|||
creditsLoad->request({}, [=](Data::CreditsStatusSlice slice) {
|
||||
if (const auto strong = weak.get()) {
|
||||
strong->credits().apply(id, slice.balance);
|
||||
creditsLoadLifetime->destroy();
|
||||
}
|
||||
creditsLoadLifetime->destroy();
|
||||
});
|
||||
base::timer_once(kTimeout) | rpl::start_with_next([=] {
|
||||
creditsLoadLifetime->destroy();
|
||||
|
@ -1380,17 +1380,16 @@ void ApplyChannelUpdate(
|
|||
const auto currencyLoadLifetime = std::make_shared<rpl::lifetime>();
|
||||
const auto currencyLoad
|
||||
= currencyLoadLifetime->make_state<Api::EarnStatistics>(channel);
|
||||
currencyLoad->request(
|
||||
) | rpl::start_with_error_done([=](const QString &error) {
|
||||
currencyLoadLifetime->destroy();
|
||||
}, [=] {
|
||||
const auto apply = [=](Data::EarnInt balance) {
|
||||
if (const auto strong = weak.get()) {
|
||||
strong->credits().applyCurrency(
|
||||
id,
|
||||
currencyLoad->data().currentBalance);
|
||||
currencyLoadLifetime->destroy();
|
||||
strong->credits().applyCurrency(id, balance);
|
||||
}
|
||||
}, *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([=] {
|
||||
currencyLoadLifetime->destroy();
|
||||
}, *currencyLoadLifetime);
|
||||
|
|
|
@ -778,8 +778,8 @@ void ApplyUserUpdate(not_null<UserData*> user, const MTPDuserFull &update) {
|
|||
creditsLoad->request({}, [=](Data::CreditsStatusSlice slice) {
|
||||
if (const auto strong = weak.get()) {
|
||||
strong->credits().apply(id, slice.balance);
|
||||
creditsLoadLifetime->destroy();
|
||||
}
|
||||
creditsLoadLifetime->destroy();
|
||||
});
|
||||
base::timer_once(kTimeout) | rpl::start_with_next([=] {
|
||||
creditsLoadLifetime->destroy();
|
||||
|
@ -788,17 +788,16 @@ void ApplyUserUpdate(not_null<UserData*> user, const MTPDuserFull &update) {
|
|||
= std::make_shared<rpl::lifetime>();
|
||||
const auto currencyLoad
|
||||
= currencyLoadLifetime->make_state<Api::EarnStatistics>(user);
|
||||
currencyLoad->request(
|
||||
) | rpl::start_with_error_done([=](const QString &error) {
|
||||
currencyLoadLifetime->destroy();
|
||||
}, [=] {
|
||||
const auto apply = [=](Data::EarnInt balance) {
|
||||
if (const auto strong = weak.get()) {
|
||||
strong->credits().applyCurrency(
|
||||
id,
|
||||
currencyLoad->data().currentBalance);
|
||||
currencyLoadLifetime->destroy();
|
||||
strong->credits().applyCurrency(id, balance);
|
||||
}
|
||||
}, *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([=] {
|
||||
currencyLoadLifetime->destroy();
|
||||
}, *currencyLoadLifetime);
|
||||
|
|
|
@ -887,15 +887,16 @@ rpl::producer<uint64> AddCurrencyAction(
|
|||
= std::make_shared<rpl::lifetime>();
|
||||
const auto currencyLoad
|
||||
= currencyLoadLifetime->make_state<Api::EarnStatistics>(user);
|
||||
currencyLoad->request(
|
||||
) | rpl::start_with_error_done([=](const QString &error) {
|
||||
currencyLoadLifetime->destroy();
|
||||
}, [=] {
|
||||
const auto done = [=](Data::EarnInt balance) {
|
||||
if ([[maybe_unused]] const auto strong = weak.data()) {
|
||||
state->balance = currencyLoad->data().currentBalance;
|
||||
state->balance = balance;
|
||||
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 button = wrapButton->entity();
|
||||
|
@ -915,7 +916,7 @@ rpl::producer<uint64> AddCurrencyAction(
|
|||
) | rpl::start_with_next([=, &st](
|
||||
int width,
|
||||
const QString &button,
|
||||
uint64 balance) {
|
||||
Data::EarnInt balance) {
|
||||
const auto available = width
|
||||
- rect::m::sum::h(st.padding)
|
||||
- st.style.font->width(button)
|
||||
|
|
Loading…
Add table
Reference in a new issue