diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 058a3b68fd..17840c510c 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -3560,7 +3560,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_gift_buy_resale_title" = "Buy {name}"; "lng_gift_buy_resale_button" = "Buy for {cost}"; "lng_gift_buy_resale_equals" = "Equals to {cost}"; -"lng_gift_buy_resale_only_ton" = "The seller only accepts TON as payment"; +"lng_gift_buy_resale_only_ton" = "The seller only accepts TON as payment."; "lng_gift_buy_resale_pay_stars" = "Pay in Stars"; "lng_gift_buy_resale_pay_ton" = "Pay in TON"; "lng_gift_buy_resale_confirm" = "Do you want to buy {name} for {price} and gift it to {user}?"; diff --git a/Telegram/SourceFiles/boxes/transfer_gift_box.cpp b/Telegram/SourceFiles/boxes/transfer_gift_box.cpp index b47672ae67..2b697bcbdb 100644 --- a/Telegram/SourceFiles/boxes/transfer_gift_box.cpp +++ b/Telegram/SourceFiles/boxes/transfer_gift_box.cpp @@ -23,6 +23,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_session.h" #include "payments/payments_checkout_process.h" #include "ui/boxes/confirm_box.h" +#include "ui/controls/sub_tabs.h" #include "ui/controls/ton_common.h" #include "ui/layers/generic_box.h" #include "ui/text/text_utilities.h" @@ -678,19 +679,59 @@ void ShowBuyResaleGiftBox( not_null to, Fn closeParentBox) { show->show(Box([=](not_null box) { - box->setTitle(tr::lng_gift_buy_resale_title( - lt_name, - rpl::single(UniqueGiftName(*gift)))); - - auto transfer = tr::lng_gift_buy_resale_button( - lt_cost, - rpl::single(Data::FormatGiftResaleAsked(*gift)), - Ui::Text::WithEntities); - struct State { + rpl::variable ton; bool sent = false; }; const auto state = std::make_shared(); + state->ton = gift->onlyAcceptTon; + + if (gift->onlyAcceptTon) { + box->addRow( + object_ptr( + box, + tr::lng_gift_buy_resale_only_ton( + Ui::Text::RichLangValue), + st::resaleConfirmTonOnly), + st::boxRowPadding + st::resaleConfirmTonOnlyMargin); + } else { + const auto tabs = box->addRow( + object_ptr( + box, + Ui::SubTabsOptions{ + .selected = u"stars"_q, + .centered = true, + }, + std::vector{ + { + u"stars"_q, + tr::lng_gift_buy_resale_pay_stars( + tr::now, + Ui::Text::WithEntities), + }, + { + u"ton"_q, + tr::lng_gift_buy_resale_pay_ton( + tr::now, + Ui::Text::WithEntities), + }, + }), + st::boxRowPadding + st::resaleConfirmTonOnlyMargin); + tabs->activated() | rpl::start_with_next([=](QString id) { + tabs->setActiveTab(id); + state->ton = (id == u"ton"_q); + }, tabs->lifetime()); + } + + auto transfer = state->ton.value() | rpl::map([=](bool ton) { + return tr::lng_gift_buy_resale_button( + lt_cost, + rpl::single(ton + ? Data::FormatGiftResaleTon(*gift) + : Data::FormatGiftResaleStars(*gift)), + Ui::Text::WithEntities); + }) | rpl::flatten_latest(); + auto callback = [=](Fn close) { if (state->sent) { return; @@ -704,48 +745,41 @@ void ShowBuyResaleGiftBox( } else if (result != Payments::CheckoutResult::Paid) { state->sent = false; } else { - show->showToast(u"done!"_q); closeParentBox(); close(); } }; - const auto type = gift->onlyAcceptTon + const auto type = state->ton.current() ? CreditsType::Ton : CreditsType::Stars; BuyResaleGift(show, to, gift, type, done); }; + auto price = state->ton.value() | rpl::map([=](bool ton) { + return ton + ? tr::lng_action_gift_for_ton( + lt_count_decimal, + rpl::single(gift->nanoTonForResale + / float64(Ui::kNanosInOne)), + Ui::Text::Bold) + : tr::lng_action_gift_for_stars( + lt_count_decimal, + rpl::single(gift->starsForResale * 1.), + Ui::Text::Bold); + }) | rpl::flatten_latest(); Ui::ConfirmBox(box, { .text = to->isSelf() ? tr::lng_gift_buy_resale_confirm_self( lt_name, rpl::single(Ui::Text::Bold(UniqueGiftName(*gift))), lt_price, - (gift->onlyAcceptTon - ? tr::lng_action_gift_for_ton( - lt_count, - rpl::single(gift->nanoTonForResale - / float64(Ui::kNanosInOne)), - Ui::Text::Bold) - : tr::lng_action_gift_for_stars( - lt_count_decimal, - rpl::single(gift->starsForResale * 1.), - Ui::Text::Bold)), + std::move(price), Ui::Text::WithEntities) : tr::lng_gift_buy_resale_confirm( lt_name, rpl::single(Ui::Text::Bold(UniqueGiftName(*gift))), lt_price, - (gift->onlyAcceptTon - ? tr::lng_action_gift_for_ton( - lt_count, - rpl::single(gift->nanoTonForResale - / float64(Ui::kNanosInOne)), - Ui::Text::Bold) - : tr::lng_action_gift_for_stars( - lt_count_decimal, - rpl::single(gift->starsForResale * 1.), - Ui::Text::Bold)), + std::move(price), lt_user, rpl::single(Ui::Text::Bold(to->shortName())), Ui::Text::WithEntities), diff --git a/Telegram/SourceFiles/settings/settings_credits_graphics.cpp b/Telegram/SourceFiles/settings/settings_credits_graphics.cpp index e82e6d3012..c314abd938 100644 --- a/Telegram/SourceFiles/settings/settings_credits_graphics.cpp +++ b/Telegram/SourceFiles/settings/settings_credits_graphics.cpp @@ -2114,8 +2114,8 @@ void GenericCreditsEntryBox( lt_cost, rpl::single(Data::FormatGiftResaleStars(*uniqueGift)), Ui::Text::WithEntities), - st::giftResaleButtonTitle, - st::giftResaleButtonSubtitle); + st::resaleButtonTitle, + st::resaleButtonSubtitle); } else { button->setText(tr::lng_gift_buy_resale_button( lt_cost, diff --git a/Telegram/SourceFiles/ui/effects/credits.style b/Telegram/SourceFiles/ui/effects/credits.style index 6a0483ceea..8881c8bbb8 100644 --- a/Telegram/SourceFiles/ui/effects/credits.style +++ b/Telegram/SourceFiles/ui/effects/credits.style @@ -323,13 +323,18 @@ creditsHistoryRowRightMinorTop: 18px; creditsHistoryRowRightStyle: TextStyle(defaultTextStyle) { font: font(fsize); } -giftResaleButtonTitle: FlatLabel(defaultFlatLabel) { +resaleButtonTitle: FlatLabel(defaultFlatLabel) { style: semiboldTextStyle; textFg: activeButtonFg; } -giftResaleButtonSubtitle: FlatLabel(defaultFlatLabel) { +resaleButtonSubtitle: FlatLabel(defaultFlatLabel) { style: TextStyle(defaultTextStyle) { font: font(12px semibold); } textFg: activeButtonFg; } + +resaleConfirmTonOnly: FlatLabel(boxLabel) { + textFg: windowSubTextFg; +} +resaleConfirmTonOnlyMargin: margins(0px, 12px, 0px, 12px);