From a488fbc4d2cfb8c315a1640cdeb72d5d4289a8a8 Mon Sep 17 00:00:00 2001 From: spacedandy-agents-simplex <342056592+spacedandy-agents-simplex@users.noreply.github.com> Date: Wed, 14 Oct 2026 18:06:13 +0000 Subject: [PATCH] core: move SubscriptionState to Badges.Types (structural) BadgeState, which lives in Badges.Types, is about to carry a subscription's state, and Badges.Service imports Badges.Types. Service re-exports it, as it does BadgeServiceErrorCode. No behaviour change. Run: 003-badge-subscriptions-ui, slice 1 --- src/Simplex/Chat/Badges/Service.hs | 31 ------------------------------ src/Simplex/Chat/Badges/Types.hs | 31 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/Simplex/Chat/Badges/Service.hs b/src/Simplex/Chat/Badges/Service.hs index f72e4f4161..70611bd788 100644 --- a/src/Simplex/Chat/Badges/Service.hs +++ b/src/Simplex/Chat/Badges/Service.hs @@ -43,7 +43,6 @@ import Simplex.Chat.Badges import Simplex.Chat.Badges.Types import Simplex.Chat.PaymentService import qualified Simplex.Messaging.Crypto as C -import Simplex.Messaging.Encoding.String (TextEncoding (..), textParseJSON, textToEncoding, textToJSON) import Simplex.Messaging.Parsers (defaultJSON, dropPrefix, taggedObjectJSON) import Simplex.Messaging.Version (VersionRange, VersionScope, mkVersionRange) import Simplex.Messaging.Version.Internal (Version (..)) @@ -132,15 +131,6 @@ data BadgeServiceResponse retryAfter :: Maybe Word32 } --- | The store's answer as the service last read it. A client reads a state it does not know as not ended. -data SubscriptionState - = SSRenewing - | SSCancelled -- auto-renew is off, and the paid period still runs - | SSBillingRetry -- a charge failed and the store is retrying it: grace, retry or hold - | SSEnded -- no charge will come: expired, revoked or refunded - | SSUnknown Text -- forwards-compatible: service is deployed ahead of clients - deriving (Eq, Show) - data BadgeCatalog = BadgeCatalog { prices :: [BadgePrice], offers :: [BadgeOffer] @@ -248,27 +238,6 @@ instance ToJSON StatementDebitType where SDUnknown _ j -> JE.value $ J.Object j v -> $(JQ.mkToEncoding (taggedObjectJSON $ dropPrefix "SD") ''StatementDebitType) v -instance TextEncoding SubscriptionState where - textEncode = \case - SSRenewing -> "renewing" - SSCancelled -> "cancelled" - SSBillingRetry -> "billingRetry" - SSEnded -> "ended" - SSUnknown t -> t - textDecode s = Just $ case s of - "renewing" -> SSRenewing - "cancelled" -> SSCancelled - "billingRetry" -> SSBillingRetry - "ended" -> SSEnded - t -> SSUnknown t - -instance ToJSON SubscriptionState where - toJSON = textToJSON - toEncoding = textToEncoding - -instance FromJSON SubscriptionState where - parseJSON = textParseJSON "SubscriptionState" - $(JQ.deriveJSON (taggedObjectJSON $ dropPrefix "SE") ''StatementEntryType) $(JQ.deriveJSON defaultJSON ''StatementEntry) diff --git a/src/Simplex/Chat/Badges/Types.hs b/src/Simplex/Chat/Badges/Types.hs index f0addfa675..b773ef409a 100644 --- a/src/Simplex/Chat/Badges/Types.hs +++ b/src/Simplex/Chat/Badges/Types.hs @@ -20,6 +20,7 @@ module Simplex.Chat.Badges.Types LedgerDebitType (..), BadgeAlertKind (..), BadgeServiceErrorCode (..), + SubscriptionState (..), BadgeIssueFailure (..), BadgeIssueError (..), BadgeFunding (..), @@ -249,6 +250,15 @@ data BadgeServiceErrorCode | BSEUnknown Text -- forwards-compatible: service is deployed ahead of clients deriving (Eq, Show) +-- | The store's answer as the service last read it. A client reads a state it does not know as not ended. +data SubscriptionState + = SSRenewing + | SSCancelled -- auto-renew is off, and the paid period still runs + | SSBillingRetry -- a charge failed and the store is retrying it: grace, retry or hold + | SSEnded -- no charge will come: expired, revoked or refunded + | SSUnknown Text -- forwards-compatible: service is deployed ahead of clients + deriving (Eq, Show) + -- | Why a renewal request ended without a credential stored. retryable is the service's own view of -- transience: it gave retryAfter, which holds for codes this version does not know. data BadgeIssueFailure @@ -378,6 +388,27 @@ instance ToJSON BadgeServiceErrorCode where instance FromJSON BadgeServiceErrorCode where parseJSON = textParseJSON "BadgeServiceErrorCode" +instance TextEncoding SubscriptionState where + textEncode = \case + SSRenewing -> "renewing" + SSCancelled -> "cancelled" + SSBillingRetry -> "billingRetry" + SSEnded -> "ended" + SSUnknown t -> t + textDecode s = Just $ case s of + "renewing" -> SSRenewing + "cancelled" -> SSCancelled + "billingRetry" -> SSBillingRetry + "ended" -> SSEnded + t -> SSUnknown t + +instance ToJSON SubscriptionState where + toJSON = textToJSON + toEncoding = textToEncoding + +instance FromJSON SubscriptionState where + parseJSON = textParseJSON "SubscriptionState" + instance StrEncoding BadgeIssueFailure where strEncode = \case BIFServiceError {code, retryable} -> "service_error " <> (if retryable then "retry " else "final ") <> encodeUtf8 (textEncode code)