Skip to content

Eliminate force unwraps, extract chart hover helper, optimize token sort#109

Merged
KyleNesium merged 1 commit intomainfrom
refactor/code-quality-phase1
Mar 14, 2026
Merged

Eliminate force unwraps, extract chart hover helper, optimize token sort#109
KyleNesium merged 1 commit intomainfrom
refactor/code-quality-phase1

Conversation

@KyleNesium
Copy link
Owner

Summary

  • Replace force unwraps in UsageSnapshot.interpolate() and autoResolvedMode with safe access — prevents potential crashes on empty/unexpected data
  • Extract shared chartHoverOverlay() in ActivityChartView — eliminates 3× duplicated GeometryReader + Rectangle + onContinuousHover boilerplate across daily/hourly/monthly charts
  • Replace sortedTokens (copies + mutates array every render) with orderedTokens that builds iteration order without modifying the source array
  • Clarify ModelPricing linear scan comment (6 entries, already cached per model ID)

Test plan

  • CI passes (build + 434 tests)
  • Chart hover tooltips still work on all 3 modes (12H, 7D, 12M)
  • Token section still shows active model first with ▶ indicator
  • Auto mode still resolves to correct metric under all priority tiers

…ze token sort

- Replace force unwraps in UsageSnapshot.interpolate() and autoResolvedMode
  with safe access (guard-let, optional chaining) to prevent potential crashes
- Extract shared chartHoverOverlay() helper in ActivityChartView, eliminating
  3× duplicated GeometryReader + Rectangle + onContinuousHover boilerplate
- Replace sortedTokens (copies + mutates array every render) with orderedTokens
  that builds iteration order without modifying the source array
- Add clarifying comment on ModelPricing linear scan (6 entries, already cached)
@KyleNesium KyleNesium merged commit 0aaee29 into main Mar 14, 2026
1 check passed
@KyleNesium KyleNesium deleted the refactor/code-quality-phase1 branch March 14, 2026 11:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant