@@ -106,31 +106,35 @@ private struct GroupListCellView: View {
106
106
Spacer ( minLength: 8 )
107
107
108
108
let defaultCurrency = group. group. defaultCurrencyCode
109
- let userBalance = group. userBalance [ defaultCurrency] ?? group. userBalance. first? . value ?? 0
110
- VStack ( alignment: . trailing, spacing: 0 ) {
111
- let isBorrowed = group. userBalance. allSatisfy { $0. value < 0 }
112
- if group. userBalance. allSatisfy ( { $0. value == 0 } ) {
113
- Text ( group. group. hasExpenses ? " settled up " : " no expense " )
114
- . font ( . caption1( ) )
115
- . foregroundStyle ( disableText)
116
- . padding ( . trailing, 4 )
117
- } else {
118
- Text ( isBorrowed ? " you owe " : " you are owed " )
119
- . font ( . caption1( ) )
120
-
121
- let currency = group. userBalance [ defaultCurrency] == nil ? group. userBalance. first? . key : defaultCurrency
122
- Text ( userBalance. formattedCurrencyWithSign ( currency) )
123
- . font ( . body1( ) )
124
- + Text( group. userBalance. count > 1 ? " * " : " " )
125
- . font ( . body1( ) )
126
- . baselineOffset ( 1 )
109
+ let initialBalance = group. userBalance. first ( where: { $0. value != 0 } )
110
+ let defaultBalance = group. userBalance. filter { $0. key == defaultCurrency && $0. value != 0 }
111
+ let userBalance = defaultBalance. isEmpty ? initialBalance : defaultBalance. first
112
+
113
+ if let userBalance {
114
+ let isBorrowed = userBalance. value < 0
115
+ VStack ( alignment: . trailing, spacing: 0 ) {
116
+ if group. userBalance. allSatisfy ( { $0. value == 0 } ) {
117
+ Text ( group. group. hasExpenses ? " settled up " : " no expense " )
118
+ . font ( . caption1( ) )
119
+ . foregroundStyle ( disableText)
120
+ . padding ( . trailing, 4 )
121
+ } else {
122
+ Text ( isBorrowed ? " you owe " : " you are owed " )
123
+ . font ( . caption1( ) )
124
+
125
+ Text ( userBalance. value. formattedCurrencyWithSign ( userBalance. key) )
126
+ . font ( . body1( ) )
127
+ + Text( group. userBalance. count > 1 ? " * " : " " )
128
+ . font ( . body1( ) )
129
+ . baselineOffset ( 1 )
130
+ }
127
131
}
128
- }
129
- . lineLimit ( 1 )
130
- . foregroundStyle ( group. userBalance. allSatisfy { $0. value < 0 } ? errorColor : successColor)
132
+ . lineLimit ( 1 )
133
+ . foregroundStyle ( isBorrowed ? errorColor : successColor)
131
134
132
- if userBalance != 0 {
133
- GroupExpandBtnView ( showInfo: $showInfo, isFirstGroup: isFirstGroup)
135
+ if userBalance. value != 0 {
136
+ GroupExpandBtnView ( showInfo: $showInfo, isFirstGroup: isFirstGroup)
137
+ }
134
138
}
135
139
}
136
140
. padding ( . horizontal, 16 )
0 commit comments