fix(swaps): skip fee calc quietly for unverified swaps - #54
Conversation
The partner swaps listing (getAffiliateSwaps) passes every partnerCode swap through calculateFeeForSwap, including failed/unverified ones with no affiliateVerificationDetails — which logged a misleading "Verified swap ... missing affiliate bps" WARN on every fetch. Add an early return on !isAffiliateVerified: those legitimately have no fee, so return null silently. The WARN now fires only for the genuinely unexpected case (a verified swap missing bps/sell amount). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
Warning Review limit reached
Next review available in: 27 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe ChangesAffiliate Verification Guard
Estimated code review effort: 1 (Trivial) | ~5 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@apps/swap-service/src/swaps/__tests__/utils.test.ts`:
- Around line 34-40: The test in utils.test.ts leaves a prototype spy on
Logger.prototype.warn active after the non-affiliate-verified swap case, which
can leak into later tests. Restore the spy after this test by calling the mock’s
restore method in a cleanup path, or add a describe-level afterEach with
jest.restoreAllMocks() so calculateFeeForSwap and the Logger.warn spy don’t
affect other cases.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 4df70059-0790-4727-87b1-664a72a54d30
📒 Files selected for processing (2)
apps/swap-service/src/swaps/__tests__/utils.test.tsapps/swap-service/src/swaps/utils.ts
The FAILED short-circuit in verifySwap set isAffiliateVerified=false but left any prior affiliateVerificationDetails intact, so a previously-verified swap re-processed while FAILED could carry stale details. Null them out so the invariant holds: isAffiliateVerified=false always implies null details. This lets calculateFeeForSwap rely solely on the !isAffiliateVerified early return. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Description
The partner swaps listing (
getAffiliateSwaps) queries bypartnerCodeonly — noisAffiliateVerified/statusfilter — so it intentionally includes failed/unverified swaps to display them, then runs each throughcalculateFeeForSwap. For a failed/unverified row (noaffiliateVerificationDetails), that logged a misleadingWARN [SwapsService] Verified swap <id> missing affiliate bps in verification details, skippingon every fetch, even though the row correctly resolves to null fees.verifySwaponly setsisAffiliateVerified = truefor a successful affiliate swap (failed/pending/no-affiliate → false), so it's the clean gate. Add an earlyreturn nullon!isAffiliateVerifiedincalculateFeeForSwap: those legitimately have no fee, so skip silently. The WARN now fires only for the genuinely unexpected case — a verified swap missing bps/sell amount.Centralized in
calculateFeeForSwapso all callers benefit (getAffiliateSwaps,getPartnerStats,calculateReferralFees); the stats paths already filterisAffiliateVerified: trueso their behavior is unchanged.Testing
yarn test swaps/__tests__/utils.test.ts— 4/4 pass, including a new case asserting an unverified swap returnsnullwithout logging a warning (spies onLogger.prototype.warn).Summary by CodeRabbit