Skip to content

Commit

Permalink
SwiftUI platform view
Browse files Browse the repository at this point in the history
  • Loading branch information
ant013 authored and ealymbaev committed Jun 3, 2024
1 parent b741c5f commit c2f3a19
Show file tree
Hide file tree
Showing 9 changed files with 324 additions and 28 deletions.
19 changes: 12 additions & 7 deletions UnstoppableWallet/UnstoppableWallet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2125,6 +2125,10 @@
6B29072A2AF0CB8A006157D6 /* EventHandler.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B29071E2AF0CB8A006157D6 /* EventHandler.swift */; };
6B55E33B2AF26D6400616B60 /* Starscream in Frameworks */ = {isa = PBXBuildFile; productRef = 6B55E33A2AF26D6400616B60 /* Starscream */; };
6B55E33D2AF26D7A00616B60 /* Starscream in Frameworks */ = {isa = PBXBuildFile; productRef = 6B55E33C2AF26D7A00616B60 /* Starscream */; };
6B5F5E0E2C0C65F700E03EB2 /* MarketPlatformViewNew.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B5F5E0D2C0C65F700E03EB2 /* MarketPlatformViewNew.swift */; };
6B5F5E0F2C0C65F700E03EB2 /* MarketPlatformViewNew.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B5F5E0D2C0C65F700E03EB2 /* MarketPlatformViewNew.swift */; };
6B5F5E112C0C660900E03EB2 /* MarketPlatformViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B5F5E102C0C660900E03EB2 /* MarketPlatformViewModel.swift */; };
6B5F5E122C0C660900E03EB2 /* MarketPlatformViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B5F5E102C0C660900E03EB2 /* MarketPlatformViewModel.swift */; };
6BA5117D2BCFA06F00CB5A54 /* FirstAppearModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BA5117C2BCFA06F00CB5A54 /* FirstAppearModifier.swift */; };
6BA5117E2BCFA06F00CB5A54 /* FirstAppearModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BA5117C2BCFA06F00CB5A54 /* FirstAppearModifier.swift */; };
6BAAF3472B9B245C00EFE5B2 /* ShimmerEffect.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BAAF3442B9B245C00EFE5B2 /* ShimmerEffect.swift */; };
Expand Down Expand Up @@ -3140,8 +3144,6 @@
D3833AE22BEE3FE800ACECFB /* MarketPlatformsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3833AE02BEE3FE800ACECFB /* MarketPlatformsViewModel.swift */; };
D3833AEA2BEE4CAA00ACECFB /* TopPlatform.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3833AE92BEE4CAA00ACECFB /* TopPlatform.swift */; };
D3833AEB2BEE4CAA00ACECFB /* TopPlatform.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3833AE92BEE4CAA00ACECFB /* TopPlatform.swift */; };
D3833AEE2BF1F0C400ACECFB /* MarketPlatformView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3833AED2BF1F0C400ACECFB /* MarketPlatformView.swift */; };
D3833AEF2BF1F0C400ACECFB /* MarketPlatformView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3833AED2BF1F0C400ACECFB /* MarketPlatformView.swift */; };
D3833AF22BF20B8600ACECFB /* MarketPairsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3833AF12BF20B8600ACECFB /* MarketPairsView.swift */; };
D3833AF32BF20B8600ACECFB /* MarketPairsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3833AF12BF20B8600ACECFB /* MarketPairsView.swift */; };
D3833AF52BF20B8D00ACECFB /* MarketPairsViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = D3833AF42BF20B8D00ACECFB /* MarketPairsViewModel.swift */; };
Expand Down Expand Up @@ -3269,7 +3271,6 @@
D3BA259F2ADFAF23002B13EA /* HsToolKit in Frameworks */ = {isa = PBXBuildFile; productRef = D3BA25982ADFAF23002B13EA /* HsToolKit */; };
D3BA25A02ADFAF23002B13EA /* Intents.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D3948F092ADA887300FAE566 /* Intents.framework */; };
D3BA25A72ADFB042002B13EA /* IntentExtension Prod.appex in Embed Foundation Extensions */ = {isa = PBXBuildFile; fileRef = D3BA25A52ADFAF23002B13EA /* IntentExtension Prod.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
D3BC25802B0B5E1E0092F682 /* TonKitKmm.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = D3BC257F2B0B5E1E0092F682 /* TonKitKmm.xcframework */; };
D3BC25812B0B5E1E0092F682 /* TonKitKmm.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D3BC257F2B0B5E1E0092F682 /* TonKitKmm.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
D3BC25832B0B5E460092F682 /* TonKitKmm.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = D3BC257F2B0B5E1E0092F682 /* TonKitKmm.xcframework */; };
D3BC25842B0B5E460092F682 /* TonKitKmm.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = D3BC257F2B0B5E1E0092F682 /* TonKitKmm.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
Expand Down Expand Up @@ -4514,6 +4515,8 @@
6B29071B2AF0CB8A006157D6 /* WalletConnectAppShowView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WalletConnectAppShowView.swift; sourceTree = "<group>"; };
6B29071D2AF0CB8A006157D6 /* WidgetCoinAppShowModule.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WidgetCoinAppShowModule.swift; sourceTree = "<group>"; };
6B29071E2AF0CB8A006157D6 /* EventHandler.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = EventHandler.swift; sourceTree = "<group>"; };
6B5F5E0D2C0C65F700E03EB2 /* MarketPlatformViewNew.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarketPlatformViewNew.swift; sourceTree = "<group>"; };
6B5F5E102C0C660900E03EB2 /* MarketPlatformViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarketPlatformViewModel.swift; sourceTree = "<group>"; };
6BA5117C2BCFA06F00CB5A54 /* FirstAppearModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FirstAppearModifier.swift; sourceTree = "<group>"; };
6BAAF3442B9B245C00EFE5B2 /* ShimmerEffect.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ShimmerEffect.swift; sourceTree = "<group>"; };
6BAAF3452B9B245C00EFE5B2 /* SlideButtonStyling.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SlideButtonStyling.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -5013,7 +5016,6 @@
D3833ADD2BEE3FE000ACECFB /* MarketPlatformsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarketPlatformsView.swift; sourceTree = "<group>"; };
D3833AE02BEE3FE800ACECFB /* MarketPlatformsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarketPlatformsViewModel.swift; sourceTree = "<group>"; };
D3833AE92BEE4CAA00ACECFB /* TopPlatform.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TopPlatform.swift; sourceTree = "<group>"; };
D3833AED2BF1F0C400ACECFB /* MarketPlatformView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarketPlatformView.swift; sourceTree = "<group>"; };
D3833AF12BF20B8600ACECFB /* MarketPairsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarketPairsView.swift; sourceTree = "<group>"; };
D3833AF42BF20B8D00ACECFB /* MarketPairsViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarketPairsViewModel.swift; sourceTree = "<group>"; };
D3833AF72BF2181800ACECFB /* MarketPair.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MarketPair.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -9464,7 +9466,8 @@
D3833AEC2BF1F0AC00ACECFB /* Platform */ = {
isa = PBXGroup;
children = (
D3833AED2BF1F0C400ACECFB /* MarketPlatformView.swift */,
6B5F5E0D2C0C65F700E03EB2 /* MarketPlatformViewNew.swift */,
6B5F5E102C0C660900E03EB2 /* MarketPlatformViewModel.swift */,
);
path = Platform;
sourceTree = "<group>";
Expand Down Expand Up @@ -9951,6 +9954,7 @@
D084F6BF2BEB94F700407FA4 /* OutputSelectView2.swift in Sources */,
3C7B99D3D6AE0B1C0D8E5F09 /* UrlManager.swift in Sources */,
58AAA3BE2D0DEF53CE6CEE97 /* EvmKitManager.swift in Sources */,
6B5F5E0F2C0C65F700E03EB2 /* MarketPlatformViewNew.swift in Sources */,
58AAABE8E8374ED4211F610C /* Eip20Adapter.swift in Sources */,
58AAA4A377F356194AE08055 /* BaseEvmAdapter.swift in Sources */,
1A56415A4BB89B9156C6442D /* Decimal.swift in Sources */,
Expand Down Expand Up @@ -10383,7 +10387,6 @@
D36DE0E2272FD887000BC916 /* OneInchProvider.swift in Sources */,
D3DB51A02BD6854A0091BBDB /* MarketSearchView.swift in Sources */,
D36DE100272FD92F000BC916 /* SwapSelectProviderViewModel.swift in Sources */,
D3833AEF2BF1F0C400ACECFB /* MarketPlatformView.swift in Sources */,
58AAAAEDC64AE5716BC07673 /* SwapSlippageViewModel.swift in Sources */,
58AAA56C780EF5C92C1D1A32 /* AddressResolutionProvider.swift in Sources */,
58AAA3762D78142A83A22F50 /* SwapViewModel.swift in Sources */,
Expand Down Expand Up @@ -10904,6 +10907,7 @@
2FA5D43131923C094E518B94 /* EvmRollupGasDataService.swift in Sources */,
2FA5DB16A7E67A97A08D43DC /* NonceDataSource.swift in Sources */,
2FA5D8E83DFBD235B805C79C /* NonceService.swift in Sources */,
6B5F5E122C0C660900E03EB2 /* MarketPlatformViewModel.swift in Sources */,
2FA5D01D1C1E23AC162B267B /* NonceViewModel.swift in Sources */,
2FA5D6E8F9B4E66D9FC52C37 /* LegacyGasPriceService.swift in Sources */,
2FA5D5268D73DCC5651C09AF /* LegacyEvmFeeViewModel.swift in Sources */,
Expand Down Expand Up @@ -11534,6 +11538,7 @@
D084F6BE2BEB94F700407FA4 /* OutputSelectView2.swift in Sources */,
58AAA745D76A13D06800BDD1 /* EvmKitManager.swift in Sources */,
58AAA82745E47084A2B18F95 /* Eip20Adapter.swift in Sources */,
6B5F5E0E2C0C65F700E03EB2 /* MarketPlatformViewNew.swift in Sources */,
58AAAF011B2E9CDF8455CA7B /* BaseEvmAdapter.swift in Sources */,
1A56491DC545ED4F8A6E6D40 /* Decimal.swift in Sources */,
11B35DE3E7E6EB3CFAB81329 /* UnlinkViewController.swift in Sources */,
Expand Down Expand Up @@ -11966,7 +11971,6 @@
D0D5BCBC2976CB9F00587FDB /* PasswordInputView.swift in Sources */,
D3DB519F2BD6854A0091BBDB /* MarketSearchView.swift in Sources */,
58AAA10B748931BA5FA867DA /* SwapViewModel.swift in Sources */,
D3833AEE2BF1F0C400ACECFB /* MarketPlatformView.swift in Sources */,
58AAA9475B1C057E82B25C76 /* OneInchFeeService.swift in Sources */,
58AAA6371183D7FB9606FEDA /* OneInchSendEvmTransactionService.swift in Sources */,
11B35299107843A4663542F9 /* WalletAdapterService.swift in Sources */,
Expand Down Expand Up @@ -12487,6 +12491,7 @@
2FA5D98FF7412EBBD2FFFBC4 /* EvmFeeService.swift in Sources */,
2FA5D01A5570C6DE5D07E2C4 /* EvmFeeViewItemFactory.swift in Sources */,
2FA5DE1153742388007774D3 /* EvmRollupGasDataService.swift in Sources */,
6B5F5E112C0C660900E03EB2 /* MarketPlatformViewModel.swift in Sources */,
2FA5DE2D347DBC660830CB41 /* NonceDataSource.swift in Sources */,
2FA5D1F6979A345597788DE9 /* NonceService.swift in Sources */,
2FA5D62FF4A9D8F54848D2C0 /* NonceViewModel.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ class ChartUiView: UIView {
.heightDoubleLineCell
+ configuration.mainHeight
+ (configuration.showIndicatorArea ? configuration.indicatorHeight : 0)
+ (timePeriodView.isHidden ? 0 : (.margin8 + .heightCell48))
+ (timePeriodView.isHidden ? 0 : .heightCell48)
+ .margin8
}

Expand Down Expand Up @@ -370,8 +370,8 @@ class ChartUiView: UIView {
chartSecondaryDiffLabel.isHidden = true
}
case let .custom(title, value):
currentSecondaryTitleLabel.isHidden = false
currentSecondaryValueLabel.isHidden = false
chartSecondaryTitleLabel.isHidden = false
chartSecondaryValueLabel.isHidden = false
chartSecondaryDiffLabel.isHidden = true

chartSecondaryTitleLabel.text = title
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import Combine
import Foundation
import HsExtensions
import MarketKit

class MarketPlatformViewModel: ObservableObject {
private let marketKit = App.shared.marketKit
private let currencyManager = App.shared.currencyManager

let platform: TopPlatform

private var cancellables = Set<AnyCancellable>()
private var tasks = Set<AnyTask>()

private var internalState: State = .loading {
didSet {
syncState()
}
}

@Published var state: State = .loading

var sortBy: MarketModule.SortBy = .highestCap {
didSet {
stat(page: .topPlatform, event: .switchSortType(sortType: sortBy.statSortType))
syncState()
}
}

init(platform: TopPlatform) {
self.platform = platform
currencyManager.$baseCurrency
.sink { [weak self] _ in
self?.sync()
}
.store(in: &cancellables)

sync()
}

private func syncState() {
switch internalState {
case .loading:
state = .loading
case let .loaded(marketInfos):
state = .loaded(marketInfos: marketInfos.sorted(sortBy: sortBy, timePeriod: .day1))
case let .failed(error):
state = .failed(error: error)
}
}
}

extension MarketPlatformViewModel {
var currency: Currency {
currencyManager.baseCurrency
}

var sortBys: [MarketModule.SortBy] {
[.highestCap, .lowestCap, .gainers, .losers]
}

func sync() {
tasks = Set()

if case .failed = internalState {
internalState = .loading
}

let platform = platform

Task { [weak self, marketKit, currency] in
do {
let marketInfos = try await marketKit.topPlatformMarketInfos(blockchain: platform.blockchain.uid, currencyCode: currency.code)

await MainActor.run { [weak self] in
self?.internalState = .loaded(marketInfos: marketInfos)
}
} catch {
await MainActor.run { [weak self] in
self?.internalState = .failed(error: error)
}
}
}
.store(in: &tasks)
}
}

extension MarketPlatformViewModel {
enum State {
case loading
case loaded(marketInfos: [MarketInfo])
case failed(error: Error)
}
}
Loading

0 comments on commit c2f3a19

Please sign in to comment.