Skip to content

Commit

Permalink
Fix amount view on list screen
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-amisha-i committed Jan 22, 2025
1 parent ce76ca6 commit fa4d5ee
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion Data/Data/Model/AppUser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public struct AppUser: Identifiable, Codable, Hashable, Sendable {
public var imageUrl: String?
public var deviceFcmToken: String?
public var loginType: LoginType
public var totalOweAmount: [String: Double]
public var totalOweAmount: [String: Double] /// [currency: balance]
public var isActive: Bool

public var fullName: String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ private struct GroupMemberCellView: View {

Spacer()

if let firstBalance = balance.first {
if let firstBalance = balance.first(where: { $0.value != 0 }) {
let currency = firstBalance.key
let amount = firstBalance.value
let isBorrowed = amount < 0
Expand Down
50 changes: 27 additions & 23 deletions Splito/UI/Home/Groups/GroupListWithDetailView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -106,31 +106,35 @@ private struct GroupListCellView: View {
Spacer(minLength: 8)

let defaultCurrency = group.group.defaultCurrencyCode
let userBalance = group.userBalance[defaultCurrency] ?? group.userBalance.first?.value ?? 0
VStack(alignment: .trailing, spacing: 0) {
let isBorrowed = group.userBalance.allSatisfy { $0.value < 0 }
if group.userBalance.allSatisfy({ $0.value == 0 }) {
Text(group.group.hasExpenses ? "settled up" : "no expense")
.font(.caption1())
.foregroundStyle(disableText)
.padding(.trailing, 4)
} else {
Text(isBorrowed ? "you owe" : "you are owed")
.font(.caption1())

let currency = group.userBalance[defaultCurrency] == nil ? group.userBalance.first?.key : defaultCurrency
Text(userBalance.formattedCurrencyWithSign(currency))
.font(.body1())
+ Text(group.userBalance.count > 1 ? "*" : "")
.font(.body1())
.baselineOffset(1)
let initialBalance = group.userBalance.first(where: { $0.value != 0 })
let defaultBalance = group.userBalance.filter { $0.key == defaultCurrency && $0.value != 0 }
let userBalance = defaultBalance.isEmpty ? initialBalance : defaultBalance.first

if let userBalance {
let isBorrowed = userBalance.value < 0
VStack(alignment: .trailing, spacing: 0) {
if group.userBalance.allSatisfy({ $0.value == 0 }) {
Text(group.group.hasExpenses ? "settled up" : "no expense")
.font(.caption1())
.foregroundStyle(disableText)
.padding(.trailing, 4)
} else {
Text(isBorrowed ? "you owe" : "you are owed")
.font(.caption1())

Text(userBalance.value.formattedCurrencyWithSign(userBalance.key))
.font(.body1())
+ Text(group.userBalance.count > 1 ? "*" : "")
.font(.body1())
.baselineOffset(1)
}
}
}
.lineLimit(1)
.foregroundStyle(group.userBalance.allSatisfy { $0.value < 0 } ? errorColor : successColor)
.lineLimit(1)
.foregroundStyle(isBorrowed ? errorColor : successColor)

if userBalance != 0 {
GroupExpandBtnView(showInfo: $showInfo, isFirstGroup: isFirstGroup)
if userBalance.value != 0 {
GroupExpandBtnView(showInfo: $showInfo, isFirstGroup: isFirstGroup)
}
}
}
.padding(.horizontal, 16)
Expand Down

0 comments on commit fa4d5ee

Please sign in to comment.