Skip to content

🟠 HIGH: Replace SharedState god object with feature-specific state #211

@arkavo-com

Description

@arkavo-com

Problem

SharedState class in ArkavoApp.swift (lines 946-1031) is a god object mixing unrelated concerns with an untyped state storage dictionary.

Current Implementation

class SharedState: ObservableObject {
    @Published var selectedTab: Tab = .home
    @Published var selectedCreatorPublicID: Data?
    @Published var isOfflineMode: Bool = false
    @Published var registrationError: String?
    @Published var isAwaiting: Bool = false
    // ... 10+ more @Published properties
    
    private var stateStorage: [String: Any] = [:]  // Untyped bag!
    
    func setState(_ value: Any, forKey key: String) {
        stateStorage[key] = value
    }
}

Issues

  1. Mixed concerns: Tab selection, offline mode, errors, registration all in one class
  2. Untyped storage: [String: Any] loses all type safety
  3. Implicit dependencies: Views access random keys without compile-time checking
  4. Debugging difficulty: State changes hard to trace
  5. Testing difficulty: Cannot mock specific state

Proposed Solution

// Separate, focused state objects
class NavigationState: ObservableObject {
    @Published var selectedTab: Tab = .home
}

class ConnectionState: ObservableObject {
    @Published var isOffline: Bool = false
    @Published var connectionError: Error?
}

class RegistrationState: ObservableObject {
    @Published var step: RegistrationStep = .initial
    @Published var error: RegistrationError?
}

// Inject only what each view needs

Acceptance Criteria

  • SharedState removed entirely
  • Feature-specific state objects created
  • No [String: Any] untyped storage
  • Each state object has clear ownership
  • Views inject only the state they need

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions