Various improvements

This commit is contained in:
Ilya Laktyushin 2022-05-21 14:50:31 +04:00
parent 31300c3c16
commit b79105092c
4 changed files with 27 additions and 4 deletions

View File

@ -79,6 +79,9 @@ public final class BotCheckoutController: ViewController {
private let invoice: TelegramMediaInvoice
private let source: BotPaymentInvoiceSource
private let completed: (String, EngineMessage.Id?) -> Void
private let pending: () -> Void
private let cancelled: () -> Void
private let failed: () -> Void
private var presentationData: PresentationData
@ -86,12 +89,14 @@ public final class BotCheckoutController: ViewController {
private let inputData: Promise<BotCheckoutController.InputData?>
public init(context: AccountContext, invoice: TelegramMediaInvoice, source: BotPaymentInvoiceSource, inputData: Promise<BotCheckoutController.InputData?>, completed: @escaping (String, EngineMessage.Id?) -> Void) {
public init(context: AccountContext, invoice: TelegramMediaInvoice, source: BotPaymentInvoiceSource, inputData: Promise<BotCheckoutController.InputData?>, completed: @escaping (String, EngineMessage.Id?) -> Void, pending: @escaping () -> Void = {}, cancelled: @escaping () -> Void = {}, failed: @escaping () -> Void = {}) {
self.context = context
self.invoice = invoice
self.source = source
self.inputData = inputData
self.completed = completed
self.cancelled = cancelled
self.failed = failed
self.presentationData = context.sharedContext.currentPresentationData.with { $0 }
@ -122,6 +127,12 @@ public final class BotCheckoutController: ViewController {
displayNode.dismiss = { [weak self] in
self?.presentingViewController?.dismiss(animated: false, completion: nil)
}
displayNode.pending = { [weak self] in
self?.pending()
}
displayNode.failed = { [weak self] in
self?.failed()
}
self.displayNode = displayNode
super.displayNodeDidLoad()
@ -146,6 +157,7 @@ public final class BotCheckoutController: ViewController {
}
@objc private func cancelPressed() {
self.cancelled()
self.dismiss()
}
}

View File

@ -497,7 +497,10 @@ final class BotCheckoutControllerNode: ItemListControllerNode, PKPaymentAuthoriz
private let present: (ViewController, Any?) -> Void
private let dismissAnimated: () -> Void
private let completed: (String, EngineMessage.Id?) -> Void
var pending: () -> Void = {}
var failed: () -> Void = {}
private var stateValue = BotCheckoutControllerState()
private let state = ValuePromise(BotCheckoutControllerState(), ignoreRepeated: true)
private var arguments: BotCheckoutControllerArguments?
@ -1312,6 +1315,8 @@ final class BotCheckoutControllerNode: ItemListControllerNode, PKPaymentAuthoriz
}
strongSelf.present(textAlertController(context: strongSelf.context, title: nil, text: text, actions: [TextAlertAction(type: .defaultAction, title: strongSelf.presentationData.strings.Common_OK, action: {})]), nil)
strongSelf.failed()
}
}))
}

View File

@ -3504,6 +3504,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
}, getNavigationController: { [weak self] in
return self?.effectiveNavigationController
})
controller.navigationPresentation = .flatModal
strongSelf.currentWebAppController = controller
strongSelf.present(controller, in: .window(.root))
}, error: { [weak self] error in
@ -3529,6 +3530,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
}, getNavigationController: { [weak self] in
return self?.effectiveNavigationController
})
controller.navigationPresentation = .flatModal
strongSelf.currentWebAppController = controller
strongSelf.present(controller, in: .window(.root))
}, error: { [weak self] error in
@ -14758,7 +14760,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
$0.updatedBotStartPayload(startPayload.payload)
})
} else if let navigationController = strongSelf.effectiveNavigationController {
strongSelf.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: strongSelf.context, chatLocation: .peer(id: peerId), botStart: startPayload))
strongSelf.context.sharedContext.navigateToChatController(NavigateToChatControllerParams(navigationController: navigationController, context: strongSelf.context, chatLocation: .peer(id: peerId), botStart: startPayload, keepStack: .always))
}
case let .withAttachBot(attachBotStart):
if let navigationController = strongSelf.effectiveNavigationController {

View File

@ -602,7 +602,11 @@ public final class WebAppController: ViewController, AttachmentContainable {
})
if let navigationController = strongSelf.controller?.getNavigationController() {
let checkoutController = BotCheckoutController(context: strongSelf.context, invoice: invoice, source: .slug(slug), inputData: inputData, completed: { currencyValue, receiptMessageId in
self?.sendInvoiceClosedEvent(slug: slug, result: .paid)
}, cancelled: { [weak self] in
self?.sendInvoiceClosedEvent(slug: slug, result: .cancelled)
}, failed: { [weak self] in
self?.sendInvoiceClosedEvent(slug: slug, result: .failed)
})
checkoutController.navigationPresentation = .modal
navigationController.pushViewController(checkoutController)