Skip to content

[Frontend] Implement optimistic state rollback with toast feedback upon network failure in Activity Feed Component - #1677

Merged
emdevelopa merged 1 commit into
emdevelopa:mainfrom
floraispretty:feature/fe-implement-optimistic-state-rollback-with-toast-feedback-upon-network-failure-in-activity-feed-component
Oct 21, 2026
Merged

emdevelopa merged 1 commit into
emdevelopa:mainfrom
floraispretty:feature/fe-implement-optimistic-state-rollback-with-toast-feedback-upon-network-failure-in-activity-feed-component

Conversation

@floraispretty

@floraispretty floraispretty commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Implements optimistic UI updates with automatic rollback and toast notifications for enhanced UX in the Activity Feed Component.

Changes

Core Features:

  • ✅ Optimistic state management for real-time payment updates
  • ✅ Automatic verification of optimistic payments (3-second delay)
  • ✅ Network failure detection and rollback mechanism
  • ✅ Toast notifications for payment events and network errors
  • ✅ Visual indicators for verifying payments
  • ✅ Retry action on initial fetch failures

Technical Implementation:

interface Payment {
  // ... existing fields
  isOptimistic?: boolean; // NEW: Track optimistic updates
}
  1. Optimistic Updates:

    • Real-time payments added immediately via WebSocket
    • Marked with isOptimistic: true flag
    • Scheduled for verification after 3 seconds
  2. Verification Flow:

    • verifyPayment() function calls backend with 5s timeout
    • On success: removes optimistic flag, confirms payment
    • On failure: rolls back by removing payment from state
  3. Toast Integration:

    • Sonner toast library for notifications
    • Three toast types:
      • Success: "New payment received" (3s)
      • Error: "Payment verification failed" with rollback info (5s)
      • Error: "Network error" with retry button (10s)
  4. Visual Feedback:

    • Optimistic payments show pulsing animation
    • Small animated dot in status badge
    • Accessibility labels include "(Verifying)" state
    • Mobile and desktop responsive

File Modified:

  • frontend/src/components/ActivityFeed.tsx
    • Added imports: useRef, toast, Toaster from sonner
    • Added isOptimistic to Payment interface
    • Added verificationTimeouts ref for tracking
    • Implemented verifyPayment with network failure handling
    • Enhanced handleConfirmed with optimistic state + verification scheduling
    • Updated fetch error handling with toast + retry action
    • Added visual indicators to PaymentRow and mobile cards
    • Added Toaster component to all render paths

UX Improvements

Before:

  • Real-time payments appeared but no verification
  • Network failures showed generic error state
  • No feedback for transient states
  • No retry mechanism

After:

  • Immediate optimistic feedback with visual indicator
  • Automatic verification with rollback on failure
  • Clear toast notifications for all state changes
  • Retry button for network failures
  • Smooth state transitions without UI jumps

Testing

Tested Scenarios:

  • ✅ Mobile responsiveness maintained
  • ✅ Desktop table view with optimistic indicators
  • ✅ Accessibility (WCAG 2.1 AA) labels enhanced
  • ✅ Optimistic updates roll back on verification failure
  • ✅ Toast notifications appear correctly (top-right, closeable)
  • ✅ Retry action on initial fetch failure
  • ✅ Cleanup of verification timeouts on unmount

User Flow:

  1. New payment arrives via WebSocket → optimistic state + success toast
  2. Payment shows with pulsing animation + verifying indicator
  3. After 3s, backend verification occurs:
    • Success: animation stops, confirmed state
    • Failure: payment removed, error toast with details

Screenshots

(Visual indicators for optimistic payments with pulsing animation and dot)

Desktop View:

  • Status badge shows pulsing dot for verifying payments
  • Row animates subtly during verification

Mobile View:

  • Card pulsing animation
  • Status badge indicator
  • Toast positioned appropriately

Technical Details

State Management:

  • Optimistic payments tracked via isOptimistic flag
  • Verification timeouts stored in ref (persists across renders)
  • Cleanup on unmount prevents memory leaks

Network Handling:

  • 5-second timeout for verification requests
  • AbortSignal.timeout() for clean cancellation
  • Graceful fallback on network errors

Performance:

  • Memoized components (PaymentRow already optimized)
  • Ref-based timeout tracking (no re-renders)
  • Efficient state updates with functional setters

Design Standards

  • ✅ Tailwind CSS tokens maintained
  • ✅ Drips Wave design consistency
  • ✅ Responsive across desktop/mobile
  • ✅ Accessible (keyboard navigation, ARIA labels, screen reader support)
  • ✅ Consistent state transitions
  • ✅ Visual feedback for all interactions

Documentation

Toast Types:

  • Success toast: New payment confirmation
  • Error toast: Verification failure with rollback notice
  • Network error toast: With retry action button

Accessibility:

  • ARIA labels updated with verification state
  • Toaster has rich colors + close button
  • Keyboard navigable retry button
  • Screen reader announcements for state changes

Closes #1653
Closes #1638
Closes #1640
Closes #1645

…ck upon network failure in Activity Feed Component

Implements optimistic UI updates with automatic rollback and toast notifications
for enhanced user experience in the Activity Feed Component.

Key Features:
- Optimistic state management for real-time payment updates
- Automatic verification of optimistic payments (3s delay)
- Network failure detection and rollback mechanism
- Toast notifications for payment events and network errors
- Visual indicators for verifying payments (pulsing animation + dot)
- Retry action on initial fetch failures

Technical Implementation:
- Added `isOptimistic` flag to Payment interface
- Implemented `verifyPayment` function with 5s timeout
- Integrated Sonner toast library for notifications
- Added ref-based verification timeout tracking
- Enhanced error handling with toast feedback
- Mobile and desktop responsive indicators

UX Improvements:
- Success toast on new payment arrival
- Error toast with rollback notification on verification failure
- Network error toast with retry action button
- Accessibility labels updated for verifying state
- Subtle pulsing animation for optimistic payments
- Clean state transitions without jarring UI jumps

Toast Types:
1. Success: New payment received (3s duration)
2. Error: Payment verification failed with rollback info (5s duration)
3. Error: Network failure with retry action (10s duration)

Testing:
- Mobile responsiveness maintained
- Accessibility (WCAG 2.1 AA) labels enhanced
- Optimistic updates roll back correctly on network failure
- Toast notifications appear at top-right with close button

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@drips-wave

drips-wave Bot commented Oct 21, 2026

Copy link
Copy Markdown

@floraispretty 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

@vercel

vercel Bot commented Oct 21, 2026

Copy link
Copy Markdown

@floraispretty is attempting to deploy a commit to the Emmanuel's projects Team on Vercel.

A member of the Team first needs to authorize it.

@emdevelopa
emdevelopa merged commit df91967 into emdevelopa:main Oct 21, 2026
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment