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

Migrate CoinMajorHolders module into SwiftUI #5920

Merged
merged 2 commits into from
Jun 14, 2024
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
90 changes: 33 additions & 57 deletions UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,13 @@ extension EvmLabelManager {

return address.shortened
}

func addressLabelMap() -> [String: String] {
do {
let addressLabels = try storage.allAddressLabels()
return addressLabels.reduce(into: [String: String]()) { $0[$1.address] = $1.label }
} catch {
return [:]
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ extension EvmLabelStorage {
}
}

func allAddressLabels() throws -> [EvmAddressLabel] {
try dbPool.read { db in
try EvmAddressLabel.fetchAll(db)
}
}

func evmAddressLabel(address: String) throws -> EvmAddressLabel? {
try dbPool.read { db in
try EvmAddressLabel.filter(EvmAddressLabel.Columns.address == address).fetchOne(db)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct CoinAnalyticsView: View {
CoinProChartView(coin: viewModel.coin, type: type, isPresented: Binding(get: { presentedProChartType != nil }, set: { if !$0 { presentedProChartType = nil } }))
}
.sheet(item: $presentedHolderBlockchain) { blockchain in
CoinMajorHoldersView(coin: viewModel.coin, blockchain: blockchain).ignoresSafeArea()
CoinMajorHoldersView(coin: viewModel.coin, blockchain: blockchain, isPresented: Binding(get: { presentedHolderBlockchain != nil }, set: { if !$0 { presentedHolderBlockchain = nil } }))
}
.sheet(isPresented: $tvlRankPresented) {
ThemeNavigationView {
Expand Down Expand Up @@ -414,7 +414,7 @@ struct CoinAnalyticsView: View {
cardValue(text: value, info: viewItem.isPreview ? nil : "coin_analytics.current".localized)
}

let chartItems: [(CGFloat, Color)] = {
let chartItems: [(Decimal, Color)] = {
switch viewItem {
case .preview: return [
(0.5, Color.themeGray.opacity(0.8)),
Expand All @@ -433,13 +433,13 @@ struct CoinAnalyticsView: View {
alpha = max(alpha - 0.25, 0.25)
}

return ((viewItem.percent as NSDecimalNumber).doubleValue, resolvedColor)
return (viewItem.percent, resolvedColor)
}
}
}()

if !chartItems.isEmpty {
holdersChart(items: chartItems)
CoinHoldersChart(items: chartItems)
}
}
}
Expand Down Expand Up @@ -546,8 +546,6 @@ struct CoinAnalyticsView: View {
value: reports
) {
CoinReportsView(coinUid: viewModel.coin.uid)
.navigationTitle("coin_analytics.reports".localized)
.ignoresSafeArea()
}
}

Expand Down Expand Up @@ -597,24 +595,6 @@ struct CoinAnalyticsView: View {
}
}

@ViewBuilder private func holdersChart(items: [(CGFloat, Color)]) -> some View {
let spacing: CGFloat = 1
let count = CGFloat(items.count)

GeometryReader { proxy in
HStack(spacing: spacing) {
ForEach(items.indices, id: \.self) { index in
let (percent, color) = items[index]

RoundedRectangle(cornerRadius: .cornerRadius2, style: .continuous)
.fill(color)
.frame(width: (proxy.size.width - (count - 1) * spacing) * percent)
}
}
}
.frame(height: 40)
}

@ViewBuilder private func analysisRow(viewItem: CoinAnalyticsViewModel.IssueBlockchainViewItem) -> some View {
ClickableRow {
presentedAnalysisViewItem = viewItem
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import SwiftUI

struct CoinHoldersChart: View {
let items: [(Decimal, Color)]

private let spacing: CGFloat = 1

var body: some View {
let count = CGFloat(items.count)

GeometryReader { proxy in
HStack(spacing: spacing) {
ForEach(items.indices, id: \.self) { index in
let (percent, color) = items[index]
let doublePercent = (percent as NSDecimalNumber).doubleValue

RoundedRectangle(cornerRadius: .cornerRadius2, style: .continuous)
.fill(color)
.frame(width: (proxy.size.width - (count - 1) * spacing) * doublePercent)
}
}
}
.frame(height: 40)
}
}

This file was deleted.

This file was deleted.

This file was deleted.

Loading