Skip to content

Commit

Permalink
Add holders rank to coin analytics page
Browse files Browse the repository at this point in the history
  • Loading branch information
ealymbaev committed May 29, 2023
1 parent 301deba commit ba07fab
Show file tree
Hide file tree
Showing 9 changed files with 73 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9704,7 +9704,7 @@
repositoryURL = "https://github.com/horizontalsystems/MarketKit.Swift";
requirement = {
kind = exactVersion;
version = 2.0.1;
version = 2.0.3;
};
};
D3604E7128F03B0A0066C366 /* XCRemoteSwiftPackageReference "ScanQrKit.Swift" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ class SubscriptionManager {
extension SubscriptionManager {

func set(authToken: String) {
print("SET: \(authToken)")
self.authToken = authToken
localStorage.set(value: authToken, for: keyAuthToken)
}

func invalidateAuthToken() {
print("INVALIDATE: \(authToken)")
authToken = nil
localStorage.set(value: authToken, for: keyAuthToken)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ extension CoinAnalyticsViewController: SectionsDataSource {
)
}

private func holdersSection(viewItem: Previewable<CoinAnalyticsViewModel.HoldersViewItem>) -> SectionProtocol {
private func holdersSection(viewItem: Previewable<CoinAnalyticsViewModel.HoldersViewItem>, rank: Previewable<String>?) -> SectionProtocol {
struct Blockchain {
let imageUrl: String?
let name: String
Expand Down Expand Up @@ -677,48 +677,65 @@ extension CoinAnalyticsViewController: SectionsDataSource {
chartItems = viewItem.holderViewItems.map { ($0.percent, $0.blockchain.type.brandColor) }
}

return Section(
id: "holders",
headerState: .margin(height: .margin12),
rows: [
Row<MarketWideCardCell>(
id: "holders",
height: MarketWideCardCell.height(hasChart: false, bottomMargin: .margin12),
bind: { [weak self] cell, _ in
cell.set(backgroundStyle: .lawrence, isFirst: true)
cell.selectionStyle = .none
var rows: [RowProtocol] = [
Row<MarketWideCardCell>(
id: "holders",
height: MarketWideCardCell.height(hasChart: false, bottomMargin: .margin12),
bind: { [weak self] cell, _ in
cell.set(backgroundStyle: .lawrence, isFirst: true)
cell.selectionStyle = .none

cell.bind(
title: "coin_analytics.holders".localized,
value: value,
valueInfo: viewItem.isPreview ? nil : "coin_analytics.current".localized,
onTapInfo: {
self?.openHoldersInfo()
}
)
}
),
Row<CoinAnalyticsHoldersCell>(
id: "holders-pie",
height: CoinAnalyticsHoldersCell.chartHeight + .margin16,
bind: { cell, _ in
cell.set(backgroundStyle: .lawrence)
cell.topSeparatorView.isHidden = true
cell.bind(items: chartItems)
}
)
] + blockchains.enumerated().map { index, blockchain in
tableView.universalRow56(
id: "holders-blockchain-\(index)",
image: .url(blockchain.imageUrl, placeholder: "placeholder_rectangle_32"),
title: .subhead2(blockchain.name),
value: .subhead1(blockchain.value),
cell.bind(
title: "coin_analytics.holders".localized,
value: value,
valueInfo: viewItem.isPreview ? nil : "coin_analytics.current".localized,
onTapInfo: {
self?.openHoldersInfo()
}
)
}
),
Row<CoinAnalyticsHoldersCell>(
id: "holders-pie",
height: CoinAnalyticsHoldersCell.chartHeight + .margin16,
bind: { cell, _ in
cell.set(backgroundStyle: .lawrence)
cell.topSeparatorView.isHidden = true
cell.bind(items: chartItems)
}
)
] + blockchains.enumerated().map { index, blockchain in
tableView.universalRow56(
id: "holders-blockchain-\(index)",
image: .url(blockchain.imageUrl, placeholder: "placeholder_rectangle_32"),
title: .subhead2(blockchain.name),
value: .subhead1(blockchain.value),
accessoryType: .disclosure,
autoDeselect: true,
isLast: index == blockchains.count - 1 && rank == nil,
action: blockchain.action
)
}

if let rank {
rows.append(
previewableRow(
id: "holders-rank",
title: "coin_analytics.holders_rank".localized,
value: rank,
accessoryType: .disclosure,
autoDeselect: true,
isLast: index == blockchains.count - 1,
action: blockchain.action
isLast: true,
action: rank.previewableValue { _ in { [weak self] in
self?.openRanks(type: .holders)
}}
)
}
)
}

return Section(
id: "holders",
headerState: .margin(height: .margin12),
rows: rows
)
}

Expand Down Expand Up @@ -938,8 +955,8 @@ extension CoinAnalyticsViewController: SectionsDataSource {
sections.append(txCountSection(viewItem: viewItem))
}

if let viewItem = viewItem.holders {
sections.append(holdersSection(viewItem: viewItem))
if let holdersViewItem = viewItem.holders {
sections.append(holdersSection(viewItem: holdersViewItem, rank: viewItem.holdersRank))
}

if let viewItem = viewItem.tvl {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ class CoinAnalyticsViewModel {
rank: analytics.transactions?.rank30d
),
holders: holdersViewItem(holderBlockchains: analytics.holders),
holdersRank: analytics.holdersRank.map { .regular(value: rankString(value: $0)) },
tvl: tvlViewItem(
points: analytics.tvl?.chartPoints,
rank: analytics.tvl?.rank,
Expand Down Expand Up @@ -283,6 +284,7 @@ class CoinAnalyticsViewModel {
activeAddresses: data.addresses ? ActiveAddressesViewItem(chart: .preview, count30d: data.addressesCount30d ? .preview : nil, rank: data.addressesRank30d ? .preview : nil) : nil,
transactionCount: data.transactions ? TransactionCountViewItem(chart: .preview, volume: data.transactionsVolume30d ? .preview : nil, rank: data.transactionsRank30d ? .preview : nil) : nil,
holders: data.holders ? .preview : nil,
holdersRank: data.holdersRank ? .preview : nil,
tvl: data.tvl ? TvlViewItem(chart: .preview, rank: data.tvlRank ? .preview : nil, ratio: data.tvlRatio ? .preview : nil) : nil,
revenue: data.revenue ? RevenueViewItem(value: .preview, rank: data.revenueRank30d ? .preview : nil) : nil,
reports: data.reports ? .preview : nil,
Expand Down Expand Up @@ -340,6 +342,7 @@ extension CoinAnalyticsViewModel {
let activeAddresses: ActiveAddressesViewItem?
let transactionCount: TransactionCountViewItem?
let holders: Previewable<HoldersViewItem>?
let holdersRank: Previewable<String>?
let tvl: TvlViewItem?
let revenue: RevenueViewItem?
let reports: Previewable<String>?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extension CoinRankModule {
case dexLiquidity
case address
case txCount
case holders
case revenue
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class CoinRankService {
case .dexLiquidity: values = try await marketKit.dexLiquidityRanks().map { .single(value: $0) }
case .address: values = try await marketKit.activeAddressRanks().map { .multi(value: $0) }
case .txCount: values = try await marketKit.transactionCountRanks().map { .multi(value: $0) }
case .holders: values = try await marketKit.holdersRanks().map { .single(value: $0) }
case .revenue: values = try await marketKit.revenueRanks(currencyCode: currencyCode).map { .multi(value: $0) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,7 @@ class CoinRankViewController: ThemeViewController {
private func sync(viewItems: [CoinRankViewModel.ViewItem]?) {
self.viewItems = viewItems

if let viewItems, !viewItems.isEmpty {
tableView.isHidden = false
} else {
tableView.isHidden = true
}

tableView.isHidden = viewItems == nil
tableView.reload()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class CoinRankViewModel {
switch service.type {
case .cexVolume, .dexVolume, .dexLiquidity, .revenue:
return ValueFormatter.instance.formatShort(currencyValue: CurrencyValue(currency: currency, value: value))
case .address, .txCount:
case .address, .txCount, .holders:
return ValueFormatter.instance.formatShort(value: value)
}
}
Expand Down Expand Up @@ -104,6 +104,7 @@ extension CoinRankViewModel {
case .dexLiquidity: return "coin_analytics.dex_liquidity_rank".localized
case .address: return "coin_analytics.active_addresses_rank".localized
case .txCount: return "coin_analytics.transaction_count_rank".localized
case .holders: return "coin_analytics.holders_rank".localized
case .revenue: return "coin_analytics.project_revenue_rank".localized
}
}
Expand All @@ -115,6 +116,7 @@ extension CoinRankViewModel {
case .dexLiquidity: return "coin_analytics.dex_liquidity_rank.description".localized
case .address: return "coin_analytics.active_addresses_rank.description".localized
case .txCount: return "coin_analytics.transaction_count_rank.description".localized
case .holders: return "coin_analytics.holders_rank.description".localized
case .revenue: return "coin_analytics.project_revenue_rank.description".localized
}
}
Expand All @@ -126,6 +128,7 @@ extension CoinRankViewModel {
case .dexLiquidity: return "dex_liquidity"
case .address: return "active_addresses"
case .txCount: return "trx_count"
case .holders: return "holders"
case .revenue: return "revenue"
}
}
Expand All @@ -142,7 +145,7 @@ extension CoinRankViewModel {
var selectorItems: [String]? {
switch service.type {
case .cexVolume, .dexVolume, .address, .txCount, .revenue: return timePeriods.map { $0.title }
case .dexLiquidity: return nil
case .dexLiquidity, .holders: return nil
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,8 @@ Go to Settings - > Unstoppable and allow access to the camera.";
"coin_analytics.transaction_count.info5" = "The total number of tokens transferred over the blockchain over the 30 day period.";

"coin_analytics.holders" = "Holders";
"coin_analytics.holders_rank" = "Holders Rank";
"coin_analytics.holders_rank.description" = "Ranking tokens by unique addresses holding them on multiple blockchains.";
"coin_analytics.holders.info1" = "Total number of unique addresses holding the token on various blockchains.";
"coin_analytics.holders.info2" = "Top 10 wallets holding the token on each blockchain.";
"coin_analytics.holders.tracked_blockchains" = "Tracked blockchains: Ethereum, Binance Smart Chain, Optimism, Arbitrum, Celo, Cronos, Avalanche, Fantom, Polygon";
Expand Down

0 comments on commit ba07fab

Please sign in to comment.