Points System

Overview

The Med.Fun points system is a gamification layer that rewards users for platform engagement. Users earn points for various activities, level up as they accumulate points, and unlock badges at milestone levels.

How It Works

  1. Earn Points: Complete actions like trading, logging in, creating tokens, referring friends

  2. Accumulate: Points are added to your total permanently (no decay)

  3. Level Up: Every 1,000 points equals one level

  4. Unlock Badges: Earn special badges at levels 5, 10, 20, and 50

  5. Track Progress: View point history and progress to next level

  6. Recognition: Display your level and badges on your profile

Database Schema

user_points

Main table storing user point totals and progression.

Column
Type
Nullable
Default
Description

id

uuid

No

gen_random_uuid()

Primary key

user_wallet

text

No

-

User's wallet address

total_points

integer

No

0

Cumulative points

level

integer

No

1

Current level

badges

jsonb

No

[]

Array of earned badges

created_at

timestamptz

No

now()

Account creation

updated_at

timestamptz

No

now()

Last point change

Constraints:

  • Unique index on user_wallet

  • Check: total_points >= 0

  • Check: level >= 1

RLS Policies:

  • Users can view their own points

  • Users can create their initial points record

  • Users can update their own points

  • System can insert/update points

point_transactions

Historical record of all point-earning activities.

Column
Type
Nullable
Default
Description

id

uuid

No

gen_random_uuid()

Primary key

user_wallet

text

No

-

User's wallet address

points

integer

No

-

Points awarded (can be negative)

action_type

text

No

-

Type of action

description

text

Yes

null

Human-readable description

metadata

jsonb

Yes

{}

Additional context data

created_at

timestamptz

No

now()

Transaction timestamp

Common Action Types:

  • daily_login - Daily login bonus

  • trade_completed - Completed a trade

  • token_created - Created a new token

  • referral - Referred a friend

  • comment - Left a comment

  • stream_started - Started a livestream

  • achievement - Unlocked an achievement

Constraints:

  • Foreign key to user_points(user_wallet) (conceptual)

RLS Policies:

  • Users can view their own transactions

  • System can insert transactions

Point Earning Activities

Default Point Values

Action
Points
Description

Daily Login

+10

First login each day

Complete Trade

+50

Buy or sell tokens

Create Token

+200

Launch a new token

Refer Friend

+100

Friend signs up with your code

Leave Comment

+5

Comment on a token

Start Stream

+150

Go live on a token

Unlock Achievement

Varies

Special achievements

Custom Point Awards

The system supports custom point awards with metadata:

Negative Points

While not commonly used, the system supports negative point values for penalties:

Level System

Level Calculation

Formula: Level = floor(totalPoints / 1000) + 1

Examples:

  • 0-999 points = Level 1

  • 1,000-1,999 points = Level 2

  • 2,000-2,999 points = Level 3

  • 10,000-10,999 points = Level 11

Points Per Level

Each level requires 1,000 points. This creates a linear progression system that's easy to understand and predict.

Level Progress Tracking

Calculate current level:

Calculate progress within current level:

Calculate points to next level:

Level Benefits

While the current system is primarily recognition-based, levels can be used to unlock features:

Potential Level Benefits:

  • Access to exclusive channels

  • Custom profile badges

  • Priority customer support

  • Early access to new features

  • Reduced trading fees

  • Enhanced referral rates

Badge System

Badge Definitions

Badge Unlocking

Badges are automatically awarded when users reach the required level:

Badge
Level Required
Points Required
Icon

Bronze Explorer

5

4,000+

πŸ₯‰

Silver Trader

10

9,000+

πŸ₯ˆ

Gold Master

20

19,000+

πŸ₯‡

Diamond Legend

50

49,000+

πŸ’Ž

Badge Storage

Badges are stored as a JSONB array in the user_points table:

Badge Display

Badges can be displayed in:

  • User profiles

  • Leaderboards

  • Chat messages

  • Point dashboard

Point Transactions

Transaction Structure

Each transaction represents a single point-earning (or losing) event:

Transaction History

The system maintains a complete history of all point transactions, limited to the most recent 50 entries per user:

Metadata Usage

Metadata can store contextual information about point awards:

Real-time Updates

Supabase Subscriptions

Points Updates:

Transaction Updates:

Auto-refresh

When points change, the UI automatically:

  1. Recalculates level

  2. Updates progress bar

  3. Checks for new badges

  4. Refreshes transaction history

  5. Shows toast notification for level-ups and badges

Frontend Components

usePoints Hook

Location: /src/hooks/usePoints.tsx

Purpose: Manages all point-related data and operations

State Management:

Key Functions:

addPoints:

fetchPointsData:

PointsDashboard Component

Location: /src/components/PointsDashboard.tsx

Features:

  • Current level and progress display

  • Points to next level

  • Badge showcase

  • Point transaction history

  • Animated progress bar

  • Mobile-responsive design

UI Structure:

Integration Points

Award Points on Trade

Award Points on Token Creation

Daily Login Bonus

Referral Bonus

User Flows

Flow 1: First Time User

Flow 2: Level Up

Flow 3: Badge Unlock

Flow 4: View History

Best Practices

For Developers

1. Always validate point amounts:

2. Use descriptive action types:

3. Include metadata for context:

4. Handle errors gracefully:

For Product

1. Point values should feel rewarding

  • Small actions: 5-10 points

  • Medium actions: 50-100 points

  • Large actions: 150-200 points

2. Level progression should be achievable

  • 1,000 points per level = 20 trades per level

  • First badge at level 5 = ~80-100 actions

  • Keeps users engaged without feeling impossible

3. Badges should be meaningful

  • Tied to significant milestones

  • Not too easy or too hard to obtain

  • Visual recognition is important

4. Transaction history builds trust

  • Users can verify point awards

  • Transparency in gamification

  • Helps debug issues

Troubleshooting

Points Not Adding

Check:

  1. Is wallet connected?

  2. Does user_points record exist?

  3. Check browser console for errors

  4. Verify database connection

  5. Check RLS policies

Level Not Updating

Check:

  1. Verify calculation: floor(totalPoints / 1000) + 1

  2. Check if database was updated

  3. Verify real-time subscription is active

  4. Try manual refresh

Badges Not Appearing

Check:

  1. Is user at required level?

  2. Check badges array in database

  3. Verify LEVEL_BADGES constant

  4. Check badge comparison logic

Duplicate Transactions

Prevent:

Performance Considerations

Database Indexes

Query Optimization

  • Limit transaction history to 50 most recent

  • Use single query for user points (don't aggregate transactions)

  • Cache badge definitions in application layer

  • Use database triggers for automatic level calculation

Caching Strategy

Future Enhancements

Potential Features

  • Leaderboards: Top point earners displayed publicly

  • Daily Challenges: Bonus points for specific actions

  • Point Multipliers: 2x points during events

  • Point Shop: Spend points on perks

  • Achievement System: Complex multi-step achievements

  • Seasonal Badges: Limited-time special badges

  • Point Decay: Points expire after inactivity (optional)

Technical Improvements

  • Database trigger for automatic level calculation

  • Point expiration system

  • Batch point awards for efficiency

  • Analytics dashboard for point distribution

  • A/B testing framework for point values

Last updated

Was this helpful?