Skip to content

feat(referral): switch to link-based claims with flat $5 rewards#546

Merged
senamakel merged 2 commits into
tinyhumansai:mainfrom
senamakel:feat/referral
Apr 13, 2026
Merged

feat(referral): switch to link-based claims with flat $5 rewards#546
senamakel merged 2 commits into
tinyhumansai:mainfrom
senamakel:feat/referral

Conversation

@senamakel
Copy link
Copy Markdown
Member

@senamakel senamakel commented Apr 13, 2026

Summary

  • Rename endpoint POST /referral/applyPOST /referral/claim (Rust RPC + frontend API client)
  • Update reward model from percentage-based (20% BPS) to flat $5 credit for both referrer and referred user
  • Remove rewardRateBps from types, API normalization, and UI display
  • Update UI copy to communicate the new $5-per-referral structure and subscription-based eligibility
  • Update mock server, tests, and Referral-doc.md to reflect the new system

Mirrors backend changes from tinyhumansai/backend#631.

Test plan

  • Rust core compiles (cargo check)
  • TypeScript typechecks (tsc --noEmit)
  • All 13 referral API unit tests pass (vitest)
  • Manual: verify referral stats page shows "$5" copy instead of percentage
  • Manual: verify claiming a referral via onboarding step calls /referral/claim
  • Manual: verify share/copy link works on rewards page

Summary by CodeRabbit

  • New Features

    • Referral program updated: Both referrer and referred users now receive a flat $5 account credit when the referred user's first subscription is confirmed.
    • Referral links can only be claimed before subscribing.
  • UI Updates

    • Removed reward percentage display; simplified referral messaging to clearly communicate the $5 credit benefit for both parties.

…structure

- Transitioned to a link-based referral system offering a one-time $5 credit to both the referrer and the referred user upon the first subscription payment.
- Removed the previous reward rate in basis points and eliminated recurring rewards, ensuring clarity in the referral process.
- Updated API endpoints and service methods to reflect the new `claimReferral` functionality, enhancing user experience and eligibility checks.
- Revised documentation and tests to align with the new referral structure, ensuring comprehensive coverage and understanding of the changes.
… function

- Streamlined the `handle_referral_claim` function by removing unnecessary `as_deref()` and `filter()` calls, enhancing code clarity and performance.
- Updated the JSON response construction to eliminate redundant line breaks, improving readability without altering functionality.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 13, 2026

📝 Walkthrough

Walkthrough

The referral system transitions from a percentage-based apply-code model with configurable recurring rewards to a link-based flat-$5 one-time claim model. Both referrer and referred user receive $5 credit upon the referred user's first confirmed subscription payment. The API endpoint changes from /referral/apply to /referral/claim.

Changes

Cohort / File(s) Summary
Documentation Updates
referral-doc.md
Replaces percentage-based payment reward model with flat $5 one-time rewards; changes rules from configurable apply/recurring behavior to subscription-gated claim-before-payment requirement; removes RECURRING_REFERRAL_REWARD configuration; updates ReferralTransaction with recipientType field.
Frontend API Service
app/src/services/api/referralApi.ts, app/src/services/api/__tests__/referralApi.test.ts
Renames applyCode to claimReferral; updates RPC command from openhuman.referral_apply to openhuman.referral_claim; removes rewardRateBps parsing and normalization from normalizeReferralStats.
Frontend UI Components
app/src/components/referral/ReferralRewardsSection.tsx, app/src/pages/onboarding/steps/ReferralApplyStep.tsx
Updates form submission to call claimReferral instead of applyCode; replaces "eligible payments share" UI with fixed "$5 monthly plan credit" copy; removes reward-rate percentage display.
Type Definitions
app/src/types/referral.ts
Removes rewardRateBps field from ReferralStats interface; updates canApplyReferral documentation to reference "claim" eligibility instead of "apply".
Backend Rust Operations
src/openhuman/referral/ops.rs
Renames public function from apply_code to claim_referral; updates POST endpoint from /referral/apply to /referral/claim; retains same parameter signature and request body construction.
Backend Schema & Controller
src/openhuman/referral/schemas.rs
Renames ReferralApplyParams to ReferralClaimParams; updates controller registration from referral_apply/handle_referral_apply to referral_claim/handle_referral_claim; changes handler to call claim_referral instead of apply_code.
Mock & Test Data
scripts/mock-api-core.mjs
Updates /referral/stats mock to remove rewardRateBps, increase totalRewardUsd from 4.2 to 10, change individual reward from 2.1 to 5; replaces /referral/apply endpoint with /referral/claim with updated success message.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

  • PR #430: Directly modifies the same referral feature codepaths, renaming apply→claim RPC operations and updating client APIs alongside referral stats normalization.
  • PR #457: Related changes to ReferralApplyStep.tsx affecting the referral onboarding flow's apply/claim handler and error handling.

