-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Fix the logging #2623
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the logging #2623
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
WalkthroughThe 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
Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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
📒 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...`, |
There was a problem hiding this comment.
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.tsLength 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.
Summary by CodeRabbit