@@ -9,88 +9,82 @@ import SwiftUI
9
9
10
10
struct ActivityHomeHeaderView : View {
11
11
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 )
18
18
}
19
19
20
- let dataSource : ActivityHomeHeaderView . DataSource
20
+ let state : State
21
21
22
22
let showAllTransactions : ( ) -> Void
23
23
24
24
var body : some View {
25
25
HStack {
26
26
Text ( " Activity " )
27
27
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)
36
50
37
- if !dataSource. needsFullScan {
38
51
Text ( " / " )
39
52
. padding ( . trailing, - 5.0 )
40
53
. transition ( . opacity)
41
- Text ( " \( dataSource . totalScripts) " )
54
+ Text ( " \( totalScripts) " )
42
55
. contentTransition ( . numericText( ) )
43
56
. transition ( . opacity)
44
57
}
45
- }
46
58
47
- if !dataSource. needsFullScan {
48
59
Text (
49
60
String (
50
61
format: " %.0f%% " ,
51
- dataSource . progress * 100
62
+ progress * 100
52
63
)
53
64
)
54
65
. contentTransition ( . numericText( ) )
55
66
. transition ( . opacity)
56
67
}
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)
57
75
}
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)
65
76
}
66
77
HStack {
67
78
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
86
80
}
87
81
. contentTransition ( . symbolEffect( . replace. offUp) )
88
82
89
83
}
90
84
. foregroundStyle ( . secondary)
91
85
. font ( . caption)
92
-
93
- if dataSource . walletSyncState == . synced {
86
+
87
+ if case . synced = state {
94
88
Button {
95
89
self . showAllTransactions ( )
96
90
} label: {
@@ -103,8 +97,40 @@ struct ActivityHomeHeaderView: View {
103
97
. fontWeight ( . regular)
104
98
}
105
99
}
106
-
107
100
}
108
101
. fontWeight ( . bold)
109
102
}
110
103
}
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