fix: model pricing use correct display type - #4426
Conversation
WalkthroughThe changes update currency formatting logic across two components to dynamically derive display configurations from a centralized source instead of using fixed values. The tier price column header and price values now reflect configured currency symbols and exchange rates read from localStorage, with values appropriately scaled before display. 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 (2)
web/src/helpers/utils.jsx (1)
903-915: Replace the inlined currency config withgetCurrencyConfig().This block duplicates
getCurrencyConfig()defined inweb/src/helpers/render.jsx(lines 1102-1128), which is already exported from thehelpersbarrel and consumed elsewhere (e.g.,DynamicPricingBreakdown.jsxafter this PR). Reusing the helper avoids drift if fallback rules (e.g., CNY default rate of 7, custom symbol¤) change later.♻️ Proposed refactor
- const quotaDisplayType = localStorage.getItem('quota_display_type') || 'USD'; - let symbol = '$'; - let rate = 1; - try { - const s = JSON.parse(localStorage.getItem('status') || '{}'); - if (quotaDisplayType === 'CNY') { - symbol = '¥'; - rate = s?.usd_exchange_rate || 7; - } else if (quotaDisplayType === 'CUSTOM') { - symbol = s?.custom_currency_symbol || '¤'; - rate = s?.custom_currency_exchange_rate || 1; - } - } catch (e) {} + const { symbol, rate } = getCurrencyConfig();Add the import at the top of the file:
-import { Toast, Pagination } from '@douyinfe/semi-ui'; +import { Toast, Pagination } from '@douyinfe/semi-ui'; +import { getCurrencyConfig } from './render';🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@web/src/helpers/utils.jsx` around lines 903 - 915, Replace the inlined currency config block that computes quotaDisplayType, symbol and rate with a call to the shared helper getCurrencyConfig(): remove the JSON.parse/localStorage logic and use getCurrencyConfig(quotaDisplayType) to obtain symbol and rate (preserving the existing quotaDisplayType retrieval), and add the import for getCurrencyConfig from the helpers barrel (the function is defined in render.jsx as getCurrencyConfig); ensure variables quotaDisplayType, symbol and rate are set from the helper's return so fallback rules (CNY default rate 7, custom symbol ¤, etc.) come from the centralized implementation.web/src/components/table/model-pricing/modal/components/DynamicPricingBreakdown.jsx (1)
134-136: Optional: reuseconvertUSDToCurrencyhelper for the cell render.The render expression
${symbol}${(v * rate).toFixed(4)}on Line 136 is exactly whatconvertUSDToCurrency(v, 4)returns (seeweb/src/helpers/render.jsx:1136-1140). The column title still needs the rawsymbol, so keepinggetCurrencyConfig()above is fine — but the cell renderer could delegate for consistency with the rest of the codebase.♻️ Proposed refactor
-import { parseTiersFromExpr, getCurrencyConfig } from '../../../../../helpers'; +import { parseTiersFromExpr, getCurrencyConfig, convertUSDToCurrency } from '../../../../../helpers'; @@ - const { symbol, rate } = getCurrencyConfig(); + const { symbol } = getCurrencyConfig(); @@ title: `${t(label)} (${symbol}/1M tokens)`, dataIndex: field, - render: (v) => v > 0 ? <Text strong>{`${symbol}${(v * rate).toFixed(4)}`}</Text> : '-', + render: (v) => v > 0 ? <Text strong>{convertUSDToCurrency(v, 4)}</Text> : '-',🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@web/src/components/table/model-pricing/modal/components/DynamicPricingBreakdown.jsx` around lines 134 - 136, The cell renderer is duplicating currency formatting; replace the inline template `${symbol}${(v * rate).toFixed(4)}` with the existing helper convertUSDToCurrency so formatting is consistent with the app. In the DynamicPricingBreakdown column definition (where getCurrencyConfig() supplies symbol and rate), call convertUSDToCurrency(v, 4) inside the render function (keeping the title using symbol unchanged) and return '-' when v <= 0 to preserve existing behavior.
🤖 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/components/table/model-pricing/modal/components/DynamicPricingBreakdown.jsx`:
- Around line 134-136: The cell renderer is duplicating currency formatting;
replace the inline template `${symbol}${(v * rate).toFixed(4)}` with the
existing helper convertUSDToCurrency so formatting is consistent with the app.
In the DynamicPricingBreakdown column definition (where getCurrencyConfig()
supplies symbol and rate), call convertUSDToCurrency(v, 4) inside the render
function (keeping the title using symbol unchanged) and return '-' when v <= 0
to preserve existing behavior.
In `@web/src/helpers/utils.jsx`:
- Around line 903-915: Replace the inlined currency config block that computes
quotaDisplayType, symbol and rate with a call to the shared helper
getCurrencyConfig(): remove the JSON.parse/localStorage logic and use
getCurrencyConfig(quotaDisplayType) to obtain symbol and rate (preserving the
existing quotaDisplayType retrieval), and add the import for getCurrencyConfig
from the helpers barrel (the function is defined in render.jsx as
getCurrencyConfig); ensure variables quotaDisplayType, symbol and rate are set
from the helper's return so fallback rules (CNY default rate 7, custom symbol ¤,
etc.) come from the centralized implementation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d4c44840-89c9-44f1-90d6-d5f14ab5eadb
📒 Files selected for processing (2)
web/src/components/table/model-pricing/modal/components/DynamicPricingBreakdown.jsxweb/src/helpers/utils.jsx
…fdeda866258c19f4 fix: model pricing use correct display type
提交说明 / PR Notice
修复模型广场 动态计费未按设置的展示单位显示的问题
变更描述 / Description
获取后台设置的展示单位进行正确的显示
运行证明 / Proof of Work
修改前:

修改后:

Summary by CodeRabbit