fix: usePortfolio hook uses relative API paths and bypasses retry/timeout logic
Débutant
bughelp wantedMaybe RewardedGrantFox OSSfrontendThird Campaign
2 ★
Poids du clone léger
Mise à jour
Description
## Problem
In `frontend/src/hooks/usePortfolio.ts`, both `fetchPortfolio` and `executeRebalance` call `fetch()` directly with relative paths like `/api/portfolio/${portfolioId}`. This bypasses:
1. The centralized `API_CONFIG.BASE_URL` from `frontend/src/config/api.ts` — needed for non-same-origin deployments (e.g., the production Render URL)
2. The `apiRequest` wrapper's retry logic (3 attempts with exponential backoff)
3. The 15-second timeout via `AbortController`
In production, if the API is on a different origin, the hook's calls silently fail or hit the wrong endpoint. This was partially addressed in issue #47 but the hook was not updated — only `Dashboard.tsx` and `Landing.tsx` use `API_CONFIG.BASE_URL`.
## Proposed Fix
### 1. Use `API_CONFIG.BASE_URL`
Import `API_CONFIG` from `../config/api` and prefix all fetch URLs:
```typescript
const response = await fetch(`${API_CONFIG.BASE_URL}/api/portfolio/${portfolioId}`);
```
### 2. Replace with `apiRequest`
Use the existing `apiRequest` wrapper for automatic retry, timeout, and error parsing:
```typescript
import { apiRequest, API_CONFIG } from '../config/api';
const data = await apiRequest(`${API_CONFIG.BASE_URL}/api/portfolio/${portfolioId}`);
```
### 3. Verify response parsing
`apiRequest` returns parsed JSON. The `GET /portfolio/:id` route returns `{ success: true, portfolio: {...} }`, so make sure `setPortfolio(data.portfolio)` still works correctly.
### Files to modify
- `frontend/src/hooks/usePortfolio.ts` — update `fetchPortfolio` and `executeRebalance`
## Acceptance Criteria
- [ ] Import `API_CONFIG` from `../config/api`
- [ ] All fetch URLs prefixed with `API_CONFIG.BASE_URL`
- [ ] Replace direct `fetch()` with `apiRequest` wrapper
- [ ] `setPortfolio(data.portfolio)` still works correctly with parsed JSON response
- [ ] Hook works when `VITE_API_URL` is set to a remote URL
- [ ] Network errors show error state and retry per `apiRequest` config
## Affected Area
Frontend
Issues similaires
Tout voir
TypeScript
Débutant
[Good First Issue] 🐡 Add new Japan Fact 251 - Beginner-Friendly Open-source Contribution
## 🟢 Good First Issue: Add Japan Fact #251 — Beginner-Friendly Open Source Contribution ![Time: <1 minute](h…
Mise à jour
TypeScript
Débutant
Error bucketing
It would be great to bucket the errors in different types i.e. Code exception, configuration exception, envir…
Mise à jour
TypeScript
Débutant
LP lock links omit the /token|lp/ URL segment, causing wrong-type lookups on the detail page
## Summary Lock detail links should include the lock's kind in the URL, e.g. `/app/lock/lp/:id` or `/app/loc…
Mise à jour