iap: add loading spinner to purchase actions

Apple In-app purchases do not respond immediately. This commit adds a
loading spinner element, to improve the UX and avoid the appearance of a
broken/unresponsive element.

Testing
--------

Device: iPhone 15 simulator
iOS: 17.2
Damus: This commit
Setup:
- Using the sandbox environment
- No tx to start with
- IAP experimental support enabled on developer settings in Damus
Steps:
1. Click "purchase" in any option on the damus purple screen
2. It should show a loading spinner while the purchase action is loading. PASS
3. On the confirmation screen, cancel the purchase.
4. Purchase buttons should show again. PASS

Closes: https://github.com/damus-io/damus/issues/2020
Signed-off-by: Daniel D’Aquino <daniel@daquino.me>
Link: 20240223212945.37384-1-daniel@daquino.me
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
Daniel D’Aquino
2024-02-23 21:29:52 +00:00
committed by William Casarin
parent 58326f679e
commit 003348c103

View File

@@ -21,8 +21,19 @@ extension DamusPurpleView {
let subscribe: (Product) async throws -> Void let subscribe: (Product) async throws -> Void
@State var show_manage_subscriptions = false @State var show_manage_subscriptions = false
@State var subscription_purchase_loading = false
var body: some View { var body: some View {
if subscription_purchase_loading {
HStack(spacing: 10) {
Text(NSLocalizedString("Purchasing", comment: "Loading label indicating the purchase action is in progress"))
.foregroundStyle(.white)
ProgressView()
.progressViewStyle(.circular)
.tint(.white)
}
}
else {
switch self.products { switch self.products {
case .failed: case .failed:
PurpleViewPrimitives.ProductLoadErrorView() PurpleViewPrimitives.ProductLoadErrorView()
@@ -37,6 +48,7 @@ extension DamusPurpleView {
.progressViewStyle(.circular) .progressViewStyle(.circular)
} }
} }
}
func PurchasedView(_ purchased: PurchasedProduct) -> some View { func PurchasedView(_ purchased: PurchasedProduct) -> some View {
return Group { return Group {
@@ -107,7 +119,9 @@ extension DamusPurpleView {
Button(action: { Button(action: {
Task { @MainActor in Task { @MainActor in
do { do {
subscription_purchase_loading = true
try await subscribe(product) try await subscribe(product)
subscription_purchase_loading = false
} catch { } catch {
print(error.localizedDescription) print(error.localizedDescription)
} }