Skip to content

Commit fa4d5ee

Browse files
committed
Fix amount view on list screen
1 parent ce76ca6 commit fa4d5ee

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

Data/Data/Model/AppUser.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public struct AppUser: Identifiable, Codable, Hashable, Sendable {
1717
public var imageUrl: String?
1818
public var deviceFcmToken: String?
1919
public var loginType: LoginType
20-
public var totalOweAmount: [String: Double]
20+
public var totalOweAmount: [String: Double] /// [currency: balance]
2121
public var isActive: Bool
2222

2323
public var fullName: String {

Splito/UI/Home/Groups/Group/Group Setting/GroupSettingView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ private struct GroupMemberCellView: View {
247247

248248
Spacer()
249249

250-
if let firstBalance = balance.first {
250+
if let firstBalance = balance.first(where: { $0.value != 0 }) {
251251
let currency = firstBalance.key
252252
let amount = firstBalance.value
253253
let isBorrowed = amount < 0

Splito/UI/Home/Groups/GroupListWithDetailView.swift

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -106,31 +106,35 @@ private struct GroupListCellView: View {
106106
Spacer(minLength: 8)
107107

108108
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+
}
127131
}
128-
}
129-
.lineLimit(1)
130-
.foregroundStyle(group.userBalance.allSatisfy { $0.value < 0 } ? errorColor : successColor)
132+
.lineLimit(1)
133+
.foregroundStyle(isBorrowed ? errorColor : successColor)
131134

132-
if userBalance != 0 {
133-
GroupExpandBtnView(showInfo: $showInfo, isFirstGroup: isFirstGroup)
135+
if userBalance.value != 0 {
136+
GroupExpandBtnView(showInfo: $showInfo, isFirstGroup: isFirstGroup)
137+
}
134138
}
135139
}
136140
.padding(.horizontal, 16)

0 commit comments

Comments
 (0)