Currency-blind formatting renders wrong amounts for zero- and three-decimal currencies in UCP and spend-request output
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:10packages/cli/src/commands/ucp/catalog-search.tsx:31packages/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:
- Use
formatAmountdirectly and drop the redundant code for currencies with a symbol. - Add an option to
formatAmountto 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
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di stripe/link-cli
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 1/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 48/100
I maintainer di solito rispondono entro 1 giorno
-
Device-flow refresh token rejected immediately: 400 "refresh_token is invalid" on first refreshAperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 32/100
stripe/link-cli#406 · 3 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
bunx hangs after link-cli commands by implicitly starting a development serverForse già presa @awesamarth l’ha presa 39 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di stripe/link-cli
Issue simili
-
skillopt: success-reflect prompt omits the edit schema, so every success-only edit is droppedAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Workspace secrets/constants containing "$" are corrupted when resolved in data source optionsApertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 67/100
mobile-next/mobile-mcp#526 ·
I maintainer di solito rispondono entro 1 giorno
-
e2e-failure ready-to-code
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 73/100
redhat-developer/rhdh-plugin-export-overlays#4470 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno