mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Improved process of mtp updates for revenue credits in earn section.
This commit is contained in:
parent
a95fb5b28d
commit
1ed81b1c9c
1 changed files with 33 additions and 13 deletions
|
@ -308,14 +308,25 @@ void InnerWidget::load() {
|
||||||
using TLNotificationUpdate = MTPDupdateServiceNotification;
|
using TLNotificationUpdate = MTPDupdateServiceNotification;
|
||||||
Api::PerformForUpdate<TLCreditsUpdate>(updates, [&](
|
Api::PerformForUpdate<TLCreditsUpdate>(updates, [&](
|
||||||
const TLCreditsUpdate &d) {
|
const TLCreditsUpdate &d) {
|
||||||
if (peerId == peerFromMTP(d.vpeer())) {
|
if (peerId != peerFromMTP(d.vpeer())) {
|
||||||
apiCredits->request(
|
return;
|
||||||
) | rpl::start_with_error_done(fail, [=] {
|
|
||||||
state->apiCreditsLifetime.destroy();
|
|
||||||
_state.creditsEarn = state->apiCredits.data();
|
|
||||||
_stateUpdated.fire({});
|
|
||||||
}, state->apiCreditsLifetime);
|
|
||||||
}
|
}
|
||||||
|
const auto &data = d.vstatus().data();
|
||||||
|
auto &e = _state.creditsEarn;
|
||||||
|
e.currentBalance = data.vcurrent_balance().v;
|
||||||
|
e.availableBalance = data.vavailable_balance().v;
|
||||||
|
e.overallRevenue = data.voverall_revenue().v;
|
||||||
|
e.overallRevenue = data.voverall_revenue().v;
|
||||||
|
e.isWithdrawalEnabled = data.is_withdrawal_enabled();
|
||||||
|
e.nextWithdrawalAt = data.vnext_withdrawal_at()
|
||||||
|
? base::unixtime::parse(
|
||||||
|
data.vnext_withdrawal_at()->v)
|
||||||
|
: QDateTime();
|
||||||
|
state->apiCreditsHistory.request({}, [=](
|
||||||
|
const Data::CreditsStatusSlice &data) {
|
||||||
|
_state.creditsStatusSlice = data;
|
||||||
|
_stateUpdated.fire({});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Api::PerformForUpdate<TLCurrencyUpdate>(updates, [&](
|
Api::PerformForUpdate<TLCurrencyUpdate>(updates, [&](
|
||||||
const TLCurrencyUpdate &d) {
|
const TLCurrencyUpdate &d) {
|
||||||
|
@ -710,7 +721,8 @@ void InnerWidget::fill() {
|
||||||
const auto addOverview = [&](
|
const auto addOverview = [&](
|
||||||
rpl::producer<EarnInt> currencyValue,
|
rpl::producer<EarnInt> currencyValue,
|
||||||
rpl::producer<EarnInt> creditsValue,
|
rpl::producer<EarnInt> creditsValue,
|
||||||
const tr::phrase<> &text) {
|
const tr::phrase<> &text,
|
||||||
|
bool showCredits) {
|
||||||
const auto line = container->add(
|
const auto line = container->add(
|
||||||
Ui::CreateSkipWidget(container, 0),
|
Ui::CreateSkipWidget(container, 0),
|
||||||
st::boxRowPadding);
|
st::boxRowPadding);
|
||||||
|
@ -764,7 +776,7 @@ void InnerWidget::fill() {
|
||||||
size.width(),
|
size.width(),
|
||||||
st::channelEarnOverviewMinorLabelSkip);
|
st::channelEarnOverviewMinorLabelSkip);
|
||||||
secondMinorLabel->resizeToWidth(
|
secondMinorLabel->resizeToWidth(
|
||||||
(credits ? (available / 2) : available)
|
(showCredits ? (available / 2) : available)
|
||||||
- size.width()
|
- size.width()
|
||||||
- minorLabel->width());
|
- minorLabel->width());
|
||||||
secondMinorLabel->moveToLeft(
|
secondMinorLabel->moveToLeft(
|
||||||
|
@ -780,7 +792,7 @@ void InnerWidget::fill() {
|
||||||
st::channelEarnOverviewSubMinorLabelPos.y());
|
st::channelEarnOverviewSubMinorLabelPos.y());
|
||||||
creditsSecondLabel->resizeToWidth(
|
creditsSecondLabel->resizeToWidth(
|
||||||
available - creditsSecondLabel->pos().x());
|
available - creditsSecondLabel->pos().x());
|
||||||
if (!credits) {
|
if (!showCredits) {
|
||||||
const auto x = std::numeric_limits<int>::max();
|
const auto x = std::numeric_limits<int>::max();
|
||||||
icon->moveToLeft(x, 0);
|
icon->moveToLeft(x, 0);
|
||||||
creditsLabel->moveToLeft(x, 0);
|
creditsLabel->moveToLeft(x, 0);
|
||||||
|
@ -801,22 +813,28 @@ void InnerWidget::fill() {
|
||||||
auto availValueMap = [](const auto &v) { return v.availableBalance; };
|
auto availValueMap = [](const auto &v) { return v.availableBalance; };
|
||||||
auto currentValueMap = [](const auto &v) { return v.currentBalance; };
|
auto currentValueMap = [](const auto &v) { return v.currentBalance; };
|
||||||
auto overallValueMap = [](const auto &v) { return v.overallRevenue; };
|
auto overallValueMap = [](const auto &v) { return v.overallRevenue; };
|
||||||
|
const auto hasAnyCredits = creditsData.availableBalance
|
||||||
|
|| creditsData.currentBalance
|
||||||
|
|| creditsData.overallRevenue;
|
||||||
addOverview(
|
addOverview(
|
||||||
rpl::duplicate(currencyStateValue) | rpl::map(availValueMap),
|
rpl::duplicate(currencyStateValue) | rpl::map(availValueMap),
|
||||||
rpl::duplicate(creditsStateValue) | rpl::map(availValueMap),
|
rpl::duplicate(creditsStateValue) | rpl::map(availValueMap),
|
||||||
tr::lng_channel_earn_available);
|
tr::lng_channel_earn_available,
|
||||||
|
hasAnyCredits);
|
||||||
Ui::AddSkip(container);
|
Ui::AddSkip(container);
|
||||||
Ui::AddSkip(container);
|
Ui::AddSkip(container);
|
||||||
addOverview(
|
addOverview(
|
||||||
rpl::duplicate(currencyStateValue) | rpl::map(currentValueMap),
|
rpl::duplicate(currencyStateValue) | rpl::map(currentValueMap),
|
||||||
rpl::duplicate(creditsStateValue) | rpl::map(currentValueMap),
|
rpl::duplicate(creditsStateValue) | rpl::map(currentValueMap),
|
||||||
tr::lng_channel_earn_reward);
|
tr::lng_channel_earn_reward,
|
||||||
|
hasAnyCredits);
|
||||||
Ui::AddSkip(container);
|
Ui::AddSkip(container);
|
||||||
Ui::AddSkip(container);
|
Ui::AddSkip(container);
|
||||||
addOverview(
|
addOverview(
|
||||||
rpl::duplicate(currencyStateValue) | rpl::map(overallValueMap),
|
rpl::duplicate(currencyStateValue) | rpl::map(overallValueMap),
|
||||||
rpl::duplicate(creditsStateValue) | rpl::map(overallValueMap),
|
rpl::duplicate(creditsStateValue) | rpl::map(overallValueMap),
|
||||||
tr::lng_channel_earn_total);
|
tr::lng_channel_earn_total,
|
||||||
|
hasAnyCredits);
|
||||||
Ui::AddSkip(container);
|
Ui::AddSkip(container);
|
||||||
}
|
}
|
||||||
#ifndef _DEBUG
|
#ifndef _DEBUG
|
||||||
|
@ -1408,6 +1426,8 @@ void InnerWidget::fill() {
|
||||||
Ui::AddDivider(listsContainer);
|
Ui::AddDivider(listsContainer);
|
||||||
Ui::AddSkip(listsContainer);
|
Ui::AddSkip(listsContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
listsContainer->resizeToWidth(width());
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto historyContainer = container->add(
|
const auto historyContainer = container->add(
|
||||||
|
|
Loading…
Add table
Reference in a new issue