Repository navigation
fix: system chat user token quota - #7830
Conversation
| if (!tokenQuota) return '0 / 不限' | ||
| const used = formatTokenNumber(tokenQuota.used_tokens) | ||
| if (tokenQuota.quota_type === QUOTA_TYPE.UNLIMITED) return `${used} / 不限` | ||
| return `${used} / ${formatTokenNumber(tokenQuota.token_limit)}` |
There was a problem hiding this comment.
The main issue is semantic, not syntactic:
-
Missing quota data is being treated as “0 / 不限” (0 / Unlimited).
!tokenQuotacan mean the data is still loading, failed to load, or is genuinely absent. Rendering “0 / 不限” can falsely tell users they have unlimited quota and hide an error/loading state. Safer to keep'-', use a loading/error placeholder, or only return'0 / 不限'if the business rule explicitly defines “no quota object” as “zero usage, unlimited.” -
Hardcoded localized text:
'不限'is repeated. If the app supports i18n, use a translation key/constant instead. At minimum, extract a constant to avoid duplication. -
Add tests for:
tokenQuotaundefined- unlimited quota with
used_tokens > 0 - limited quota
- possibly
nullat runtime if the API can return it
Suggested safer version:
const UNLIMITED_LABEL = '不限'
function formatQuotaUsage(tokenQuota?: ChatUser['token_quota']) {
if (!tokenQuota) return '-' // or a loading/error placeholder
const used = formatTokenNumber(tokenQuota.used_tokens)
if (tokenQuota.quota_type === QUOTA_TYPE.UNLIMITED) {
return `${used} / ${UNLIMITED_LABEL}`
}
return `${used} / ${formatTokenNumber(tokenQuota.token_limit)}`
}If the new behavior is intentional, add a comment explaining that missing quota data means “0 used / unlimited,” and ensure callers only pass undefined in that specific case rather than during loading or errors.
【【门户】用户配额用尽后对话,接口已返回了配额用尽提醒,但是前端没有显示】
https://www.tapd.cn/tapd_fe/45245355/bug/detail/1145245355001079171