Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@devkiran
Copy link
Collaborator

@devkiran devkiran commented Jul 8, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Improved accuracy of available balance display by standardizing the formatting, ensuring consistent output across different currencies.

@vercel
Copy link
Contributor

vercel bot commented Jul 8, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
dub ✅ Ready (Inspect) Visit Preview Jul 8, 2025 4:41pm

@devkiran devkiran requested a review from steven-tey July 8, 2025 16:31
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jul 8, 2025

Walkthrough

The code change removes the currency-specific adjustment for zero-decimal currencies when logging the available balance. Instead, it now logs the available balance directly divided by 100, without considering currency-specific formatting. The function's control flow and error handling remain unchanged.

Changes

File(s) Change Summary
apps/web/app/(ee)/api/stripe/connect/webhook/balance-available.ts Removed conditional adjustment for zero-decimal currencies; logs available balance as raw value/100

Possibly related PRs

Suggested reviewers

  • steven-tey

Poem

A balance once twisted by currency’s dance,
Now logs with a simpler, more straightforward glance.
No more decimals to ponder or chase,
Just numbers divided, a much cleaner space.
The rabbit approves, with a hop and a cheer—
Simpler code is always dear! 🐇

✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
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.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c129e82 and 2bd9923.

📒 Files selected for processing (1)
  • apps/web/app/(ee)/api/stripe/connect/webhook/balance-available.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/web/app/(ee)/api/stripe/connect/webhook/balance-available.ts (1)
packages/utils/src/functions/currency-formatter.ts (1)
  • currencyFormatter (1-11)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build


console.log(
`The adjusted available balance (${currencyFormatter(adjustedBalanceInCents / 100, { maximumFractionDigits: 2 })}) for partner ${partner.email} (${stripeAccount}) is less than or equal to 0 after subtracting pending payouts. Skipping...`,
`The available balance (${currencyFormatter(availableBalance / 100, { maximumFractionDigits: 2 })}) for partner ${partner.email} (${stripeAccount}) is less than or equal to 0 after subtracting pending payouts. Skipping...`,
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Critical bug: Incorrect currency formatting for zero-decimal currencies

The removal of currency-specific adjustment introduces a critical bug. Dividing availableBalance by 100 is incorrect for zero-decimal currencies (JPY, KRW, etc.) where Stripe stores amounts in base units, not cents.

Apply this diff to fix the currency formatting:

-      `The available balance (${currencyFormatter(availableBalance / 100, { maximumFractionDigits: 2 })}) for partner ${partner.email} (${stripeAccount}) is less than or equal to 0 after subtracting pending payouts. Skipping...`,
+      `The available balance (${currencyFormatter(
+        ZERO_DECIMAL_CURRENCIES.includes(currency.toUpperCase()) 
+          ? availableBalance 
+          : availableBalance / 100, 
+        { maximumFractionDigits: 2 }, 
+        currency
+      )}) for partner ${partner.email} (${stripeAccount}) is less than or equal to 0 after subtracting pending payouts. Skipping...`,

Check if this same issue exists in other logging statements:


🏁 Script executed:

#!/bin/bash
# Description: Find all currencyFormatter calls to verify currency parameter usage
# Expected: Should show calls without currency parameter that need fixing

rg -A 2 -B 2 "currencyFormatter.*/" 

Length of output: 68298


🏁 Script executed:

#!/bin/bash
# Show imports and ZERO_DECIMAL_CURRENCIES logic for currency adjustments
rg -n -A5 -B5 "ZERO_DECIMAL_CURRENCIES" apps/web/app/\(ee\)/api/stripe/connect/webhook/balance-available.ts

Length of output: 654


Critical bug: Incorrect formatting of zero-decimal currencies in Stripe balance webhook logs

The webhook always divides raw Stripe amounts by 100, which breaks JPY, KRW, etc. (they’re already in base units). All currencyFormatter calls on Stripe values in this file must respect ZERO_DECIMAL_CURRENCIES and pass the currency code.

Locations to update in apps/web/app/(ee)/api/stripe/connect/webhook/balance-available.ts:

  • Available-balance skip log (≈ line 105)
  • Min-withdrawal check log (converted USD; enforce 'USD')
  • Error message mapping of transfers.data
  • Payout success log

Example helper + diffs:

// add near top of file, after imports
function formatRaw(value: number) {
  const amount = ZERO_DECIMAL_CURRENCIES.includes(currency.toUpperCase())
    ? value
    : value / 100;
  return currencyFormatter(amount, { maximumFractionDigits: 2 }, currency);
}
- `The available balance (${currencyFormatter(availableBalance / 100, { maximumFractionDigits: 2 })}) …`
+ `The available balance (${formatRaw(availableBalance)}) …`

- `… (${currencyFormatter(convertedUsdAmount / 100, { maximumFractionDigits: 2 })})`
+ `… (${currencyFormatter(convertedUsdAmount / 100, { maximumFractionDigits: 2 }, 'USD')})`

- transfers.data.map(t => currencyFormatter(t.amount / 100))
+ transfers.data.map(t => formatRaw(t.amount))

- `${currencyFormatter(payout.amount / 100, { maximumFractionDigits: 2 })}`
+ `${formatRaw(payout.amount)}`
🤖 Prompt for AI Agents
In apps/web/app/(ee)/api/stripe/connect/webhook/balance-available.ts at line 105
and other related log lines, the code incorrectly divides all Stripe amounts by
100 before formatting, which breaks zero-decimal currencies like JPY and KRW. To
fix this, implement a helper function that checks if the currency is in
ZERO_DECIMAL_CURRENCIES and only divides by 100 if not, then use this helper to
format all Stripe amounts consistently by passing the currency code. Update the
available-balance skip log, min-withdrawal check log (forcing 'USD'), error
message mapping for transfers.data, and payout success log to use this helper
for correct currency formatting.

@steven-tey steven-tey merged commit 24926db into main Jul 8, 2025
9 of 10 checks passed
@steven-tey steven-tey deleted the fix-balance-log branch July 8, 2025 18:33
@coderabbitai coderabbitai bot mentioned this pull request Jul 11, 2025
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.

3 participants