Skip to content

Commit

Permalink
Use payment bot's info instead of chat's
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali committed Apr 11, 2021
1 parent 7382d41 commit 2977568
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
15 changes: 13 additions & 2 deletions submodules/BotPaymentsUI/Sources/BotCheckoutControllerNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Peer?, NoError> 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)

Expand Down Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions submodules/TelegramCore/Sources/BotPaymentForm.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -198,7 +199,7 @@ public func fetchBotPaymentForm(postbox: Postbox, network: Network, messageId: M
|> mapToSignal { result -> Signal<BotPaymentForm, BotPaymentFormRequestError> 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)
Expand All @@ -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 }
Expand Down

0 comments on commit 2977568

Please sign in to comment.