From 205c8ea9b2c6dfa62bc8b2342d1aa71e2da7d6ac Mon Sep 17 00:00:00 2001 From: Christian Cleberg Date: Tue, 14 Apr 2026 10:42:05 -0500 Subject: fix: remove prototype screens from developer menu - removed prototype screens - limited Recent section to 3 items - added initial support for tips Fixes: https://todo.sr.ht/~ccleberg/hutch/65 --- Hutch/Views/More/TipStoreViewModel.swift | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Hutch/Views/More/TipStoreViewModel.swift (limited to 'Hutch/Views/More/TipStoreViewModel.swift') diff --git a/Hutch/Views/More/TipStoreViewModel.swift b/Hutch/Views/More/TipStoreViewModel.swift new file mode 100644 index 0000000..54868ba --- /dev/null +++ b/Hutch/Views/More/TipStoreViewModel.swift @@ -0,0 +1,44 @@ +import StoreKit + +@Observable +final class TipStoreViewModel { + var products: [Product] = [] + var isLoading = false + var errorMessage: String? + + private let productIDs = [ + "net.cleberg.hutch.tip.small", + "net.cleberg.hutch.tip.medium", + "net.cleberg.hutch.tip.large" + ] + + func loadProducts() async { + isLoading = true + defer { isLoading = false } + do { + let fetched = try await Product.products(for: productIDs) + // Sort by price ascending to maintain small/medium/large order + products = fetched.sorted { $0.price < $1.price } + } catch { + errorMessage = error.localizedDescription + } + } + + func purchase(_ product: Product) async { + do { + let result = try await product.purchase() + switch result { + case .success(let verification): + if case .verified(let transaction) = verification { + await transaction.finish() + } + case .userCancelled, .pending: + break + @unknown default: + break + } + } catch { + errorMessage = error.localizedDescription + } + } +} -- cgit v1.2.3