Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Technical indicators #5081

Merged
merged 2 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,9 @@ class ChartCell: UITableViewCell {
}
}

chartView.setCurve(colorType: viewItem.chartTrend.chartColorType)
if !chartView.isPressed {
chartView.setCurve(colorType: viewItem.chartTrend.chartColorType)
}
chartView.set(chartData: viewItem.chartData, indicators: viewItem.indicators, showIndicators: showIndicators, animated: true)
chartView.set(highLimitText: viewItem.maxValue, lowLimitText: viewItem.minValue)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,17 @@ struct CoinAnalyticsModule {
accountManager: App.shared.accountManager,
appConfigProvider: App.shared.appConfigProvider
)
let viewModel = CoinAnalyticsViewModel(service: service)
let technicalIndicatorService = TechnicalIndicatorService(
coinUid: fullCoin.coin.uid,
currencyKit: App.shared.currencyKit,
marketKit: App.shared.marketKit
)
let coinIndicatorViewItemFactory = CoinIndicatorViewItemFactory()
let viewModel = CoinAnalyticsViewModel(
service: service,
technicalIndicatorService: technicalIndicatorService,
coinIndicatorViewItemFactory: coinIndicatorViewItemFactory
)

return CoinAnalyticsViewController(viewModel: viewModel)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Combine
import UIKit
import RxSwift
import ThemeKit
Expand All @@ -9,10 +10,11 @@ import MarketKit
import Chart

