@@ -9,88 +9,82 @@ import SwiftUI
99
1010struct ActivityHomeHeaderView : View {
1111
12- struct DataSource {
13- let walletSyncState : WalletSyncState
14- let progress : Float
15- let inspectedScripts : UInt64
16- let totalScripts : UInt64
17- let needsFullScan : Bool
12+ enum State {
13+ case synced
14+ case fullSyncing ( inspectedScripts : UInt64 )
15+ case syncing ( progress : Float , inspectedScripts: UInt64 , totalScripts : UInt64 )
16+ case notStarted
17+ case error ( Error )
1818 }
1919
20- let dataSource : ActivityHomeHeaderView . DataSource
20+ let state : State
2121
2222 let showAllTransactions : ( ) -> Void
2323
2424 var body : some View {
2525 HStack {
2626 Text ( " Activity " )
2727 Spacer ( )
28- if dataSource. walletSyncState == . syncing {
29- HStack {
30- if dataSource. progress < 1.0 {
31- Text ( " \( dataSource. inspectedScripts) " )
32- . padding ( . trailing, - 5.0 )
33- . fontWeight ( . semibold)
34- . contentTransition ( . numericText( ) )
35- . transition ( . opacity)
28+
29+ HStack {
30+ if case let . fullSyncing( inspectedScripts) = state {
31+ Text ( " \( inspectedScripts) " )
32+ . padding ( . trailing, - 5.0 )
33+ . fontWeight ( . semibold)
34+ . contentTransition ( . numericText( ) )
35+ . transition ( . opacity)
36+ . fontDesign ( . monospaced)
37+ . foregroundStyle ( . secondary)
38+ . font ( . caption2)
39+ . fontWeight ( . thin)
40+ . animation ( . easeInOut, value: inspectedScripts)
41+ }
42+ if case let . syncing( progress, inspectedScripts, totalScripts) = state {
43+ HStack {
44+ if progress < 1.0 {
45+ Text ( " \( inspectedScripts) " )
46+ . padding ( . trailing, - 5.0 )
47+ . fontWeight ( . semibold)
48+ . contentTransition ( . numericText( ) )
49+ . transition ( . opacity)
3650
37- if !dataSource. needsFullScan {
3851 Text ( " / " )
3952 . padding ( . trailing, - 5.0 )
4053 . transition ( . opacity)
41- Text ( " \( dataSource . totalScripts) " )
54+ Text ( " \( totalScripts) " )
4255 . contentTransition ( . numericText( ) )
4356 . transition ( . opacity)
4457 }
45- }
4658
47- if !dataSource. needsFullScan {
4859 Text (
4960 String (
5061 format: " %.0f%% " ,
51- dataSource . progress * 100
62+ progress * 100
5263 )
5364 )
5465 . contentTransition ( . numericText( ) )
5566 . transition ( . opacity)
5667 }
68+ . fontDesign ( . monospaced)
69+ . foregroundStyle ( . secondary)
70+ . font ( . caption2)
71+ . fontWeight ( . thin)
72+ . animation ( . easeInOut, value: inspectedScripts)
73+ . animation ( . easeInOut, value: totalScripts)
74+ . animation ( . easeInOut, value: progress)
5775 }
58- . fontDesign ( . monospaced)
59- . foregroundStyle ( . secondary)
60- . font ( . caption2)
61- . fontWeight ( . thin)
62- . animation ( . easeInOut, value: dataSource. inspectedScripts)
63- . animation ( . easeInOut, value: dataSource. totalScripts)
64- . animation ( . easeInOut, value: dataSource. progress)
6576 }
6677 HStack {
6778 HStack ( spacing: 5 ) {
68- if dataSource. walletSyncState == . syncing {
69- Image ( systemName: " slowmo " )
70- . symbolEffect (
71- . variableColor. cumulative
72- )
73- } else if dataSource. walletSyncState == . synced {
74- Image ( systemName: " checkmark.circle.fill " )
75- . foregroundStyle (
76- dataSource. walletSyncState == . synced
77- ? . green : . secondary
78- )
79- } else if dataSource. walletSyncState == . notStarted {
80- Image ( systemName: " arrow.clockwise " )
81- } else {
82- Image (
83- systemName: " person.crop.circle.badge.exclamationmark "
84- )
85- }
79+ state. syncImageIndicator
8680 }
8781 . contentTransition ( . symbolEffect( . replace. offUp) )
8882
8983 }
9084 . foregroundStyle ( . secondary)
9185 . font ( . caption)
92-
93- if dataSource . walletSyncState == . synced {
86+
87+ if case . synced = state {
9488 Button {
9589 self . showAllTransactions ( )
9690 } label: {
@@ -103,8 +97,40 @@ struct ActivityHomeHeaderView: View {
10397 . fontWeight ( . regular)
10498 }
10599 }
106-
107100 }
108101 . fontWeight ( . bold)
109102 }
110103}
104+
105+
106+ fileprivate extension ActivityHomeHeaderView . State {
107+
108+ var syncImageIndicator : some View {
109+ switch self {
110+ case . synced:
111+ return AnyView (
112+ Image ( systemName: " checkmark.circle.fill " )
113+ . foregroundStyle ( . green)
114+ )
115+
116+ case . syncing( _, _, _) , . fullSyncing( _) :
117+ return AnyView (
118+ Image ( systemName: " slowmo " )
119+ . symbolEffect (
120+ . variableColor. cumulative
121+ )
122+ )
123+
124+ case . notStarted:
125+ return AnyView (
126+ Image ( systemName: " arrow.clockwise " )
127+ )
128+ default :
129+ return AnyView (
130+ Image (
131+ systemName: " person.crop.circle.badge.exclamationmark "
132+ )
133+ )
134+ }
135+ }
136+ }
0 commit comments