Add Achievement System to Progress Tracker - #381
Merged
Conversation
|
@rhemy-arc 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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Here's a comprehensive PR message for the achievement system implementation:
Add Achievement System to Progress Tracker
Summary
Implements a gamification achievement system that tracks learner milestones to drive engagement and motivate continued learning. The system awards achievements for key learning milestones and makes them queryable via on-chain functions.
Changes
Added Achievement struct with fields: achievement_type, earned_at, and optional course_id
Added AchievementType enum with values: FirstCourse, PerfectScore, SpeedLearner, CourseMaster, PerfectCourse
Extended ProgressTrackerDataKey enum with: Achievements(Address) and AchievementEarned(Address, AchievementType)
2. Achievement Functions (lib.rs):
earn_achievement(): Internal function that checks for duplicates before awarding achievements
get_achievements(): Public query function to retrieve all achievements for a learner
has_achievement(): Public query to check if a learner has earned a specific achievement type
3. Achievement Triggers:
FirstCourse: Awarded when eligible_for_credential becomes true (course completion)
PerfectScore: Awarded when submitting a quiz with 100% score
CourseMaster: Awarded when completing 5+ courses (checks via get_learner_stats)
4. Events:
Added achievement_earned event emitted when any achievement is earned
Key Features
✅ Achievements are tracked - Each achievement is stored with timestamp and optional course context ✅ Achievements are queryable - get_achievements() returns chronological list, has_achievement() checks specific types ✅ Achievements emit events - achievement_earned events notify indexers in real-time ✅ Achievement types are extensible - Enum-based design allows easy addition of new achievement types
Technical Details
Achievements are stored in two keys: list of all achievements per learner, and deduplication map
Internal earn_achievement() prevents duplicate awards for same achievement type
Achievements automatically trigger when relevant milestones are reached (no manual claiming needed)
Achievement data is persisted with TTL extensions for long-term storage
Testing Considerations
FirstCourse achievement triggers when credential eligibility is reached
PerfectScore achievement triggers on quiz submissions with score=100
CourseMaster achievement triggers when 5+ courses completed
Events are emitted for indexer consumption
Query functions return empty lists for learners with no achievements
Future Extensions
The system is designed to be easily extended with:
Additional achievement types (e.g., PerfectCourse for 100% completion)
SpeedLearner achievement (requires tracking course completion timestamps)
Achievement badges or visual representations in frontend
Achievement-based rewards or leaderboards
Closes #258
Closes #257
Closes #256
Closes #255