Files
Termind/Frameworks/TermindPresentation/ProPaywallState.swift
T
Kaede AkinoandClaude Code 975358f98a refactor: remove redundant code and over-defensive branches
Consolidate code that existed twice and drop code nothing reaches.

- SSH: hoist the duplicated ASCII hex-nibble decoder out of
  RemoteCharsetConverter and SSHPTYChannel into SSHWireEncoding.hexDigit.
- Transcript: AgentToolDetail.Tint shares BatchTint's vocabulary, so the
  byte-identical detailColor map now delegates to batchColor.
- Commerce: replace ProPaywallState's unreachable default branch and its
  `preconditionFailure("Handled above")` with an exhaustive switch the
  compiler can prove complete.
- Strings: delete the unreferenced Workspace.closePaneAction (the live help
  text uses closePane) and its orphan catalog entry.
- Drop the unused SwiftData and UniformTypeIdentifiers imports.

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-10-08 11:01:27 +08:00

61 lines
2.1 KiB
Swift

import Foundation
import TermindDomain
/// Data-only contract for RevenueCat's remote visibility rules and localized text.
public nonisolated struct ProPaywallState {
public let hasProAccess: Bool
public let canManageSubscription: Bool
public let isFamilyShared: Bool
public let expiresAt: Date?
/// Protocol values consumed by the dashboard, never displayed as app copy.
public let state: String
public init(status: EntitlementStatus) {
hasProAccess = status.hasProAccess
switch status {
case .subscription(let subscription):
canManageSubscription = subscription.ownership == .purchased
isFamilyShared = subscription.ownership == .familyShared
expiresAt = subscription.expiresAt
switch subscription.phase {
case .introductoryTrial: state = "trial"
case .subscribed:
switch subscription.willAutoRenew {
case true: state = "renewing"
case false: state = "ending"
case nil: state = "active"
}
case .gracePeriod: state = "grace"
case .billingRetry: state = "retry"
case .expired: state = "expired"
case .revoked: state = "revoked"
}
case .purchased(let ownership):
canManageSubscription = false
isFamilyShared = ownership == .familyShared
expiresAt = nil
state = "lifetime"
case .loading:
canManageSubscription = false
isFamilyShared = false
expiresAt = nil
state = "loading"
case .free:
canManageSubscription = false
isFamilyShared = false
expiresAt = nil
state = "free"
case .verificationFailed:
canManageSubscription = false
isFamilyShared = false
expiresAt = nil
state = "unverified"
case .unrestrictedForTesting:
canManageSubscription = false
isFamilyShared = false
expiresAt = nil
state = "development"
}
}
}