Skip to content

Convert the agent detail page to the shared useApi hook and add a typed total fetch #178

Description

@mikewheeleer

Refactor the agent detail fetches onto useApi with proper cancellation

Description

src/app/agents/[agent]/page.tsx fires two apiGet calls inside a useEffect with no cancellation token, so navigating between agents quickly can let a slow earlier response set state for the wrong agent, and the optional total request swallows errors with an empty catch. The repo ships useApi with a clean loading | error | ok machine and cancellation. This issue moves the primary usage fetch onto useApi and adds a guarded total fetch.

Requirements and context

  • Repository scope: Agentpay-Org/Agentpay-frontend only.
  • Migrate the primary /api/v1/agents/{agent}/usage fetch to useApi<Usage>(path), keyed on the encoded agent so it refetches on navigation and cancels superseded requests.
  • Keep the optional /total fetch's soft-failure but guard it against out-of-order responses (latest agent wins).
  • Preserve the monospace heading, the per-service list, and the error role="alert"; observable happy-path behaviour must not change.
  • Coordinate with the agent-detail loading-states work if it lands; this issue is the network-layer refactor.

Suggested execution

Test and commit

  • Run npm run lint, npm run typecheck, npm test, and npm run build.
  • Cover edge cases: rapid agent switch, slow then fast response, usage error, and optional-total failure.
  • Include the npm test output.

Example commit message

refactor(agents): adopt useApi and guard the total fetch on the detail page

Guidelines

  • Minimum 95 percent test coverage for the changed page.
  • 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 one assigned
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions