Skip to content

Commit f46ca5f

Browse files
committed
Fixed: group spending summary amount not shown with sign
1 parent de0cc38 commit f46ca5f

19 files changed

+37
-43
lines changed

Data/Data/Extension/Double+Extension.swift

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Foundation
99

1010
public extension Double {
1111

12-
func formattedCurrencyWithSign(_ code: String?) -> String {
12+
func formattedCurrency(_ code: String?, _ showSign: Bool = false) -> String {
1313
let amount: String
1414
let formatter = NumberFormatter()
1515
formatter.locale = Locale.current
@@ -21,17 +21,11 @@ public extension Double {
2121
}
2222

2323
let currencySymbol = Currency.getCurrencyFromCode(code).symbol
24-
return currencySymbol.isEmpty ? amount : (currencySymbol + " " + amount)
25-
}
26-
27-
var formattedCurrency: String {
28-
let formatter = NumberFormatter()
29-
formatter.locale = Locale.current
30-
31-
if let formattedAmount = formatter.string(from: NSNumber(value: self)) {
32-
return formattedAmount.hasPrefix("-") ? String(formattedAmount.dropFirst()) : formattedAmount
24+
if showSign {
25+
let sign = self < 0 ? "-" : ""
26+
return currencySymbol.isEmpty ? "\(sign)\(amount)" : "\(sign)\(currencySymbol) \(amount)"
3327
} else {
34-
return String(format: "%.2f", self.rounded()) // Fallback to a basic decimal format
28+
return currencySymbol.isEmpty ? amount : (currencySymbol + " " + amount)
3529
}
3630
}
3731

Data/Data/Model/Expense.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public struct Expense: Codable, Hashable, Identifiable {
7676

7777
// Calculated properties for better UI representation
7878
public var formattedAmount: String {
79-
return amount.formattedCurrencyWithSign(currencyCode)
79+
return amount.formattedCurrency(currencyCode)
8080
}
8181
}
8282

Splito/UI/Home/ActivityLog/ActivityLogView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,10 +185,10 @@ private struct ActivityListCellView: View {
185185
return ""
186186
case .expenseAdded, .expenseUpdated, .expenseDeleted, .expenseRestored:
187187
let action = (amount > 0 ? "get back" : "owe")
188-
return (amount == 0) ? "You do not owe anything" : "You \(action) \(amount.formattedCurrencyWithSign(activityLog.amountCurrency))"
188+
return (amount == 0) ? "You do not owe anything" : "You \(action) \(amount.formattedCurrency(activityLog.amountCurrency))"
189189
case .transactionAdded, .transactionUpdated, .transactionDeleted, .transactionRestored:
190190
let action = (amount > 0 ? "paid" : "received")
191-
return (amount == 0) ? "You do not owe anything" : "You \(action) \(amount.formattedCurrencyWithSign(activityLog.amountCurrency))"
191+
return (amount == 0) ? "You do not owe anything" : "You \(action) \(amount.formattedCurrency(activityLog.amountCurrency))"
192192
}
193193
}
194194
}

Splito/UI/Home/Expense/AddExpenseViewModel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,11 @@ extension AddExpenseViewModel {
356356
let amountDescription = totalSharedAmount < expenseAmount ? "short" : "over"
357357
let differenceAmount = totalSharedAmount < expenseAmount ? (expenseAmount - totalSharedAmount) : (totalSharedAmount - expenseAmount)
358358
showAlertFor(title: "Error!",
359-
message: "The amounts do not add up to the total cost of \(expenseAmount.formattedCurrencyWithSign(selectedCurrency.code)). You are \(amountDescription) by \(differenceAmount.formattedCurrencyWithSign(selectedCurrency.code)).")
359+
message: "The amounts do not add up to the total cost of \(expenseAmount.formattedCurrency(selectedCurrency.code)). You are \(amountDescription) by \(differenceAmount.formattedCurrency(selectedCurrency.code)).")
360360
return false
361361
} else if selectedPayers.count > 1 && totalPaidAmount != expenseAmount {
362362
showAlertFor(title: "Error",
363-
message: "The total of everyone's paid shares (\(totalPaidAmount.formattedCurrencyWithSign(selectedCurrency.code))) is different than the total cost (\(expenseAmount.formattedCurrencyWithSign(selectedCurrency.code)))")
363+
message: "The total of everyone's paid shares (\(totalPaidAmount.formattedCurrency(selectedCurrency.code))) is different than the total cost (\(expenseAmount.formattedCurrency(selectedCurrency.code)))")
364364
return false
365365
} else if selectedPayers.count == 1 && selectedPayers.values.reduce(0, +) != expenseAmount {
366366
showAlertFor(title: "Error",

Splito/UI/Home/Expense/Detail Selection/Expense Split Option/ExpenseSplitOptionsTabView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ struct MemberCellView: View {
257257
.foregroundStyle(primaryText)
258258

259259
if let splitAmount {
260-
Text(splitAmount.formattedCurrencyWithSign(amountCurrency))
260+
Text(splitAmount.formattedCurrency(amountCurrency))
261261
.font(.body3(12))
262262
.foregroundStyle(disableText)
263263
}

Splito/UI/Home/Expense/Detail Selection/Expense Split Option/ExpenseSplitOptionsView.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ private struct SplitOptionsBottomView: View {
7171
switch viewModel.selectedTab {
7272
case .equally:
7373
let selectedCurrency = viewModel.selectedCurrency
74-
BottomInfoCardView(title: "\(viewModel.splitAmount.formattedCurrencyWithSign(selectedCurrency))/person",
74+
BottomInfoCardView(title: "\(viewModel.splitAmount.formattedCurrency(selectedCurrency))/person",
7575
value: "\(viewModel.selectedMembers.count) people",
7676
memberCount: viewModel.selectedMembers.count, isAllSelected: viewModel.isAllSelected,
7777
isForEqualSplit: true, onAllBtnTap: viewModel.handleAllBtnAction)
7878
case .fixedAmount:
7979
let selectedCurrency = viewModel.selectedCurrency
80-
BottomInfoCardView(title: "\(viewModel.totalFixedAmount.formattedCurrencyWithSign(selectedCurrency)) of \(viewModel.expenseAmount.formattedCurrencyWithSign(selectedCurrency))",
81-
value: "\((viewModel.expenseAmount - viewModel.totalFixedAmount).formattedCurrencyWithSign(selectedCurrency)) left")
80+
BottomInfoCardView(title: "\(viewModel.totalFixedAmount.formattedCurrency(selectedCurrency)) of \(viewModel.expenseAmount.formattedCurrency(selectedCurrency))",
81+
value: "\((viewModel.expenseAmount - viewModel.totalFixedAmount).formattedCurrency(selectedCurrency)) left")
8282
case .percentage:
8383
BottomInfoCardView(title: "\(String(format: "%.0f", viewModel.totalPercentage))% of 100%",
8484
value: "\(String(format: "%.0f", 100 - viewModel.totalPercentage))% left")

Splito/UI/Home/Expense/Detail Selection/Expense Split Option/ExpenseSplitOptionsViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ class ExpenseSplitOptionsViewModel: BaseViewModel, ObservableObject {
190190
let amountDescription = totalFixedAmount < expenseAmount ? "short" : "over"
191191
let differenceAmount = totalFixedAmount < expenseAmount ? (expenseAmount - totalFixedAmount) : (totalFixedAmount - expenseAmount)
192192

193-
showAlertFor(title: "Whoops!", message: "The amounts do not add up to the total cost of \(expenseAmount.formattedCurrencyWithSign(selectedCurrency)). You are \(amountDescription) by \(differenceAmount.formattedCurrencyWithSign(selectedCurrency)).")
193+
showAlertFor(title: "Whoops!", message: "The amounts do not add up to the total cost of \(expenseAmount.formattedCurrency(selectedCurrency)). You are \(amountDescription) by \(differenceAmount.formattedCurrency(selectedCurrency)).")
194194
return completion(false)
195195
}
196196
case .percentage:

Splito/UI/Home/Expense/Detail Selection/Payer/ChooseMultiplePayerView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ struct ChooseMultiplePayerView: View {
4747
.scrollBounceBehavior(.basedOnSize)
4848

4949
let currency = viewModel.amountCurrency
50-
BottomInfoCardView(title: "\(viewModel.totalAmount.formattedCurrencyWithSign(currency)) of \(viewModel.expenseAmount.formattedCurrencyWithSign(currency))",
51-
value: "\((viewModel.expenseAmount - viewModel.totalAmount).formattedCurrencyWithSign(currency)) left")
50+
BottomInfoCardView(title: "\(viewModel.totalAmount.formattedCurrency(currency)) of \(viewModel.expenseAmount.formattedCurrency(currency))",
51+
value: "\((viewModel.expenseAmount - viewModel.totalAmount).formattedCurrency(currency)) left")
5252
}
5353
}
5454
.background(surfaceColor)

Splito/UI/Home/Expense/Detail Selection/Payer/ChooseMultiplePayerViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class ChooseMultiplePayerViewModel: BaseViewModel, ObservableObject {
7979
let differenceAmount = totalAmount < expenseAmount ? (expenseAmount - totalAmount) : (totalAmount - expenseAmount)
8080

8181
showAlertFor(title: "Whoops!",
82-
message: "The payment values do not add up to the total cost of \(expenseAmount.formattedCurrencyWithSign(amountCurrency)). You are \(amountDescription) by \(differenceAmount.formattedCurrencyWithSign(amountCurrency)).")
82+
message: "The payment values do not add up to the total cost of \(expenseAmount.formattedCurrency(amountCurrency)). You are \(amountDescription) by \(differenceAmount.formattedCurrency(amountCurrency)).")
8383
return
8484
}
8585

Splito/UI/Home/Expense/Expense Detail/ExpenseDetailsView.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,9 @@ private struct ExpenseInfoView: View {
211211
MemberProfileImageView(imageUrl: userData.imageUrl, height: SUB_IMAGE_HEIGHT, scaleEffect: 0.6)
212212

213213
if let splitTo = expense?.splitTo, splitTo.contains(userData.id) {
214-
Text("\(memberName.localized) paid \(paidAmount.formattedCurrencyWithSign(currencyCode)) and \(owes.localized) \(splitAmount)")
214+
Text("\(memberName.localized) paid \(paidAmount.formattedCurrency(currencyCode)) and \(owes.localized) \(splitAmount)")
215215
} else {
216-
Text("\(memberName.localized) paid \(paidAmount.formattedCurrencyWithSign(currencyCode))")
216+
Text("\(memberName.localized) paid \(paidAmount.formattedCurrency(currencyCode))")
217217
}
218218
} else if let splitTo = expense?.splitTo, splitTo.contains(userData.id) {
219219
MemberProfileImageView(imageUrl: userData.imageUrl, height: SUB_IMAGE_HEIGHT, scaleEffect: 0.6)

0 commit comments

Comments
 (0)