From 66d3170afad1b9f032310e935db889f64869de2b Mon Sep 17 00:00:00 2001 From: EA Date: Thu, 30 May 2024 12:32:01 +0600 Subject: [PATCH] Integrate icons into Market Etf module --- .../UnstoppableWallet/Extensions/Etf.swift | 6 +++ .../UnstoppableWallet/Extensions/Misc.swift | 5 +++ .../Modules/Market/Etf/MarketEtfView.swift | 4 +- .../Market/Pairs/MarketPairsView.swift | 44 +++++++++++-------- 4 files changed, 38 insertions(+), 21 deletions(-) diff --git a/UnstoppableWallet/UnstoppableWallet/Extensions/Etf.swift b/UnstoppableWallet/UnstoppableWallet/Extensions/Etf.swift index cbf41240f7..188394ad9c 100644 --- a/UnstoppableWallet/UnstoppableWallet/Extensions/Etf.swift +++ b/UnstoppableWallet/UnstoppableWallet/Extensions/Etf.swift @@ -1,5 +1,6 @@ import Foundation import MarketKit +import UIKit extension Etf: Hashable { public static func == (lhs: Etf, rhs: Etf) -> Bool { @@ -12,6 +13,11 @@ extension Etf: Hashable { } extension Etf { + var imageUrl: String { + let scale = Int(UIScreen.main.scale) + return "https://cdn.blocksdecoded.com/etf-tresuries/\(ticker)@\(scale)x.png" + } + func inflow(timePeriod: MarketEtfViewModel.TimePeriod) -> Decimal? { switch timePeriod { case let .period(timePeriod): return inflows[timePeriod] diff --git a/UnstoppableWallet/UnstoppableWallet/Extensions/Misc.swift b/UnstoppableWallet/UnstoppableWallet/Extensions/Misc.swift index 2b389e49d4..9fbd355e4e 100644 --- a/UnstoppableWallet/UnstoppableWallet/Extensions/Misc.swift +++ b/UnstoppableWallet/UnstoppableWallet/Extensions/Misc.swift @@ -5,4 +5,9 @@ extension String { let scale = Int(UIScreen.main.scale) return "https://cdn.blocksdecoded.com/header-images/\(self)@\(scale)x.png" } + + var fiatImageUrl: String { + let scale = Int(UIScreen.main.scale) + return "https://cdn.blocksdecoded.com/fiat-icons/\(self)@\(scale)x.png" + } } diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Market/Etf/MarketEtfView.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Market/Etf/MarketEtfView.swift index 740055ee80..f003baba9b 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Market/Etf/MarketEtfView.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Market/Etf/MarketEtfView.swift @@ -70,7 +70,7 @@ struct MarketEtfView: View { } .padding(.vertical, .margin12) - KFImage.url(URL(string: "https://cdn.blocksdecoded.com/category-icons/lending@3x.png")) + KFImage.url(URL(string: "ETF_bitcoin".headerImageUrl)) .resizable() .frame(width: 76, height: 108) } @@ -138,7 +138,7 @@ struct MarketEtfView: View { ListForEach(etfs) { etf in ListRow { itemContent( - imageUrl: nil, + imageUrl: URL(string: etf.imageUrl), ticker: etf.ticker, name: etf.name, totalAssets: etf.totalAssets, diff --git a/UnstoppableWallet/UnstoppableWallet/Modules/Market/Pairs/MarketPairsView.swift b/UnstoppableWallet/UnstoppableWallet/Modules/Market/Pairs/MarketPairsView.swift index 32df1390b9..ab8e54bef1 100644 --- a/UnstoppableWallet/UnstoppableWallet/Modules/Market/Pairs/MarketPairsView.swift +++ b/UnstoppableWallet/UnstoppableWallet/Modules/Market/Pairs/MarketPairsView.swift @@ -52,8 +52,8 @@ struct MarketPairsView: View { } }) { itemContent( - frontCoin: pair.baseCoin, - backCoin: pair.targetCoin, + baseCoin: pair.baseCoin, + targetCoin: pair.targetCoin, base: pair.base, target: pair.target, volume: pair.volume.flatMap { ValueFormatter.instance.formatShort(currency: viewModel.currency, value: $0) } ?? "n/a".localized, @@ -73,8 +73,8 @@ struct MarketPairsView: View { ThemeList(Array(0 ... 10)) { _ in ListRow { itemContent( - frontCoin: nil, - backCoin: nil, + baseCoin: nil, + targetCoin: nil, base: "CODE", target: "CODE", volume: "$123.4 B", @@ -89,26 +89,14 @@ struct MarketPairsView: View { .simultaneousGesture(DragGesture(minimumDistance: 0), including: .all) } - @ViewBuilder private func itemContent(frontCoin: Coin?, backCoin: Coin?, base: String, target: String, volume: String, marketName: String, rank: Int, price: String) -> some View { + @ViewBuilder private func itemContent(baseCoin: Coin?, targetCoin: Coin?, base: String, target: String, volume: String, marketName: String, rank: Int, price: String) -> some View { ZStack(alignment: .leading) { HStack { Spacer() - ZStack { - Circle() - .fill(Color.themeTyler) - .frame(width: .iconSize32, height: .iconSize32) - - CoinIconView(coin: backCoin) - } + icon(coin: targetCoin, ticker: target) } - ZStack { - Circle() - .fill(Color.themeTyler) - .frame(width: .iconSize32, height: .iconSize32) - - CoinIconView(coin: frontCoin) - } + icon(coin: baseCoin, ticker: base) } .frame(width: 52) @@ -130,6 +118,24 @@ struct MarketPairsView: View { } } + @ViewBuilder private func icon(coin: Coin?, ticker: String) -> some View { + ZStack { + Circle() + .fill(Color.themeTyler) + .frame(width: .iconSize32, height: .iconSize32) + + if let coin { + CoinIconView(coin: coin) + } else { + KFImage.url(URL(string: ticker.fiatImageUrl)) + .resizable() + .placeholder { Circle().fill(Color.themeSteel20) } + .clipShape(Circle()) + .frame(width: .iconSize32, height: .iconSize32) + } + } + } + private func volumeSortIcon() -> Image { switch viewModel.volumeSortOrder { case .asc: return Image("arrow_medium_2_up_20")