Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

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

Chiusa Adatta ai principianti
#393 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
cli

Direzione di ricerca

Leggi packages/cli/src/utils/format-amount.ts e confrontane il comportamento con i tre punti di chiamata indicati nell’issue. Controlla i test UCP esistenti in packages/cli/src/commands/ucp/__tests__/ucp.test.tsx e aggiungi la copertura per le valute con zero e tre cifre decimali. Il lavoro è completato quando tutti e tre gli output formattano correttamente gli importi e il comportamento del suffisso del codice valuta è risolto in modo coerente.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
TypeScript
Stelle
856
Fork
143
Merge medio
19h 32m
PR unite (30g)
75

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di stripe/link-cli

Tutte le issue di stripe/link-cli

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.