Merge commit '689a5e04277ef6cfedb53e99cc563e86d7a9c97a'

This commit is contained in:
Ali 2022-07-26 15:38:32 +02:00
commit 64076541cd
2 changed files with 24 additions and 4 deletions

View File

@ -13,6 +13,18 @@ private let productIdentifiers = [
"org.telegram.telegramPremium.threeMonths"
]
private extension NSDecimalNumber {
func round(_ decimals: Int) -> NSDecimalNumber {
return self.rounding(accordingToBehavior:
NSDecimalNumberHandler(roundingMode: .down,
scale: Int16(decimals),
raiseOnExactness: false,
raiseOnOverflow: false,
raiseOnUnderflow: false,
raiseOnDivideByZero: false))
}
}
public final class InAppPurchaseManager: NSObject {
public final class Product: Equatable {
private lazy var numberFormatter: NumberFormatter = {
@ -47,7 +59,7 @@ public final class InAppPurchaseManager: NSObject {
}
public func pricePerMonth(_ monthsCount: Int) -> String {
let price = self.skProduct.price.dividing(by: NSDecimalNumber(value: monthsCount))
let price = self.skProduct.price.dividing(by: NSDecimalNumber(value: monthsCount)).round(2)
return self.numberFormatter.string(from: price) ?? ""
}
@ -57,7 +69,7 @@ public final class InAppPurchaseManager: NSObject {
public var priceCurrencyAndAmount: (currency: String, amount: Int64) {
if let currencyCode = self.numberFormatter.currencyCode,
let amount = fractionalToCurrencyAmount(value: self.priceValue.doubleValue, currency: currencyCode) {
let amount = fractionalToCurrencyAmount(value: self.priceValue.doubleValue, currency: currencyCode) {
return (currencyCode, amount)
} else {
return ("", 0)

View File

@ -1259,7 +1259,11 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable {
if let undoOverlayController = strongSelf.undoOverlayController {
undoOverlayController.content = .image(image: image ?? UIImage(), text: text)
} else {
let undoOverlayController = UndoOverlayController(presentationData: presentationData, content: .image(image: image ?? UIImage(), text: text), elevatedLayout: false, action: { [weak self] action in
var elevatedLayout = true
if let layout = strongSelf.validLayout, case .regular = layout.metrics.widthClass {
elevatedLayout = false
}
let undoOverlayController = UndoOverlayController(presentationData: presentationData, content: .image(image: image ?? UIImage(), text: text), elevatedLayout: elevatedLayout, action: { [weak self] action in
guard let strongSelf = self else {
return true
}
@ -1271,7 +1275,11 @@ public final class MediaPickerScreen: ViewController, AttachmentContainable {
}
return true
})
strongSelf.present(undoOverlayController, in: .current)
if let layout = strongSelf.validLayout, case .regular = layout.metrics.widthClass {
strongSelf.present(undoOverlayController, in: .current)
} else {
strongSelf.present(undoOverlayController, in: .window(.root))
}
strongSelf.undoOverlayController = undoOverlayController
}
})