diff --git a/Telegram/Telegram-iOS/en.lproj/Localizable.strings b/Telegram/Telegram-iOS/en.lproj/Localizable.strings index a96e20a07f..b64080c9e6 100644 --- a/Telegram/Telegram-iOS/en.lproj/Localizable.strings +++ b/Telegram/Telegram-iOS/en.lproj/Localizable.strings @@ -15221,6 +15221,7 @@ Error: %8$@"; "Gift.AuctionBid.AddMoreStars.Stars_1" = "%@ Star"; "Gift.AuctionBid.AddMoreStars.Stars_any" = "%@ Stars"; "Gift.AuctionBid.Top" = "TOP %@"; +"Gift.AuctionBid.Custom" = "Custom"; "Gift.Auction.Context.About" = "About"; "Gift.Auction.Context.CopyLink" = "Copy Link"; diff --git a/submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGiftsAuctions.swift b/submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGiftsAuctions.swift index a032c64bc5..c4bf54f9a3 100644 --- a/submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGiftsAuctions.swift +++ b/submodules/TelegramCore/Sources/TelegramEngine/Payments/StarGiftsAuctions.swift @@ -350,7 +350,7 @@ public class GiftAuctionsManager { for (giftId, update) in updates { if let auctionContext = self.auctionContexts[giftId] { auctionContext.updateAuctionState(update) - } else { + } else if case .ongoing = update { reload = true break } diff --git a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/BadgeLabelView.swift b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/BadgeLabelView.swift index 6e24d18396..de97a6580f 100644 --- a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/BadgeLabelView.swift +++ b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/BadgeLabelView.swift @@ -98,6 +98,7 @@ final class BadgeLabelView: UIView { } } + func update(value: String, transition: ComponentTransition) -> CGSize { if value.contains(" ") { for (_, view) in self.itemViews { diff --git a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftAuctionBidScreen.swift b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftAuctionBidScreen.swift index 24b78f2d89..474aded7b7 100644 --- a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftAuctionBidScreen.swift +++ b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftAuctionBidScreen.swift @@ -952,7 +952,7 @@ private final class GiftAuctionBidScreenComponent: Component { private static func makeSliderSteps(minRealValue: Int, maxRealValue: Int, isLogarithmic: Bool) -> [Int] { if isLogarithmic { - var sliderSteps: [Int] = [1, 10, 50, 100, 500, 1_000, 2_000, 5_000, 7_500, 10_000, 20_000, 30_000] + var sliderSteps: [Int] = [1, 10, 50, 100, 500, 1_000, 2_000, 5_000, 7_500, 15_000, 20_000, 30_000, 40_000, 50_000] sliderSteps.removeAll(where: { $0 <= minRealValue }) sliderSteps.insert(minRealValue, at: 0) sliderSteps.removeAll(where: { $0 >= maxRealValue }) @@ -1028,6 +1028,10 @@ private final class GiftAuctionBidScreenComponent: Component { func withMinAllowedRealValue(_ minAllowedRealValue: Int) -> Amount { return Amount(realValue: self.realValue, minRealValue: self.minRealValue, minAllowedRealValue: minAllowedRealValue, maxRealValue: self.maxRealValue, maxSliderValue: self.maxSliderValue, isLogarithmic: self.isLogarithmic) } + + func withMaxRealValue(_ maxRealValue: Int) -> Amount { + return Amount(realValue: self.realValue, minRealValue: self.minRealValue, minAllowedRealValue: self.minAllowedRealValue, maxRealValue: maxRealValue, maxSliderValue: self.maxSliderValue, isLogarithmic: self.isLogarithmic) + } } final class View: UIView, UIScrollViewDelegate { @@ -1369,13 +1373,12 @@ private final class GiftAuctionBidScreenComponent: Component { } private var isLoading = false - private func placeBid() { + private func commitBid(value: Int64) { guard let component = self.component, case let .generic(gift) = component.gift, let controller = self.environment?.controller() else { return } var isUpdate = false - let value = Int64(self.amount.realValue) if let myBidAmount = self.giftAuctionState?.myState.bidAmount { isUpdate = true if value == myBidAmount { @@ -1447,10 +1450,19 @@ private final class GiftAuctionBidScreenComponent: Component { return } self.isLoading = false + + let newMaxValue = Int(Double(value) * 1.5) + var updatedAmount = self.amount.withMinAllowedRealValue(Int(value)) + if newMaxValue > self.amount.maxRealValue { + updatedAmount = updatedAmount.withMaxRealValue(newMaxValue) + } + self.amount = updatedAmount self.state?.updated() - self.amount = self.amount.withMinAllowedRealValue(Int(value)) - + if !isUpdate { + component.auctionContext.load() + } + let title = isUpdate ? presentationData.strings.Gift_AuctionBid_Increased_Title : presentationData.strings.Gift_AuctionBid_Placed_Title let text = isUpdate ? presentationData.strings.Gift_AuctionBid_Increased_Text("\(giftsPerRounds)").string : presentationData.strings.Gift_AuctionBid_Placed_Text("\(giftsPerRounds)").string @@ -1737,8 +1749,12 @@ private final class GiftAuctionBidScreenComponent: Component { peerIds.append(context.account.peerId) var minBidAmount: Int64 = 100 - if case let .ongoing(_, _, _, auctionMinBidAmount, _, _, _, _, _, _) = state?.auctionState { + var maxBidAmount: Int64 = 50000 + if case let .ongoing(_, _, _, auctionMinBidAmount, bidLevels, _, _, _, _, _) = state?.auctionState { minBidAmount = auctionMinBidAmount + if let firstLevel = bidLevels.first(where: { $0.position == 1 }) { + maxBidAmount = max(maxBidAmount, Int64(Double(firstLevel.amount) * 1.5)) + } } var currentValue = max(Int(minBidAmount), 100) if let myBidAmount = state?.myState.bidAmount { @@ -1750,7 +1766,7 @@ private final class GiftAuctionBidScreenComponent: Component { minAllowedRealValue = myBidAmount } - self.amount = Amount(realValue: currentValue, minRealValue: Int(minBidAmount), minAllowedRealValue: Int(minAllowedRealValue), maxRealValue: 30000, maxSliderValue: 999, isLogarithmic: true) + self.amount = Amount(realValue: currentValue, minRealValue: Int(minBidAmount), minAllowedRealValue: Int(minAllowedRealValue), maxRealValue: Int(maxBidAmount), maxSliderValue: 999, isLogarithmic: true) transition = .immediate } @@ -2521,8 +2537,7 @@ private final class GiftAuctionBidScreenComponent: Component { return } - - self.placeBid() + self.commitBid(value: Int64(self.amount.realValue)) } )), environment: {}, @@ -2666,10 +2681,26 @@ public class GiftAuctionBidScreen: ViewControllerComponentContainer { } } + fileprivate func dismissAllTooltips() { + self.window?.forEachController({ controller in + if let controller = controller as? UndoOverlayController { + controller.dismiss() + } + }) + self.forEachController({ controller in + if let controller = controller as? UndoOverlayController { + controller.dismiss() + } + return true + }) + } + override public func dismiss(completion: (() -> Void)? = nil) { if !self.isDismissed { self.isDismissed = true + self.dismissAllTooltips() + if let componentView = self.node.hostView.componentView as? GiftAuctionBidScreenComponent.View { componentView.animateOut(completion: { [weak self] in completion?() diff --git a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftViewScreen.swift b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftViewScreen.swift index f10ececef5..9306999fb1 100644 --- a/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftViewScreen.swift +++ b/submodules/TelegramUI/Components/Gifts/GiftViewScreen/Sources/GiftViewScreen.swift @@ -292,9 +292,7 @@ private final class GiftViewSheetContent: CombinedComponent { } })) - if arguments.upgradeStars == nil { - self.fetchUpgradeForm() - } + self.fetchUpgradeForm() } } @@ -2139,6 +2137,31 @@ private final class GiftViewSheetContent: CombinedComponent { } } else { self.scheduledUpgradeCommit = true + + self.inProgress = true + self.updated() + + Queue.mainQueue().after(5.0, { + if self.scheduledUpgradeCommit { + self.scheduledUpgradeCommit = false + self.inProgress = false + self.updated() + + let presentationData = self.context.sharedContext.currentPresentationData.with { $0 } + let alertController = textAlertController( + context: self.context, + title: nil, + text: presentationData.strings.Login_UnknownError, + actions: [ + TextAlertAction(type: .defaultAction, title: presentationData.strings.Common_OK, action: {}) + ], + parseMarkdown: true + ) + if let controller = self.getController() { + controller.present(alertController, in: .window(.root)) + } + } + }) } }