@@ -344,98 +344,93 @@ final class GiftSetupScreenComponent: Component {
344344 let entities = generateChatInputTextEntities ( self . textInputState. text)
345345 let source : BotPaymentInvoiceSource = . starGift( hideName: self . hideName, includeUpgrade: self . includeUpgrade, peerId: peerId, giftId: starGift. id, text: self . textInputState. text. string, entities: entities)
346346
347- let inputData = BotCheckoutController . InputData. fetch ( context: component. context, source: source)
348- |> map ( Optional . init)
349- |> `catch` { _ -> Signal < BotCheckoutController . InputData ? , NoError > in
350- return . single( nil )
351- }
352347
353348 let completion = component. completion
354349
355- let _ = ( inputData
356- |> deliverOnMainQueue) . startStandalone ( next: { [ weak self] inputData in
357- guard let inputData else {
350+ let signal = BotCheckoutController . InputData. fetch ( context: component. context, source: source)
351+ |> `catch` { _ -> Signal < BotCheckoutController . InputData , SendBotPaymentFormError > in
352+ return . fail( . generic)
353+ }
354+ |> mapToSignal { inputData -> Signal < SendBotPaymentResult , SendBotPaymentFormError > in
355+ return component. context. engine. payments. sendStarsPaymentForm ( formId: inputData. form. id, source: source)
356+ }
357+ |> deliverOnMainQueue
358+
359+ let _ = signal. start ( next: { [ weak self] result in
360+ guard let self, let controller = self . environment? . controller ( ) , let navigationController = controller. navigationController as? NavigationController else {
358361 return
359362 }
360- let _ = ( component. context. engine. payments. sendStarsPaymentForm ( formId: inputData. form. id, source: source)
361- |> deliverOnMainQueue) . start ( next: { [ weak self] result in
362- if let self, peerId. namespace == Namespaces . Peer. CloudChannel, let controller = self . environment? . controller ( ) , let navigationController = controller. navigationController as? NavigationController {
363- var controllers = navigationController. viewControllers
364- controllers = controllers. filter { !( $0 is GiftSetupScreen ) && !( $0 is GiftOptionsScreenProtocol ) }
365- navigationController. setViewControllers ( controllers, animated: true )
366-
367- let tooltipController = UndoOverlayController (
368- presentationData: presentationData,
369- content: . sticker(
370- context: context,
371- file: starGift. file,
372- loop: true ,
373- title: nil ,
374- text: presentationData. strings. Gift_Send_Success ( self . peerMap [ peerId] ? . compactDisplayTitle ?? " " , presentationData. strings. Gift_Send_Success_Stars ( Int32 ( starGift. price) ) ) . string,
375- undoText: nil ,
376- customAction: nil
377- ) ,
378- action: { _ in return true }
379- )
380- ( navigationController. viewControllers. last as? ViewController ) ? . present ( tooltipController, in: . current)
381-
382- navigationController. view. addSubview ( ConfettiView ( frame: navigationController. view. bounds) )
383- }
363+
364+ if peerId. namespace == Namespaces . Peer. CloudChannel {
365+ var controllers = navigationController. viewControllers
366+ controllers = controllers. filter { !( $0 is GiftSetupScreen ) && !( $0 is GiftOptionsScreenProtocol ) }
367+ navigationController. setViewControllers ( controllers, animated: true )
384368
385- if let completion {
386- completion ( )
387-
388- if let self, let controller = self . environment? . controller ( ) {
389- controller. dismiss ( )
390- }
391- } else {
392- guard let self, let controller = self . environment? . controller ( ) , let navigationController = controller. navigationController as? NavigationController else {
393- return
394- }
395-
396- if peerId. namespace != Namespaces . Peer. CloudChannel {
397- var controllers = navigationController. viewControllers
398- controllers = controllers. filter { !( $0 is GiftSetupScreen ) && !( $0 is GiftOptionsScreenProtocol ) && !( $0 is PeerInfoScreen ) && !( $0 is ContactSelectionController ) }
399- var foundController = false
400- for controller in controllers. reversed ( ) {
401- if let chatController = controller as? ChatController , case . peer( id: component. peerId) = chatController. chatLocation {
402- chatController. hintPlayNextOutgoingGift ( )
403- foundController = true
404- break
405- }
406- }
407- if !foundController {
408- let chatController = component. context. sharedContext. makeChatController ( context: component. context, chatLocation: . peer( id: component. peerId) , subject: nil , botStart: nil , mode: . standard( . default) , params: nil )
409- chatController. hintPlayNextOutgoingGift ( )
410- controllers. append ( chatController)
411- }
412- navigationController. setViewControllers ( controllers, animated: true )
413- }
414- }
369+ let tooltipController = UndoOverlayController (
370+ presentationData: presentationData,
371+ content: . sticker(
372+ context: context,
373+ file: starGift. file,
374+ loop: true ,
375+ title: nil ,
376+ text: presentationData. strings. Gift_Send_Success ( self . peerMap [ peerId] ? . compactDisplayTitle ?? " " , presentationData. strings. Gift_Send_Success_Stars ( Int32 ( starGift. price) ) ) . string,
377+ undoText: nil ,
378+ customAction: nil
379+ ) ,
380+ action: { _ in return true }
381+ )
382+ ( navigationController. viewControllers. last as? ViewController ) ? . present ( tooltipController, in: . current)
415383
416- starsContext. load ( force: true )
417- } , error: { [ weak self] error in
418- guard let self, let controller = self . environment? . controller ( ) else {
419- return
384+ navigationController. view. addSubview ( ConfettiView ( frame: navigationController. view. bounds) )
385+ } else if peerId. namespace == Namespaces . Peer. CloudUser {
386+ var controllers = navigationController. viewControllers
387+ controllers = controllers. filter { !( $0 is GiftSetupScreen ) && !( $0 is GiftOptionsScreenProtocol ) && !( $0 is PeerInfoScreen ) && !( $0 is ContactSelectionController ) }
388+ var foundController = false
389+ for controller in controllers. reversed ( ) {
390+ if let chatController = controller as? ChatController , case . peer( id: component. peerId) = chatController. chatLocation {
391+ chatController. hintPlayNextOutgoingGift ( )
392+ foundController = true
393+ break
394+ }
420395 }
421-
422- self . inProgress = false
423- self . state? . updated ( )
424-
425- let presentationData = component. context. sharedContext. currentPresentationData. with { $0 }
426- var errorText : String ?
427- switch error {
428- case . starGiftOutOfStock:
429- errorText = presentationData. strings. Gift_Send_ErrorOutOfStock
430- default :
431- errorText = presentationData. strings. Gift_Send_ErrorUnknown
396+ if !foundController {
397+ let chatController = component. context. sharedContext. makeChatController ( context: component. context, chatLocation: . peer( id: component. peerId) , subject: nil , botStart: nil , mode: . standard( . default) , params: nil )
398+ chatController. hintPlayNextOutgoingGift ( )
399+ controllers. append ( chatController)
432400 }
401+ navigationController. setViewControllers ( controllers, animated: true )
402+ }
403+
404+ if let completion {
405+ completion ( )
433406
434- if let errorText = errorText {
435- let alertController = textAlertController ( context: component. context, title: nil , text: errorText, actions: [ TextAlertAction ( type: . defaultAction, title: presentationData. strings. Common_OK, action: { } ) ] )
436- controller. present ( alertController, in: . window( . root) )
407+ if let controller = self . environment? . controller ( ) {
408+ controller. dismiss ( )
437409 }
438- } )
410+ }
411+
412+ starsContext. load ( force: true )
413+ } , error: { [ weak self] error in
414+ guard let self, let controller = self . environment? . controller ( ) else {
415+ return
416+ }
417+
418+ self . inProgress = false
419+ self . state? . updated ( )
420+
421+ let presentationData = component. context. sharedContext. currentPresentationData. with { $0 }
422+ var errorText : String ?
423+ switch error {
424+ case . starGiftOutOfStock:
425+ errorText = presentationData. strings. Gift_Send_ErrorOutOfStock
426+ default :
427+ errorText = presentationData. strings. Gift_Send_ErrorUnknown
428+ }
429+
430+ if let errorText = errorText {
431+ let alertController = textAlertController ( context: component. context, title: nil , text: errorText, actions: [ TextAlertAction ( type: . defaultAction, title: presentationData. strings. Common_OK, action: { } ) ] )
432+ controller. present ( alertController, in: . window( . root) )
433+ }
439434 } )
440435 }
441436
0 commit comments