Clean up the loose typing on the API keys page
Description
src/app/api-keys/page.tsx declares state with useState(null as KeyItem[] | null) and casts apiGet results with (b as { items: KeyItem[] }).items and (res as { key: string }).key, bypassing the generic typing that src/lib/apiClient.ts provides (apiGet<T>/apiPost<T>). This is inconsistent with the rest of the codebase (e.g. webhooks uses apiGet<{ items: Webhook[] }>) and weakens type safety. This issue tightens the typing without changing behaviour.
Requirements and context
- Repository scope: Agentpay-Org/Agentpay-frontend only.
- Replace
useState(null as …) with the generic form useState<… | null>(null).
- Use
apiGet<{ items: KeyItem[] }> and apiPost<{ key: string }> so the as casts can be removed.
- Do not change any rendered behaviour, the reveal/copy/revoke flows, or the API paths.
- Keep the file passing lint with no new
any/unsafe casts.
Suggested execution
- Fork the repo and create a branch
git checkout -b refactor/api-keys-typed-state
- Implement changes
- Write code in:
src/app/api-keys/page.tsx.
- Write comprehensive tests in: ensure
src/app/api-keys/page.test.tsx still passes; add an assertion that create returns the typed key.
- Add documentation: none beyond a short JSDoc on any extracted type if needed.
- Validate
npm run typecheck passes with no casts removed losing safety.
- Test and commit
Test and commit
- Run
npm run lint, npm run typecheck, npm test, and npm run build.
- Cover edge cases: create success, list load, and revoke — all unchanged.
- Include the
npm test output.
Example commit message
refactor(api-keys): use typed apiClient generics instead of as-casts
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.
Clean up the loose typing on the API keys page
Description
src/app/api-keys/page.tsxdeclares state withuseState(null as KeyItem[] | null)and castsapiGetresults with(b as { items: KeyItem[] }).itemsand(res as { key: string }).key, bypassing the generic typing thatsrc/lib/apiClient.tsprovides (apiGet<T>/apiPost<T>). This is inconsistent with the rest of the codebase (e.g. webhooks usesapiGet<{ items: Webhook[] }>) and weakens type safety. This issue tightens the typing without changing behaviour.Requirements and context
useState(null as …)with the generic formuseState<… | null>(null).apiGet<{ items: KeyItem[] }>andapiPost<{ key: string }>so theascasts can be removed.any/unsafe casts.Suggested execution
git checkout -b refactor/api-keys-typed-statesrc/app/api-keys/page.tsx.src/app/api-keys/page.test.tsxstill passes; add an assertion that create returns the typed key.npm run typecheckpasses with no casts removed losing safety.Test and commit
npm run lint,npm run typecheck,npm test, andnpm run build.npm testoutput.Example commit message
refactor(api-keys): use typed apiClient generics instead of as-castsGuidelines
Community & contribution rewards