Intelligence, Advanced Charting & Trading Platform
feature/chartnova-ios-widget
diagnostics/chartnova-blank-screen-2026-10-15
diagnostics/chartnova-stage2-v27-preview-2026-10-15
docs/chartnova-stage1-reconcile-manifest-2026-10-15
feature/chartnova-ios-widget
feature/chartnova-light-catalog-lazy-series-2026-10-15
feature/chartnova-market-terminal
feature/chartnova-multimarket-chart-ws-foundation
feature/chartnova-neon-direct-history
feature/chartnova-neon-history
feature/paper-trading-risk-controls-2026-10-14
fix/alpha-vantage-live-payload
fix/chartnova-progressive-loading-2026-10-15
fix/live-proof-runner-cwd-2026-10-14
foundation/phase-0
foundation/postgres-core
main
ops/chartnova-emergency-rollback-2026-10-15
phase-1/candle-builder
phase-1/data-proof-artifact
phase-1/data-proof-metrics
phase-1/data-proof-report
phase-1/external-gates-state
phase-1/gold-api-fallback
phase-1/ingestion-pipeline
phase-1/live-proof-runner
phase-1/market-calendar
phase-1/market-domain
phase-1/neon-live-proof
phase-1/persistence-contract
phase-1/postgres-ci
phase-1/provider-adapters
phase-1/provider-recovery
phase-1/quality-propagation
phase-1/spike-detection
phase-1/xau-provider-adapter
risk/chartnova-alert-runtime-atomic-2026-10-22
risk/chartnova-atomic-outbox-2026-10-22
risk/chartnova-seven-track-safety-2026-10-21
safety/p0-triage-2026-10-13
| 1 | import SwiftUI |
| 2 | import WidgetKit |
| 3 | |
| 4 | struct ChartNovaTimelineEntry: TimelineEntry { |
| 5 | let date: Date |
| 6 | let selectedSymbols: [String] |
| 7 | let appearance: WidgetAppearance |
| 8 | let quotes: [MarketQuote] |
| 9 | let fetchedAt: String? |
| 10 | let source: String |
| 11 | let stale: Bool |
| 12 | let usedOfflineCache: Bool |
| 13 | |
| 14 | func quote(for symbol: String) -> MarketQuote? { |
| 15 | quotes.first(where: { $0.symbol == symbol }) |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | struct ChartNovaTimelineProvider: TimelineProvider { |
| 20 | func placeholder(in context: Context) -> ChartNovaTimelineEntry { |
| 21 | entry(quotes: [], fetchedAt: nil, source: "ChartNova", stale: true, offline: false) |
| 22 | } |
| 23 | |
| 24 | func getSnapshot(in context: Context, completion: @escaping (ChartNovaTimelineEntry) -> Void) { |
| 25 | if context.isPreview { |
| 26 | completion(placeholder(in: context)) |
| 27 | } else { |
| 28 | Task { completion(await downloadEntry()) } |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | func getTimeline(in context: Context, completion: @escaping (Timeline<ChartNovaTimelineEntry>) -> Void) { |
| 33 | Task { |
| 34 | let current = await downloadEntry() |
| 35 | // System decides when to honor this request; 15 minutes is not guaranteed. |
| 36 | let earliestRefresh = Date().addingTimeInterval(current.usedOfflineCache ? 5 * 60 : 15 * 60) |
| 37 | completion(Timeline(entries: [current], policy: .after(earliestRefresh))) |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | private func downloadEntry() async -> ChartNovaTimelineEntry { |
| 42 | let config = WidgetSettingsStore.load() |
| 43 | guard !config.selectedSymbols.isEmpty else { |
| 44 | return entry(quotes: [], fetchedAt: nil, source: "ChartNova", stale: true, offline: false) |
| 45 | } |
| 46 | do { |
| 47 | let feed = try await MarketAPI().fetchWidget(symbols: config.selectedSymbols) |
| 48 | WidgetQuoteCache.save(feed) |
| 49 | return entry(quotes: feed.items, fetchedAt: feed.fetchedAt, source: feed.source ?? "ChartNova", |
| 50 | stale: feed.isStale() || feed.items.contains(where: { $0.providerSaysFresh == false }), |
| 51 | offline: false, prefs: config) |
| 52 | } catch { |
| 53 | let cached = WidgetQuoteCache.load() |
| 54 | return entry(quotes: cached?.items ?? [], fetchedAt: cached?.fetchedAt, source: cached?.source ?? "ChartNova", |
| 55 | stale: true, offline: true, prefs: config) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | private func entry(quotes: [MarketQuote], fetchedAt: String?, source: String, stale: Bool, |
| 60 | offline: Bool, prefs: WidgetPreferences = WidgetSettingsStore.load()) -> ChartNovaTimelineEntry { |
| 61 | ChartNovaTimelineEntry(date: Date(), selectedSymbols: prefs.selectedSymbols, |
| 62 | appearance: prefs.appearance, quotes: quotes, fetchedAt: fetchedAt, |
| 63 | source: source, stale: stale, usedOfflineCache: offline) |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | struct ChartNovaWidget: Widget { |
| 68 | let kind = "ChartNovaMultiAssetWidget" |
| 69 | |
| 70 | var body: some WidgetConfiguration { |
| 71 | StaticConfiguration(kind: kind, provider: ChartNovaTimelineProvider()) { entry in |
| 72 | ChartNovaWidgetView(entry: entry) |
| 73 | } |
| 74 | .configurationDisplayName("چارتنوا | قیمتهای منتخب") |
| 75 | .description("چند ارز، تتر، سکه و گرم طلا را در صفحه اصلی آیفون ببین.") |
| 76 | .supportedFamilies([.systemSmall, .systemMedium, .systemLarge]) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | @main |
| 81 | struct ChartNovaWidgetBundle: WidgetBundle { |
| 82 | var body: some Widget { |
| 83 | ChartNovaWidget() |
| 84 | } |
| 85 | } |