arrow_backRetour aux issues
grantFoxin/SentientFi
#66
Débutant
Ouvrirarrow_forward
Débutant
Ouvrirarrow_forward
Débutant
Ouvrirarrow_forward
fix: usePortfolio hook uses relative API paths and bypasses retry/timeout logic
ecoDébutant
bug
help wanted
Maybe Rewarded
GrantFox OSS
frontend
Third Campaign
descriptionDescription
## 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
lingdojo/kana-dojo
star3.2k
Poids du dépôt lourd
[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](https://img…
TypeScript
enhancement
help wanted
WasiqB/multiple-cucumber-html-reporter
star281
Poids du dépôt moyen
Error bucketing
It would be great to bucket the errors in different types i.e. Code exception, configuration exception, environmental e…
TypeScript
enhancement
help wanted
StellarLock/StellarLock
star0
Poids du dépôt léger
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/lock/token/:i…
TypeScript
bug
good first issue