summaryrefslogtreecommitdiff
path: root/Hutch/Views/More/TipStoreViewModel.swift
diff options
context:
space:
mode:
authorChristian Cleberg <[email protected]>2026-04-14 10:42:05 -0500
committerChristian Cleberg <[email protected]>2026-04-14 10:42:05 -0500
commit205c8ea9b2c6dfa62bc8b2342d1aa71e2da7d6ac (patch)
treee7e9b8190ffc15d3cd3e696da4c8acf8c472a193 /Hutch/Views/More/TipStoreViewModel.swift
parentd6968ea122d910b432bd539cf2fa3d1cee962fdb (diff)
downloadhutch-3.1.6.tar.gz
hutch-3.1.6.tar.bz2
hutch-3.1.6.zip
fix: remove prototype screens from developer menuv3.1.6
- removed prototype screens - limited Recent section to 3 items - added initial support for tips Fixes: https://todo.sr.ht/~ccleberg/hutch/65
Diffstat (limited to 'Hutch/Views/More/TipStoreViewModel.swift')
-rw-r--r--Hutch/Views/More/TipStoreViewModel.swift44
1 files changed, 44 insertions, 0 deletions
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
+ }
+ }
+}