Skip to content

feat(react): add useStreamCountdown hook for cliff and cancellation deadlines (#830) - #889

Merged
Jaydbrown merged 6 commits into
conduit-protocol:mainfrom
esthereze:feat/830-use-stream-countdown
Oct 5, 2026
Merged

Jaydbrown merged 6 commits into
conduit-protocol:mainfrom
esthereze:feat/830-use-stream-countdown

Conversation

@esthereze

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds useStreamCountdown to @streamfi/react — a 1-second-tick countdown to a cliff, cancellation, or completion deadline — so vesting and payroll cards no longer hand-roll timers.

Type of change

  • New feature / method

Related issue

Closes #830

Changes

File Change
packages/react/src/hooks/useStreamCountdown.ts New hook returning { days, hours, minutes, seconds, isPast, progressFraction }
packages/react/src/index.ts Export useStreamCountdown and UseStreamCountdownResult
packages/react/src/__tests__/useStreamCountdown.test.tsx 13 tests: unit split, auto-tick, isPast, progressFraction, boundaries, cleanup
docs/react-hooks.md New useStreamCountdown guide section
CHANGELOG.md [Unreleased] entry
packages/react/src/hooks/{useCircuitState,useTransactionHistory}.ts Fix broken ../../src/... relative imports that stopped the package barrel, JS bundle and test suite from loading

Design notes

  • targetTimestamp (and the optional startTimestamp) are Unix timestamps in seconds, matching StreamInfo.startTime / StreamInfo.endTime.
  • A deadline alone cannot define a progress range, so progressFraction is null unless startTimestamp is supplied. When supplied it is the clamped 0–1 elapsed share of the window.
  • null, undefined, or a non-finite target yields a zeroed, isPast: false result so a card can render while the stream is still loading.
  • The timer is cleared on unmount and re-synced when the target changes.

Quick usage:

const { days, hours, minutes, seconds, isPast, progressFraction } =
  useStreamCountdown(stream.endTime, stream.startTime);

Checklist

  • New unit tests pass — 13/13 for the hook, 27/27 for the packages/react suite
  • No any types introduced
  • src/index.ts updated with the new export
  • New public hook documented in docs/react-hooks.md
  • CHANGELOG.md updated under [Unreleased]
  • No co-authors
  • npm run typecheck / npm run build for packages/react — see note below

Breaking changes?

  • No

Notes for reviewers

main is already red on unrelated checks: the WebSocket heartbeat tests in src/tests/relayer-stress.test.ts time out, the repo-root ESLint run has 6 pre-existing errors, and other packages/react hooks carry pre-existing typecheck/DTS errors (useStreamNotes, useGovernorConfig, useStreamsBySender/Recipient). This PR introduces no new typecheck or lint errors — the two import-path fixes were required for the package's JS bundle and test suite to resolve the barrel at all, and they simply turn the old TS2307 cannot find module into the TS6059 rootDir diagnostic for those two pre-existing hooks, whose real fix (importing the reducer/circuit modules through the SDK's public exports) is a separate concern.

…ol#830)

Describe the countdown contract for cliff and cancellation deadlines
before the hook exists: remaining days/hours/minutes/seconds, the
1-second auto-tick, and the isPast clamp at zero. These fail on main
with an unresolved import, matching the repo's test-first convention.
…lines (conduit-protocol#830)

Add a dependency-free hook that turns a Unix-seconds deadline into
days/hours/minutes/seconds with a 1-second auto-tick, so vesting and
payroll cards no longer hand-roll timers. An optional startTimestamp
adds progressFraction for the elapsed share of the window; without it
the fraction is null since a deadline alone cannot define a range.

Closes conduit-protocol#830
Exercise the paths a card actually hits: progressFraction before,
during and past the window, zero-length windows, missing/non-finite
timestamps, target changes mid-countdown, long-duration decomposition,
and interval cleanup on unmount.
Add a usage example, return type and parameter notes to
docs/react-hooks.md, and an [Unreleased] changelog entry, so the new
public export is discoverable (the repo requires new public hooks to be
documented).
The conduit-protocol#768/conduit-protocol#769 hooks reached into root SDK modules via '../../src/...',
which resolves inside packages/react and does not exist, so importing
'@streamfi/react' — and therefore bundling or testing the new
useStreamCountdown export — failed before the build got started. Point
both at the repo-root src/ path, matching examples/dashboard, so the
JS bundle and the package test suite load again.
@drips-wave

drips-wave Bot commented Sep 29, 2026

Copy link
Copy Markdown

@esthereze Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@esthereze

esthereze commented Oct 1, 2026 via email

Copy link
Copy Markdown
Contributor Author

@esthereze

esthereze commented Oct 5, 2026 via email

Copy link
Copy Markdown
Contributor Author

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.

packages/react: add useStreamCountdown hook for cliff and cancellation deadlines

2 participants