From 3fb0fa689203f06c3d7b65557f33f3bc474184d2 Mon Sep 17 00:00:00 2001 From: John Preston Date: Wed, 22 Jan 2025 13:35:48 +0400 Subject: [PATCH] Swap confirm and password boxes on export. --- .../SourceFiles/boxes/transfer_gift_box.cpp | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/Telegram/SourceFiles/boxes/transfer_gift_box.cpp b/Telegram/SourceFiles/boxes/transfer_gift_box.cpp index 875d9c02d..8d297bb27 100644 --- a/Telegram/SourceFiles/boxes/transfer_gift_box.cpp +++ b/Telegram/SourceFiles/boxes/transfer_gift_box.cpp @@ -78,8 +78,7 @@ private: void ConfirmExportBox( not_null box, std::shared_ptr gift, - const QString &url, - Fn wentToUrl) { + Fn close)> confirmed) { box->setTitle(tr::lng_gift_transfer_confirm_title()); box->addRow(object_ptr( box, @@ -89,9 +88,11 @@ void ConfirmExportBox( Ui::Text::WithEntities), st::boxLabel)); box->addButton(tr::lng_gift_transfer_confirm_button(), [=] { - UrlClickHandler::Open(url); - wentToUrl(); - box->closeBox(); + confirmed([weak = Ui::MakeWeak(box)] { + if (const auto strong = weak.data()) { + strong->closeBox(); + } + }); }); box->addButton(tr::lng_cancel(), [=] { box->closeBox(); @@ -103,7 +104,7 @@ void ExportOnBlockchain( not_null parent, std::shared_ptr gift, Data::SavedStarGiftId giftId, - Fn waitFinished, + Fn boxShown, Fn wentToUrl) { struct State { bool loading = false; @@ -125,16 +126,14 @@ void ExportOnBlockchain( tr::lng_gift_transfer_password_about(tr::now), }); if (box) { - waitFinished(); show->show(std::move(box)); + boxShown(); return; } state->lifetime = session->api().cloudPassword().state( ) | rpl::take( 1 ) | rpl::start_with_next([=](const Core::CloudPasswordState &pass) { - waitFinished(); - auto fields = PasscodeBox::CloudFields::From(pass); fields.customTitle = tr::lng_gift_transfer_password_title(); fields.customDescription @@ -149,8 +148,8 @@ void ExportOnBlockchain( Api::InputSavedStarGiftId(giftId), result.result) ).done([=](const ExportUrl &result) { - const auto url = qs(result.data().vurl()); - show->show(Box(ConfirmExportBox, gift, url, wentToUrl)); + UrlClickHandler::Open(qs(result.data().vurl())); + wentToUrl(); if (box) { box->closeBox(); } @@ -162,6 +161,7 @@ void ExportOnBlockchain( }).send(); }); show->show(Box(session, fields)); + boxShown(); }); }).send(); } @@ -182,17 +182,21 @@ void ExportOnBlockchain( const auto left = (when > now) ? (when - now) : 0; const auto hours = left ? std::max((left + 1800) / 3600, 1) : 0; if (!hours) { - if (state->exporting) { - return; - } - state->exporting = true; - ExportOnBlockchain(window, box, gift, giftId, [=] { - state->exporting = false; - }, [=] { - if (const auto strong = weak.data()) { - strong->closeBox(); + window->show(Box(ConfirmExportBox, gift, [=](Fn close) { + if (state->exporting) { + return; } - }); + state->exporting = true; + ExportOnBlockchain(window, box, gift, giftId, [=] { + state->exporting = false; + close(); + }, [=] { + if (const auto strong = weak.data()) { + strong->closeBox(); + } + close(); + }); + })); return; } window->show(Ui::MakeInformBox({