Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Currency-blind formatting renders wrong amounts for zero- and three-decimal currencies in UCP and spend-request output

クローズ 初心者向け
#393 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
72/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
typescript
領域
cli

調査の方向性

packages/cli/src/utils/format-amount.tsを読み、issueで示されている3つの呼び出し箇所と動作を比較してください。packages/cli/src/commands/ucp/__tests__/ucp.test.tsxにある既存のUCPテストを確認し、小数点以下が0桁および3桁の通貨のカバレッジを追加してください。3つすべての出力で金額が正しくフォーマットされ、通貨コードのサフィックスの動作が一貫して解決されていれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Summary

Three call sites format a minor-unit amount with a hardcoded $ and /100:

  • packages/cli/src/commands/ucp/checkout-summary.tsx:10
  • packages/cli/src/commands/ucp/catalog-search.tsx:31
  • packages/cli/src/commands/spend-request/list.tsx:84

Each returns:

`$${(amount / 100).toFixed(2)} ${(currency ?? 'usd').toUpperCase()}`

A currency-aware helper already exists at packages/cli/src/utils/format-amount.ts, and it is used by transactions/list, payment-methods/list, approval-policy/retrieve, and spend-request/create. These three sites bypass it.

Actual vs expected

Amounts are in the currency's smallest unit.

Input Expected Current output
JPY 1000 ¥1,000 $10.00 JPY
KRW 5000 ₩5,000 $50.00 KRW
KWD 1000 KWD 1.000 $10.00 KWD
EUR 1234 €12.34 $12.34 EUR
USD 1234 $12.34 $12.34 USD

The JPY and KRW cases are off by 100x, KWD by 10x, and every non-USD case shows the wrong symbol.

Reproduction

import { formatAmount } from './packages/cli/src/utils/format-amount';

// copied verbatim from the three call sites above
const current = (amount: number, currency: string) =>
  `$${(amount / 100).toFixed(2)} ${(currency ?? 'usd').toUpperCase()}`;

formatAmount(1000, 'jpy'); // "¥1,000"
current(1000, 'jpy'); // "$10.00 JPY"

Why the current tests do not catch it

packages/cli/src/commands/ucp/__tests__/ucp.test.tsx asserts only USD strings ($99.00 USD, $25.00 USD, $0.50 USD), so only the one currency where /100 happens to be correct is exercised.

Reachability

Currency is not restricted to USD. packages/cli/src/commands/spend-request/schema.ts:40 is z.string().length(3).default('usd'), so any ISO code is accepted, and the UCP currency comes from the merchant.

Open question before a patch

The shared helper returns values without a currency-code suffix ($12.34), while these sites append the code ($12.34 USD). So the fix is a decision, not a pure swap:

  1. Use formatAmount directly and drop the redundant code for currencies with a symbol.
  2. Add an option to formatAmount to append the code, and use it at all sites.

Happy to open a PR for whichever behavior you prefer.

主要言語
TypeScript
スター
873
フォーク
147
平均マージ
23時間 53分
マージ済み PR(30日)
76

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

stripe/link-cli のほかの issue

stripe/link-cli の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。