Problem
The frontend reaches the backend three different ways, which duplicates configuration and error handling:
src/api.ts uses a hardcoded base with raw fetch.
- Several pages call relative
/api/... paths directly: src/pages/RpcMetricsDashboard.tsx, src/pages/SetupPage.tsx, src/pages/BatchMultiCall.tsx, src/pages/RateLimitDashboard.tsx, and src/hooks/useTxStatus.ts.
src/services/sandbox-api.ts uses its own VITE_API_URL base.
Unifying these is cross-cutting: it touches the new shared client, every ad-hoc caller, and their tests.
What needs to be done
- Create a single API client (
src/services/apiClient.ts) that owns the base URL (from the configurable-base work), JSON handling, typed error normalization, and admin auth headers.
- Route all callers through it:
src/api.ts, src/services/sandbox-api.ts, src/hooks/useTxStatus.ts, and the four pages listed above.
- Standardize error handling so non-2xx responses throw a typed error with status and message.
- Add or update tests for the client and the migrated callers.
Files
- new
src/services/apiClient.ts
src/api.ts, src/services/sandbox-api.ts, src/hooks/useTxStatus.ts
src/pages/RpcMetricsDashboard.tsx, src/pages/SetupPage.tsx, src/pages/BatchMultiCall.tsx, src/pages/RateLimitDashboard.tsx
- tests under
test/
Acceptance deliverables
- Exactly one module defines the API base and fetch/error behavior.
- No page constructs API URLs or handles fetch errors ad hoc.
- All CI checks pass; the change cannot be merged until CI is green.
Tests to pass
- Unit tests for
apiClient: success parsing, non-2xx throwing a typed error, base URL resolution.
- Existing page tests continue to pass after the migration.
Problem
The frontend reaches the backend three different ways, which duplicates configuration and error handling:
src/api.tsuses a hardcoded base with rawfetch./api/...paths directly:src/pages/RpcMetricsDashboard.tsx,src/pages/SetupPage.tsx,src/pages/BatchMultiCall.tsx,src/pages/RateLimitDashboard.tsx, andsrc/hooks/useTxStatus.ts.src/services/sandbox-api.tsuses its ownVITE_API_URLbase.Unifying these is cross-cutting: it touches the new shared client, every ad-hoc caller, and their tests.
What needs to be done
src/services/apiClient.ts) that owns the base URL (from the configurable-base work), JSON handling, typed error normalization, and admin auth headers.src/api.ts,src/services/sandbox-api.ts,src/hooks/useTxStatus.ts, and the four pages listed above.Files
src/services/apiClient.tssrc/api.ts,src/services/sandbox-api.ts,src/hooks/useTxStatus.tssrc/pages/RpcMetricsDashboard.tsx,src/pages/SetupPage.tsx,src/pages/BatchMultiCall.tsx,src/pages/RateLimitDashboard.tsxtest/Acceptance deliverables
Tests to pass
apiClient: success parsing, non-2xx throwing a typed error, base URL resolution.