Skip to content

Extract the duplicated positive-integer field validation into a shared helper #96

Description

@mikewheeleer

Consolidate the repeated numeric-field validation logic

Description

The non-negative-integer guard for priceStroops is re-implemented in src/app/services/new/page.tsx and src/app/services/[serviceId]/edit/page.tsx, and a similar positive-integer guard for requests lives in src/app/usage/page.tsx — three copies of essentially the same parse-and-validate logic. This issue extracts a single tested helper and adopts it in all three forms.

Requirements and context

  • Repository scope: Agentpay-Org/Agentpay-frontend only.
  • Create src/lib/validateNumber.ts (e.g. parseNonNegativeInt / parsePositiveInt) returning a typed { ok, value } or { ok: false, message }.
  • Replace the inline checks in the three pages with the helper, preserving each page's exact accepted range (≥ 0 for price, ≥ 1 for requests).
  • Surface validation messages via TextField's error prop where the forms already use it.
  • Do not change the wire payloads or observable success behaviour.

Suggested execution

  • Fork the repo and create a branch
  • git checkout -b refactor/forms-shared-number-validation
  • Implement changes
    • Write code in: create src/lib/validateNumber.ts; update the three pages.
    • Write comprehensive tests in: create src/lib/__tests__/validateNumber.test.ts and update the affected page tests.
    • Add documentation: JSDoc the helper; note the validation rules in README.md.
    • Validate the accepted ranges per form are unchanged.
  • Test and commit

Test and commit

  • Run npm run lint, npm run typecheck, npm test, and npm run build.
  • Cover edge cases: empty, negative, float, leading-zero, and a valid integer for each range.
  • Include the npm test output and coverage for the helper.

Example commit message

refactor(forms): extract shared numeric-field validation helper

Guidelines

  • Minimum 95 percent test coverage for the helper and changed pages.
  • Clear, reviewer-focused documentation.
  • Timeframe: 96 hours.

Community & contribution rewards

  • 💬 Join the AgentPay community on Discord for questions, reviews, and faster merges: https://discord.gg/eXvRKkgcv
  • ⭐ This is a GrantFox OSS / Official Campaign task and may be rewarded. When your PR is merged you'll be prompted to rate the project — if this issue and the maintainers helped you ship, we'd be grateful for a 5-star rating. Clear questions in Discord and tidy, well-tested PRs are the fastest path to a merge and a reward.

Metadata

Metadata

Assignees

No fields configured for Feature.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions