diff --git a/Telegram/Telegram-iOS/en.lproj/Localizable.strings b/Telegram/Telegram-iOS/en.lproj/Localizable.strings index 3a8c7e0841..1cdd9161e3 100644 --- a/Telegram/Telegram-iOS/en.lproj/Localizable.strings +++ b/Telegram/Telegram-iOS/en.lproj/Localizable.strings @@ -12851,3 +12851,7 @@ Sorry for the inconvenience."; "Stars.Transaction.Giveaway.Prize" = "Prize"; "Stars.Transaction.Giveaway.Stars_1" = "%@ Star"; "Stars.Transaction.Giveaway.Stars_any" = "%@ Stars"; + +"Stats.RevenueInTon" = "Revenue in TON"; +"Stats.RevenueInStars" = "Revenue in Stars"; +"Stats.RevenueInUsd" = "Revenue in USD"; diff --git a/submodules/GraphCore/Sources/Charts/Controllers/GeneralChartComponentController.swift b/submodules/GraphCore/Sources/Charts/Controllers/GeneralChartComponentController.swift index c8e6a429af..8d9774fa20 100644 --- a/submodules/GraphCore/Sources/Charts/Controllers/GeneralChartComponentController.swift +++ b/submodules/GraphCore/Sources/Charts/Controllers/GeneralChartComponentController.swift @@ -35,6 +35,9 @@ class GeneralChartComponentController: ChartThemeContainer { var initialHorizontalRange: ClosedRange = BaseConstants.defaultRange var initialVerticalRange: ClosedRange = BaseConstants.defaultRange + var currency: GraphCurrency? + var conversionRate: Double = 1.0 + public var cartViewBounds: (() -> CGRect) = { fatalError() } public var chartFrame: (() -> CGRect) = { fatalError() } @@ -201,7 +204,7 @@ class GeneralChartComponentController: ChartThemeContainer { var detailsVisible = false func showDetailsView(at chartPosition: CGFloat, detailsViewPosition: CGFloat, dataIndex: Int, date: Date, animated: Bool, feedback: Bool) { - setDetailsViewModel?(chartDetailsViewModel(closestDate: date, pointIndex: dataIndex), animated, feedback) + setDetailsViewModel?(chartDetailsViewModel(closestDate: date, pointIndex: dataIndex, currency: self.currency, rate: self.conversionRate), animated, feedback) setDetailsChartVisibleClosure?(true, true) setDetailsViewPositionClosure?(detailsViewPosition) detailsVisible = true @@ -329,8 +332,8 @@ class GeneralChartComponentController: ChartThemeContainer { return (updatedRange, verticalLabels) } - func chartDetailsViewModel(closestDate: Date, pointIndex: Int) -> ChartDetailsViewModel { - let values: [ChartDetailsViewModel.Value] = chartsCollection.chartValues.enumerated().map { arg in + func chartDetailsViewModel(closestDate: Date, pointIndex: Int, currency: GraphCurrency? = nil, rate: Double = 1.0) -> ChartDetailsViewModel { + var values: [ChartDetailsViewModel.Value] = chartsCollection.chartValues.enumerated().map { arg in let (index, component) = arg return ChartDetailsViewModel.Value(prefix: nil, title: component.name, @@ -338,6 +341,39 @@ class GeneralChartComponentController: ChartThemeContainer { color: component.color, visible: chartVisibility[index]) } + + if let currency, let firstValue = values.first, let color = GColor(hexString: "#dda747") { + let updatedTitle: String + switch currency { + case .ton: + updatedTitle = self.strings.revenueInTon + case .xtr: + updatedTitle = self.strings.revenueInStars + } + values[0] = ChartDetailsViewModel.Value( + prefix: nil, + title: updatedTitle, + value: firstValue.value, + color: color, + visible: firstValue.visible + ) + + let convertedValue = (self.verticalLimitsNumberFormatter.number(from: firstValue.value) as? Double ?? 0.0) * rate + let convertedValueString: String + if convertedValue > 1.0 { + convertedValueString = String(format: "%0.1f", convertedValue) + } else { + convertedValueString = String(format: "%0.3f", convertedValue) + } + values.append(ChartDetailsViewModel.Value( + prefix: nil, + title: self.strings.revenueInUsd, + value: "≈$\(convertedValueString)", + color: color, + visible: firstValue.visible + )) + } + let dateString: String if isZoomed { dateString = BaseConstants.timeDateFormatter.string(from: closestDate) diff --git a/submodules/GraphCore/Sources/Charts/Controllers/Percent And Pie/PercentChartComponentController.swift b/submodules/GraphCore/Sources/Charts/Controllers/Percent And Pie/PercentChartComponentController.swift index 53b3cd87cb..d050e9f09d 100644 --- a/submodules/GraphCore/Sources/Charts/Controllers/Percent And Pie/PercentChartComponentController.swift +++ b/submodules/GraphCore/Sources/Charts/Controllers/Percent And Pie/PercentChartComponentController.swift @@ -131,7 +131,7 @@ class PercentChartComponentController: GeneralChartComponentController { verticalScalesRenderer.setVisible(visibility.contains(true), animated: animated) } - override func chartDetailsViewModel(closestDate: Date, pointIndex: Int) -> ChartDetailsViewModel { + override func chartDetailsViewModel(closestDate: Date, pointIndex: Int, currency: GraphCurrency? = nil, rate: Double = 1.0) -> ChartDetailsViewModel { let visibleValues = visibleDetailsChartValues let total = visibleValues.map { $0.values[pointIndex] }.reduce(0, +) diff --git a/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/BarsComponentController.swift b/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/BarsComponentController.swift index b1738c797f..9f1339a6e6 100644 --- a/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/BarsComponentController.swift +++ b/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/BarsComponentController.swift @@ -149,7 +149,6 @@ class BarsComponentController: GeneralChartComponentController { components: visibleComponents) } - var conversionRate: Double = 1.0 func verticalLimitsLabels(verticalRange: ClosedRange, secondary: Bool) -> (ClosedRange, [LinesChartLabel]) { var (range, labels) = super.verticalLimitsLabels(verticalRange: verticalRange) if secondary { @@ -223,8 +222,8 @@ class BarsComponentController: GeneralChartComponentController { return visibleCharts } - override func chartDetailsViewModel(closestDate: Date, pointIndex: Int) -> ChartDetailsViewModel { - var viewModel = super.chartDetailsViewModel(closestDate: closestDate, pointIndex: pointIndex) + override func chartDetailsViewModel(closestDate: Date, pointIndex: Int, currency: GraphCurrency? = nil, rate: Double = 1.0) -> ChartDetailsViewModel { + var viewModel = super.chartDetailsViewModel(closestDate: closestDate, pointIndex: pointIndex, currency: currency, rate: rate) let visibleChartValues = self.visibleChartValues let totalSumm: CGFloat = visibleChartValues.map { CGFloat($0.values[pointIndex]) }.reduce(0, +) viewModel.hideAction = { [weak self] in diff --git a/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/StackedBarsChartController.swift b/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/StackedBarsChartController.swift index 613e946a42..af304c683f 100644 --- a/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/StackedBarsChartController.swift +++ b/submodules/GraphCore/Sources/Charts/Controllers/Stacked Bars/StackedBarsChartController.swift @@ -28,8 +28,6 @@ public enum GraphCurrency : String { } public class StackedBarsChartController: BaseChartController { - - let barsController: BarsComponentController let zoomedBarsController: BarsComponentController @@ -55,6 +53,7 @@ public class StackedBarsChartController: BaseChartController { secondaryScalesRenderer: secondaryScalesRenderer, previewBarsChartRenderer: BarChartRenderer()) if let currency { + barsController.currency = currency barsController.conversionRate = rate barsController.verticalLimitsNumberFormatter = currency.formatter barsController.detailsNumberFormatter = currency.formatter diff --git a/submodules/GraphCore/Sources/Models/ColorMode.swift b/submodules/GraphCore/Sources/Models/ColorMode.swift index 0cce800064..94a6ce0186 100644 --- a/submodules/GraphCore/Sources/Models/ColorMode.swift +++ b/submodules/GraphCore/Sources/Models/ColorMode.swift @@ -30,13 +30,31 @@ public protocol ChartThemeContainer { public class ChartStrings { public let zoomOut: String public let total: String + public let revenueInTon: String + public let revenueInStars: String + public let revenueInUsd: String - public init(zoomOut: String, total: String) { + public init( + zoomOut: String, + total: String, + revenueInTon: String, + revenueInStars: String, + revenueInUsd: String + ) { self.zoomOut = zoomOut self.total = total + self.revenueInTon = revenueInTon + self.revenueInStars = revenueInStars + self.revenueInUsd = revenueInUsd } - public static var defaultStrings = ChartStrings(zoomOut: "Zoom Out", total: "Total") + public static var defaultStrings = ChartStrings( + zoomOut: "Zoom Out", + total: "Total", + revenueInTon: "Revenue in TON", + revenueInStars: "Revenue in Stars", + revenueInUsd: "Revenue in USD" + ) } public class ChartTheme { diff --git a/submodules/StatisticsUI/Sources/StatsGraphItem.swift b/submodules/StatisticsUI/Sources/StatsGraphItem.swift index c462f1bd27..7f8d1c8517 100644 --- a/submodules/StatisticsUI/Sources/StatsGraphItem.swift +++ b/submodules/StatisticsUI/Sources/StatsGraphItem.swift @@ -295,7 +295,16 @@ public final class StatsGraphItemNode: ListViewItemNode { strongSelf.activityIndicator.type = .custom(item.presentationData.theme.list.itemSecondaryTextColor, 16.0, 2.0, false) if let updatedTheme = updatedTheme { - strongSelf.chartNode.setup(theme: ChartTheme(presentationTheme: updatedTheme), strings: ChartStrings(zoomOut: item.presentationData.strings.Stats_ZoomOut, total: item.presentationData.strings.Stats_Total)) + strongSelf.chartNode.setup( + theme: ChartTheme(presentationTheme: updatedTheme), + strings: ChartStrings( + zoomOut: item.presentationData.strings.Stats_ZoomOut, + total: item.presentationData.strings.Stats_Total, + revenueInTon: item.presentationData.strings.Stats_RevenueInTon, + revenueInStars: item.presentationData.strings.Stats_RevenueInStars, + revenueInUsd: item.presentationData.strings.Stats_RevenueInUsd + ) + ) } if let updatedGraph = updatedGraph {