mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-04-15 13:47:05 +02:00
Added initial support of withdraw button in channel earn info section.
This commit is contained in:
parent
9b0f3bedff
commit
2f07bb3973
7 changed files with 146 additions and 37 deletions
|
@ -120,6 +120,8 @@ PRIVATE
|
|||
api/api_common.h
|
||||
api/api_confirm_phone.cpp
|
||||
api/api_confirm_phone.h
|
||||
api/api_earn.cpp
|
||||
api/api_earn.h
|
||||
api/api_editing.cpp
|
||||
api/api_editing.h
|
||||
api/api_global_privacy.cpp
|
||||
|
|
|
@ -4979,9 +4979,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
"lng_channel_earn_reward" = "Proceeds since last withdrawal";
|
||||
"lng_channel_earn_total" = "Total lifetime proceeds";
|
||||
"lng_channel_earn_balance_title" = "Available balance";
|
||||
"lng_channel_earn_balance_placeholder" = "Enter your TON address";
|
||||
"lng_channel_earn_balance_button" = "Withdraw";
|
||||
"lng_channel_earn_balance_about" = "By the end of May, you will be able to collect your reward using Fragment, a third-party platform used by the advertiser to pay for the ad. {link}";
|
||||
"lng_channel_earn_balance_password_title" = "Two-step verification";
|
||||
"lng_channel_earn_balance_password_description" = "Please enter your password to withdraw.";
|
||||
"lng_channel_earn_balance_about" = "Collect your reward using Fragment, a third-party platform used by the advertiser to pay for the ad. {link}";
|
||||
"lng_channel_earn_balance_about_temp" = "By the end of May, you will be able to collect your reward using Fragment, a third-party platform used by the advertiser to pay for the ad. {link}";
|
||||
"lng_channel_earn_transfer_sure_about1" = "Check the address of the recipient:";
|
||||
"lng_channel_earn_transfer_sure_about2" = "This action can not be undone. If the address above is incorrect you will lose your TON.";
|
||||
"lng_channel_earn_history_title" = "Transaction history";
|
||||
|
|
88
Telegram/SourceFiles/api/api_earn.cpp
Normal file
88
Telegram/SourceFiles/api/api_earn.cpp
Normal file
|
@ -0,0 +1,88 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#include "api/api_earn.h"
|
||||
|
||||
#include "api/api_cloud_password.h"
|
||||
#include "apiwrap.h"
|
||||
#include "boxes/passcode_box.h"
|
||||
#include "data/data_channel.h"
|
||||
#include "data/data_session.h"
|
||||
#include "lang/lang_keys.h"
|
||||
#include "main/main_session.h"
|
||||
#include "ui/basic_click_handlers.h"
|
||||
#include "ui/widgets/buttons.h"
|
||||
|
||||
namespace Api {
|
||||
|
||||
void RestrictSponsored(
|
||||
not_null<ChannelData*> channel,
|
||||
bool restricted,
|
||||
Fn<void(QString)> failed) {
|
||||
channel->session().api().request(MTPchannels_RestrictSponsoredMessages(
|
||||
channel->inputChannel,
|
||||
MTP_bool(restricted))
|
||||
).done([=](const MTPUpdates &updates) {
|
||||
channel->session().api().applyUpdates(updates);
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
failed(error.type());
|
||||
}).send();
|
||||
}
|
||||
|
||||
void HandleWithdrawalButton(
|
||||
not_null<ChannelData*> channel,
|
||||
not_null<Ui::RippleButton*> button,
|
||||
std::shared_ptr<Ui::Show> show) {
|
||||
struct State {
|
||||
rpl::lifetime lifetime;
|
||||
bool loading = false;
|
||||
};
|
||||
|
||||
const auto state = button->lifetime().make_state<State>();
|
||||
const auto session = &channel->session();
|
||||
|
||||
session->api().cloudPassword().reload();
|
||||
button->setClickedCallback([=] {
|
||||
if (state->loading) {
|
||||
return;
|
||||
}
|
||||
state->loading = true;
|
||||
state->lifetime = session->api().cloudPassword().state(
|
||||
) | rpl::take(
|
||||
1
|
||||
) | rpl::start_with_next([=](const Core::CloudPasswordState &pass) {
|
||||
state->loading = false;
|
||||
|
||||
auto fields = PasscodeBox::CloudFields::From(pass);
|
||||
fields.customTitle =
|
||||
tr::lng_channel_earn_balance_password_title();
|
||||
fields.customDescription =
|
||||
tr::lng_channel_earn_balance_password_description(tr::now);
|
||||
fields.customSubmitButton = tr::lng_passcode_submit();
|
||||
fields.customCheckCallback = crl::guard(button, [=](
|
||||
const Core::CloudPasswordResult &result) {
|
||||
session->api().request(
|
||||
MTPstats_GetBroadcastRevenueWithdrawalUrl(
|
||||
channel->inputChannel,
|
||||
result.result
|
||||
)).done([=](const MTPstats_BroadcastRevenueWithdrawalUrl &r) {
|
||||
const auto url = qs(r.data().vurl());
|
||||
|
||||
if (!url.isEmpty()) {
|
||||
UrlClickHandler::Open(url);
|
||||
}
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
show->showToast(error.type());
|
||||
}).send();
|
||||
});
|
||||
show->show(Box<PasscodeBox>(session, fields));
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace Api
|
29
Telegram/SourceFiles/api/api_earn.h
Normal file
29
Telegram/SourceFiles/api/api_earn.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
This file is part of Telegram Desktop,
|
||||
the official desktop application for the Telegram messaging service.
|
||||
|
||||
For license and copyright information please follow this link:
|
||||
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
class ChannelData;
|
||||
|
||||
namespace Ui {
|
||||
class RippleButton;
|
||||
class Show;
|
||||
} // namespace Ui
|
||||
|
||||
namespace Api {
|
||||
|
||||
void RestrictSponsored(
|
||||
not_null<ChannelData*> channel,
|
||||
bool restricted,
|
||||
Fn<void(QString)> failed);
|
||||
|
||||
void HandleWithdrawalButton(
|
||||
not_null<ChannelData*> channel,
|
||||
not_null<Ui::RippleButton*> button,
|
||||
std::shared_ptr<Ui::Show> show);
|
||||
|
||||
} // namespace Api
|
|
@ -566,21 +566,3 @@ SponsoredMessages::State SponsoredMessages::state(
|
|||
}
|
||||
|
||||
} // namespace Data
|
||||
|
||||
namespace Api {
|
||||
|
||||
void RestrictSponsored(
|
||||
not_null<ChannelData*> channel,
|
||||
bool restricted,
|
||||
Fn<void(QString)> failed) {
|
||||
channel->session().api().request(MTPchannels_RestrictSponsoredMessages(
|
||||
channel->inputChannel,
|
||||
MTP_bool(restricted))
|
||||
).done([=](const MTPUpdates &updates) {
|
||||
channel->session().api().applyUpdates(updates);
|
||||
}).fail([=](const MTP::Error &error) {
|
||||
failed(error.type());
|
||||
}).send();
|
||||
}
|
||||
|
||||
} // namespace Api
|
||||
|
|
|
@ -158,13 +158,3 @@ private:
|
|||
};
|
||||
|
||||
} // namespace Data
|
||||
|
||||
namespace Api {
|
||||
|
||||
void RestrictSponsored(
|
||||
not_null<ChannelData*> channel,
|
||||
bool restricted,
|
||||
Fn<void(QString)> failed);
|
||||
|
||||
} // namespace Api
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
*/
|
||||
#include "info/channel_statistics/earn/info_earn_inner_widget.h"
|
||||
|
||||
#include "api/api_earn.h"
|
||||
#include "api/api_statistics.h"
|
||||
#include "base/random.h"
|
||||
#include "base/unixtime.h"
|
||||
|
@ -17,13 +18,13 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "data/data_peer.h"
|
||||
#include "data/data_premium_limits.h"
|
||||
#include "data/data_session.h"
|
||||
#include "data/data_sponsored_messages.h"
|
||||
#include "data/stickers/data_custom_emoji.h"
|
||||
#include "info/channel_statistics/earn/info_earn_widget.h"
|
||||
#include "info/info_controller.h"
|
||||
#include "info/profile/info_profile_values.h" // Info::Profile::NameValue.
|
||||
#include "info/statistics/info_statistics_inner_widget.h" // FillLoading.
|
||||
#include "lang/lang_keys.h"
|
||||
#include "main/main_app_config.h"
|
||||
#include "main/main_session.h"
|
||||
#include "statistics/chart_widget.h"
|
||||
#include "ui/boxes/boost_box.h"
|
||||
|
@ -36,6 +37,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|||
#include "ui/text/text_utilities.h"
|
||||
#include "ui/vertical_list.h"
|
||||
#include "ui/widgets/continuous_sliders.h"
|
||||
#include "main/main_account.h"
|
||||
#include "main/main_app_config.h"
|
||||
#include "ui/widgets/fields/input_field.h"
|
||||
#include "ui/wrap/slide_wrap.h"
|
||||
#include "styles/style_boxes.h"
|
||||
|
@ -97,6 +100,11 @@ constexpr auto kDot = QChar('.');
|
|||
+ MinorPart(result);
|
||||
}
|
||||
|
||||
[[nodiscard]] bool WithdrawalEnabled(not_null<Main::Session*> session) {
|
||||
const auto key = u"channel_revenue_withdrawal_enabled"_q;
|
||||
return session->appConfig().get<bool>(key, false);
|
||||
}
|
||||
|
||||
void AddHeader(
|
||||
not_null<Ui::VerticalLayout*> content,
|
||||
tr::phrase<> text) {
|
||||
|
@ -211,6 +219,8 @@ void InnerWidget::fill() {
|
|||
const auto multiplier = data.usdRate;
|
||||
|
||||
const auto session = &_peer->session();
|
||||
const auto channel = _peer->asChannel();
|
||||
const auto withdrawalEnabled = WithdrawalEnabled(session);
|
||||
const auto makeContext = [=](not_null<Ui::FlatLabel*> l) {
|
||||
return Core::MarkedTextContext{
|
||||
.session = session,
|
||||
|
@ -511,7 +521,7 @@ void InnerWidget::fill() {
|
|||
Ui::AddSkip(container);
|
||||
Ui::AddDivider(container);
|
||||
Ui::AddSkip(container);
|
||||
{
|
||||
if (channel) {
|
||||
const auto value = data.availableBalance;
|
||||
Ui::AddSkip(container);
|
||||
AddHeader(container, tr::lng_channel_earn_balance_title);
|
||||
|
@ -591,15 +601,21 @@ void InnerWidget::fill() {
|
|||
stButton.textFg->c,
|
||||
anim::interpolateF(.5, 1., value)));
|
||||
};
|
||||
colorText(1.);
|
||||
colorText(withdrawalEnabled ? 1. : 0.);
|
||||
#ifndef _DEBUG
|
||||
button->setAttribute(
|
||||
Qt::WA_TransparentForMouseEvents,
|
||||
!withdrawalEnabled);
|
||||
#endif
|
||||
|
||||
button->setClickedCallback([=] {
|
||||
});
|
||||
Api::HandleWithdrawalButton(channel, button, _controller->uiShow());
|
||||
Ui::ToggleChildrenVisibility(button, true);
|
||||
|
||||
Ui::AddSkip(container);
|
||||
Ui::AddSkip(container);
|
||||
addAboutWithLearn(tr::lng_channel_earn_balance_about);
|
||||
addAboutWithLearn(withdrawalEnabled
|
||||
? tr::lng_channel_earn_balance_about
|
||||
: tr::lng_channel_earn_balance_about_temp);
|
||||
Ui::AddSkip(container);
|
||||
}
|
||||
Ui::AddSkip(container);
|
||||
|
@ -844,7 +860,7 @@ void InnerWidget::fill() {
|
|||
Ui::AddSkip(container);
|
||||
Ui::AddDivider(container);
|
||||
Ui::AddSkip(container);
|
||||
if (const auto channel = _peer->asChannel()) {
|
||||
if (channel) {
|
||||
constexpr auto kMaxCPM = 50; // Debug.
|
||||
const auto requiredLevel = Data::LevelLimits(session)
|
||||
.channelRestrictSponsoredLevelMin();
|
||||
|
|
Loading…
Add table
Reference in a new issue