From 29775680c99d107a90561a640af68047348dec5e Mon Sep 17 00:00:00 2001 From: Ali <> Date: Sun, 11 Apr 2021 23:40:09 +0400 Subject: [PATCH] Use payment bot's info instead of chat's --- .../Sources/BotCheckoutControllerNode.swift | 15 +++++++++++++-- .../TelegramCore/Sources/BotPaymentForm.swift | 5 +++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/submodules/BotPaymentsUI/Sources/BotCheckoutControllerNode.swift b/submodules/BotPaymentsUI/Sources/BotCheckoutControllerNode.swift index 07891d3406d..cf03bb4a04f 100644 --- a/submodules/BotPaymentsUI/Sources/BotCheckoutControllerNode.swift +++ b/submodules/BotPaymentsUI/Sources/BotCheckoutControllerNode.swift @@ -564,8 +564,19 @@ final class BotCheckoutControllerNode: ItemListControllerNode, PKPaymentAuthoriz }, ensureTipInputVisible: { ensureTipInputVisibleImpl?() }) + + let paymentBotPeer = paymentFormAndInfo.get() + |> map { paymentFormAndInfo -> PeerId? in + return paymentFormAndInfo?.0.paymentBotId + } + |> distinctUntilChanged + |> mapToSignal { peerId -> Signal in + return context.account.postbox.transaction { transaction -> Peer? in + return peerId.flatMap(transaction.getPeer) + } + } - let signal: Signal<(ItemListPresentationData, (ItemListNodeState, Any)), NoError> = combineLatest(context.sharedContext.presentationData, self.state.get(), paymentFormAndInfo.get(), context.account.postbox.loadedPeerWithId(messageId.peerId)) + let signal: Signal<(ItemListPresentationData, (ItemListNodeState, Any)), NoError> = combineLatest(queue: .mainQueue(), context.sharedContext.presentationData, self.state.get(), paymentFormAndInfo.get(), paymentBotPeer) |> map { presentationData, state, paymentFormAndInfo, botPeer -> (ItemListPresentationData, (ItemListNodeState, Any)) in let nodeState = ItemListNodeState(presentationData: ItemListPresentationData(presentationData), entries: botCheckoutControllerEntries(presentationData: presentationData, state: state, invoice: invoice, paymentForm: paymentFormAndInfo?.0, formInfo: paymentFormAndInfo?.1, validatedFormInfo: paymentFormAndInfo?.2, currentShippingOptionId: paymentFormAndInfo?.3, currentPaymentMethod: paymentFormAndInfo?.4, currentTip: paymentFormAndInfo?.5, botPeer: botPeer), style: .blocks, focusItemTag: nil, emptyStateItem: nil, animateChanges: false) @@ -1184,7 +1195,7 @@ final class BotCheckoutControllerNode: ItemListControllerNode, PKPaymentAuthoriz } return nil } - let _ = (combineLatest(ApplicationSpecificNotice.getBotPaymentLiability(accountManager: self.context.sharedContext.accountManager, peerId: self.messageId.peerId), botPeer, self.context.account.postbox.loadedPeerWithId(paymentForm.providerId)) + let _ = (combineLatest(ApplicationSpecificNotice.getBotPaymentLiability(accountManager: self.context.sharedContext.accountManager, peerId: paymentForm.paymentBotId), botPeer, self.context.account.postbox.loadedPeerWithId(paymentForm.providerId)) |> deliverOnMainQueue).start(next: { [weak self] value, botPeer, providerPeer in if let strongSelf = self, let botPeer = botPeer { if value { diff --git a/submodules/TelegramCore/Sources/BotPaymentForm.swift b/submodules/TelegramCore/Sources/BotPaymentForm.swift index 24f75b8f919..1252be59fa4 100644 --- a/submodules/TelegramCore/Sources/BotPaymentForm.swift +++ b/submodules/TelegramCore/Sources/BotPaymentForm.swift @@ -106,6 +106,7 @@ public struct BotPaymentForm : Equatable { public let canSaveCredentials: Bool public let passwordMissing: Bool public let invoice: BotPaymentInvoice + public let paymentBotId: PeerId public let providerId: PeerId public let url: String public let nativeProvider: BotPaymentNativeProvider? @@ -198,7 +199,7 @@ public func fetchBotPaymentForm(postbox: Postbox, network: Network, messageId: M |> mapToSignal { result -> Signal in return postbox.transaction { transaction -> BotPaymentForm in switch result { - case let .paymentForm(flags, id, _, invoice, providerId, url, nativeProvider, nativeParams, savedInfo, savedCredentials, apiUsers): + case let .paymentForm(flags, id, botId, invoice, providerId, url, nativeProvider, nativeParams, savedInfo, savedCredentials, apiUsers): var peers: [Peer] = [] for user in apiUsers { let parsed = TelegramUser(user: user) @@ -224,7 +225,7 @@ public func fetchBotPaymentForm(postbox: Postbox, network: Network, messageId: M parsedSavedCredentials = .card(id: id, title: title) } } - return BotPaymentForm(id: id, canSaveCredentials: (flags & (1 << 2)) != 0, passwordMissing: (flags & (1 << 3)) != 0, invoice: parsedInvoice, providerId: PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt32Value(providerId)), url: url, nativeProvider: parsedNativeProvider, savedInfo: parsedSavedInfo, savedCredentials: parsedSavedCredentials) + return BotPaymentForm(id: id, canSaveCredentials: (flags & (1 << 2)) != 0, passwordMissing: (flags & (1 << 3)) != 0, invoice: parsedInvoice, paymentBotId: PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt32Value(botId)), providerId: PeerId(namespace: Namespaces.Peer.CloudUser, id: PeerId.Id._internalFromInt32Value(providerId)), url: url, nativeProvider: parsedNativeProvider, savedInfo: parsedSavedInfo, savedCredentials: parsedSavedCredentials) } } |> mapError { _ -> BotPaymentFormRequestError in }