Skip to content

feat: add treasury-balance-derived at-risk health state to StreamDetail sidebar (Closes #1280) - #1376

Open
waterWang wants to merge 1 commit into
Fluxora-Org:mainfrom
waterWang:feature/stream-detail-at-risk-health-state
Open

feat: add treasury-balance-derived at-risk health state to StreamDetail sidebar (Closes #1280)#1376
waterWang wants to merge 1 commit into
Fluxora-Org:mainfrom
waterWang:feature/stream-detail-at-risk-health-state

Conversation

@waterWang

Copy link
Copy Markdown

Closes #1280

Description

Add a treasury-balance-derived "At risk" funding health state to the StreamDetail sidebar. The existing health pill reflects the stream's own status (active/paused/completed); this adds a distinct, layered indicator that surfaces when the remaining balance only covers under 48 hours of accrual at the stream's monthly rate.

Changes

  • src/pages/StreamDetail.tsx

    • Added AT_RISK_RUNWAY_HOURS = 48 named constant (single, tunable threshold).
    • Added HOURS_PER_MONTH = 720 (30-day month) for the runway calculation.
    • Added computeFundingRunwayHours(remainingAmount, monthlyRate) — returns Infinity when the monthly rate is zero (no accrual → no funding risk) and 0 when the remaining balance is exhausted.
    • Added isFundingAtRisk(stream) — true when the computed runway is below the 48-hour threshold, and excludes completed streams (already settled).
    • Rendered an "At risk" badge (alert-triangle icon + label, not color alone) next to the existing health pill when isFundingAtRisk is true. It uses design tokens (--color-error-subtle, --color-error, --color-error-border), is role="alert" for screen readers, and is responsive (inline-flex, wraps alongside the pill).
  • src/pages/__tests__/StreamDetail.edgeCases.test.tsx

    • Unit tests for computeFundingRunwayHours (happy path, zero/negative rate, zero/negative balance).
    • Unit tests for isFundingAtRisk (below/above threshold, completed streams, zero rate).
    • Integration tests asserting the at-risk badge renders when runway < 48h, and does not render for sufficient runway or completed streams.

Verification

  • New tests pass: 12/12 (vitest run ... -t "Funding").
  • tsc --noEmit reports no new errors in StreamDetail.tsx / its tests.
  • The threshold is a single named constant so it can be tuned without hunting through the component.
  • WCAG 2.1 AA: the badge is announced via role="alert" and relies on an icon + label (not color alone).

Screenshots / a11y notes

  • At-risk badge: red-tinted pill with an alert-triangle icon and "Funding at risk — less than 48h of runway" text, shown inline next to the stream's health pill.
  • Non-at-risk streams: unchanged (no badge).

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.

Add a treasury-balance-derived "at risk" health state to src/pages/StreamDetail.tsx's sidebar when remaining balance covers under 48 hours of accrual

1 participant