Skip to content

refactor: standardise API client layer - #344

Merged
El-swaggerito merged 1 commit into
Axionvera:mainfrom
DevALVIN-24:feature/standardize-api-client
Jul 29, 2026
Merged

refactor: standardise API client layer#344
El-swaggerito merged 1 commit into
Axionvera:mainfrom
DevALVIN-24:feature/standardize-api-client

Conversation

@DevALVIN-24

Copy link
Copy Markdown
Contributor

Closes #333

Summary

This PR standardises the dashboard API client layer by unifying scattered direct fetch calls under the robust EnhancedApiClient located in src/utils/enhancedApiClient.ts.

Current Behaviour

API calls were scattered across components, services, and utility files (e.g., WalletContext, protocolHealth, sorobanRpcFetcher), relying on raw fetch calls with inconsistent error handling and retry logic.

Expected Behaviour

The dashboard now uses a central API client layer providing:

  • Consistent JSON parsing and error wrapping (AppError types).
  • Automatic, configurable retry policies for transient errors (NETWORK, TIMEOUT, SERVER).
  • Telemetry & logging for API calls.

Key Changes

  • Audited and Refactored API Call Sites:
    • src/contexts/WalletContext.tsx
    • src/services/events/sorobanRpcFetcher.ts
    • src/services/protocolHealth.ts
    • src/utils/telemetry.ts
  • Fixed EnhancedApiClient Empty Body Bug: Handled 204 No Content / empty responses safely by skipping JSON parsing when appropriate to prevent unnecessary json() parse errors (e.g., during telemetry tracking).
  • Cleanup: Removed unused src/utils/apiClient.ts as its core functions (sorobanRpc fetching) are now natively supported via apiPost.
  • Documentation: Created docs/API_CLIENT.md to document the convention of using EnhancedApiClient (apiGet, apiPost), including its error categorisation and retry policies.

Let me know if there's anything else you need!

@El-swaggerito
El-swaggerito merged commit b74b642 into Axionvera:main Jul 29, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Standardise Axionvera dashboard API client layer

2 participants