fix(cli)(#36): invoice pay --amount accepts human units#37
Open
vrogojin wants to merge 1 commit into
Open
Conversation
Closes the cross-command inconsistency PR #35 deferred: payments send 50 UCT → 50 whole UCT ✓ human units invoice create --asset 50 UCT → 50 whole UCT ✓ human units (PR #35) invoice return … --asset 50 UCT → 50 whole UCT ✓ human units (PR #35) invoice pay <id> --amount 50 → 50 whole UCT ✓ NOW human units PR #35 left `invoice-pay --amount` parsing the raw value as smallest units because the command takes only the amount (no coin token); the coin is implicit in the invoice's target/asset entry. This patch resolves the invoice via `sphere.accounting!.getInvoice(invoiceId)`, reads the target's first asset, fails fast on NFT targets or missing targets, looks up decimals through `resolveCoin(symbol)`, and pipes the value through `toSmallestUnit()` — exactly the same conversion path PR #35 used for create/return. Side-effect on COMMAND_HELP: - description: mentions partial/over-payment use case (per the issue's "Why deferred" rationale) - --amount flag desc: documents human-unit semantics with a fractional example - examples: switched to `sphere invoice pay …` form with human-readable amounts (0.5 UCT, 25 UCT) - notes: explicit reminder that NFT targets reject --amount Picked Option A from the issue (--amount <value> stays single-token, coin inferred from the invoice). Option B (--amount <value> <coin>) was rejected because forcing the user to re-type a coin the invoice already pins adds friction without information; on `--asset` the coin is being *declared* (create/return), on `pay` it's *fixed by the invoice*. == Verification == - npx tsc --noEmit: clean - npx vitest run: 126/126 pass - node bin/sphere.mjs invoice pay --help: renders cleanly with new description / flag / examples / notes - npx tsup: clean ESM + CJS + DTS build Issue: #36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
sphere invoice pay <id> --amount 50now means 50 whole UCT (or whatever the invoice's coin is), matchingpayments send 50 UCTandinvoice create --asset 50 UCT.--amount, coin inferred from the invoice). Option B (--amount <value> <coin>) was rejected because forcing the user to re-type the coin the invoice already pins adds friction without information.Implementation
invoice-payresolves the invoice viasphere.accounting!.getInvoice(invoiceId), readsterms.targets[targetIndex].assets[0], and:resolveCoin(symbol);toSmallestUnit(rawAmount, decimals);failWithHelp.This mirrors exactly the conversion path PR #35 added for
invoice-create/invoice-return.Help block updates
descriptionmentions the partial / over-payment use case--amountflag doc spells out human units and gives a fractional examplesphere invoice pay …form with human-readable amounts (0.5 UCT, 25 UCT)notesline reminds operators that NFT targets reject--amountOut of scope
--asset-indexselector (target.assets[N] beyond N=0) — issue's "Out of scope" section, parked.PayInvoiceParams.amountstays a smallest-unit string. All conversion happens in the CLI.Test plan
npx tsc --noEmit— cleannpx vitest run— 126/126 pass (legacy-cli-ux static-guard tests still green)node bin/sphere.mjs invoice pay --help— help block renders with new description / flag / examples / notesnpx tsup— ESM + CJS + DTS build cleanmanual-test-accounting-roundtrip.shwith a partial-payment leg exercising--amount— flagged in the issue as a nice-to-have to guard the new pathCloses #36.