Check first craft gift address.

This commit is contained in:
John Preston
2026-02-18 15:04:48 +04:00
parent edc3006fbe
commit fc2fd60cdb
4 changed files with 41 additions and 7 deletions
+1
View File
@@ -4201,6 +4201,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_gift_craft_another_button" = "Craft Another Gift";
"lng_gift_craft_unavailable" = "Crafting unavailable";
"lng_gift_craft_when" = "This gift will become available for crafting on {date} at {time}.";
"lng_gift_craft_address_error" = "This gift has been exported to the blockchain and can't be used as the primary gift for crafting.";
"lng_auction_about_title" = "Auction";
"lng_auction_about_subtitle" = "Join the battle for exclusive gifts.";
@@ -660,7 +660,8 @@ void ShowSelectGiftBox(
uint64 giftId,
Fn<void(GiftForCraft)> chosen,
std::vector<GiftForCraft> selected,
Fn<void()> boxClosed) {
Fn<void()> boxClosed,
bool firstSlot) {
struct Entry {
Data::SavedStarGift gift;
GiftButton *button = nullptr;
@@ -690,10 +691,13 @@ void ShowSelectGiftBox(
const auto got = crl::guard(box, [=](
std::shared_ptr<Data::UniqueGift> gift) {
if (!ShowCraftLaterError(box->uiShow(), gift)) {
chosen(GiftForCraft{ .unique = gift });
box->closeBox();
if (ShowCraftLaterError(box->uiShow(), gift)
|| (firstSlot
&& ShowCraftAddressError(box->uiShow(), gift))) {
return;
}
chosen(GiftForCraft{ .unique = gift });
box->closeBox();
});
AddCraftGiftsList(
@@ -1190,7 +1194,7 @@ void Craft(
ShowSelectGiftBox(controller, giftId, [=](GiftForCraft chosen) {
ShowGiftCraftBox(controller, { chosen }, false);
closeCurrent();
}, {}, [=] { *requested = false; });
}, {}, [=] { *requested = false; }, true);
};
StartCraftAnimation(
box,
@@ -1415,12 +1419,14 @@ void MakeCraftContent(
}
state->chosen = std::move(copy);
};
const auto first = (state->requestingIndex == 0);
ShowSelectGiftBox(
controller,
giftId,
crl::guard(raw, callback),
state->chosen.current(),
crl::guard(raw, [=] { state->requestingIndex = -1; }));
crl::guard(raw, [=] { state->requestingIndex = -1; }),
first);
}, raw->lifetime());
auto fullName = state->chosen.value(
@@ -1497,10 +1503,14 @@ void MakeCraftContent(
if (state->crafting) {
return;
}
const auto &gifts = state->chosen.current();
if (!gifts.empty()
&& ShowCraftAddressError(box->uiShow(), gifts.front().unique)) {
return;
}
state->crafting = true;
const auto &cs = state->craftState;
const auto &gifts = state->chosen.current();
cs->giftName = state->name.current();
cs->successPermille = state->successPercentPermille.current();
@@ -1731,4 +1741,17 @@ void ShowCraftLaterError(
}));
}
bool ShowCraftAddressError(
std::shared_ptr<Show> show,
std::shared_ptr<Data::UniqueGift> gift) {
if (gift->giftAddress.isEmpty()) {
return false;
}
show->show(MakeInformBox({
.text = tr::lng_gift_craft_address_error(tr::marked),
.title = tr::lng_gift_craft_unavailable(),
}));
return true;
}
} // namespace Ui
@@ -43,4 +43,8 @@ void ShowCraftLaterError(
std::shared_ptr<Show> show,
TimeId when);
[[nodiscard]] bool ShowCraftAddressError(
std::shared_ptr<Show> show,
std::shared_ptr<Data::UniqueGift> gift);
} // namespace Ui
@@ -1135,6 +1135,9 @@ void FillUniqueGiftMenu(
if (Ui::ShowCraftLaterError(show, unique)) {
return;
}
if (Ui::ShowCraftAddressError(show, unique)) {
return;
}
const auto savedId = EntryToSavedStarGiftId(&show->session(), e);
if (const auto window = show->resolveWindow()) {
Ui::ShowGiftCraftInfoBox(window, unique, savedId);
@@ -1604,6 +1607,9 @@ void GenericCreditsEntryBody(
if (Ui::ShowCraftLaterError(show, unique)) {
return;
}
if (Ui::ShowCraftAddressError(show, unique)) {
return;
}
const auto savedId = EntryToSavedStarGiftId(&show->session(), e);
if (const auto window = show->resolveWindow()) {
Ui::ShowGiftCraftInfoBox(window, unique, savedId);