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
- Fork the repo and create a branch
git checkout -b refactor/agents-detail-useapi
- Implement changes
- Test and commit
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.
Refactor the agent detail fetches onto useApi with proper cancellation
Description
src/app/agents/[agent]/page.tsxfires twoapiGetcalls inside auseEffectwith no cancellation token, so navigating between agents quickly can let a slow earlier response set state for the wrong agent, and the optionaltotalrequest swallows errors with an emptycatch. The repo shipsuseApiwith a cleanloading | error | okmachine and cancellation. This issue moves the primary usage fetch ontouseApiand adds a guarded total fetch.Requirements and context
/api/v1/agents/{agent}/usagefetch touseApi<Usage>(path), keyed on the encoded agent so it refetches on navigation and cancels superseded requests./totalfetch's soft-failure but guard it against out-of-order responses (latest agent wins).role="alert"; observable happy-path behaviour must not change.Suggested execution
git checkout -b refactor/agents-detail-useapisrc/app/agents/[agent]/page.tsx; reusesrc/lib/useApi.ts.src/app/agents/[agent]/page.test.tsx— assert a stale response for a previous agent is ignored and the latest wins.README.md.Test and commit
npm run lint,npm run typecheck,npm test, andnpm run build.npm testoutput.Example commit message
refactor(agents): adopt useApi and guard the total fetch on the detail pageGuidelines
Community & contribution rewards