new-api icon indicating copy to clipboard operation
new-api copied to clipboard

feat(credit-limit): 支持邀请的额度单位切换

Open a3339530357 opened this issue 1 year ago • 1 comments

  • 邀请增加额度单位状态,可在 Token、USD、CNY 和自定义货币间切换
  • 根据选定单位动态转换和显示额度值,保持后台数据为 Token 单位
  • 根据单位调整输入步长,支持小数精度输入
  • 增加自定义货币符号和汇率支持,汇率从配置项读取
  • 在额度输入框显示对应单位后缀,提高用户体验
  • 优化表单值处理,使用 useMemo 缓存计算结果减少无效渲染
  • 增加单位选择下拉框,便于用户快速切换显示模式

Summary by CodeRabbit

Release Notes

  • New Features
    • Credit limits can now be configured in multiple currencies: Token, USD, CNY, or custom currency units.
    • Added automatic conversion between different currency units for credit limit values.
    • Implemented currency unit selector with dynamic input formatting, step sizes, and unit suffixes based on selected currency.
    • Form values synchronize with the currently selected currency unit.

✏️ Tip: You can customize this high-level summary in your review settings.

a3339530357 avatar Nov 22 '25 06:11 a3339530357

Walkthrough

Multiple frontend UI updates (theme, wallpaper, new AnyRouter route, sidebar entry, icons), a multi-unit quota input feature on the credit-limit settings page, small content/label tweaks, backend additions to allow plaintext-password mode (env-controlled) and early-return handling in crypto, and a change to invite/quota logic permitting negative quotas and atomic inviter increment.

Changes

Cohort / File(s) Change Summary
Settings — multi‑unit quota UI
web/src/pages/Setting/Operation/SettingsCreditLimit.jsx
Added unit selection state (quotaUnit), memoized exchange-rate/config values, bidirectional conversion helpers (tokenToDisplay, displayToToken), unit-aware input step/suffix handling, displayInputs derived for Form, unit Select control, and synchronization on options changes.
Frontend — routing, sidebar, icons, wallpaper & theme
web/src/App.jsx, web/src/pages/AnyRouter.jsx (new), web/src/components/layout/SiderBar.jsx, web/src/helpers/render.jsx, web/src/hooks/common/useSidebar.js, web/src/index.css
Added AnyRouter route and mounted route (/console/anyrouter), new sidebar item and feature flag, Lucide Network icon mapping for anyrouter, dynamic wallpaper loader on mount that sets document background to redirected image URL, and large translucent/glassy theme/CSS overhaul (dark/light variants, blur, backdrop rules).
Frontend — small UI/content edits
web/src/components/layout/Footer.jsx, web/src/components/layout/headerbar/index.jsx, web/src/components/auth/RegisterForm.jsx, web/src/components/topup/InvitationCard.jsx
Footer: added contact and LoliAPI credit and reworked layout; headerbar: reduced header opacity (75%→60%); RegisterForm: label text change for Gmail-only registration; InvitationCard: reward text changed and replaced reward bullets with an image block.
Backend — plaintext password flag & crypto changes
common/init.go, common/constants.go, common/crypto.go
Introduced exported EnablePlaintextPassword (env ENABLE_PLAINTEXT_PASSWORD) with warning logs on init; common/constants.go exposes EnablePlaintextPassword default false; crypto.go short-circuits hashing/validation when flag is true (returns plain password / direct compare) and added fmt import/logging.
Model — invite & quota logic
model/user.go
Replaced fetch-modify-save in inviteUser with single SQL increment of inviter aff_count; adjusted inviter/invitee quota changes to apply only when configured non-zero and allow negative quotas; removed strict non-negative check in IncreaseUserQuota to permit deductions; logs updated accordingly.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Areas to focus on:
    • Security impact of EnablePlaintextPassword (init logging, crypto short-circuit, environment gating).
    • Correctness and rounding/edge cases in bidirectional unit conversion and synchronization between inputs, inputsRow, and displayInputs.
    • AnyRouter routing and sidebar feature-flag interaction with visibility checks.
    • Atomic updater in inviteUser (SQL correctness, concurrency) and ensuring quota changes are applied consistently when negative values are allowed.
    • Large CSS/theme changes for regressions in component visuals and cross-browser backdrop-filter support.

Possibly related PRs

  • QuantumNous/new-api#1923 — closely related: frontend quota unit/display feature (USD/CNY/TOKEN/CUSTOM) and conversion logic.
  • QuantumNous/new-api#1593 — related UI styling changes to header transparency/backdrop blur.

Suggested reviewers

  • seefs001
  • creamlike1024

Poem

🐰 I nibble tokens, count them one by one,
Now dollars, yuan, and custom shine like sun.
With memos and radians my math hops light,
Converting your quotas from morning to night,
A crunchy carrot for each merged delight! 🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title clearly and specifically summarizes the main change: adding support for credit-limit unit switching (邀请的额度单位切换). It directly corresponds to the primary objective in the PR objectives, which focuses on enabling users to switch between Token, USD, CNY, and custom currencies for credit-limit display.
✨ Finishing touches
  • [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

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.

coderabbitai[bot] avatar Nov 22 '25 06:11 coderabbitai[bot]