fix: use configured currency symbol in top-up history payment amount column - #4482
fix: use configured currency symbol in top-up history payment amount column#4482paspy wants to merge 1 commit into
Conversation
…column The "支付金额" column in the top-up history modal hardcoded ¥ for every record regardless of the configured QuotaDisplayType. Operators using Stripe, Creem, or Waffo with QuotaDisplayType=USD or CUSTOM saw the wrong currency symbol and unconverted amounts. - Add convertCNYToCurrency() helper to render.jsx for CNY→display-currency conversion (reads usd_exchange_rate from localStorage status cache) - Replace hardcoded ¥ in TopupHistoryModal with provider-aware renderPaymentAmount(): USD-denominated gateways (stripe/creem/waffo) call convertUSDToCurrency(); CNY-denominated gateways (epay/alipay/wxpay) call convertCNYToCurrency() No backend changes. No regressions for existing CNY deployments.
WalkthroughThe PR modifies currency display logic in the topup history modal and introduces a new currency conversion utility. Instead of always formatting amounts as RMB with fixed precision, the system now conditionally formats amounts based on payment provider/method, selecting between CNY and USD conversion utilities and handling missing/invalid values gracefully. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
web/src/helpers/render.jsx (1)
1148-1160: Helper looks correct; minor note on the silent7fallback.Logic mirrors existing patterns: when
quota_display_type === 'CNY', format directly with the CNY symbol; otherwise convert CNY → USD usingusd_exchange_rate, then delegate toconvertUSDToCurrency(which applies the USD→display rate). This composes correctly for bothUSDandCUSTOMdisplay types.One small thing:
s?.usd_exchange_rate || 7will silently swallow0,null,NaN, or any falsy mis‑configured value and fall back to7. That matches the existing convention in this file (e.g.getCurrencyConfigat line 1114), so consistency-wise it’s fine, but it can mask backend misconfiguration. If you want to harden it, use a numeric check:♻️ Optional hardening
- let usdExchangeRate = 7; - try { - const s = JSON.parse(localStorage.getItem('status') || '{}'); - usdExchangeRate = s?.usd_exchange_rate || 7; - } catch (e) {} + let usdExchangeRate = 7; + try { + const s = JSON.parse(localStorage.getItem('status') || '{}'); + const parsed = Number(s?.usd_exchange_rate); + if (Number.isFinite(parsed) && parsed > 0) usdExchangeRate = parsed; + } catch (e) {}🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@web/src/helpers/render.jsx` around lines 1148 - 1160, The fallback to 7 in convertCNYToCurrency silently treats any falsy usd_exchange_rate (0, null, NaN, '') as validly missing; change the logic that sets usdExchangeRate (inside convertCNYToCurrency) to parse and validate the stored value numerically (e.g., parseFloat and Number.isFinite) and only fall back to 7 when the parsed value is not a finite number so genuine numeric values like 0 are preserved.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@web/src/helpers/render.jsx`:
- Around line 1148-1160: The fallback to 7 in convertCNYToCurrency silently
treats any falsy usd_exchange_rate (0, null, NaN, '') as validly missing; change
the logic that sets usdExchangeRate (inside convertCNYToCurrency) to parse and
validate the stored value numerically (e.g., parseFloat and Number.isFinite) and
only fall back to 7 when the parsed value is not a finite number so genuine
numeric values like 0 are preserved.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f598ad87-6597-467e-a312-9b0081e47e47
📒 Files selected for processing (2)
web/src/components/topup/modals/TopupHistoryModal.jsxweb/src/helpers/render.jsx
问题描述 / Problem
充值账单历史弹窗(
TopupHistoryModal)的「支付金额」列对所有记录硬编码了¥,与运营商在「系统设置」中配置的QuotaDisplayType完全无关。使用 Stripe、Creem 或 Waffo(美元计价网关)且将QuotaDisplayType设为USD或CUSTOM的运营商,看到的是错误的货币符号和未换算的金额。The "支付金额" column in the top-up history modal hardcodes
¥for every record, ignoring the operator's configuredQuotaDisplayType. Operators using Stripe, Creem, or Waffo withQuotaDisplayType=USDorCUSTOMsee the wrong currency symbol and unconverted amounts.原因 / Root Cause
TopupHistoryModal.jsx原代码:修复方案 / Fix
TopUp.Money的货币语义因支付网关而异:修改内容(仅前端,2 个文件):
web/src/helpers/render.jsx— 新增convertCNYToCurrency()工具函数:CNY 金额 → 当前显示货币(复用已有的getCurrencyConfig()和convertUSDToCurrency())web/src/components/topup/modals/TopupHistoryModal.jsx— 以 provider-aware 的renderPaymentAmount()替换硬编码的¥:USD 网关调用convertUSDToCurrency();CNY 网关调用convertCNYToCurrency()Note:
WeChatPaymentModal.jsx中也有¥字面量,但那里显示的是用户需要用微信钱包扫码支付的实际人民币金额(结构上只能是 CNY),有意不在本 PR 修改。修复后效果 / After Fix
¥10.00❌$10.00✓¥10.00❌¥73.00✓¥73.00✓¥73.00✓¥73.00❌$10.00✓¥5.00❌€5.00✓无后端改动;对现有 CNY 部署无回归。
✅ 提交前检查项 / Checklist
bun run build零错误)getCurrencyConfig()/convertUSDToCurrency()helpersSummary by CodeRabbit
Release Notes
New Features
Bug Fixes