@@ -1145,7 +1145,7 @@ private final class GiftViewSheetContent: CombinedComponent {
11451145 }
11461146 }
11471147
1148- func commitBuy( skipConfirmation: Bool = false ) {
1148+ func commitBuy( acceptedPrice : Int64 ? = nil , skipConfirmation: Bool = false ) {
11491149 guard let resellStars = self . subject. arguments? . resellStars, let starsContext = self . context. starsContext, let starsState = starsContext. currentState, case let . unique( uniqueGift) = self . subject. arguments? . gift else {
11501150 return
11511151 }
@@ -1157,46 +1157,74 @@ private final class GiftViewSheetContent: CombinedComponent {
11571157 let recipientPeerId = self . recipientPeerId ?? self . context. account. peerId
11581158
11591159 let action = {
1160- let proceed : ( Int64 ) -> Void = { formId in
1160+ let proceed : ( ) -> Void = {
11611161 guard let controller = self . getController ( ) as? GiftViewScreen else {
11621162 return
11631163 }
11641164
11651165 self . inProgress = true
11661166 self . updated ( )
11671167
1168- let buyGiftImpl : ( ( String , EnginePeer . Id ) -> Signal < Never , BuyStarGiftError > )
1168+ let buyGiftImpl : ( ( String , EnginePeer . Id , Int64 ? ) -> Signal < Never , BuyStarGiftError > )
11691169 if let buyGift = controller. buyGift {
1170- buyGiftImpl = { slug, peerId in
1171- return buyGift ( slug, peerId)
1170+ buyGiftImpl = { slug, peerId, price in
1171+ return buyGift ( slug, peerId, price )
11721172 |> afterCompleted {
11731173 context. starsContext? . load ( force: true )
11741174 }
11751175 }
11761176 } else {
1177- buyGiftImpl = { slug, peerId in
1178- return self . context. engine. payments. buyStarGift ( slug: slug, peerId: peerId)
1177+ buyGiftImpl = { slug, peerId, price in
1178+ return self . context. engine. payments. buyStarGift ( slug: slug, peerId: peerId, price : price )
11791179 |> afterCompleted {
11801180 context. starsContext? . load ( force: true )
11811181 }
11821182 }
11831183 }
11841184
1185- self . buyDisposable = ( buyGiftImpl ( uniqueGift. slug, recipientPeerId)
1186- |> deliverOnMainQueue) . start ( error: { [ weak self] error in
1187- guard let self, let controller = self . getController ( ) else {
1188- return
1189- }
1190-
1191- self . inProgress = false
1192- self . updated ( )
1193-
1194- let errorText = presentationData. strings. Gift_Send_ErrorUnknown
1195-
1196- let alertController = textAlertController ( context: context, title: nil , text: errorText, actions: [ TextAlertAction ( type: . defaultAction, title: presentationData. strings. Common_OK, action: { } ) ] , parseMarkdown: true )
1197- controller. present ( alertController, in: . window( . root) )
1198- } , completed: { [ weak self, weak starsContext] in
1199- guard let self, let controller = self . getController ( ) as? GiftViewScreen else {
1185+ self . buyDisposable = ( buyGiftImpl ( uniqueGift. slug, recipientPeerId, acceptedPrice ?? resellStars)
1186+ |> deliverOnMainQueue) . start (
1187+ error: { [ weak self] error in
1188+ guard let self, let controller = self . getController ( ) else {
1189+ return
1190+ }
1191+
1192+ self . inProgress = false
1193+ self . updated ( )
1194+
1195+ switch error {
1196+ case let . priceChanged( newPrice) :
1197+ let errorTitle = presentationData. strings. Gift_Buy_ErrorPriceChanged_Title
1198+ let originalPriceString = presentationData. strings. Gift_Buy_ErrorPriceChanged_Text_Stars ( Int32 ( resellStars) )
1199+ let newPriceString = presentationData. strings. Gift_Buy_ErrorPriceChanged_Text_Stars ( Int32 ( newPrice) )
1200+ let errorText = presentationData. strings. Gift_Buy_ErrorPriceChanged_Text ( originalPriceString, newPriceString) . string
1201+
1202+ let alertController = textAlertController (
1203+ context: context,
1204+ title: errorTitle,
1205+ text: errorText,
1206+ actions: [
1207+ TextAlertAction ( type: . defaultAction, title: presentationData. strings. Gift_Buy_Confirm_BuyFor ( Int32 ( newPrice) ) , action: { [ weak self] in
1208+ guard let self else {
1209+ return
1210+ }
1211+ self . commitBuy ( acceptedPrice: newPrice, skipConfirmation: true )
1212+ } ) ,
1213+ TextAlertAction ( type: . genericAction, title: presentationData. strings. Common_Cancel, action: {
1214+ } )
1215+ ] ,
1216+ actionLayout: . vertical,
1217+ parseMarkdown: true
1218+ )
1219+ controller. present ( alertController, in: . window( . root) )
1220+ default :
1221+ let alertController = textAlertController ( context: context, title: nil , text: presentationData. strings. Gift_Buy_ErrorUnknown, actions: [ TextAlertAction ( type: . defaultAction, title: presentationData. strings. Common_OK, action: { } ) ] , parseMarkdown: true )
1222+ controller. present ( alertController, in: . window( . root) )
1223+ }
1224+ } ,
1225+ completed: { [ weak self, weak starsContext] in
1226+ guard let self,
1227+ let controller = self . getController ( ) as? GiftViewScreen else {
12001228 return
12011229 }
12021230 self . inProgress = false
@@ -1303,7 +1331,7 @@ private final class GiftViewSheetContent: CombinedComponent {
13031331
13041332 self . commitBuy ( skipConfirmation: true )
13051333 } else {
1306- proceed ( buyForm . id )
1334+ proceed ( )
13071335 }
13081336 } ) ;
13091337 } )
@@ -1312,7 +1340,7 @@ private final class GiftViewSheetContent: CombinedComponent {
13121340 controller. push ( purchaseController)
13131341 } )
13141342 } else {
1315- proceed ( buyForm . id )
1343+ proceed ( )
13161344 }
13171345 }
13181346 }
@@ -1321,7 +1349,7 @@ private final class GiftViewSheetContent: CombinedComponent {
13211349 action ( )
13221350 } else {
13231351 let _ = ( self . context. engine. data. get ( TelegramEngine . EngineData. Item. Peer. Peer ( id: recipientPeerId) )
1324- |> deliverOnMainQueue) . start ( next: { [ weak self] peer in
1352+ |> deliverOnMainQueue) . start ( next: { [ weak self] peer in
13251353 guard let self, let peer else {
13261354 return
13271355 }
@@ -3565,7 +3593,7 @@ public class GiftViewScreen: ViewControllerComponentContainer {
35653593 fileprivate let convertToStars : ( ( ) -> Void ) ?
35663594 fileprivate let transferGift : ( ( Bool , EnginePeer . Id ) -> Signal < Never , TransferStarGiftError > ) ?
35673595 fileprivate let upgradeGift : ( ( Int64 ? , Bool ) -> Signal < ProfileGiftsContext . State . StarGift , UpgradeStarGiftError > ) ?
3568- fileprivate let buyGift : ( ( String , EnginePeer . Id ) -> Signal < Never , BuyStarGiftError > ) ?
3596+ fileprivate let buyGift : ( ( String , EnginePeer . Id , Int64 ? ) -> Signal < Never , BuyStarGiftError > ) ?
35693597 fileprivate let updateResellStars : ( ( Int64 ? ) -> Signal < Never , UpdateStarGiftPriceError > ) ?
35703598 fileprivate let togglePinnedToTop : ( ( Bool ) -> Bool ) ?
35713599 fileprivate let shareStory : ( ( StarGift . UniqueGift ) -> Void ) ?
@@ -3582,7 +3610,7 @@ public class GiftViewScreen: ViewControllerComponentContainer {
35823610 convertToStars: ( ( ) -> Void ) ? = nil ,
35833611 transferGift: ( ( Bool , EnginePeer . Id ) -> Signal < Never , TransferStarGiftError > ) ? = nil ,
35843612 upgradeGift: ( ( Int64 ? , Bool ) -> Signal < ProfileGiftsContext . State . StarGift , UpgradeStarGiftError > ) ? = nil ,
3585- buyGift: ( ( String , EnginePeer . Id ) -> Signal < Never , BuyStarGiftError > ) ? = nil ,
3613+ buyGift: ( ( String , EnginePeer . Id , Int64 ? ) -> Signal < Never , BuyStarGiftError > ) ? = nil ,
35863614 updateResellStars: ( ( Int64 ? ) -> Signal < Never , UpdateStarGiftPriceError > ) ? = nil ,
35873615 togglePinnedToTop: ( ( Bool ) -> Bool ) ? = nil ,
35883616 shareStory: ( ( StarGift . UniqueGift ) -> Void ) ? = nil
0 commit comments