diff --git a/PadelClub/Views/Cashier/Event/EventCreationView.swift b/PadelClub/Views/Cashier/Event/EventCreationView.swift index 50a7265..6c959d1 100644 --- a/PadelClub/Views/Cashier/Event/EventCreationView.swift +++ b/PadelClub/Views/Cashier/Event/EventCreationView.swift @@ -93,7 +93,7 @@ struct EventCreationView: View { Section { RowButtonView("Valider") { - let event = Event(creator: dataStore.user.id, name: eventName) + let event = Event(creator: Store.main.userId, name: eventName) event.club = selectedClub?.id tournaments.forEach { tournament in tournament.event = event.id diff --git a/PadelClub/Views/Navigation/MainView.swift b/PadelClub/Views/Navigation/MainView.swift index 8b1e540..6ca28c7 100644 --- a/PadelClub/Views/Navigation/MainView.swift +++ b/PadelClub/Views/Navigation/MainView.swift @@ -59,8 +59,8 @@ struct MainView: View { // PadelClubView() // .tabItem(for: .padelClub) } - .id(Store.main.currentUserUUID) - .onChange(of: Store.main.currentUserUUID) { + .id(Store.main.userId) + .onChange(of: Store.main.userId) { navigation.path.removeLast(navigation.path.count) } .environmentObject(dataStore) diff --git a/PadelClub/Views/Navigation/Organizer/TournamentOrganizerView.swift b/PadelClub/Views/Navigation/Organizer/TournamentOrganizerView.swift index 3a6ee6f..c0b0724 100644 --- a/PadelClub/Views/Navigation/Organizer/TournamentOrganizerView.swift +++ b/PadelClub/Views/Navigation/Organizer/TournamentOrganizerView.swift @@ -43,7 +43,7 @@ struct TournamentOrganizerView: View { } } } - .onChange(of: Store.main.currentUserUUID) { + .onChange(of: Store.main.userId) { navigation.organizerTournament = nil } } diff --git a/PadelClub/Views/Navigation/Toolbox/DebugSettingsView.swift b/PadelClub/Views/Navigation/Toolbox/DebugSettingsView.swift index bc5e9e1..30fcf8f 100644 --- a/PadelClub/Views/Navigation/Toolbox/DebugSettingsView.swift +++ b/PadelClub/Views/Navigation/Toolbox/DebugSettingsView.swift @@ -11,7 +11,7 @@ import LeStorage struct DebugSettingsView: View { var body: some View { List { - LabeledContent("UUID", value: Store.main.currentUserUUID?.uuidString ?? "") + LabeledContent("UUID", value: Store.main.userId ?? "") LabeledContent("User Name", value: Store.main.userName() ?? "") LabeledContent("Token", value: Store.main.token() ?? "") LabeledContent("Server", value: PListReader.readString(plist: "local", key: "server") ?? "") diff --git a/PadelClub/Views/Subscription/Guard.swift b/PadelClub/Views/Subscription/Guard.swift index ccc1f04..5aa7039 100644 --- a/PadelClub/Views/Subscription/Guard.swift +++ b/PadelClub/Views/Subscription/Guard.swift @@ -115,7 +115,7 @@ import LeStorage fileprivate func _addPurchaseIfPossible(transaction: StoreKit.Transaction) throws { if self.purchases.hasLoadedFromServer { if self._purchaseById(transaction.originalID) == nil { - let purchase: Purchase = transaction.purchase() + let purchase: Purchase = try transaction.purchase() try self.purchases.addOrUpdate(instance: purchase) } } @@ -157,7 +157,7 @@ import LeStorage func userFilteredPurchases() -> [StoreKit.Transaction] { // Logger.log("self.purchasedTransactions = \(self.purchasedTransactions.count)") - guard let currentUserUUID: UUID = Store.main.currentUserUUID else { + guard let userId = Store.main.userId, let currentUserUUID: UUID = UUID(uuidString: userId) else { return [] } @@ -253,8 +253,10 @@ struct PurchaseRow: Identifiable { fileprivate extension StoreKit.Transaction { - func purchase() -> Purchase { - let userId = Store.main.mandatoryUserUUID().uuidString + func purchase() throws -> Purchase { + guard let userId = Store.main.userId else { + throw StoreError.missingUserId + } return Purchase(user: userId, identifier: self.originalID, purchaseDate: self.purchaseDate, diff --git a/PadelClub/Views/Subscription/StoreManager.swift b/PadelClub/Views/Subscription/StoreManager.swift index c8d4921..8222e0d 100644 --- a/PadelClub/Views/Subscription/StoreManager.swift +++ b/PadelClub/Views/Subscription/StoreManager.swift @@ -100,8 +100,11 @@ class StoreManager { func purchase(_ product: Product, quantity: Int? = nil) async throws -> StoreKit.Transaction? { Logger.log("Store purchase started...") + guard let userId = Store.main.userId, let uuid: UUID = UUID(uuidString: userId) else { + throw StoreError.missingUserId + } + var options: Set = [] - let uuid: UUID = Store.main.mandatoryUserUUID() let tokenOption = Product.PurchaseOption.appAccountToken(uuid) options.insert(tokenOption) diff --git a/PadelClubTests/ServerDataTests.swift b/PadelClubTests/ServerDataTests.swift index 4da5c93..5fdf538 100644 --- a/PadelClubTests/ServerDataTests.swift +++ b/PadelClubTests/ServerDataTests.swift @@ -69,7 +69,7 @@ final class ServerDataTests: XCTestCase { func testEvent() async throws { - guard let userId = Store.main.currentUserUUID?.uuidString else { + guard let userId = Store.main.userId else { assertionFailure("missing user UUID") return } @@ -337,7 +337,7 @@ final class ServerDataTests: XCTestCase { func testPurchase() async throws { - guard let userId = Store.main.currentUserUUID?.uuidString.lowercased() else { + guard let userId = Store.main.userId else { assertionFailure("missing user UUID") return }