Skip to content

Add balance-aware amount validation on distribution and stream forms #27

@pragmaticAweds

Description

@pragmaticAweds

Context

The amount validation utilities (utils/amount-validation.ts) validate that inputs are positive numbers with correct decimal precision, but they don't check whether the entered amount exceeds the user's actual token balance. Users can fill in amounts larger than what they hold and only discover the problem when the transaction fails during signing. This wastes time and creates confusion.

What Success Looks Like

  • Amount inputs on the Distribution and Payment Stream forms validate against the user's real token balance
  • If the entered amount exceeds the available balance, an inline error message appears immediately (e.g., "Insufficient balance. You have 500 USDC")
  • The validation is debounced to avoid excessive balance queries
  • Balance is fetched once and cached, then re-validated when the amount input changes
  • The submit button is disabled when the amount exceeds the balance

Implementation Guidance

  • apps/web/src/utils/amount-validation.ts — existing validation to extend with a balance check
  • apps/web/src/app/(overview)/distribution/page.tsx — total amount input for equal distribution
  • apps/web/src/components/modules/payment-stream/PaymentStreamForm.tsx — stream amount input
  • apps/web/src/services/stellar.service.ts — balance fetching methods
  • Fetch the balance for the selected token using the existing service layer
  • Add a maxAmount parameter to the validation function that compares against the fetched balance
  • Use TanStack Query for caching the balance (it's already in the project)
  • Show the user's current balance near the amount input as a helpful reference

Metadata

Metadata

Assignees

No one assigned

    Labels

    difficulty: mediumStandard features across multiple codebase sections

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions