mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-11-07 09:20:08 +00:00
Merge commit 'cf3bc1edbdbab6fecc24a4446a78cee8777ac2f6'
This commit is contained in:
commit
633b44843a
@ -28,7 +28,7 @@ public func formatTonUsdValue(_ value: Int64, divide: Bool = true, rate: Double
|
|||||||
return "$\(formattedValue)"
|
return "$\(formattedValue)"
|
||||||
}
|
}
|
||||||
|
|
||||||
public func formatTonAmountText(_ value: Int64, dateTimeFormat: PresentationDateTimeFormat, showPlus: Bool = false, maxDecimalPositions: Int = 2) -> String {
|
public func formatTonAmountText(_ value: Int64, dateTimeFormat: PresentationDateTimeFormat, showPlus: Bool = false, maxDecimalPositions: Int? = 2) -> String {
|
||||||
var balanceText = "\(abs(value))"
|
var balanceText = "\(abs(value))"
|
||||||
while balanceText.count < 10 {
|
while balanceText.count < 10 {
|
||||||
balanceText.insert("0", at: balanceText.startIndex)
|
balanceText.insert("0", at: balanceText.startIndex)
|
||||||
@ -49,10 +49,12 @@ public func formatTonAmountText(_ value: Int64, dateTimeFormat: PresentationDate
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let dotIndex = balanceText.range(of: dateTimeFormat.decimalSeparator) {
|
if let dotIndex = balanceText.range(of: dateTimeFormat.decimalSeparator) {
|
||||||
if let endIndex = balanceText.index(dotIndex.upperBound, offsetBy: maxDecimalPositions, limitedBy: balanceText.endIndex) {
|
if let maxDecimalPositions {
|
||||||
balanceText = String(balanceText[balanceText.startIndex..<endIndex])
|
if let endIndex = balanceText.index(dotIndex.upperBound, offsetBy: maxDecimalPositions, limitedBy: balanceText.endIndex) {
|
||||||
} else {
|
balanceText = String(balanceText[balanceText.startIndex..<endIndex])
|
||||||
balanceText = String(balanceText[balanceText.startIndex..<balanceText.endIndex])
|
} else {
|
||||||
|
balanceText = String(balanceText[balanceText.startIndex..<balanceText.endIndex])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let integerPartString = balanceText[..<dotIndex.lowerBound]
|
let integerPartString = balanceText[..<dotIndex.lowerBound]
|
||||||
|
|||||||
@ -421,7 +421,6 @@ private final class GiftViewSheetContent: CombinedComponent {
|
|||||||
UndoOverlayController(
|
UndoOverlayController(
|
||||||
presentationData: presentationData,
|
presentationData: presentationData,
|
||||||
content: .copy(text: presentationData.strings.Gift_View_CopiedAddress),
|
content: .copy(text: presentationData.strings.Gift_View_CopiedAddress),
|
||||||
elevatedLayout: false,
|
|
||||||
position: .bottom,
|
position: .bottom,
|
||||||
action: { _ in return true }
|
action: { _ in return true }
|
||||||
),
|
),
|
||||||
@ -484,7 +483,7 @@ private final class GiftViewSheetContent: CombinedComponent {
|
|||||||
undoText: presentationData.strings.Gift_Displayed_View,
|
undoText: presentationData.strings.Gift_Displayed_View,
|
||||||
customAction: nil
|
customAction: nil
|
||||||
),
|
),
|
||||||
elevatedLayout: lastController is ChatController,
|
elevatedLayout: !(lastController is ChatController),
|
||||||
action: { [weak navigationController] action in
|
action: { [weak navigationController] action in
|
||||||
if case .undo = action, let navigationController, let giftsPeerId {
|
if case .undo = action, let navigationController, let giftsPeerId {
|
||||||
let _ = (self.context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: giftsPeerId))
|
let _ = (self.context.engine.data.get(TelegramEngine.EngineData.Item.Peer.Peer(id: giftsPeerId))
|
||||||
@ -508,7 +507,7 @@ private final class GiftViewSheetContent: CombinedComponent {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
lastController.present(resultController, in: .window(.root))
|
lastController.present(resultController, in: .current)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -608,10 +607,10 @@ private final class GiftViewSheetContent: CombinedComponent {
|
|||||||
customUndoText: nil,
|
customUndoText: nil,
|
||||||
timeout: nil
|
timeout: nil
|
||||||
),
|
),
|
||||||
elevatedLayout: lastController is ChatController,
|
elevatedLayout: !(lastController is ChatController),
|
||||||
action: { _ in return true }
|
action: { _ in return true }
|
||||||
)
|
)
|
||||||
lastController.present(resultController, in: .window(.root))
|
lastController.present(resultController, in: .current)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -799,6 +798,8 @@ private final class GiftViewSheetContent: CombinedComponent {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let isTablet = controller.validLayout?.metrics.isTablet ?? false
|
||||||
|
|
||||||
controller.dismissAllTooltips()
|
controller.dismissAllTooltips()
|
||||||
|
|
||||||
let presentationData = self.context.sharedContext.currentPresentationData.with { $0 }
|
let presentationData = self.context.sharedContext.currentPresentationData.with { $0 }
|
||||||
@ -862,12 +863,12 @@ private final class GiftViewSheetContent: CombinedComponent {
|
|||||||
),
|
),
|
||||||
position: .bottom,
|
position: .bottom,
|
||||||
animateInAsReplacement: false,
|
animateInAsReplacement: false,
|
||||||
appearance: UndoOverlayController.Appearance(sideInset: 16.0, bottomInset: 62.0),
|
appearance: isTablet ? nil : UndoOverlayController.Appearance(sideInset: 16.0, bottomInset: 62.0),
|
||||||
action: { action in
|
action: { action in
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
controller.present(tooltipController, in: .window(.root))
|
controller.present(tooltipController, in: isTablet ? .current : .window(.root))
|
||||||
})
|
})
|
||||||
}),
|
}),
|
||||||
TextAlertAction(type: .genericAction, title: presentationData.strings.Common_Cancel, action: {
|
TextAlertAction(type: .genericAction, title: presentationData.strings.Common_Cancel, action: {
|
||||||
@ -932,7 +933,7 @@ private final class GiftViewSheetContent: CombinedComponent {
|
|||||||
case .stars:
|
case .stars:
|
||||||
priceString = presentationData.strings.Gift_View_Resale_Relist_Success_Stars(Int32(price.amount.value))
|
priceString = presentationData.strings.Gift_View_Resale_Relist_Success_Stars(Int32(price.amount.value))
|
||||||
case .ton:
|
case .ton:
|
||||||
priceString = formatTonAmountText(price.amount.value, dateTimeFormat: presentationData.dateTimeFormat) + " TON"
|
priceString = formatTonAmountText(price.amount.value, dateTimeFormat: presentationData.dateTimeFormat, maxDecimalPositions: nil) + " TON"
|
||||||
}
|
}
|
||||||
text = presentationData.strings.Gift_View_Resale_Relist_Success(giftTitle, priceString).string
|
text = presentationData.strings.Gift_View_Resale_Relist_Success(giftTitle, priceString).string
|
||||||
}
|
}
|
||||||
@ -949,12 +950,12 @@ private final class GiftViewSheetContent: CombinedComponent {
|
|||||||
),
|
),
|
||||||
position: .bottom,
|
position: .bottom,
|
||||||
animateInAsReplacement: false,
|
animateInAsReplacement: false,
|
||||||
appearance: UndoOverlayController.Appearance(sideInset: 16.0, bottomInset: 62.0),
|
appearance: isTablet ? nil : UndoOverlayController.Appearance(sideInset: 16.0, bottomInset: 62.0),
|
||||||
action: { action in
|
action: { action in
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
controller.present(tooltipController, in: .window(.root))
|
controller.present(tooltipController, in: isTablet ? .current : .window(.root))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
controller.push(resellController)
|
controller.push(resellController)
|
||||||
@ -1012,7 +1013,7 @@ private final class GiftViewSheetContent: CombinedComponent {
|
|||||||
let strings = presentationData.strings
|
let strings = presentationData.strings
|
||||||
|
|
||||||
if let _ = arguments.reference, case .unique = arguments.gift, let togglePinnedToTop = controller.togglePinnedToTop, let pinnedToTop = arguments.pinnedToTop {
|
if let _ = arguments.reference, case .unique = arguments.gift, let togglePinnedToTop = controller.togglePinnedToTop, let pinnedToTop = arguments.pinnedToTop {
|
||||||
items.append(.action(ContextMenuActionItem(text: pinnedToTop ? strings.PeerInfo_Gifts_Context_Unpin : strings.PeerInfo_Gifts_Context_Pin , icon: { theme in generateTintedImage(image: UIImage(bundleImageName: pinnedToTop ? "Chat/Context Menu/Unpin" : "Chat/Context Menu/Pin"), color: theme.contextMenu.primaryColor) }, action: { [weak self] c, f in
|
items.append(.action(ContextMenuActionItem(text: pinnedToTop ? strings.PeerInfo_Gifts_Context_Unpin : strings.PeerInfo_Gifts_Context_Pin , icon: { theme in generateTintedImage(image: UIImage(bundleImageName: pinnedToTop ? "Chat/Context Menu/Unpin" : "Chat/Context Menu/Pin"), color: theme.contextMenu.primaryColor) }, action: { [weak self] c, f in
|
||||||
c?.dismiss(completion: { [weak self, weak controller] in
|
c?.dismiss(completion: { [weak self, weak controller] in
|
||||||
guard let self, let controller else {
|
guard let self, let controller else {
|
||||||
return
|
return
|
||||||
@ -1257,7 +1258,7 @@ private final class GiftViewSheetContent: CombinedComponent {
|
|||||||
case .stars:
|
case .stars:
|
||||||
originalPriceString = presentationData.strings.Gift_Buy_ErrorPriceChanged_Text_Stars(Int32(resellAmount.amount.value))
|
originalPriceString = presentationData.strings.Gift_Buy_ErrorPriceChanged_Text_Stars(Int32(resellAmount.amount.value))
|
||||||
case .ton:
|
case .ton:
|
||||||
originalPriceString = formatTonAmountText(resellAmount.amount.value, dateTimeFormat: presentationData.dateTimeFormat) + " TON"
|
originalPriceString = formatTonAmountText(resellAmount.amount.value, dateTimeFormat: presentationData.dateTimeFormat, maxDecimalPositions: nil) + " TON"
|
||||||
}
|
}
|
||||||
|
|
||||||
let newPriceString: String
|
let newPriceString: String
|
||||||
@ -1267,7 +1268,7 @@ private final class GiftViewSheetContent: CombinedComponent {
|
|||||||
newPriceString = presentationData.strings.Gift_Buy_ErrorPriceChanged_Text_Stars(Int32(newPrice.amount.value))
|
newPriceString = presentationData.strings.Gift_Buy_ErrorPriceChanged_Text_Stars(Int32(newPrice.amount.value))
|
||||||
buttonText = presentationData.strings.Gift_Buy_Confirm_BuyFor(Int32(newPrice.amount.value))
|
buttonText = presentationData.strings.Gift_Buy_Confirm_BuyFor(Int32(newPrice.amount.value))
|
||||||
case .ton:
|
case .ton:
|
||||||
let tonValueString = formatTonAmountText(newPrice.amount.value, dateTimeFormat: presentationData.dateTimeFormat)
|
let tonValueString = formatTonAmountText(newPrice.amount.value, dateTimeFormat: presentationData.dateTimeFormat, maxDecimalPositions: nil)
|
||||||
newPriceString = tonValueString + " TON"
|
newPriceString = tonValueString + " TON"
|
||||||
buttonText = presentationData.strings.Gift_Buy_Confirm_BuyForTon(tonValueString).string
|
buttonText = presentationData.strings.Gift_Buy_Confirm_BuyForTon(tonValueString).string
|
||||||
}
|
}
|
||||||
@ -1323,12 +1324,12 @@ private final class GiftViewSheetContent: CombinedComponent {
|
|||||||
let resultController = UndoOverlayController(
|
let resultController = UndoOverlayController(
|
||||||
presentationData: presentationData,
|
presentationData: presentationData,
|
||||||
content: .sticker(context: context, file: animationFile, loop: false, title: presentationData.strings.Gift_View_Resale_SuccessYou_Title, text: presentationData.strings.Gift_View_Resale_SuccessYou_Text(giftTitle).string, undoText: nil, customAction: nil),
|
content: .sticker(context: context, file: animationFile, loop: false, title: presentationData.strings.Gift_View_Resale_SuccessYou_Title, text: presentationData.strings.Gift_View_Resale_SuccessYou_Text(giftTitle).string, undoText: nil, customAction: nil),
|
||||||
elevatedLayout: lastController is ChatController,
|
elevatedLayout: !(lastController is ChatController),
|
||||||
action: { _ in
|
action: { _ in
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
lastController.present(resultController, in: .window(.root))
|
lastController.present(resultController, in: .current)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@ -1345,12 +1346,12 @@ private final class GiftViewSheetContent: CombinedComponent {
|
|||||||
let resultController = UndoOverlayController(
|
let resultController = UndoOverlayController(
|
||||||
presentationData: presentationData,
|
presentationData: presentationData,
|
||||||
content: .sticker(context: context, file: animationFile, loop: false, title: presentationData.strings.Gift_View_Resale_Success_Title, text: presentationData.strings.Gift_View_Resale_Success_Text(peer.compactDisplayTitle).string, undoText: nil, customAction: nil),
|
content: .sticker(context: context, file: animationFile, loop: false, title: presentationData.strings.Gift_View_Resale_Success_Title, text: presentationData.strings.Gift_View_Resale_Success_Text(peer.compactDisplayTitle).string, undoText: nil, customAction: nil),
|
||||||
elevatedLayout: lastController is ChatController,
|
elevatedLayout: !(lastController is ChatController),
|
||||||
action: { _ in
|
action: { _ in
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
lastController.present(resultController, in: .window(.root))
|
lastController.present(resultController, in: .current)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@ -3383,6 +3384,8 @@ private final class GiftViewSheetContent: CombinedComponent {
|
|||||||
HapticFeedback().impact(.light)
|
HapticFeedback().impact(.light)
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
|
let isTablet = environment.metrics.isTablet
|
||||||
|
|
||||||
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
let presentationData = context.sharedContext.currentPresentationData.with { $0 }
|
||||||
let text = strings.Gift_View_TooltipPremiumWearing
|
let text = strings.Gift_View_TooltipPremiumWearing
|
||||||
let tooltipController = UndoOverlayController(
|
let tooltipController = UndoOverlayController(
|
||||||
@ -3390,7 +3393,7 @@ private final class GiftViewSheetContent: CombinedComponent {
|
|||||||
content: .premiumPaywall(title: nil, text: text, customUndoText: nil, timeout: nil, linkAction: nil),
|
content: .premiumPaywall(title: nil, text: text, customUndoText: nil, timeout: nil, linkAction: nil),
|
||||||
position: .bottom,
|
position: .bottom,
|
||||||
animateInAsReplacement: false,
|
animateInAsReplacement: false,
|
||||||
appearance: UndoOverlayController.Appearance(sideInset: 16.0, bottomInset: 62.0),
|
appearance: isTablet ? nil : UndoOverlayController.Appearance(sideInset: 16.0, bottomInset: 62.0),
|
||||||
action: { [weak controller, weak state] action in
|
action: { [weak controller, weak state] action in
|
||||||
if case .info = action {
|
if case .info = action {
|
||||||
controller?.dismissAllTooltips()
|
controller?.dismissAllTooltips()
|
||||||
@ -3404,7 +3407,7 @@ private final class GiftViewSheetContent: CombinedComponent {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
controller.present(tooltipController, in: .window(.root))
|
controller.present(tooltipController, in: isTablet ? .current : .window(.root))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
state.commitWear(uniqueGift)
|
state.commitWear(uniqueGift)
|
||||||
@ -3540,7 +3543,7 @@ private final class GiftViewSheetContent: CombinedComponent {
|
|||||||
currencyAmount = formatStarsAmountText(resellAmount.amount, dateTimeFormat: environment.dateTimeFormat)
|
currencyAmount = formatStarsAmountText(resellAmount.amount, dateTimeFormat: environment.dateTimeFormat)
|
||||||
case .ton:
|
case .ton:
|
||||||
currencySymbol = "$"
|
currencySymbol = "$"
|
||||||
currencyAmount = formatTonAmountText(resellAmount.amount.value, dateTimeFormat: environment.dateTimeFormat)
|
currencyAmount = formatTonAmountText(resellAmount.amount.value, dateTimeFormat: environment.dateTimeFormat, maxDecimalPositions: nil)
|
||||||
|
|
||||||
if let starsAmount = uniqueGift?.resellAmounts?.first(where: { $0.currency == .stars }) {
|
if let starsAmount = uniqueGift?.resellAmounts?.first(where: { $0.currency == .stars }) {
|
||||||
//TODO:localize
|
//TODO:localize
|
||||||
@ -3723,12 +3726,19 @@ final class GiftViewSheetComponent: CombinedComponent {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if let controller = controller(), !controller.automaticallyControlPresentationContextLayout {
|
if let controller = controller(), !controller.automaticallyControlPresentationContextLayout {
|
||||||
|
var sideInset: CGFloat = 0.0
|
||||||
|
var bottomInset: CGFloat = max(environment.safeInsets.bottom, sheetExternalState.contentHeight)
|
||||||
|
if case .regular = environment.metrics.widthClass {
|
||||||
|
sideInset = floor((context.availableSize.width - 430.0) / 2.0) - 12.0
|
||||||
|
bottomInset = (context.availableSize.height - sheetExternalState.contentHeight) / 2.0 + sheetExternalState.contentHeight
|
||||||
|
}
|
||||||
|
|
||||||
let layout = ContainerViewLayout(
|
let layout = ContainerViewLayout(
|
||||||
size: context.availableSize,
|
size: context.availableSize,
|
||||||
metrics: environment.metrics,
|
metrics: environment.metrics,
|
||||||
deviceMetrics: environment.deviceMetrics,
|
deviceMetrics: environment.deviceMetrics,
|
||||||
intrinsicInsets: UIEdgeInsets(top: 0.0, left: 0.0, bottom: max(environment.safeInsets.bottom, sheetExternalState.contentHeight), right: 0.0),
|
intrinsicInsets: UIEdgeInsets(top: 0.0, left: 0.0, bottom: bottomInset, right: 0.0),
|
||||||
safeInsets: UIEdgeInsets(top: 0.0, left: environment.safeInsets.left, bottom: 0.0, right: environment.safeInsets.right),
|
safeInsets: UIEdgeInsets(top: 0.0, left: max(sideInset, environment.safeInsets.left), bottom: 0.0, right: max(sideInset, environment.safeInsets.right)),
|
||||||
additionalInsets: .zero,
|
additionalInsets: .zero,
|
||||||
statusBarHeight: environment.statusBarHeight,
|
statusBarHeight: environment.statusBarHeight,
|
||||||
inputHeight: nil,
|
inputHeight: nil,
|
||||||
|
|||||||
@ -45,7 +45,7 @@ public final class StarsBalanceOverlayComponent: Component {
|
|||||||
|
|
||||||
public final class View: UIView {
|
public final class View: UIView {
|
||||||
private let backgroundView = BlurredBackgroundView(color: nil)
|
private let backgroundView = BlurredBackgroundView(color: nil)
|
||||||
private let text = ComponentView<Empty>()
|
private var text = ComponentView<Empty>()
|
||||||
private let action = ComponentView<Empty>()
|
private let action = ComponentView<Empty>()
|
||||||
|
|
||||||
private var component: StarsBalanceOverlayComponent?
|
private var component: StarsBalanceOverlayComponent?
|
||||||
@ -89,6 +89,7 @@ public final class StarsBalanceOverlayComponent: Component {
|
|||||||
defer {
|
defer {
|
||||||
self.isUpdating = false
|
self.isUpdating = false
|
||||||
}
|
}
|
||||||
|
let previousComponent = self.component
|
||||||
self.component = component
|
self.component = component
|
||||||
self.state = state
|
self.state = state
|
||||||
|
|
||||||
@ -169,6 +170,13 @@ public final class StarsBalanceOverlayComponent: Component {
|
|||||||
attributedText.addAttribute(.baselineOffset, value: 1.0, range: tonRange)
|
attributedText.addAttribute(.baselineOffset, value: 1.0, range: tonRange)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if previousComponent?.currency != component.currency {
|
||||||
|
if let textView = self.text.view {
|
||||||
|
textView.removeFromSuperview()
|
||||||
|
}
|
||||||
|
self.text = ComponentView()
|
||||||
|
}
|
||||||
|
|
||||||
let textSize = self.text.update(
|
let textSize = self.text.update(
|
||||||
transition: .immediate,
|
transition: .immediate,
|
||||||
component: AnyComponent(
|
component: AnyComponent(
|
||||||
@ -223,7 +231,6 @@ public final class StarsBalanceOverlayComponent: Component {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if let textView = self.text.view {
|
if let textView = self.text.view {
|
||||||
if textView.superview == nil {
|
if textView.superview == nil {
|
||||||
self.backgroundView.addSubview(textView)
|
self.backgroundView.addSubview(textView)
|
||||||
|
|||||||
@ -660,7 +660,7 @@ private final class StarsTransactionSheetContent: CombinedComponent {
|
|||||||
case .stars:
|
case .stars:
|
||||||
formattedAmount = formatStarsAmountText(absCount, dateTimeFormat: dateTimeFormat)
|
formattedAmount = formatStarsAmountText(absCount, dateTimeFormat: dateTimeFormat)
|
||||||
case .ton:
|
case .ton:
|
||||||
formattedAmount = formatTonAmountText(absCount.value, dateTimeFormat: dateTimeFormat)
|
formattedAmount = formatTonAmountText(absCount.value, dateTimeFormat: dateTimeFormat, maxDecimalPositions: nil)
|
||||||
}
|
}
|
||||||
let countColor: UIColor
|
let countColor: UIColor
|
||||||
var countFont: UIFont = isSubscription || isSubscriber ? Font.regular(17.0) : Font.semibold(17.0)
|
var countFont: UIFont = isSubscription || isSubscriber ? Font.regular(17.0) : Font.semibold(17.0)
|
||||||
@ -1207,14 +1207,25 @@ private final class StarsTransactionSheetContent: CombinedComponent {
|
|||||||
if transaction.flags.contains(.isPaidMessage) || transaction.flags.contains(.isStarGiftResale) {
|
if transaction.flags.contains(.isPaidMessage) || transaction.flags.contains(.isStarGiftResale) {
|
||||||
var totalStars = transaction.count
|
var totalStars = transaction.count
|
||||||
if let starrefCount = transaction.starrefAmount {
|
if let starrefCount = transaction.starrefAmount {
|
||||||
totalStars = CurrencyAmount(amount: totalStars.amount + starrefCount, currency: .stars)
|
totalStars = CurrencyAmount(amount: totalStars.amount + starrefCount, currency: totalStars.currency)
|
||||||
|
}
|
||||||
|
var valueString = formatCurrencyAmountText(totalStars, dateTimeFormat: dateTimeFormat)
|
||||||
|
switch totalStars.currency {
|
||||||
|
case .stars:
|
||||||
|
valueString = "\(valueString)⭐️"
|
||||||
|
case .ton:
|
||||||
|
valueString = "💎\(valueString)"
|
||||||
}
|
}
|
||||||
let valueString = "\(presentationStringsFormattedNumber(abs(Int32(totalStars.amount.value)), dateTimeFormat.groupingSeparator))⭐️"
|
|
||||||
let valueAttributedString = NSMutableAttributedString(string: valueString, font: tableBoldFont, textColor: theme.list.itemDisclosureActions.constructive.fillColor)
|
let valueAttributedString = NSMutableAttributedString(string: valueString, font: tableBoldFont, textColor: theme.list.itemDisclosureActions.constructive.fillColor)
|
||||||
let range = (valueAttributedString.string as NSString).range(of: "⭐️")
|
let starRange = (valueAttributedString.string as NSString).range(of: "⭐️")
|
||||||
if range.location != NSNotFound {
|
if starRange.location != NSNotFound {
|
||||||
valueAttributedString.addAttribute(ChatTextInputAttributes.customEmoji, value: ChatTextInputTextCustomEmojiAttribute(interactivelySelectedFromPackId: nil, fileId: 0, file: nil, custom: .stars(tinted: false)), range: range)
|
valueAttributedString.addAttribute(ChatTextInputAttributes.customEmoji, value: ChatTextInputTextCustomEmojiAttribute(interactivelySelectedFromPackId: nil, fileId: 0, file: nil, custom: .stars(tinted: false)), range: starRange)
|
||||||
valueAttributedString.addAttribute(.baselineOffset, value: 1.0, range: range)
|
valueAttributedString.addAttribute(.baselineOffset, value: 1.0, range: starRange)
|
||||||
|
}
|
||||||
|
let tonRange = (valueAttributedString.string as NSString).range(of: "💎")
|
||||||
|
if tonRange.location != NSNotFound {
|
||||||
|
valueAttributedString.addAttribute(ChatTextInputAttributes.customEmoji, value: ChatTextInputTextCustomEmojiAttribute(interactivelySelectedFromPackId: nil, fileId: 0, file: nil, custom: .ton(tinted: true)), range: tonRange)
|
||||||
|
valueAttributedString.addAttribute(.baselineOffset, value: 1.0, range: tonRange)
|
||||||
}
|
}
|
||||||
tableItems.append(.init(
|
tableItems.append(.init(
|
||||||
id: "paid",
|
id: "paid",
|
||||||
|
|||||||
@ -467,7 +467,7 @@ private final class SheetContent: CombinedComponent {
|
|||||||
case .ton:
|
case .ton:
|
||||||
if let value = state.amount?.value, value > 0 {
|
if let value = state.amount?.value, value > 0 {
|
||||||
let tonValue = Int64(Float(value) * Float(resaleConfiguration.starGiftCommissionTonPermille) / 1000.0)
|
let tonValue = Int64(Float(value) * Float(resaleConfiguration.starGiftCommissionTonPermille) / 1000.0)
|
||||||
let tonString = formatTonAmountText(tonValue, dateTimeFormat: environment.dateTimeFormat) + " TON"
|
let tonString = formatTonAmountText(tonValue, dateTimeFormat: environment.dateTimeFormat, maxDecimalPositions: nil) + " TON"
|
||||||
amountInfoString = NSAttributedString(attributedString: parseMarkdownIntoAttributedString(environment.strings.Stars_SellGift_AmountInfo(tonString).string, attributes: amountMarkdownAttributes, textAlignment: .natural))
|
amountInfoString = NSAttributedString(attributedString: parseMarkdownIntoAttributedString(environment.strings.Stars_SellGift_AmountInfo(tonString).string, attributes: amountMarkdownAttributes, textAlignment: .natural))
|
||||||
|
|
||||||
if let tonUsdRate = withdrawConfiguration.tonUsdRate {
|
if let tonUsdRate = withdrawConfiguration.tonUsdRate {
|
||||||
@ -778,7 +778,7 @@ private final class SheetContent: CombinedComponent {
|
|||||||
currencyAmount = presentationStringsFormattedNumber(amount, environment.dateTimeFormat.groupingSeparator)
|
currencyAmount = presentationStringsFormattedNumber(amount, environment.dateTimeFormat.groupingSeparator)
|
||||||
case .ton:
|
case .ton:
|
||||||
currencySymbol = "$"
|
currencySymbol = "$"
|
||||||
currencyAmount = formatTonAmountText(amount.value, dateTimeFormat: environment.dateTimeFormat)
|
currencyAmount = formatTonAmountText(amount.value, dateTimeFormat: environment.dateTimeFormat, maxDecimalPositions: nil)
|
||||||
}
|
}
|
||||||
buttonString = "\(environment.strings.Stars_SellGift_SellFor) \(currencySymbol) \(currencyAmount)"
|
buttonString = "\(environment.strings.Stars_SellGift_SellFor) \(currencySymbol) \(currencyAmount)"
|
||||||
} else {
|
} else {
|
||||||
@ -798,7 +798,7 @@ private final class SheetContent: CombinedComponent {
|
|||||||
currencyAmount = presentationStringsFormattedNumber(amount, environment.dateTimeFormat.groupingSeparator)
|
currencyAmount = presentationStringsFormattedNumber(amount, environment.dateTimeFormat.groupingSeparator)
|
||||||
case .ton:
|
case .ton:
|
||||||
currencySymbol = "$"
|
currencySymbol = "$"
|
||||||
currencyAmount = formatTonAmountText(amount.value, dateTimeFormat: environment.dateTimeFormat)
|
currencyAmount = formatTonAmountText(amount.value, dateTimeFormat: environment.dateTimeFormat, maxDecimalPositions: nil)
|
||||||
}
|
}
|
||||||
buttonString = environment.strings.Chat_PostSuggestion_Suggest_OfferButtonPrice("\(currencySymbol) \(currencyAmount)").string
|
buttonString = environment.strings.Chat_PostSuggestion_Suggest_OfferButtonPrice("\(currencySymbol) \(currencyAmount)").string
|
||||||
} else {
|
} else {
|
||||||
@ -1423,7 +1423,7 @@ private final class AmountFieldStarsFormatter: NSObject, UITextFieldDelegate {
|
|||||||
case .stars:
|
case .stars:
|
||||||
textField.text = "\(self.maxValue)"
|
textField.text = "\(self.maxValue)"
|
||||||
case .ton:
|
case .ton:
|
||||||
textField.text = "\(formatTonAmountText(self.maxValue, dateTimeFormat: PresentationDateTimeFormat(timeFormat: self.dateTimeFormat.timeFormat, dateFormat: self.dateTimeFormat.dateFormat, dateSeparator: "", dateSuffix: "", requiresFullYear: false, decimalSeparator: ".", groupingSeparator: "")))"
|
textField.text = "\(formatTonAmountText(self.maxValue, dateTimeFormat: PresentationDateTimeFormat(timeFormat: self.dateTimeFormat.timeFormat, dateFormat: self.dateTimeFormat.dateFormat, dateSeparator: "", dateSuffix: "", requiresFullYear: false, decimalSeparator: ".", groupingSeparator: ""), maxDecimalPositions: nil))"
|
||||||
}
|
}
|
||||||
self.onTextChanged(text: self.textField.text ?? "")
|
self.onTextChanged(text: self.textField.text ?? "")
|
||||||
self.animateError()
|
self.animateError()
|
||||||
@ -1592,7 +1592,7 @@ private final class AmountFieldComponent: Component {
|
|||||||
case .stars:
|
case .stars:
|
||||||
text = "\(value)"
|
text = "\(value)"
|
||||||
case .ton:
|
case .ton:
|
||||||
text = "\(formatTonAmountText(value, dateTimeFormat: PresentationDateTimeFormat(timeFormat: component.dateTimeFormat.timeFormat, dateFormat: component.dateTimeFormat.dateFormat, dateSeparator: "", dateSuffix: "", requiresFullYear: false, decimalSeparator: ".", groupingSeparator: "")))"
|
text = "\(formatTonAmountText(value, dateTimeFormat: PresentationDateTimeFormat(timeFormat: component.dateTimeFormat.timeFormat, dateFormat: component.dateTimeFormat.dateFormat, dateSeparator: "", dateSuffix: "", requiresFullYear: false, decimalSeparator: ".", groupingSeparator: ""), maxDecimalPositions: nil))"
|
||||||
}
|
}
|
||||||
self.textField.text = text
|
self.textField.text = text
|
||||||
self.didSetValueOnce = true
|
self.didSetValueOnce = true
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user