diff --git a/submodules/AccountContext/Sources/AccountContext.swift b/submodules/AccountContext/Sources/AccountContext.swift index 8eae4eb612..b00dfad436 100644 --- a/submodules/AccountContext/Sources/AccountContext.swift +++ b/submodules/AccountContext/Sources/AccountContext.swift @@ -1197,7 +1197,7 @@ public protocol SharedAccountContext: AnyObject { func makeStarsAmountScreen(context: AccountContext, initialValue: Int64?, completion: @escaping (Int64) -> Void) -> ViewController func makeStarsWithdrawalScreen(context: AccountContext, stats: StarsRevenueStats, completion: @escaping (Int64) -> Void) -> ViewController func makeStarsWithdrawalScreen(context: AccountContext, subject: StarsWithdrawalScreenSubject, completion: @escaping (Int64) -> Void) -> ViewController - func makeStarGiftResellScreen(context: AccountContext, update: Bool, completion: @escaping (Int64) -> Void) -> ViewController + func makeStarGiftResellScreen(context: AccountContext, gift: StarGift.UniqueGift, update: Bool, completion: @escaping (Int64) -> Void) -> ViewController func makeStarsGiftScreen(context: AccountContext, message: EngineMessage) -> ViewController func makeStarsGiveawayBoostScreen(context: AccountContext, peerId: EnginePeer.Id, boost: ChannelBoostersContext.State.Boost) -> ViewController func makeStarsIntroScreen(context: AccountContext) -> ViewController diff --git a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftViewScreen.swift b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftViewScreen.swift index b7fb94d32c..8007194481 100644 --- a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftViewScreen.swift +++ b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftViewScreen.swift @@ -862,7 +862,7 @@ private final class GiftViewSheetContent: CombinedComponent { ) controller.present(alertController, in: .window(.root)) } else { - let resellController = self.context.sharedContext.makeStarGiftResellScreen(context: self.context, update: update, completion: { [weak self, weak controller] price in + let resellController = self.context.sharedContext.makeStarGiftResellScreen(context: self.context, gift: gift, update: update, completion: { [weak self, weak controller] price in guard let self, let controller else { return } diff --git a/submodules/TelegramUI/Components/Stars/StarsWithdrawalScreen/Sources/StarsWithdrawalScreen.swift b/submodules/TelegramUI/Components/Stars/StarsWithdrawalScreen/Sources/StarsWithdrawalScreen.swift index 3f42f70678..dec8eb1805 100644 --- a/submodules/TelegramUI/Components/Stars/StarsWithdrawalScreen/Sources/StarsWithdrawalScreen.swift +++ b/submodules/TelegramUI/Components/Stars/StarsWithdrawalScreen/Sources/StarsWithdrawalScreen.swift @@ -144,7 +144,7 @@ private final class SheetContent: CombinedComponent { minAmount = StarsAmount(value: 1, nanos: 0) maxAmount = withdrawConfiguration.maxPaidMediaAmount.flatMap { StarsAmount(value: $0, nanos: 0) } - case let .starGiftResell(update): + case let .starGiftResell(_, update): titleString = update ? environment.strings.Stars_SellGift_EditTitle : environment.strings.Stars_SellGift_Title amountTitle = environment.strings.Stars_SellGift_AmountTitle amountPlaceholder = environment.strings.Stars_SellGift_AmountPlaceholder @@ -487,6 +487,36 @@ private final class SheetContent: CombinedComponent { } }) } + + if case let .starGiftResell(giftToMatch, update) = self.mode { + if update { + if let resellStars = giftToMatch.resellStars { + self.amount = StarsAmount(value: resellStars, nanos: 0) + } + } else { + let _ = (context.engine.payments.cachedStarGifts() + |> filter { $0 != nil } + |> take(1) + |> deliverOnMainQueue).start(next: { [weak self] gifts in + guard let self, let gifts else { + return + } + guard let matchingGift = gifts.first(where: { gift in + if case let .generic(gift) = gift, gift.title == giftToMatch.title { + return true + } else { + return false + } + }) else { + return + } + if case let .generic(genericGift) = matchingGift, let minResaleStars = genericGift.availability?.minResaleStars { + self.amount = StarsAmount(value: minResaleStars, nanos: 0) + self.updated() + } + }) + } + } } deinit { @@ -592,7 +622,7 @@ public final class StarsWithdrawScreen: ViewControllerComponentContainer { case accountWithdraw case paidMedia(Int64?) case reaction(Int64?) - case starGiftResell(Bool) + case starGiftResell(StarGift.UniqueGift, Bool) case paidMessages(current: Int64, minValue: Int64, fractionAfterCommission: Int, kind: StarsWithdrawalScreenSubject.PaidMessageKind) } diff --git a/submodules/TelegramUI/Sources/SharedAccountContext.swift b/submodules/TelegramUI/Sources/SharedAccountContext.swift index 3ce34c88eb..d3c70b7909 100644 --- a/submodules/TelegramUI/Sources/SharedAccountContext.swift +++ b/submodules/TelegramUI/Sources/SharedAccountContext.swift @@ -3688,8 +3688,8 @@ public final class SharedAccountContextImpl: SharedAccountContext { return StarsWithdrawScreen(context: context, mode: mode, completion: completion) } - public func makeStarGiftResellScreen(context: AccountContext, update: Bool, completion: @escaping (Int64) -> Void) -> ViewController { - return StarsWithdrawScreen(context: context, mode: .starGiftResell(update), completion: completion) + public func makeStarGiftResellScreen(context: AccountContext, gift: StarGift.UniqueGift, update: Bool, completion: @escaping (Int64) -> Void) -> ViewController { + return StarsWithdrawScreen(context: context, mode: .starGiftResell(gift, update), completion: completion) } public func makeStarsGiftScreen(context: AccountContext, message: EngineMessage) -> ViewController {