Skip to content

Commit

Permalink
Improve loading of global market pages
Browse files Browse the repository at this point in the history
  • Loading branch information
ealymbaev committed May 28, 2024
1 parent 733e060 commit 6baac87
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,12 @@ struct MarketEtfView: View {
ThemeView {
switch viewModel.state {
case .loading:
ThemeList(bottomSpacing: .margin16) {
VStack(spacing: 0) {
header()
.listRowBackground(Color.clear)
.listRowInsets(EdgeInsets())
.listRowSeparator(.hidden)

chart()
.listRowBackground(Color.clear)
.listRowInsets(EdgeInsets())
.listRowSeparator(.hidden)

loadingList()
Spacer()
ProgressView()
Spacer()
}
.simultaneousGesture(DragGesture(minimumDistance: 0), including: .all)
case let .loaded(etfs):
ThemeList(bottomSpacing: .margin16) {
header()
Expand All @@ -52,7 +44,6 @@ struct MarketEtfView: View {
case .failed:
VStack(spacing: 0) {
header()
chart()

SyncErrorView {
viewModel.sync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,12 @@ struct MarketMarketCapView: View {
ThemeView {
switch viewModel.state {
case .loading:
ThemeList(bottomSpacing: .margin16) {
VStack(spacing: 0) {
header()
.listRowBackground(Color.clear)
.listRowInsets(EdgeInsets())
.listRowSeparator(.hidden)

chart()
.listRowBackground(Color.clear)
.listRowInsets(EdgeInsets())
.listRowSeparator(.hidden)

loadingList()
Spacer()
ProgressView()
Spacer()
}
.simultaneousGesture(DragGesture(minimumDistance: 0), including: .all)
case let .loaded(marketInfos):
ThemeList(bottomSpacing: .margin16) {
header()
Expand All @@ -53,7 +45,6 @@ struct MarketMarketCapView: View {
case .failed:
VStack(spacing: 0) {
header()
chart()

SyncErrorView {
viewModel.sync()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct MarketGlobalView: View {
@ViewBuilder private func content(marketGlobal: MarketGlobal?, redacted: Any?) -> some View {
diffView(
title: "market.global.market_cap".localized,
amount: marketGlobal?.marketCap,
amount: marketGlobal?.marketCap.flatMap { ValueFormatter.instance.formatShort(currency: viewModel.currency, value: $0) },
diff: marketGlobal?.marketCapChange.map { .percent(value: $0) },
redacted: redacted
) {
Expand All @@ -59,7 +59,7 @@ struct MarketGlobalView: View {

diffView(
title: "market.global.volume".localized,
amount: marketGlobal?.volume,
amount: marketGlobal?.volume.flatMap { ValueFormatter.instance.formatShort(currency: viewModel.currency, value: $0) },
diff: marketGlobal?.volumeChange.map { .percent(value: $0) },
redacted: redacted
) {
Expand All @@ -68,7 +68,7 @@ struct MarketGlobalView: View {

diffView(
title: "market.global.btc_dominance".localized,
amount: marketGlobal?.btcDominance,
amount: marketGlobal?.btcDominance.flatMap { ValueFormatter.instance.format(percentValue: $0, showSign: false) },
diff: marketGlobal?.btcDominanceChange.map { .percent(value: $0) },
redacted: redacted
) {
Expand All @@ -77,7 +77,7 @@ struct MarketGlobalView: View {

diffView(
title: "market.global.etf_inflow".localized,
amount: marketGlobal?.etfTotalInflow,
amount: marketGlobal?.etfTotalInflow.flatMap { ValueFormatter.instance.formatShort(currency: viewModel.currency, value: $0) },
diff: marketGlobal?.etfDailyInflow.map { .change(value: $0, currency: viewModel.currency) },
redacted: redacted
) {
Expand All @@ -86,19 +86,19 @@ struct MarketGlobalView: View {

diffView(
title: "market.global.tvl_in_defi".localized,
amount: marketGlobal?.tvl,
amount: marketGlobal?.tvl.flatMap { ValueFormatter.instance.formatShort(currency: viewModel.currency, value: $0) },
diff: marketGlobal?.tvlChange.map { .percent(value: $0) },
redacted: redacted
) {
tvlPresented = true
}
}

@ViewBuilder private func diffView(title: String, amount: Decimal?, diff: DiffText.Diff?, redacted: Any?, onTap: @escaping () -> Void) -> some View {
@ViewBuilder private func diffView(title: String, amount: String?, diff: DiffText.Diff?, redacted: Any?, onTap: @escaping () -> Void) -> some View {
HStack(spacing: .margin4) {
Text(title).textCaption()

Text(amount.flatMap { ValueFormatter.instance.formatShort(currency: viewModel.currency, value: $0) } ?? "----")
Text(amount ?? "----")
.textCaption(color: .themeBran)
.redacted(value: redacted)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,12 @@ struct MarketVolumeView: View {
ThemeView {
switch viewModel.state {
case .loading:
ThemeList(bottomSpacing: .margin16) {
VStack(spacing: 0) {
header()
.listRowBackground(Color.clear)
.listRowInsets(EdgeInsets())
.listRowSeparator(.hidden)

chart()
.listRowBackground(Color.clear)
.listRowInsets(EdgeInsets())
.listRowSeparator(.hidden)

loadingList()
Spacer()
ProgressView()
Spacer()
}
.simultaneousGesture(DragGesture(minimumDistance: 0), including: .all)
case let .loaded(marketInfos):
ThemeList(bottomSpacing: .margin16) {
header()
Expand All @@ -53,7 +45,6 @@ struct MarketVolumeView: View {
case .failed:
VStack(spacing: 0) {
header()
chart()

SyncErrorView {
viewModel.sync()
Expand Down

0 comments on commit 6baac87

Please sign in to comment.