Poem

🐰 No more percentages in the warren's care,
Five silver dollars now float in the air!
Claim your link before subscription day,
Both rabbits rejoice in the flat-reward way! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: switching from a percentage-based referral system to a link-based flat $5 reward model, which is reflected consistently across all modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@senamakel
Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 13, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
app/src/types/referral.ts (1)

33-34: Consider renaming canApplyReferral to canClaimReferral for consistency.

The JSDoc correctly describes the "claim" semantics, but the property name still uses "apply" terminology. While this is a minor inconsistency and doesn't affect functionality, renaming it would align with the new endpoint naming throughout the codebase.

♻️ Suggested rename
-  /** When false, user likely cannot claim (e.g. already subscribed); optional from backend */
-  canApplyReferral?: boolean;
+  /** When false, user likely cannot claim (e.g. already subscribed); optional from backend */
+  canClaimReferral?: boolean;

Note: This would require updating usages in ReferralRewardsSection.tsx and referralApi.ts normalization logic.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@app/src/types/referral.ts` around lines 33 - 34, The property name
canApplyReferral should be renamed to canClaimReferral to match the "claim"
semantics; update the type declaration (canApplyReferral?: boolean →
canClaimReferral?: boolean in the referral type), refactor all uses of
canApplyReferral (including UI consumption in ReferralRewardsSection.tsx) to
canClaimReferral, and adjust the referral API normalization logic in
referralApi.ts to map the backend field to canClaimReferral so runtime data
binding stays correct.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@app/src/types/referral.ts`:
- Around line 33-34: The property name canApplyReferral should be renamed to
canClaimReferral to match the "claim" semantics; update the type declaration
(canApplyReferral?: boolean → canClaimReferral?: boolean in the referral type),
refactor all uses of canApplyReferral (including UI consumption in
ReferralRewardsSection.tsx) to canClaimReferral, and adjust the referral API
normalization logic in referralApi.ts to map the backend field to
canClaimReferral so runtime data binding stays correct.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 0ac3b9f8-d7e0-4c37-8cbf-08150ec8b3d9

📥 Commits

Reviewing files that changed from the base of the PR and between 08d9fd2 and 4dd7570.

📒 Files selected for processing (9)
  • Referral-doc.md
  • app/src/components/referral/ReferralRewardsSection.tsx
  • app/src/pages/onboarding/steps/ReferralApplyStep.tsx
  • app/src/services/api/__tests__/referralApi.test.ts
  • app/src/services/api/referralApi.ts
  • app/src/types/referral.ts
  • scripts/mock-api-core.mjs
  • src/openhuman/referral/ops.rs
  • src/openhuman/referral/schemas.rs

@senamakel senamakel merged commit f26a0c5 into tinyhumansai:main Apr 13, 2026
8 of 9 checks passed
AusAgentSmith pushed a commit to AusAgentSmith/openhuman that referenced this pull request May 23, 2026
…yhumansai#546)

* refactor(referral): update referral system to a one-time flat reward structure

- Transitioned to a link-based referral system offering a one-time $5 credit to both the referrer and the referred user upon the first subscription payment.
- Removed the previous reward rate in basis points and eliminated recurring rewards, ensuring clarity in the referral process.
- Updated API endpoints and service methods to reflect the new `claimReferral` functionality, enhancing user experience and eligibility checks.
- Revised documentation and tests to align with the new referral structure, ensuring comprehensive coverage and understanding of the changes.

* refactor(referral): simplify JSON response handling in referral claim function

- Streamlined the `handle_referral_claim` function by removing unnecessary `as_deref()` and `filter()` calls, enhancing code clarity and performance.
- Updated the JSON response construction to eliminate redundant line breaks, improving readability without altering functionality.
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.

1 participant