Repository navigation
fix(ui): 行情价格按标的币种格式化,移除 4 处硬编码「$」 - #259
Merged
Merged
Conversation
SecurityHeader / OverviewView / Watchlist / StockCard 都用本地 formatPrice 拼
`$${v.toFixed(2)}`,港股、A 股、新加坡标的的本币金额被当成美元渲染:
0700.HK → `$350.00`(应为 HK$350.00),600519.SH → `$350.00`(应为 CN¥350.00)。
zh-CN 下即使标的是美股也不对(Intl 的 zh-CN 货币形态是 US$1,234.56)。
这违反 format.ts / lib/money.ts 的「NEVER hardcode $」约定;OverviewView 更是
同一视图内混用:持仓块走 formatMoney(..., holding.currency),行情块走硬编码 $。
改动:
- lib/money.ts 新增 currencyForSymbol(),作为 @finagent/shared 同名函数的渲染
进程镜像(UI 不可 import shared),映射规则完全一致;
- SecurityHeader / OverviewView 优先使用数据源上报的 StaticInfo.currency,缺失
时回落到符号路由推断;Watchlist / StockCard 直接按符号推断;
- 删除这 4 处本地硬编码辅助函数。不新增 i18n key、不改动任何文案。
新增测试(TDD,先在未修复代码上失败):
- lib/money.test.ts:后缀映射、大小写、未知/空值回落与组合输出;
- workspace/SecurityHeader.test.tsx:上报币种分支 + 推断回落分支;
- workspace/OverviewView.test.tsx、stock/Watchlist.test.tsx、
stock/StockCard.test.tsx(含「美股仍为 $」防过度修正)。
修复前 1 pass / 6 fail(另有 currencyForSymbol 缺失导致的 SyntaxError),
修复后 9 pass / 0 fail;packages/ui 321 → 332 pass,typecheck 5/5 exit 0。
Closes helsome#258
This was referenced Sep 29, 2026
6 tasks done
helsome
approved these changes
Oct 18, 2026
helsome
left a comment
Owner
There was a problem hiding this comment.
独立代码审查及精确 HEAD focused 9/0 通过。按当前顺序累计组合完整测试1924 pass / 7 skip / 0 fail、全workspace typecheck、i18n通过,secret扫描零命中。相关货币/排版确定性回归符合本PR范围,不将其声称为全桌面或真实模型E2E。
helsome
pushed a commit
that referenced
this pull request
Oct 18, 2026
AlertCard 对 price_above / price_below 调用 formatCurrency(rule.targetPrice)
不传币种,而 formatCurrency 在 currency 为空时退化成裸数字,于是港股、A 股、
美股提醒一律渲染成「Above 350」—— 币种信息整个丢失(文案 above/below 只能
由 {{price}} 承载币种,无法从别处补回)。
孪生实现 alertAtoms.ruleSummary() 则走向另一极端,用模板字符串硬编码 `$`
(Above $100.00),违反 format.ts / lib/money.ts 的「NEVER hardcode $」约定。
改动:
- AlertCard 新增 alertPrice(rule) = formatMoney(rule.targetPrice,
currencyForSymbol(rule.symbol)),price_above/price_below 共用,移除对
@finagent/i18n#formatCurrency 的直接依赖;
- alertAtoms.ruleSummary() 同样改用 formatMoney(...),与孪生体保持一致。
AlertRule 无 currency 字段,币种由 rule.symbol 的市场后缀推导。
前置改动:本 PR 需要 lib/money.ts 的 currencyForSymbol(),该函数由 #259 引入。
本 PR 对该文件的改动与 #259 逐字节一致,两个 PR 可独立合并,先合并者生效、
后合并者的该 hunk 自动变为空。
新增测试(TDD,先在未修复代码上失败):
- components/alert/AlertCard.test.tsx:港股 HK$350.00 / A 股 CN¥350.00 /
美股 $350.00;
- atoms/alertAtoms.test.ts:补 .HK、.SH 用例,原有 US 用例保持不变。
修复前 10 pass / 4 fail,修复后 14 pass / 0 fail;
packages/ui 332 → 336 pass,apps/electron 32 pass,typecheck 5/5 exit 0。
Closes #260
Lym308758
added a commit
to Lym308758/folio
that referenced
this pull request
Oct 21, 2026
QuoteCard 最新价此前硬编码 `$`,港股/A 股/新加坡标的被错标为美元 (0700.HK 显示 $350.00 而非 HK$350.00),违反 money.ts "NEVER hardcode $" 约定——同面板的 answer-block 已按币种正确渲染,两者不一致。 - 主价格改走 formatMoney(quote.lastPrice, currencyForSymbol(symbol)),复用 main 上 helsome#259 已提供的统一金额层,不再改动 money.ts;缺失/NaN 价仍渲染 em dash,fmtTime(helsome#217 范围)未动。 - 币种只由标的字符串后缀决定,与 provider 无关:Yahoo(helsome#353)只提供美股 延迟报价,但路由仍可能拿到其他市场标的,卡片必须按标的渲染而非按来源。 - 新增 QuoteCard.test.tsx:currencyForSymbol 纯函数映射、US/HK/SH/SZ/SGD 渲染、缺失价,以及 Yahoo 来源(source.delayed)下的币种与来源语义回归; 渲染断言对 ICU 符号变体稳健,仍能抓回"裸 $"回归。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #258
问题
4 处行情价格展示仍在硬编码
$,港股/A 股/新加坡标的的本币金额被当成美元渲染(0700.HK→$350.00,应为HK$350.00)。zh-CN 下即使标的为美股也不对(Intl的 zh-CN 货币形态是US$1,234.56)。这违反
packages/i18n/src/format.ts与packages/ui/src/lib/money.ts的「NEVER hardcode$」约定;OverviewView更是同一视图内混用 —— 持仓块走formatMoney(..., holding.currency),行情块走硬编码$。改动
packages/ui/src/lib/money.tscurrencyForSymbol(symbol):@finagent/shared同名函数的渲染进程镜像(UI 不可 import shared),映射规则完全一致packages/ui/src/components/workspace/SecurityHeader.tsxformatPrice;改用formatMoney(v, info?.currency ?? currencyForSymbol(symbol)),覆盖最新价与开/高/低/昨收packages/ui/src/components/workspace/OverviewView.tsxstaticInfo?.currency,覆盖行情块与表现块packages/ui/src/components/stock/Watchlist.tsxformatPrice;行内改用formatMoney(quote.lastPrice, currencyForSymbol(symbol))packages/ui/src/components/stock/StockCard.tsxH:/L:行改用同一格式层不新增 i18n key、不改动任何文案;展示形态完全交给既有
@finagent/i18nlocale 策略。验证(TDD)
先写测试、在未修复代码上确认失败,再修复:
Watchlist的失败信息即问题本身:Tencent Holdings 的最新价渲染成了$350.00。新增测试:
lib/money.test.ts(后缀映射与组合输出)、workspace/SecurityHeader.test.tsx(provider 上报币种与回落分支各一条)、workspace/OverviewView.test.tsx、stock/Watchlist.test.tsx、stock/StockCard.test.tsx(含「美股仍为$」防过度修正用例)。回归对照:
bun test packages/ui --isolatebun test apps/electron --isolatebun test packages/core --isolatebun run typecheck查重说明
formatPrice、currency(含已关闭)、hardcode dollar、hardcoded currency symbol等关键词 —— 唯一相关的 [UI] Unify currency formatting onto the i18n locale policy (lib/money vs @finagent/i18n) #86「Unify currency formatting onto the i18n locale policy」为已关闭的迁移工作,本 PR 正是补齐它漏掉的 4 个调用点,不存在重复报告。