Unified Dashboard
Overview
The Unified Earnings Dashboard combines all three earning systems (Referrals, Rewards, and Points) into a single, cohesive interface. It provides users with a complete view of their earnings, progress, and engagement across the Med.Fun platform.
Purpose
Instead of navigating to separate dashboards for each system, users can:
View total earnings from all sources in one place
Switch between detailed views using tabs
Track combined pending and claimed amounts
Refresh all data simultaneously
Access all earning systems from a single modal
Architecture
Component Structure
UnifiedEarningsDashboard
├── useEarnings (combined data hook)
│ ├── useReferrals
│ ├── useRewards
│ └── usePoints
├── Tabs (navigation)
│ ├── Overview (aggregated summary)
│ ├── Rewards (trading cashback)
│ ├── Referrals (commission earnings)
│ └── Points (gamification)
└── Mobile/Desktop Rendering
├── Sheet (mobile)
└── Dialog (desktop)Data Flow
useEarnings Hook
useEarnings HookLocation: /src/hooks/useEarnings.tsx
Purpose
Combines data from all three earning systems into a single, easy-to-use hook.
Implementation
Usage
Benefits
Single Import: Only need to import one hook
Aggregated Data: Automatic calculation of combined totals
Unified Loading: Single loading state for all systems
Batch Refresh: Refresh all data with one function call
Type Safety: Full TypeScript support
Performance: Hooks run in parallel, not sequentially
Component: UnifiedEarningsDashboard
Location: /src/components/UnifiedEarningsDashboard.tsx
Props
Features
Responsive Design: Adapts to mobile and desktop
Tabbed Interface: Easy navigation between systems
Real-time Updates: Live data via Supabase subscriptions
Summary Cards: Quick overview of key metrics
Detailed Views: Deep dive into each system
Claim Actions: Direct access to claim buttons
Progress Tracking: Visual progress bars for tiers and levels
Tab Structure
Tab 1: Overview (Default)
Purpose: High-level summary of all earning systems
Content:
Total Earnings card (referral + rewards)
Pending Earnings card (claimable amount)
Claimed Earnings card (historical)
Trading Rewards summary (tier, cashback)
Referral Program summary (code, tier, earnings)
Points & Level summary (level, progress, badges)
UI Layout:
Tab 2: Rewards
Purpose: Detailed trading rewards and cashback
Content:
Current tier badge
Pending cashback with claim button
Claimed cashback total
Trading stats (volume, trade count)
Progress to next tier
Cashback earnings history
Features:
Interactive claim button (min $1.00)
Color-coded tier display
Progress bar with percentage
Scrollable earnings list
Real-time balance updates
Tab 3: Referrals
Purpose: Referral program details
Content:
Referral code display
Share link functionality
Total earnings (pending + claimed)
Referral stats (active referrals, volume)
Current tier and benefits
Referral list
Features:
Copy referral link button
Share via native share API
Generate custom code option
Claim earnings button
Tier progress visualization
Tab 4: Points
Purpose: Gamification and level progression
Content:
Current level display
Total points earned
Progress to next level
Earned badges showcase
Recent point transactions
Action history
Features:
Animated progress bar
Badge gallery
Transaction timeline
Point breakdown by action
Level-up celebrations
Responsive Behavior
Desktop (≥768px)
Renders as
DialogcomponentModal overlay with backdrop blur
Fixed width (600px max-width)
Centered on screen
Smooth fade-in animation
Mobile (<768px)
Renders as
Sheetcomponent (bottom sheet)Slides up from bottom
Full-width layout
Swipe-to-dismiss gesture
Native-feeling interactions
Implementation
Integration Examples
Open Dashboard from Button
Display Earnings Summary
Quick Claim Button
User Flows
Flow 1: Check Total Earnings
Flow 2: Claim Pending Earnings
Flow 3: Track Progress
Flow 4: Deep Dive into System
Best Practices
For Developers
1. Always pass userWallet prop:
2. Handle loading states:
3. Use aggregated totals:
4. Refresh all data together:
For Product
1. Overview tab as default
Most users want quick summary first
Deep dives available via tabs
Progressive disclosure of information
2. Clear visual hierarchy
Largest numbers (totals) most prominent
System summaries secondary
Details accessible via tabs
3. Action buttons prominent
Claim buttons easily accessible
Clear minimum thresholds
Disabled state when below minimum
4. Mobile-first design
Bottom sheet on mobile feels native
Swipe gestures intuitive
Content scrolls within sheet
Performance Optimization
Data Fetching
Memoization
Real-time Updates
Each system manages its own subscriptions
Updates propagate through hook return values
No additional subscriptions needed in dashboard
Automatic UI refresh on data changes
Troubleshooting
Data Not Loading
Check:
Is userWallet prop provided?
Check browser console for errors
Verify all three hooks working individually
Check network tab for failed requests
Totals Incorrect
Check:
Verify useEarnings aggregation logic
Check individual hook return values
Ensure all values are numbers (not strings)
Look for null/undefined values
Modal Not Opening
Check:
Is
openprop being controlled?Verify
onOpenChangecallbackCheck for z-index conflicts
Ensure Dialog/Sheet components imported
Tabs Not Switching
Check:
Verify Tabs defaultValue matches TabsTrigger values
Check for JavaScript errors
Ensure TabsContent value matches triggers
Test individual tab components
Future Enhancements
Potential Features
Export Data: Download earnings report as CSV/PDF
Analytics: Charts showing earnings over time
Notifications: Alert when claim threshold reached
Filters: Filter earnings by date range
Search: Search transaction history
Breakdown: Pie chart of earnings by source
Goals: Set and track earning goals
Achievements: Special badges for milestones
Technical Improvements
Caching: Cache aggregated data for faster loads
Pagination: Paginate transaction histories
Virtual Scrolling: For long transaction lists
Optimistic Updates: Instant UI feedback
Offline Support: View data while offline
Progressive Loading: Load overview first, details later
Last updated
Was this helpful?