Files
simplex-chat/apps/ios/Shared/Views/Badges/BadgesView.swift
T
spaced4ndy e3e4709381 ui: buy a badge in the app through the App Store or Google Play (#7608)
* ui: buy a badge in the app through the App Store or Google Play

* core, ios, android: create the badge store purchase record before the store charges

* core, ios, android: fixes from the store lane review

* ios, android: show a store purchase's badge only on the profile it was credited to
2026-10-01 08:46:35 +00:00

62 lines
2.1 KiB
Swift

//
// BadgesView.swift
// SimpleX (iOS)
//
// Created by spaced4ndy on 11.09.2026.
// Copyright © 2026 SimpleX Chat. All rights reserved.
//
import SwiftUI
import SimpleXChat
struct BadgesView: View {
@EnvironmentObject var chatModel: ChatModel
@ObservedObject private var badgeModel = BadgeModel.shared
@ObservedObject private var store = BadgeStore.shared
var showsAsSheet: Bool = false
private var shownBadge: BadgeState? {
guard badgeModel.userId == chatModel.currentUser?.userId else { return nil }
if let badgeState = badgeModel.badgeState, badgeState.shown { return badgeState }
return nil
}
var body: some View {
Group {
if let badgeState = shownBadge {
BadgesYourBadgeView(badgeState: badgeState, showsAsSheet: showsAsSheet)
.transition(.opacity)
} else if let purchaseState = store.purchaseState(chatModel.currentUser?.userId) {
// holds the purchase screens' slot, so a consumable cannot be bought twice
BadgesPurchaseStateView(purchaseState: purchaseState, showsAsSheet: showsAsSheet)
.transition(.opacity)
} else {
BadgesSupportSimplexView(showsAsSheet: showsAsSheet)
.transition(.opacity)
}
}
.animation(.default, value: shownBadge != nil)
.animation(.default, value: store.purchaseState(chatModel.currentUser?.userId))
}
}
var supportSimpleXAlertAction: UIAlertAction {
UIAlertAction(title: NSLocalizedString("Support SimpleX", comment: "alert button"), style: .default) { _ in
openBadgesView()
}
}
func openBadgesView() {
showAppSheet {
NavigationView {
BadgesView(showsAsSheet: true)
.modifier(ThemedBackground())
}
}
}
// false until the badge state is loaded for the current profile, so a supporter is never pitched to
func noShownBadge() -> Bool {
BadgeModel.shared.badgeState?.shown != true && BadgeModel.shared.userId == ChatModel.shared.currentUser?.userId
}