fix(commands): add input validation for negative amounts and invalid addresses (Vibe Kanban)#9
Merged
MinaraAgent merged 5 commits intomainfrom Apr 3, 2026
Merged
Conversation
…addresses Add validation for CLI flags in swap, transfer, and withdraw commands: - Reject negative or zero amounts with clear error message - Validate addresses using existing validateAddress() utility - Catches invalid inputs before confirmation step Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request introduces CLI-level validation for amount and recipient address inputs across the swap, transfer, and withdraw commands. The feedback suggests refactoring the validation logic to throw errors instead of using manual process exits and warnings, which allows the existing wrapAction utility to handle error reporting and formatting consistently across the application.
Throw errors instead of warn + process.exit(1) for validation failures. This allows wrapAction to handle error reporting consistently with proper formatting (red error prefix) and centralized error handling. Also update tests to use valid EVM addresses (0x + 40 hex chars) since validation now properly rejects invalid addresses. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Move validation to the beginning of the action handler so invalid --amount or --to values fail immediately without entering interactive mode. Only commands with no options go into interactive mode. - swap.ts: validate amount early (before side/token prompts) - transfer.ts: validate amount and address (when chain provided) early - withdraw.ts: validate amount and address (when chain provided) early Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Validate --amount and --to options before any interactive prompts - Skip "Fetching assets" spinner in withdraw when CLI options present - Only show full interactive UI when running command with no options - Properly type chain variable as Chain type Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Validate that --chain is provided when --to is passed, rather than prompting for chain interactively. This ensures all CLI options are validated before any user interaction. - transfer.ts: fail with error if --to without --chain - withdraw.ts: fail with error if --to without --chain Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
swap,transfer, andwithdrawcommandsvalidateAddress()utility functionChanges
swap.ts
--amountflag to reject non-positive numberstransfer.ts
--amountflag to reject non-positive numbers--toaddress flag based on chain type (Solana: base58 32-44 chars, EVM: 0x + 40 hex chars)warnimport from utilswithdraw.ts
--amountflag to reject non-positive numbers--toaddress flag based on chain typewarnimport from utilsWhy
Previously, validation only occurred during interactive prompts. When values were passed via CLI flags (e.g.,
--amount -5or--to 0x123), they would bypass validation and proceed to the confirmation step or API call. This could lead to confusing errors or potentially unexpected behavior.Now all inputs are validated consistently regardless of whether they come from interactive prompts or CLI flags.
Test plan
npm run build)minara swap --amount -1shows "Amount must be a positive number"minara transfer --amount 0shows errorminara withdraw --to 0x123shows "Invalid EVM address"This PR was written using Vibe Kanban