Skip to content

Excessive NEAR RPC calls on Create Campaign page #601

@aunali8812

Description

@aunali8812

On the Create Campaign page, every user interaction (clicks, focus changes, keystrokes) triggers unnecessary calls to the free NEAR RPC
endpoint, causing excessive network traffic and potential rate limiting.

Cause

The Zod validation schema for the campaign form validates the recipient field using isNearAccountValid, which makes a direct nearRpc.query()
call (no SWR, no caching, no deduplication) to check if a NEAR account exists. The form uses mode: "all", which re-runs the entire schema
validation on every keystroke in any field — so typing in the campaign name, description, or amount all trigger an RPC call to validate the
recipient.

Additionally, useIsHuman had no SWR caching config, causing it to refetch on every window focus event.

Fix

  • Added debouncing (300ms) and an in-memory cache to isNearAccountValid so it only fires one RPC call after the user stops typing, and never
    re-validates the same account ID twice.
  • Added revalidateOnFocus: false to useIsHuman SWR config.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions