Skip to content

feat: batch syncStreams, status refresh cron, refresh token, claim flow (#136 #138 #140 #49)#190

Merged
ritik4ever merged 1 commit intoritik4ever:mainfrom
benfoster-dev:fix/issues-49-136-138-140
Apr 25, 2026
Merged

feat: batch syncStreams, status refresh cron, refresh token, claim flow (#136 #138 #140 #49)#190
ritik4ever merged 1 commit intoritik4ever:mainfrom
benfoster-dev:fix/issues-49-136-138-140

Conversation

@benfoster-dev
Copy link
Copy Markdown
Contributor

Fixes #136
Fixes #138
Fixes #140
Fixes #49

What changed

#136 — Batch syncStreams with concurrency limit

backend/src/services/streamStore.ts

  • Replaced the sequential for loop with Promise.all + p-limit(5) — max 5 simultaneous RPC calls instead of N sequential calls
  • If the parallel pass throws, falls back to a sequential per-stream loop so progress is preserved
  • Logs total sync time in ms and stream count on completion
  • Added p-limit to backend/package.json

#138 — Configurable cron for refreshStreamStatuses

backend/src/index.ts

  • refreshStreamStatuses() now runs once on startup and then every STATUS_REFRESH_INTERVAL_MS ms (default 60000)
  • Setting STATUS_REFRESH_INTERVAL_MS=0 disables automatic refresh (useful in test environments)
  • Logs the count of streams transitioned to completed on each run
  • Added refreshStreamStatuses to the streamStore import

#140 — Refresh token endpoint

backend/src/services/auth.ts

  • Added refreshToken(req, res) that verifies the current Bearer JWT and issues a new one with a fresh 24h expiry
  • Returns 401 if the token is missing, malformed, or already expired

backend/src/index.ts

  • Registered POST /api/auth/refresh

backend/src/swagger.ts

  • Added /api/auth/refresh path with 200 (new token) and 401 (invalid/expired) response schemas

#49 — Claim flow for recipient dashboard

frontend/src/services/soroban.ts (new)

  • claimStream(streamId, recipientAddress, amount) calls POST /api/streams/:id/claim with the recipient's Bearer token and returns ClaimResult + history

frontend/src/hooks/useClaimStream.ts (new)

  • State machine: idle → pending → confirmed/failed → idle
  • Monotonic claimIdRef prevents stale async callbacks from mutating state after a superseded claim
  • Blocks concurrent claims while one is in-flight
  • Auto-resets to idle after 2s in confirmed state so the "Claimed ✓" label is briefly visible

backend/src/index.ts

  • POST /api/streams/:id/claim endpoint: validates the caller is the stream recipient, checks vestedAmount > 0, records a claimed event in the local DB, returns { result: ClaimResult, history: StreamEvent[] }

…ow (ritik4ever#136 ritik4ever#138 ritik4ever#140 ritik4ever#49)

- ritik4ever#136: Replace sequential for-loop in syncStreams with p-limit concurrency
  (max 5 parallel RPC calls); falls back to sequential per-stream if the
  parallel pass throws; logs total sync time in ms on completion; adds
  p-limit to backend/package.json

- ritik4ever#138: Wire refreshStreamStatuses to run on startup and every
  STATUS_REFRESH_INTERVAL_MS (default 60000ms); setting to 0 disables
  automatic refresh; logs count of streams transitioned to completed on each
  run; imports refreshStreamStatuses from streamStore in index.ts

- ritik4ever#140: Add refreshToken() to auth.ts that verifies the current Bearer JWT
  and issues a new one with fresh 24h expiry; register POST /api/auth/refresh
  in index.ts; add Swagger docs entry with 200/401 response schemas

- ritik4ever#49: Create frontend/src/services/soroban.ts with claimStream() that calls
  POST /api/streams/:id/claim; create frontend/src/hooks/useClaimStream.ts
  with idle/pending/confirmed/failed state machine, monotonic claim ID to
  prevent stale callbacks, 2s confirmed-label hold before reset; add backend
  POST /api/streams/:id/claim endpoint that validates recipient auth, checks
  claimable amount > 0, records claim event in DB, returns ClaimResult and
  event history
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 25, 2026

@benfoster-dev is attempting to deploy a commit to the ritik4ever's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Apr 25, 2026

@benfoster-dev 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

@ritik4ever ritik4ever merged commit 80b3f0e into ritik4ever:main Apr 25, 2026
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants