Skip to content

Round remaining balance - #3233

Merged
seefs001 merged 1 commit into
QuantumNous:mainfrom
KiGamji:round-remaining-balance
Mar 14, 2026
Merged

Round remaining balance#3233
seefs001 merged 1 commit into
QuantumNous:mainfrom
KiGamji:round-remaining-balance

Conversation

@KiGamji

@KiGamji KiGamji commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

closes #3230

Summary by CodeRabbit

  • Improvements
    • Currency quota amounts now show consistent two-decimal formatting for non-token currencies, with invalid values left unchanged.
    • Balance tags display the reformatted amounts for clearer precision.
    • Balance tooltips updated for clearer localization and consistent presentation; token-based balances remain unchanged.

@KiGamji
KiGamji force-pushed the round-remaining-balance branch 2 times, most recently from c4b7067 to 1be40f0 Compare March 12, 2026 14:15
@coderabbitai

coderabbitai Bot commented Mar 12, 2026

Copy link
Copy Markdown
Contributor

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bc17e9f5-4870-41b4-9ddd-db8e62445793

📥 Commits

Reviewing files that changed from the base of the PR and between 2ab208c and 453c58e.

📒 Files selected for processing (2)
  • web/src/components/table/channels/ChannelsColumnDefs.jsx
  • web/src/helpers/render.jsx
🚧 Files skipped from review as they are similar to previous changes (2)
  • web/src/helpers/render.jsx
  • web/src/components/table/channels/ChannelsColumnDefs.jsx

Walkthrough

The renderQuotaWithAmount() function in web/src/helpers/render.jsx now coerces non-TOKENS amounts to numeric values and formats finite numbers to two decimal places before display; web/src/components/table/channels/ChannelsColumnDefs.jsx now composes a localized tooltip that uses this formatter for the remaining balance display.

Changes

Cohort / File(s) Summary
Currency Formatting
web/src/helpers/render.jsx
Coerce amount to Number, detect finite numericAmount, create formattedAmount with two decimals for CNY, CUSTOM, and USD branches; TOKENS branch unchanged.
Balance Tooltip Localization
web/src/components/table/channels/ChannelsColumnDefs.jsx
Replace simple concatenation with localized composition: t('剩余额度') + ': ' + renderQuotaWithAmount(record.balance) + t(',点击更新'); visible tag continues to use renderQuotaWithAmount(record.balance).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I nibbled numbers, neat and bright,
I curled them to two decimals' light,
Tooltips whisper, tidy and clear,
Balances hop, now trimmed and dear,
A rabbit nods—small change, delight.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately reflects the main change: numeric formatting/rounding of remaining balance values to fix UI layout issues.
Linked Issues check ✅ Passed The PR implements rounding of remaining balance values through renderQuotaWithAmount() function, directly addressing the UI layout issue shown in #3230.
Out of Scope Changes check ✅ Passed All changes are directly scoped to implementing balance rounding: the formatting logic in render.jsx and its integration in ChannelsColumnDefs.jsx tooltip.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan for PR comments
  • Generate coding plan

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 and usage tips.

@KiGamji
KiGamji force-pushed the round-remaining-balance branch 3 times, most recently from a74d945 to 7beb97e Compare March 12, 2026 14:24

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

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 the current code and only fix it if needed.

Inline comments:
In `@web/src/components/table/channels/ChannelsColumnDefs.jsx`:
- Around line 540-542: Add the new Chinese source string used in
ChannelsColumnDefs.jsx — the t('剩余额度:{{amount}},点击更新', { amount:
renderQuotaWithAmount(record.balance) }) call — to each locale file as a flat
JSON key (use the Chinese string as the key) and provide the corresponding
localized values for zh-CN.json (same Chinese text) and en.json (English
translation, e.g. "Remaining quota: {{amount}}, click to update"). Ensure both
files remain flat JSON objects and include the exact Chinese key so i18n lookup
succeeds for non-Chinese locales.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d60e4609-4105-45b8-bc42-8e014aa3fbb2

📥 Commits

Reviewing files that changed from the base of the PR and between 1f43cc9 and 7beb97e.

📒 Files selected for processing (2)
  • web/src/components/table/channels/ChannelsColumnDefs.jsx
  • web/src/helpers/render.jsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • web/src/helpers/render.jsx

Comment on lines +540 to +542
content={t('剩余额度:{{amount}},点击更新', {
amount: renderQuotaWithAmount(record.balance),
})}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add the new interpolated key to locale files before shipping.

This new t('剩余额度:{{amount}},点击更新', …) key is not present in the provided locale resources (web/src/i18n/locales/zh-CN.json:1-50 and web/src/i18n/locales/en.json:1-50), so non-Chinese users will see the raw Chinese source string in the tooltip instead of a proper translation. Please add this key to each locale file together with the corresponding localized value.

As per coding guidelines, "Translation files in web/src/i18n/locales/{lang}.json must be flat JSON with Chinese source strings as keys."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@web/src/components/table/channels/ChannelsColumnDefs.jsx` around lines 540 -
542, Add the new Chinese source string used in ChannelsColumnDefs.jsx — the
t('剩余额度:{{amount}},点击更新', { amount: renderQuotaWithAmount(record.balance) })
call — to each locale file as a flat JSON key (use the Chinese string as the
key) and provide the corresponding localized values for zh-CN.json (same Chinese
text) and en.json (English translation, e.g. "Remaining quota: {{amount}}, click
to update"). Ensure both files remain flat JSON objects and include the exact
Chinese key so i18n lookup succeeds for non-Chinese locales.

@KiGamji
KiGamji marked this pull request as draft March 12, 2026 14:31
@KiGamji
KiGamji force-pushed the round-remaining-balance branch from 2ab208c to 453c58e Compare March 12, 2026 14:35
@KiGamji
KiGamji marked this pull request as ready for review March 12, 2026 14:36
@seefs001
seefs001 merged commit 26253ac into QuantumNous:main Mar 14, 2026
1 check passed
ennnnny pushed a commit to ennnnny/new-api that referenced this pull request Mar 17, 2026
@coderabbitai coderabbitai Bot mentioned this pull request Apr 11, 2026
11 tasks
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.

Round remaining balance value

2 participants