Skip to content

Commit ce76ca6

Browse files
committed
Fix default currency
1 parent eeca86c commit ce76ca6

File tree

6 files changed

+16
-17
lines changed

6 files changed

+16
-17
lines changed

Data/Data/Model/Currency/Currency.swift

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ public struct Currency: Decodable, Hashable {
1313
public let symbol: String
1414
public let region: String
1515

16-
public static var defaultCurrency = Currency(code: "INR", name: "Indian Rupee", symbol: "", region: "IN")
16+
private static var defaultLocalCurrency = Currency(code: "INR", name: "Indian Rupee", symbol: "", region: "IN")
17+
18+
public static var defaultCurrency: Currency {
19+
let allCurrencies = getAllCurrencies()
20+
let currentLocal = Locale.current.region?.identifier
21+
let currency = allCurrencies.first(where: { $0.region == currentLocal }) ??
22+
(allCurrencies.first ?? defaultLocalCurrency)
23+
return currency
24+
}
1725

1826
public init(code: String, name: String, symbol: String, region: String) {
1927
self.code = code
@@ -32,12 +40,4 @@ public struct Currency: Decodable, Hashable {
3240
let currency = allCurrencies.first(where: { $0.code == code }) ?? defaultCurrency
3341
return currency
3442
}
35-
36-
public static func getCurrentLocalCurrency() -> Currency {
37-
let allCurrencies = getAllCurrencies()
38-
let currentLocal = Locale.current.region?.identifier
39-
let currency = allCurrencies.first(where: { $0.region == currentLocal }) ??
40-
(allCurrencies.first ?? defaultCurrency)
41-
return currency
42-
}
4343
}

Splito/UI/Home/Expense/AddExpenseViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class AddExpenseViewModel: BaseViewModel, ObservableObject {
5757
self.router = router
5858
self.groupId = groupId
5959
self.expenseId = expenseId
60-
self.selectedCurrency = Currency.getCurrentLocalCurrency()
60+
self.selectedCurrency = Currency.defaultCurrency
6161
super.init()
6262
loadInitialData()
6363
}

Splito/UI/Home/Groups/Create Group/CreateGroupViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class CreateGroupViewModel: BaseViewModel, ObservableObject {
101101
private func createGroup() async -> Bool {
102102
guard let userId = preference.user?.id else { return false }
103103

104-
let localCurrency = Currency.getCurrentLocalCurrency().code
104+
let localCurrency = Currency.defaultCurrency.code
105105
let memberBalance = GroupMemberBalance(id: userId, balanceByCurrency: [:])
106106
let group = Groups(name: groupName.trimming(spaces: .leadingAndTrailing), createdBy: userId,
107107
members: [userId], balances: [memberBalance], currencyCode: localCurrency)

Splito/UI/Home/Groups/Group/Group Options/Balances/GroupBalancesView.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,12 @@ private struct GroupBalanceItemView: View {
8787
var body: some View {
8888
VStack(alignment: .leading, spacing: 20) {
8989
HStack(spacing: 16) {
90-
let totalOwed = memberBalance.totalOwedAmount.reduce(0) { $0 + $1.value }
9190
let name = viewModel.getMemberName(id: memberBalance.id, needFullName: true)
9291

9392
HStack(spacing: 16) {
9493
MemberProfileImageView(imageUrl: imageUrl)
9594

96-
if totalOwed == 0 {
95+
if memberBalance.totalOwedAmount.allSatisfy({ $0.value == 0 }) {
9796
Group {
9897
Text(name)
9998
.font(.subTitle2())
@@ -143,7 +142,7 @@ private struct GroupBalanceItemView: View {
143142
}
144143
.frame(maxWidth: .infinity, alignment: .leading)
145144

146-
if totalOwed != 0 {
145+
if memberBalance.totalOwedAmount.allSatisfy({ $0.value != 0 }) {
147146
ScrollToTopButton(
148147
icon: "chevron.down", iconColor: primaryText, bgColor: container2Color,
149148
showWithAnimation: true, size: (10, 7), isFirstGroupCell: memberBalance.isExpanded,

Splito/UI/Home/Groups/Group/Group Options/Settlements/Transaction Detail/GroupTransactionDetailViewModel.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class GroupTransactionDetailViewModel: BaseViewModel, ObservableObject {
4848
self.router = router
4949
self.groupId = groupId
5050
self.transactionId = transactionId
51-
self.amountCurrency = "INR"
51+
self.amountCurrency = Currency.defaultCurrency.code
5252
super.init()
5353

5454
NotificationCenter.default.addObserver(self, selector: #selector(getUpdatedTransaction(notification:)), name: .updateTransaction, object: nil)
@@ -78,7 +78,7 @@ class GroupTransactionDetailViewModel: BaseViewModel, ObservableObject {
7878
private func fetchTransaction() async {
7979
do {
8080
transaction = try await transactionRepository.fetchTransactionBy(groupId: groupId, transactionId: transactionId)
81-
amountCurrency = transaction?.currencyCode ?? (group?.defaultCurrencyCode ?? "INR")
81+
amountCurrency = transaction?.currencyCode ?? (group?.defaultCurrencyCode ?? Currency.defaultCurrency.code)
8282
await setTransactionUsersData()
8383
LogD("GroupTransactionDetailViewModel: \(#function) Payment fetched successfully.")
8484
} catch {

Splito/UI/Home/Groups/Group/Group Options/Totals/GroupTotalsViewModel.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class GroupTotalsViewModel: BaseViewModel, ObservableObject {
1919

2020
@Published var showCurrencyPicker = false
2121
@Published var supportedCurrencies: [Currency] = [Currency.defaultCurrency]
22-
@Published var selectedCurrency: Currency = Currency.getCurrentLocalCurrency() {
22+
@Published var selectedCurrency: Currency = Currency.defaultCurrency {
2323
didSet {
2424
filterDataForSelectedTab() // Recalculate data when currency changes
2525
}

0 commit comments

Comments
 (0)