Skip to content

feat: implement milestone reward auto-distribution calculator - #395

Open
zeroknowledge0x wants to merge 2 commits into
PhasoraLabs:mainfrom
zeroknowledge0x:feat/reward-calculator
Open

feat: implement milestone reward auto-distribution calculator#395
zeroknowledge0x wants to merge 2 commits into
PhasoraLabs:mainfrom
zeroknowledge0x:feat/reward-calculator

Conversation

@zeroknowledge0x

Copy link
Copy Markdown

Summary

Implements the RewardCalculator component for automatic budget distribution across milestones in the Create Grant form.

Changes

  • components/grants/CreateGrantForm/RewardCalculator.tsx — New component with three distribution modes:

    • Equal split — Divides budget evenly, last milestone gets rounding remainder
    • Front-loaded — 50% first milestone, 30% second, remainder split among rest
    • Custom weight — Slider-based (1–10) proportional distribution with real-time preview
    • Undo button — Reverts to previous values within 5 seconds
    • Edge cases handled: 0 budget, 0 milestones, rounding to 2 decimal places
  • tests/components/RewardCalculator.test.tsx — Comprehensive test suite covering:

    • Disabled states (0 budget, 0 milestones)
    • Equal split with rounding verification
    • Front-loaded distribution for 1, 2, and 3+ milestones
    • Custom weight distribution
    • Undo functionality with timer
    • Decimal precision and sum verification

Testing

  • Clicking "Split equally" fills all milestone rewards with equal amounts summing to totalBudget
  • Clicking "Front-load" fills first milestone with ~50% and remaining split among others
  • Custom weight sliders update reward fields in real time
  • "Undo" button appears after distribution and reverts previous values
  • Edge cases: 1 milestone, 0 budget, rounding errors

Related Issues

Fixes #391

unsiqasik added 2 commits May 29, 2026 08:03
Add RewardCalculator component that provides three distribution modes
for splitting grant budgets across milestones.

Features:
- Equal split: divides budget evenly, last milestone gets rounding remainder
- Front-loaded: 50% first, 30% second, remainder split among rest
- Custom weight: slider-based (1-10) proportional distribution
- Undo button: reverts to previous values within 5 seconds
- Edge cases: handles 0 budget, 0 milestones, rounding to 2 decimals

Files:
- components/grants/CreateGrantForm/RewardCalculator.tsx
- tests/components/RewardCalculator.test.tsx

Fixes PhasoraLabs#391
The useEffect properly guards against unnecessary updates by checking
prev.length === milestoneCount. This pattern is intentional for resizing
the weights array when milestone count changes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement Milestone Reward Auto-Distribution Calculator

1 participant