class CoinAnalyticsViewController: ThemeViewController {
private let placeholderText = "•••"
private static let placeholderText = "•••"

private let viewModel: CoinAnalyticsViewModel
private let disposeBag = DisposeBag()
private var cancellables = Set<AnyCancellable>()

private let tableView = SectionsTableView(style: .grouped)

Expand All @@ -23,6 +25,7 @@ class CoinAnalyticsViewController: ThemeViewController {
weak var parentNavigationController: UINavigationController?

private var viewItem: CoinAnalyticsViewModel.ViewItem?
private var indicatorViewItem: CoinAnalyticsViewModel.IndicatorViewItem?

init(viewModel: CoinAnalyticsViewModel) {
self.viewModel = viewModel
Expand Down Expand Up @@ -79,6 +82,7 @@ class CoinAnalyticsViewController: ThemeViewController {
tableView.registerCell(forClass: PlaceholderCell.self)
tableView.registerCell(forClass: MarketWideCardCell.self)
tableView.registerCell(forClass: CoinAnalyticsHoldersCell.self)
tableView.registerCell(forClass: IndicatorAdviceCell.self)
tableView.sectionDataSource = self

subscribe(disposeBag, viewModel.viewItemDriver) { [weak self] in
Expand All @@ -93,6 +97,13 @@ class CoinAnalyticsViewController: ThemeViewController {
subscribe(disposeBag, viewModel.emptyViewDriver) { [weak self] visible in
self?.emptyView.isHidden = !visible
}
viewModel.indicatorViewItemsPublisher
.receive(on: DispatchQueue.main)
.sink { [weak self] in
self?.indicatorViewItem = $0
self?.tableView.reload()
}
.store(in: &cancellables)

viewModel.onLoad()
}
Expand Down Expand Up @@ -124,6 +135,17 @@ class CoinAnalyticsViewController: ThemeViewController {
parentNavigationController?.present(viewController, animated: true)
}

private func openTechnicalIndicatorInfo() {
let viewController = InfoModule.viewController(viewItems: [
.header1(text: "coin_analytics.technical_indicators".localized),
.listItem(text: "coin_analytics.technical_indicators.info1".localized),
.listItem(text: "coin_analytics.technical_indicators.info2".localized),
.listItem(text: "coin_analytics.technical_indicators.info3".localized),
])

parentNavigationController?.present(viewController, animated: true)
}

private func openCexVolumeInfo() {
let viewController = InfoModule.viewController(viewItems: [
.header1(text: "coin_analytics.cex_volume".localized),
Expand Down Expand Up @@ -260,6 +282,27 @@ class CoinAnalyticsViewController: ThemeViewController {
parentNavigationController?.present(viewController, animated: true)
}

private func openPeriodSelect() {
let viewController = SelectorModule.bottomSingleSelectorViewController(
title: "coin_analytics.period.select_title".localized,
viewItems: viewModel.periodViewItems,
onSelect: { [weak self] index in
self?.viewModel.onSelectPeriod(index: index)
}
)

present(viewController, animated: true)
}

private func openDetailAdvices() {
guard let viewItems = viewModel.detailAdviceSectionViewItems else {
return
}

let viewController = CoinDetailAdviceViewController(viewItems: viewItems)
parentNavigationController?.pushViewController(viewController, animated: true)
}

private func placeholderChartData() -> ChartData {
var chartItems = [ChartItem]()

Expand Down Expand Up @@ -287,13 +330,13 @@ class CoinAnalyticsViewController: ThemeViewController {
extension CoinAnalyticsViewController: SectionsDataSource {

private func chartRow(id: String, title: String, valueInfo: String, chartCurveType: ChartConfiguration.CurveType, viewItem: Previewable<CoinAnalyticsViewModel.ChartViewItem>, isLast: Bool, infoAction: @escaping () -> (), action: @escaping () -> ()) -> RowProtocol {
let value: String?
let value: String
let chartData: ChartData
let chartTrend: MovementTrend

switch viewItem {
case .preview:
value = placeholderText
value = Self.placeholderText
chartData = placeholderChartData()
chartTrend = .ignored
case .regular(let viewItem):
Expand Down Expand Up @@ -334,7 +377,7 @@ extension CoinAnalyticsViewController: SectionsDataSource {

if let value {
switch value {
case .preview: rowValue = placeholderText
case .preview: rowValue = Self.placeholderText
case .regular(let value): rowValue = value
}
}
Expand All @@ -359,6 +402,58 @@ extension CoinAnalyticsViewController: SectionsDataSource {
)
}

private func indicatorSection(viewItem: CoinAnalyticsViewModel.IndicatorViewItem) -> SectionProtocol {
let disableInfo = viewItem.loading || viewItem.error || viewItem.viewItems.isEmpty
return Section(
id: "indicator-section",
headerState: .margin(height: 12),
rows: [
Row<IndicatorAdviceCell>(id: "indicator-advices-row",
height: IndicatorAdviceCell.height,
autoDeselect: false,
bind: { [weak self] cell, _ in
cell.set(backgroundStyle: .lawrence, isFirst: true)
cell.set(loading: viewItem.loading)

if viewItem.error {
cell.setEmpty(value: "n/a".localized)
return
}

if viewItem.viewItems.isEmpty {
cell.setEmpty(value: Self.placeholderText)
} else {
cell.set(viewItems: viewItem.viewItems)
}

cell.onTapInfo = { [weak self] in
self?.openTechnicalIndicatorInfo()
}
}
),
tableView.universalRow48(
id: "period",
title: .subhead2("coin_analytics.period".localized, color: .themeGray),
value: .subhead2(viewModel.period, color: viewItem.switchEnabled ? .themeLeah : .themeGray),
accessoryType: .dropdown,
autoDeselect: true,
action: viewItem.switchEnabled ? { [weak self] in
self?.openPeriodSelect()
} : nil
),
tableView.universalRow48(
id: "details",
title: .subhead2("coin_analytics.details".localized, color: disableInfo ? .themeGray50 : .themeGray),
accessoryType: .disclosure,
autoDeselect: true,
isLast: true,
action: !disableInfo ? { [weak self] in
self?.openDetailAdvices()
} : nil
),
])
}

private func ratingRow(id: String, rating: Previewable<CoinAnalyticsModule.Rating>, isFirst: Bool = false, isLast: Bool = false) -> RowProtocol {
let titleElements: [CellBuilderNew.CellElement] = [
.textElement(text: .subhead2("coin_analytics.rating_scale".localized), parameters: .highHugging),
Expand All @@ -370,7 +465,7 @@ extension CoinAnalyticsViewController: SectionsDataSource {
case .preview:
return CellBuilderNew.row(
rootElement: .hStack(titleElements + [
.textElement(text: .subhead1(placeholderText), parameters: .rightAlignment)
.textElement(text: .subhead1(Self.placeholderText), parameters: .rightAlignment)
]),
tableView: tableView,
id: id,
Expand Down Expand Up @@ -747,11 +842,11 @@ extension CoinAnalyticsViewController: SectionsDataSource {

switch viewItem {
case .preview:
value = placeholderText
value = Self.placeholderText
blockchains = [
Blockchain(imageUrl: nil, name: "Blockchain 1", value: placeholderText, action: nil),
Blockchain(imageUrl: nil, name: "Blockchain 2", value: placeholderText, action: nil),
Blockchain(imageUrl: nil, name: "Blockchain 3", value: placeholderText, action: nil),
Blockchain(imageUrl: nil, name: "Blockchain 1", value: Self.placeholderText, action: nil),
Blockchain(imageUrl: nil, name: "Blockchain 2", value: Self.placeholderText, action: nil),
Blockchain(imageUrl: nil, name: "Blockchain 3", value: Self.placeholderText, action: nil),
]
chartItems = [
(0.5, UIColor.themeGray.withAlphaComponent(0.8)),
Expand Down Expand Up @@ -917,7 +1012,7 @@ extension CoinAnalyticsViewController: SectionsDataSource {

switch viewItem.value {
case .preview:
value = placeholderText
value = Self.placeholderText
valueInfo = nil
case .regular(let _value):
value = _value
Expand Down Expand Up @@ -1074,6 +1169,10 @@ extension CoinAnalyticsViewController: SectionsDataSource {
sections.append(lockInfoSection(lockInfo: lockInfo))
}

if let indicatorViewItem {
sections.append(indicatorSection(viewItem: indicatorViewItem))
}

if let viewItem = viewItem.cexVolume {
sections.append(cexVolumeSection(viewItem: viewItem))
}
Expand Down
Loading