Improved processing of giveaway creation after payment.

This commit is contained in:
23rd 2023-11-07 20:54:58 +03:00
parent 6ca777102c
commit 474fa56cc0
3 changed files with 24 additions and 10 deletions

View file

@ -228,7 +228,8 @@ void AddPremiumTopBarWithDefaultTitleBar(
void CreateGiveawayBox(
not_null<Ui::GenericBox*> box,
not_null<Info::Controller*> controller,
not_null<PeerData*> peer) {
not_null<PeerData*> peer,
Fn<void()> reloadOnDone) {
box->setWidth(st::boxWideWidth);
const auto weakWindow = base::make_weak(controller->parentController());
@ -790,12 +791,15 @@ void CreateGiveawayBox(
const auto show = box->uiShow();
const auto weak = Ui::MakeWeak(box.get());
const auto done = [=](Payments::CheckoutResult result) {
if (const auto strong = weak.data()) {
state->confirmButtonBusy = false;
strong->window()->setFocus();
strong->closeBox();
const auto isPaid = result == Payments::CheckoutResult::Paid;
if (result == Payments::CheckoutResult::Pending || isPaid) {
if (const auto strong = weak.data()) {
strong->window()->setFocus();
strong->closeBox();
}
}
if (result == Payments::CheckoutResult::Paid) {
if (isPaid) {
reloadOnDone();
const auto filter = [=](const auto &...) {
if (const auto window = weakWindow.get()) {
window->showSection(Info::Boosts::Make(peer));
@ -822,6 +826,8 @@ void CreateGiveawayBox(
.adaptive = true,
.filter = filter,
});
} else {
state->confirmButtonBusy = false;
}
};
Payments::CheckoutProcess::Start(std::move(invoice), done);

View file

@ -20,4 +20,5 @@ class GenericBox;
void CreateGiveawayBox(
not_null<Ui::GenericBox*> box,
not_null<Info::Controller*> controller,
not_null<PeerData*> peer);
not_null<PeerData*> peer,
Fn<void()> reloadOnDone);

View file

@ -216,7 +216,8 @@ void FillGetBoostsButton(
not_null<Ui::VerticalLayout*> content,
not_null<Controller*> controller,
std::shared_ptr<Ui::Show> show,
not_null<PeerData*> peer) {
not_null<PeerData*> peer,
Fn<void()> reloadOnDone) {
if (!Api::PremiumGiftCodeOptions(peer).giveawayGiftsPurchaseAvailable()) {
return;
}
@ -229,7 +230,7 @@ void FillGetBoostsButton(
tr::lng_boosts_get_boosts(),
st));
button->setClickedCallback([=] {
show->showBox(Box(CreateGiveawayBox, controller, peer));
show->showBox(Box(CreateGiveawayBox, controller, peer, reloadOnDone));
});
Ui::CreateChild<Info::Profile::FloatingIcon>(
button,
@ -428,7 +429,13 @@ void InnerWidget::fill() {
::Settings::AddSkip(inner);
::Settings::AddDividerText(inner, tr::lng_boosts_link_subtext());
FillGetBoostsButton(inner, _controller, _show, _peer);
const auto reloadOnDone = crl::guard(this, [=] {
while (Ui::VerticalLayout::count()) {
delete Ui::VerticalLayout::widgetAt(0);
}
load();
});
FillGetBoostsButton(inner, _controller, _show, _peer, reloadOnDone);
resizeToWidth(width());
crl::on_main(this, [=]{ fakeShowed->fire({}); });