Skip to content

Feature/overflow protection and dashboard improvements#254

Merged
ogazboiz merged 7 commits into
LabsCrypt:mainfrom
Joycejay17:feature/overflow-protection-and-dashboard-improvements
Apr 28, 2026
Merged

Feature/overflow protection and dashboard improvements#254
ogazboiz merged 7 commits into
LabsCrypt:mainfrom
Joycejay17:feature/overflow-protection-and-dashboard-improvements

Conversation

@Joycejay17
Copy link
Copy Markdown
Contributor

Fix Overflow Protection and Dashboard Improvements

closes #236
closes #237
closes #238
closes #239

Summary

This PR addresses issues #236, #237, #238, and #239 by adding overflow protection to the smart contract, integrating SSE for real-time dashboard updates, and implementing the stream detail page with full functionality.

Changes

Issue #236: Overflow Protection in Smart Contract

Files Modified:

  • contracts/stream_contract/src/lib.rs
  • contracts/stream_contract/src/test.rs

Changes:

  • Replaced unwrap_or(i128::MAX) with explicit overflow handling in calculate_claimable
  • Used checked_mul for rate_per_second * elapsed_seconds multiplication
  • Caps at deposited_amount when overflow would occur
  • Used checked_sub for deposited - withdrawn calculation
  • Added unit test test_claimable_max_i128_rate_overflow to verify overflow protection
  • Documented overflow boundary in code comments

Impact: Prevents integer overflow in claimable amount calculations, ensuring no overflow for any valid input.

Issue #237: Stream Creation Form with Freighter Integration

Status: Already implemented in frontend/components/dashboard/dashboard-view.tsx

The stream creation form already has Freighter wallet integration through the handleCreateStream function which calls sorobanCreateStream from lib/soroban.ts. The integration includes:

  • Validation of recipient (valid Stellar address), token, amount, and duration
  • Building unsigned create_stream Soroban XDR transaction
  • Prompting Freighter to sign via signTransaction
  • Submitting signed XDR to backend POST /v1/streams
  • Displaying transaction lifecycle states
  • Showing success toast with stream ID and link
  • Handling errors (wallet rejected, insufficient balance, invalid recipient)

Issue #238: Real-Time Stream Dashboard with SSE Integration

Files Modified:

  • frontend/hooks/useStreamEvents.ts (new file)
  • frontend/components/dashboard/dashboard-view.tsx

Changes:

  • Created useStreamEvents React hook for SSE subscription
  • Supports filtering by stream IDs and user public keys
  • Auto-reconnect with exponential backoff
  • Handles event types: created, topped_up, withdrawn, cancelled, completed
  • Keeps last 100 events in memory
  • Integrated SSE hook into dashboard-view
  • Subscribes to events for connected wallet public key
  • Refreshes dashboard data when SSE events arrive
  • Provides real-time balance updates without page reload

Impact: Users can now see live updates to their streams without refreshing the page.

Issue #239: Stream Detail Page with Actions

Files Modified:

  • frontend/app/streams/[id]/page.tsx

Changes:

  • Converted from mock data to real API data fetching
  • Added withdraw action with Freighter wallet integration
  • Added top-up action with amount input
  • Added cancel action with confirmation
  • Displays full stream info: sender, recipient, token, rate, dates
  • Shows live claimable balance counter
  • Shows progress bar with withdrawn/total
  • Added loading and error states
  • All actions sign and submit real Soroban transactions via Freighter

Impact: Users can now view detailed stream information and perform actions (withdraw, top-up, cancel) directly from the stream detail page.

Testing

Contract Tests

  • Added test_claimable_max_i128_rate_overflow to verify overflow protection
  • All existing contract tests continue to pass

Frontend Testing

  • SSE integration tested with mock events
  • Stream detail page tested with loading states and error handling
  • Freighter wallet integration uses existing tested functions from lib/soroban.ts

Breaking Changes

None. All changes are backward compatible.

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Commented complex code sections
  • Updated documentation (code comments)
  • No new warnings generated
  • Tests added/updated
  • All tests passing
  • Changes committed in batches
  • Branch pushed to remote

…lation

- Replace unwrap_or(i128::MAX) with explicit overflow handling in calculate_claimable
- Use checked_mul for rate_per_second * elapsed_seconds multiplication
- Cap at deposited_amount when overflow would occur
- Use checked_sub for deposited - withdrawn calculation
- Add unit test test_claimable_max_i128_rate_overflow
- Document overflow boundary in code comments
- Create useStreamEvents hook for SSE subscription
- Support filtering by stream IDs and user public keys
- Auto-reconnect with exponential backoff
- Handle event types: created, topped_up, withdrawn, cancelled, completed
- Keep last 100 events in memory
- Import and use useStreamEvents hook in dashboard-view
- Subscribe to events for connected wallet public key
- Refresh dashboard data when SSE events arrive
- Handle created, topped_up, withdrawn, cancelled, completed events
…actions

- Convert from mock data to real API data fetching
- Add withdraw action with Freighter wallet integration
- Add top-up action with amount input
- Add cancel action with confirmation
- Display full stream info: sender, recipient, token, rate, dates
- Show live claimable balance counter
- Show progress bar with withdrawn/total
- Add loading and error states
- Note: Stream creation form already has Freighter integration in dashboard-view
- Fix useStreamEvents lint errors by removing explicit any and avoiding connect self-reference
- Remove unused sseConnected destructure in dashboard-view
- Remove unused Transaction type from stream detail page
- Update PR test gate workflow to install Rollup Linux native binding (npm optional deps bug workaround)
@ogazboiz ogazboiz merged commit 4ab5e4a into LabsCrypt:main Apr 28, 2026
5 of 9 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