feat: require currency and network for all commands#46
Conversation
this change: - removes the inconsistency in the `amount` vs `amount-sats` - enables auto-conversion - adds future network support (e.g. on-chain btc)
📝 WalkthroughWalkthroughThis PR refactors the Alby CLI's amount handling across payment and invoice commands. It introduces a unified ChangesAmount Parsing and Multi-Rail Command Refactor
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 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.
🧹 Nitpick comments (1)
src/commands/make-invoice.ts (1)
10-19: 🏗️ Heavy liftDuplicated amount/currency/unit/network option wiring across commands.
This exact
--amount/--currency/--network/--unitblock (with identical descriptions andparseAmountNumber) is repeated verbatim inmake-hold-invoice,pay-keysend,pay-invoice,request-invoice-from-lightning-address, andreceive. Extracting a small Commander helper (e.g.addLightningAmountOptions(cmd)) would keep the descriptions and validation consistent as they evolve. Flagging here as the root; the same applies to the other five files.♻️ Sketch of a shared helper
// src/amount.ts (or a commander-options helper) export function addLightningAmountOptions(cmd: Command, { requireAmount = true } = {}) { const add = requireAmount ? cmd.requiredOption.bind(cmd) : cmd.option.bind(cmd); add("--amount <number>", "Invoice amount", parseAmountNumber); // ...currency/network/unit return cmd; }🤖 Prompt for 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. In `@src/commands/make-invoice.ts` around lines 10 - 19, The repeated .requiredOption block for --amount/--currency/--network/--unit across commands should be extracted into a shared helper (e.g., export function addLightningAmountOptions(cmd: Command, { requireAmount = true } = {})) that binds either requiredOption or option based on requireAmount, wires the same descriptions and parseAmountNumber for --amount, and returns the cmd; replace the duplicated blocks in make-invoice, make-hold-invoice, pay-keysend, pay-invoice, request-invoice-from-lightning-address, and receive with calls to addLightningAmountOptions and export the helper from a new module (e.g., src/amount.ts or a commander helper) so all commands share the exact option wiring and validation.
🤖 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.
Nitpick comments:
In `@src/commands/make-invoice.ts`:
- Around line 10-19: The repeated .requiredOption block for
--amount/--currency/--network/--unit across commands should be extracted into a
shared helper (e.g., export function addLightningAmountOptions(cmd: Command, {
requireAmount = true } = {})) that binds either requiredOption or option based
on requireAmount, wires the same descriptions and parseAmountNumber for
--amount, and returns the cmd; replace the duplicated blocks in make-invoice,
make-hold-invoice, pay-keysend, pay-invoice,
request-invoice-from-lightning-address, and receive with calls to
addLightningAmountOptions and export the helper from a new module (e.g.,
src/amount.ts or a commander helper) so all commands share the exact option
wiring and validation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 08cc7b48-135b-4b35-8ba6-a86297d9cbb0
⛔ Files ignored due to path filters (1)
yarn.lockis excluded by!**/yarn.lock,!**/*.lock
📒 Files selected for processing (29)
AGENTS.mdREADME.mdpackage.jsonsrc/amount.tssrc/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/lendaswap/swap.tssrc/test/amount-model.test.tssrc/test/amount-sats-parsing.test.tssrc/test/fetch-max-amount.test.tssrc/test/lightning-tools.test.tssrc/test/nwc-hold-invoices.test.tssrc/test/nwc-payments.test.tssrc/test/pay-command.test.tssrc/test/pay-crypto.test.tssrc/test/receive-command.test.tssrc/tools/lightning/discover.tssrc/tools/lightning/fetch.tssrc/utils.ts
💤 Files with no reviewable changes (1)
- src/test/amount-sats-parsing.test.ts
Follow up from #42
examples:
npx @getalby/cli pay hello@getalby.com --amount 5 --currency USD --network lightningnpx @getalby/cli receive --amount 5 --currency USD --network lightningnpx @getalby/cli receive --amount 21 --currency BTC --network lightning --unit satsnpx @getalby/cli pay 0x78C0...67bC --amount 2 --currency USDC --network arbitrumthis change:
amountvsamount-satsunitis required, to avoid any possible confusion between BTC & sat amounts.helpcommand in the CLI directlySummary by CodeRabbit
New Features
--amount,--currency,--unit, and--networkoptions instead of command-specific amount flagsDocumentation
Dependencies
Tests