Skip to content

fix(swaps): skip fee calc quietly for unverified swaps - #54

Merged
kaladinlight merged 3 commits into
developfrom
fix/affiliate-swaps-quiet-fee-skip
Jul 8, 2026
Merged

fix(swaps): skip fee calc quietly for unverified swaps#54
kaladinlight merged 3 commits into
developfrom
fix/affiliate-swaps-quiet-fee-skip

Conversation

@kaladinlight

@kaladinlight kaladinlight commented Jul 8, 2026

Copy link
Copy Markdown
Member

Description

The partner swaps listing (getAffiliateSwaps) queries by partnerCode only — no isAffiliateVerified/status filter — so it intentionally includes failed/unverified swaps to display them, then runs each through calculateFeeForSwap. For a failed/unverified row (no affiliateVerificationDetails), that logged a misleading WARN [SwapsService] Verified swap <id> missing affiliate bps in verification details, skipping on every fetch, even though the row correctly resolves to null fees.

verifySwap only sets isAffiliateVerified = true for a successful affiliate swap (failed/pending/no-affiliate → false), so it's the clean gate. Add an early return null on !isAffiliateVerified in calculateFeeForSwap: 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 calculateFeeForSwap so all callers benefit (getAffiliateSwaps, getPartnerStats, calculateReferralFees); the stats paths already filter isAffiliateVerified: true so their behavior is unchanged.

Testing

  • yarn test swaps/__tests__/utils.test.ts — 4/4 pass, including a new case asserting an unverified swap returns null without logging a warning (spies on Logger.prototype.warn).

Summary by CodeRabbit

  • Bug Fixes
    • Fee calculation now safely returns no fee for swaps that are not affiliate-verified.
    • Reduced unnecessary warning messages for swaps that should be skipped quietly.
    • Updated test coverage to reflect the new behavior and default swap setup.

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>
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@kaladinlight, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 27 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f315ba11-2534-417b-b058-af1017988262

📥 Commits

Reviewing files that changed from the base of the PR and between 252453d and 9677de2.

📒 Files selected for processing (2)
  • apps/swap-service/src/swaps/swaps.service.ts
  • apps/swap-service/src/swaps/utils.ts
📝 Walkthrough

Walkthrough

The calculateFeeForSwap function now returns null immediately when swap.isAffiliateVerified is false, bypassing subsequent affiliate-detail checks and warnings. Tests were updated: makeSwap defaults isAffiliateVerified to true, and a new test verifies the null return without triggering Logger.prototype.warn.

Changes

Affiliate Verification Guard

Layer / File(s) Summary
Early return guard for unverified swaps
apps/swap-service/src/swaps/utils.ts
calculateFeeForSwap returns null immediately when swap.isAffiliateVerified is false, skipping affiliate-detail checks and warnings.
Test helper and coverage update
apps/swap-service/src/swaps/__tests__/utils.test.ts
makeSwap defaults isAffiliateVerified to true; new test confirms calculateFeeForSwap returns null without warning when the swap is not affiliate-verified.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Possibly related PRs

Poem

A hop, a skip, a guard so neat,
Unverified swaps just quietly retreat 🐇
No warnings shout, no logs to fill,
Just null returned, calm and still,
This bunny cheers the tidy code —
Another clean commit down the road! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: unverified swaps now skip fee calculation quietly.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/affiliate-swaps-quiet-fee-skip

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.

❤️ Share

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0f6ad85 and 252453d.

📒 Files selected for processing (2)
  • apps/swap-service/src/swaps/__tests__/utils.test.ts
  • apps/swap-service/src/swaps/utils.ts

Comment thread apps/swap-service/src/swaps/__tests__/utils.test.ts
kaladinlight and others added 2 commits July 8, 2026 14:53
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>
@kaladinlight
kaladinlight merged commit 54aec74 into develop Jul 8, 2026
2 checks passed
@kaladinlight
kaladinlight deleted the fix/affiliate-swaps-quiet-fee-skip branch July 8, 2026 21:12
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