From a4d77078a465c19efe26f978820f34080c445118 Mon Sep 17 00:00:00 2001 From: Love Billenius Date: Fri, 10 Apr 2026 11:17:01 +0200 Subject: [PATCH] remove backend dependency from iOS demo reveal --- mobile/ios-app/Features/Round/RoundView.swift | 52 +++++++++++++------ 1 file changed, 36 insertions(+), 16 deletions(-) diff --git a/mobile/ios-app/Features/Round/RoundView.swift b/mobile/ios-app/Features/Round/RoundView.swift index 716bb66..8ae1303 100644 --- a/mobile/ios-app/Features/Round/RoundView.swift +++ b/mobile/ios-app/Features/Round/RoundView.swift @@ -329,7 +329,20 @@ struct RoundView: View { return } - guard let selectedOutcomeID, let session = repository.currentSession else { + guard let selectedOutcomeID else { + actionMessage = localization.string(for: "errors.session_expired") + return + } + + if isDemoMode { + analytics.track("selection_submitted", attributes: baseSelectionAttributes(selectedOutcomeID)) + analytics.track("selection_accepted", attributes: baseSelectionAttributes(selectedOutcomeID)) + analytics.track("market_locked", attributes: baseSelectionAttributes(selectedOutcomeID).merging(["lock_reason": "swipe_selection"]) { _, new in new }) + beginRevealTransition(for: round, selectedOutcomeID: selectedOutcomeID) + return + } + + guard let session = repository.currentSession else { actionMessage = localization.string(for: "errors.session_expired") return } @@ -371,21 +384,7 @@ struct RoundView: View { analytics.track("selection_submitted", attributes: baseSelectionAttributes(selectedOutcomeID)) analytics.track("selection_accepted", attributes: baseSelectionAttributes(selectedOutcomeID)) analytics.track("market_locked", attributes: baseSelectionAttributes(selectedOutcomeID).merging(["lock_reason": "swipe_selection"]) { _, new in new }) - - phase = .locked - playerCoordinator.play(rate: 2.0) - - transitionTask?.cancel() - transitionTask = Task { @MainActor in - try? await Task.sleep(nanoseconds: 1_100_000_000) - guard !Task.isCancelled else { - return - } - - phase = .reveal - playerCoordinator.play(url: revealMediaURL(for: round), startTimeMs: revealStartTimeMs(for: round), rate: 1.0) - analytics.track("reveal_started", attributes: roundAnalyticsAttributes(round).merging(baseSelectionAttributes(selectedOutcomeID)) { _, new in new }) - } + beginRevealTransition(for: round, selectedOutcomeID: selectedOutcomeID) } catch { actionMessage = hermesUserFacingErrorMessage(localization: localization, localeCode: localization.localeCode, error: error) ?? localization.string(for: "errors.generic") phase = .preview @@ -395,6 +394,23 @@ struct RoundView: View { } } + private func beginRevealTransition(for round: HermesRound, selectedOutcomeID: String) { + phase = .locked + playerCoordinator.play(rate: 2.0) + + transitionTask?.cancel() + transitionTask = Task { @MainActor in + try? await Task.sleep(nanoseconds: 1_100_000_000) + guard !Task.isCancelled else { + return + } + + phase = .reveal + playerCoordinator.play(url: revealMediaURL(for: round), startTimeMs: revealStartTimeMs(for: round), rate: 1.0) + analytics.track("reveal_started", attributes: roundAnalyticsAttributes(round).merging(baseSelectionAttributes(selectedOutcomeID)) { _, new in new }) + } + } + private func showResult() { guard let round = repository.currentRound, let selectedOutcomeID else { return @@ -431,6 +447,10 @@ struct RoundView: View { repository.currentSession?.deviceModel == "Demo Device" ? MockHermesData.revealMediaURL() : round.media.hlsMasterUrl } + private var isDemoMode: Bool { + repository.currentSession?.deviceModel == "Demo Device" + } + private func revealStartTimeMs(for round: HermesRound) -> Int { repository.currentSession?.deviceModel == "Demo Device" ? 0 : round.media.revealStartMs }