Skip to content

fix: keep the sign of Splitwise balances on import - #806

Open
jayhemnani9910 wants to merge 1 commit into
oss-apps:mainfrom
jayhemnani9910:fix/splitwise-import-balance-sign
Open

jayhemnani9910 wants to merge 1 commit into
oss-apps:mainfrom
jayhemnani9910:fix/splitwise-import-balance-sign

Conversation

@jayhemnani9910

@jayhemnani9910 jayhemnani9910 commented Nov 12, 2026 •

Copy link
Copy Markdown

Importing friend balances from Splitwise drops the minus sign, so a balance you owe is imported as money the friend owes you.

Splitwise returns signed balance strings ({"currency_code":"USD","amount":"-12.50"}). importUserBalanceFromSplitWise parses them with toSafeBigInt(balance.amount), and toSafeBigInt strips - unless signed is true, so -12.50 and 12.50 both become 1250 and both create the same "friend owes me" expense. It now passes signed = true.

Tests: src/tests/splitwiseImport.test.ts imports a -12.50 balance with the database mocked and checks the expense amounts; it fails before the change. jest --config jest.config.ts passes (521).

This change was made with AI assistance, used to trace the cause and draft the test; I reviewed the diff and ran the tests myself.

Summary by CodeRabbit

  • Bug Fixes
    • Splitwise balances with negative values are now imported with the correct sign, so expenses and participant amounts reflect who owes whom.
    • This corrects the amounts shown for transactions where a participant is owed money rather than owing money.

The balance import parsed Splitwise amounts with toSafeBigInt's default
signed=false, which drops the minus sign, so a balance the user owes was
imported as money the friend owes them.
@coderabbitai

coderabbitai Bot commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The Splitwise balance import now converts signed amounts. A test checks that a balance of -12.50 creates expense amounts of -1250n and 1250n.

Changes: Splitwise balance import

Layer / File(s) Summary
Convert signed balances
src/server/api/services/splitService.ts, src/tests/splitwiseImport.test.ts
The import enables sign handling when converting balances. The test checks the expense and participant amounts for a -12.50 balance.

Estimated code review effort: 2 (Simple) | ~5 minutes

Change: Bug fix

Suggested reviewers: krokosik

Merge Risk: Minimal · up to e852b

Splitwise balances that the user owes now keep their negative sign on import, so the expense direction is correct. No actionable merge-blocking risk remains.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: Splitwise balances keep their sign during import. It matches the raw summary, which says the import now parses balances with signed handling enabled, and the descripti…
Description check Passed The description covers the problem, the cause in toSafeBigInt, the fix (passing signed = true), and the test file. It also reports the test result and the full jest run. The template asks for a demo, …
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.
Full details: Title check

Explanation

The title names the main change: Splitwise balances keep their sign during import. It matches the raw summary, which says the import now parses balances with signed handling enabled, and the description, which explains the minus sign was being stripped. The title is concise and specific.

Full details: Description check

Explanation

The description covers the problem, the cause in toSafeBigInt, the fix (passing signed = true), and the test file. It also reports the test result and the full jest run. The template asks for a demo, but this is a backend fix where a screenshot is not useful. The template also asks for related issue or closing keywords, and the description does not include them. The checklist is not marked in the description. These gaps are minor.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bc62d8c1-ef0f-42cc-805a-7b20f47f315f
Commits

Reviewing files that changed from the base of the PR and between 5341ebb and e852bf5.

Files selected for processing: 2

  • src/server/api/services/splitService.ts
  • src/tests/splitwiseImport.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

This branch has not been deployed

No deployments
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