feat: make units clear across all commands#45
Conversation
remove any possible confusion for the AI to spend using the wrong unit or currency.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (16)
✅ Files skipped from review due to trivial changes (1)
🚧 Files skipped from review as they are similar to previous changes (7)
📝 WalkthroughWalkthroughRename Lightning amount flags to --amount-sats across CLI commands, add strict sats parsing (parseSatsOption), update pay destination validation to distinguish sats vs crypto amounts, and update tests, README, and version to 0.8.0. ChangesAmount flag currency suffixing refactor
Sequence DiagramsequenceDiagram
participant User as CLI User
participant Parser as Option Parser
participant Utils as parseSatsOption
participant Invoice as Invoice Service
participant Payment as Payment Service
User->>Parser: make-invoice --amount-sats 100
Parser->>Utils: validate & parse "100"
Parser->>Invoice: create(amount_in_sats: 100)
Invoice-->>User: BOLT-11 invoice
User->>Parser: pay <bolt11> --amount-sats 100
Parser->>Payment: payInvoice(amount_in_sats: 100)
Payment-->>User: payment result
🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly Related PRs
Suggested Reviewers
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/commands/fetch.ts`:
- Around line 16-18: The CLI currently uses parseInt for "--max-amount-sats"
which lets malformed inputs like "0.5" become 0 and bypass the cap; replace
parseInt in the fetch command option with a strict parser (e.g., a parseSats
function) that only accepts non-negative integer strings (validate /^\d+$/ or
Number.isInteger after parsing) and throws/returns an error for invalid input,
and also change the conversion in src/tools/lightning/fetch.ts that currently
uses "maxAmount: maxAmountSats || undefined" to a null/undefined check (e.g.,
"maxAmount: maxAmountSats === 0 ? undefined : maxAmountSats" or "maxAmount:
maxAmountSats == null ? undefined : maxAmountSats") so a valid 0 is treated as
"no limit" while malformed inputs are rejected.
In `@src/commands/fiat-to-sats.ts`:
- Line 10: The .requiredOption("--amount <n>", "Fiat amount", parseFloat)
currently allows partial numeric strings; replace the parseFloat parser with a
custom validator used in the same .requiredOption call that first tests the raw
input against a strict decimal regex (e.g. ^[+-]?\d+(\.\d+)?$ or a variant that
fits your allowed formats) and only then returns Number(input) /
parseFloat(input); if the input does not fully match the regex throw an
Error("Invalid value for --amount: <value>") so commander surfaces a parsing
error. Ensure you update the same .requiredOption("--amount <n>", ...)
invocation and validate the whole string before converting.
In `@src/commands/pay.ts`:
- Around line 91-95: Create a shared strict sats parser/validator (e.g.,
parseSatsStrict or validateSats) and replace all ad-hoc parsing in pay.ts and
the lightning command files (make-invoice, pay-invoice, pay-keysend,
make-hold-invoice, receive, request-invoice-from-lightning-address) so every
--amount-sats option uses that helper; the helper should accept a flag to
allowZero (for zero-amount invoice paths) and enforce whole integer sats (no
scientific notation or trailing text), return a normalized Number or throw/emit
a consistent CLI error on invalid input, and then update option definitions
(currently using Number or parseInt) and any post-parse checks (e.g.,
Number.isInteger and >0) to call this single function for identical behavior
across all commands.
In `@src/commands/sats-to-fiat.ts`:
- Line 9: Replace the loose parseInt usage for the commander option
requiredOption("--amount-sats <sats>", parseInt) with a strict parser that
validates the input matches /^\d+$/ and then returns Number(value); if the check
fails, throw an Error so the CLI exits with a clear validation message —
implement this as the option's custom parser function (e.g., function
parseSats(value) { if (!/^\d+$/.test(value)) throw new Error("amount-sats must
be a whole number of sats"); return Number(value); }) and use parseSats in place
of parseInt.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: d24f416d-c9f9-45aa-987b-8fa48734c26a
📒 Files selected for processing (19)
README.mdpackage.jsonsrc/commands/fetch.tssrc/commands/fiat-to-sats.tssrc/commands/make-hold-invoice.tssrc/commands/make-invoice.tssrc/commands/pay-crypto.tssrc/commands/pay-invoice.tssrc/commands/pay-keysend.tssrc/commands/pay.tssrc/commands/receive.tssrc/commands/request-invoice-from-lightning-address.tssrc/commands/sats-to-fiat.tssrc/index.tssrc/test/lightning-tools.test.tssrc/test/nwc-hold-invoices.test.tssrc/test/nwc-payments.test.tssrc/test/pay-command.test.tssrc/test/receive-command.test.ts
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
remove any possible confusion for the AI to spend using the wrong unit or currency.
Fixes #42
Summary by CodeRabbit
CLI Changes
--amount→--amount-sats;--max-amount→--max-amount-sats. Improved cross-flag validation and clearer error messages.Documentation
Tests