Skip to content

fix(commands): add input validation for negative amounts and invalid addresses (Vibe Kanban)#9

Merged
MinaraAgent merged 5 commits intomainfrom
vk/ec84-fix-input-valida
Apr 3, 2026
Merged

fix(commands): add input validation for negative amounts and invalid addresses (Vibe Kanban)#9
MinaraAgent merged 5 commits intomainfrom
vk/ec84-fix-input-valida

Conversation

@MinaraAgent
Copy link
Copy Markdown
Member

@MinaraAgent MinaraAgent commented Apr 3, 2026

Summary

  • Add validation for CLI flag inputs in swap, transfer, and withdraw commands
  • Reject negative or zero amounts with clear error message before proceeding to confirmation
  • Validate destination addresses using existing validateAddress() utility function
  • Prevent invalid inputs from reaching API calls

Changes

swap.ts

  • Added validation for --amount flag to reject non-positive numbers
  • Handles special case where "all" is valid for sell operations

transfer.ts

  • Added validation for --amount flag to reject non-positive numbers
  • Added validation for --to address flag based on chain type (Solana: base58 32-44 chars, EVM: 0x + 40 hex chars)
  • Added warn import from utils

withdraw.ts

  • Added validation for --amount flag to reject non-positive numbers
  • Added validation for --to address flag based on chain type
  • Added warn import from utils

Why

Previously, validation only occurred during interactive prompts. When values were passed via CLI flags (e.g., --amount -5 or --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

  • Build passes (npm run build)
  • Test minara swap --amount -1 shows "Amount must be a positive number"
  • Test minara transfer --amount 0 shows error
  • Test minara withdraw --to 0x123 shows "Invalid EVM address"
  • Test valid inputs still work correctly

This PR was written using Vibe Kanban

…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>
@MinaraAgent MinaraAgent changed the title Add input validation for negative amounts and invalid addresses in minara-cli. (vibe-kanban) fix(commands): add input validation for negative amounts and invalid addresses (Vibe Kanban) Apr 3, 2026
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/commands/swap.ts Outdated
Comment thread src/commands/transfer.ts Outdated
Comment thread src/commands/transfer.ts Outdated
Comment thread src/commands/transfer.ts Outdated
Comment thread src/commands/withdraw.ts Outdated
Comment thread src/commands/withdraw.ts Outdated
Comment thread src/commands/withdraw.ts Outdated
claude and others added 4 commits April 3, 2026 07:47
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>
@MinaraAgent MinaraAgent merged commit cbc0475 into main Apr 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants