flowfi icon indicating copy to clipboard operation
flowfi copied to clipboard

[SDK] @flowfi/react: Headless React Hooks & UI Primitives for Embedding Payment Streams

Open blurbeast opened this issue 2 months ago • 4 comments

Overview & Background

Third-party Stellar dApps, DAO governance frontends, and SaaS dashboards frequently want to embed payment streaming (e.g. "Subscribe via FlowFi Stream" or "Claim Grant") into their own applications. Forcing external developers to build custom contracts interaction or copy-paste React context logic creates adoption friction. FlowFi should offer an official, tree-shakable @flowfi/react package containing headless hooks, state machines, and accessible UI primitives.


Detailed Problem Statement

  1. High Integration Barrier:
    • External frontend developers must manually manage Soroban RPC calls, XDR parsing, SSE event listeners, and real-time interval tickers.
  2. Duplicated Real-Time Math:
    • Calculating real-time claimable balance with sub-second animation, cliff periods, paused durations, and decimal scaling is complex and prone to bugs when re-implemented.
  3. No Drop-In Component Kit:
    • There are no headless or pre-styled components (e.g. <StreamButton />, <ClaimableTicker />, <RunwayBadge />) that developers can drop into any Next.js or React app.

Technical Specification & Architecture

1. Package Architecture (packages/flowfi-react)

Create a new workspace package:

packages/flowfi-react/
├── src/
│   ├── hooks/
│   │   ├── useStream.ts
│   │   ├── useClaimableBalance.ts
│   │   ├── useCreateStream.ts
│   │   ├── useBatchWithdraw.ts
│   │   └── useStreamRunway.ts
│   ├── components/
│   │   ├── FlowFiProvider.tsx
│   │   ├── ClaimableTicker.tsx
│   │   ├── StreamRunwayProgress.tsx
│   │   └── StreamActionModal.tsx
│   └── index.ts
├── package.json
└── tsconfig.json

2. Core Headless Hooks

  • useClaimableBalance(streamId):
    • Automatically updates balance using requestAnimationFrame or sub-second interval.
    • Automatically handles cliff unlocks, rate conversions, and token decimals.
  • useCreateStream():
    • Provides state machine (idle, simulating, signing, broadcasting, confirmed, error).
    • Automatically simulates fees, builds Soroban transaction envelope, prompts connected wallet, and waits for confirmation.
  • useBatchWithdraw():
    • Handles multi-stream selection, gas estimation, and batch transaction dispatch.

3. Component Primitives

  • <ClaimableTicker stream={stream} format="usd" animated={true} />: Smooth liquid continuous number ticker.
  • <StreamRunwayProgress stream={stream} alertThresholdHours={48} />: Visual progress bar indicating time left before exhaustion.

Target Files

  • packages/flowfi-react/package.json
  • packages/flowfi-react/src/hooks/useClaimableBalance.ts
  • packages/flowfi-react/src/hooks/useCreateStream.ts
  • packages/flowfi-react/src/components/FlowFiProvider.tsx
  • packages/flowfi-react/src/components/ClaimableTicker.tsx
  • packages/flowfi-react/tests/useClaimableBalance.test.tsx

Acceptance Criteria

  • [ ] @flowfi/react builds cleanly into ESM and CJS bundles with full TypeScript definitions.
  • [ ] useClaimableBalance delivers smoothly animated numbers matching on-chain claimable calculations.
  • [ ] useCreateStream properly handles transaction simulation, wallet signing, and indexer confirmation.
  • [ ] Primitives work seamlessly with Tailwind CSS and popular UI frameworks (shadcn/ui, Radix UI).
  • [ ] Comprehensive unit tests cover hook lifecycles, cliff edge-cases, and wallet error handling.

blurbeast avatar Sep 27 '26 05:09 blurbeast

@bright5455 has applied to work on this issue as part of the Stellar Wave Program's 9th wave.

hello maintainer

i have read and understand the issue im a backend engineer with five years of eperience,with my level of experience,i believe i can deliver a quality PR please kindly assign this task to me

Thank you

ℹ️ Repo Maintainers: To accept this application, review their application or assign @bright5455 to this issue.

bright5455 avatar Sep 27 '26 16:09 bright5455

@Victorjonah-prog has applied to work on this issue as part of the Stellar Wave Program's 9th wave.

Hi maintainer, I've reviewed this issue and I'll love to work on it

ℹ️ Repo Maintainers: To accept this application, review their application or assign @Victorjonah-prog to this issue.

Victorjonah-prog avatar Sep 27 '26 17:09 Victorjonah-prog

Congratulations, @bright5455! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on September 30, 2026.

🧑‍💻 @bright5455: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.

[!WARNING] When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.

🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.

🌊 Happy Wave 🌊

drips-wave[bot] avatar Sep 29 '26 17:09 drips-wave[bot]

🎉 This issue has been marked as completed on GrantFox!

@bright5455's PR #1587 was approved and merged by @K1NGD4VID.

🏆 @bright5455: You earned 40 FoxPoints for this contribution! Your current tier: Builder (1,169 total points). Track your full progress on GrantFox.

👏 Great work, @bright5455! Keep contributing to LabsCrypt.

grantfox-oss[bot] avatar Oct 10 '26 08:10 grantfox-oss[bot]