Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Cerrado Apto para principiantes
#393 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
72/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
typescript
Área
cli

Línea de trabajo

Lee packages/cli/src/utils/format-amount.ts y compara su comportamiento con los tres sitios de llamada mencionados en el issue. Revisa las pruebas existentes de UCP en packages/cli/src/commands/ucp/__tests__/ucp.test.tsx y añade cobertura para monedas con cero y tres posiciones decimales. Se considera terminado cuando las tres salidas formateen correctamente los importes y el comportamiento del sufijo del código de moneda esté resuelto de forma coherente.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
TypeScript
Estrellas
873
Forks
147
Merge medio
23 h 49 min
PR fusionados (30 d)
79

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de stripe/link-cli

Todos los issues de stripe/link-cli

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.