Skip to content

fix(ui): 行情价格按标的币种格式化,移除 4 处硬编码「$」 - #259

Merged
helsome merged 1 commit into
helsome:mainfrom
wxrbyte:codex/fix-quote-currency-format
Oct 18, 2026
Merged

helsome merged 1 commit into
helsome:mainfrom
wxrbyte:codex/fix-quote-currency-format

Conversation

@wxrbyte

@wxrbyte wxrbyte commented Sep 29, 2026

Copy link
Copy Markdown
Contributor

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.ts 新增 currencyForSymbol(symbol):@finagent/shared 同名函数的渲染进程镜像(UI 不可 import shared),映射规则完全一致
packages/ui/src/components/workspace/SecurityHeader.tsx 删除本地 formatPrice;改用 formatMoney(v, info?.currency ?? currencyForSymbol(symbol)),覆盖最新价与开/高/低/昨收
packages/ui/src/components/workspace/OverviewView.tsx 同上,货币取自 staticInfo?.currency,覆盖行情块与表现块
packages/ui/src/components/stock/Watchlist.tsx 删除本地 formatPrice;行内改用 formatMoney(quote.lastPrice, currencyForSymbol(symbol))
packages/ui/src/components/stock/StockCard.tsx 最新价与 H:/L: 行改用同一格式层
5 个新增测试文件 见下

不新增 i18n key、不改动任何文案;展示形态完全交给既有 @finagent/i18n locale 策略。

验证(TDD)

先写测试、在未修复代码上确认失败,再修复:

# 修复前
(fail) prices a Hong Kong instrument in HKD, never a bare $      Expected: 1  Received: 0
(fail) falls back to the routed market when the provider reports no currency
                                                                 Expected: 5  Received: 0
(fail) formats every quote cell in the instrument currency        Expected: 5  Received: 0
(fail) prices a Hong Kong tile in HKD instead of a hardcoded $    Expected: 3  Received: 1
(fail) prices each row in that symbol currency
        Received: "0700.HKTencent Holdings$350.00+0.43%"
 1 pass / 6 fail   (+ SyntaxError: Export named 'currencyForSymbol' not found)

# 修复后
 9 pass / 0 fail

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 --isolate 321 pass / 0 fail 332 pass / 0 fail
bun test apps/electron --isolate 32 pass / 0 fail 32 pass / 0 fail
bun test packages/core --isolate 53 pass / 0 fail 53 pass / 0 fail
bun run typecheck 5/5 exit 0 5/5 exit 0

查重说明

  • 文件级:本 PR 涉及的 10 个文件对上游 57 个 open PR 的全部 265 个改动文件做了逐一比对,命中 0;仓库中也不存在已推送但未开 PR 的悬挂分支。
  • issue 级:检索 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 个调用点,不存在重复报告。
  • hunk 级:被改文件不在任何 open PR 的文件清单内,故无 hunk 交集。

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

@helsome helsome left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

独立代码审查及精确 HEAD focused 9/0 通过。按当前顺序累计组合完整测试1924 pass / 7 skip / 0 fail、全workspace typecheck、i18n通过,secret扫描零命中。相关货币/排版确定性回归符合本PR范围,不将其声称为全桌面或真实模型E2E。

@helsome
helsome merged commit 571e545 into helsome:main Oct 18, 2026
5 checks passed
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 符号变体稳健,仍能抓回"裸 $"回归。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ui: 行情价格展示层硬编码「$」,港股/A 股/新加坡标的币种显示错误(4 个调用点)

2 participants