Skip to content

fix: usePortfolio hook uses relative API paths and bypasses retry/timeout logic #66

Closed

Description

@grantfox-oss

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:

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:

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

Activity

  1. added
    bugSomething isn't working
    help wantedExtra attention is needed
    GrantFox OSSIssue tracked in GrantFox OSS
    Maybe RewardedIssue may be eligible for a GrantFox reward
    on Aug 22, 2026
  2. waterWang commented on Aug 22, 2026

    @waterWang

    I would like to work on this issue. Please assign it to me.

  3. Neziahtech commented on Aug 22, 2026

    @Neziahtech

    Hello,

    I’d love to take this issue on. I’m a full-stack developer with experience across Drips Waves 3–7, and the GrantFox oficiall 1 and2 campaign.

    My stack includes Rust, Soroban, Solidity, and TypeScript. I can deliver a clean, tested, and well-documented solution within 24 hours of assignment.

    Happy to start immediately.

  4. waterWang commented on Aug 22, 2026

    @waterWang

    Submitted PR #69 for this issue: #69

    Changes:

    • Replaced direct fetch() calls with apiRequest wrapper
    • URLs now use API_CONFIG.ENDPOINTS.PORTFOLIO_DETAIL and ENDPOINTS.PORTFOLIO_REBALANCE
    • apiRequest provides retry logic, timeout, and BASE_URL prefixing
  5. D240021 commented on Aug 22, 2026

    @D240021

    Hi! 👋

    I’m currently a Computer Science student and I’m starting to get into the world of open source contributions. I’m very interested in this issue and would like to work on it to gain experience, build confidence, and expand my CV.

    Could you please assign it to me? 🙂

    Thank you! 🚀

  6. waterWang commented on Aug 23, 2026

    @waterWang

    I would like to work on this issue. Fixing usePortfolio to use centralized API config and retry/timeout logic.

  7. Stanley-Owoh commented on Aug 23, 2026

    @Stanley-Owoh

    Good day maintainer, i would like to work on this issue. i will update usePortfolio to use API_CONFIG.BASE_URL and the apiRequest wrapper for consistent retries, timeouts, error handling, and remote API support.

  8. TCROWN10 commented on Aug 23, 2026

    @TCROWN10
    Contributor

    I would like to work on this issue. I’ve gone through the project and carefully reviewed the issue itself, and I believe it’s something I can handle effectively. I’m confident in my ability to work on it, give it my best, and get it completed successfully. I’m ready to take on the task and deliver a solid result.

  9. grantfox-oss commented on Aug 24, 2026

    @grantfox-oss
    Author

    🦊 GrantFox — @TCROWN10 has been assigned to this issue as part of the Third Campaign campaign!

    Next steps:

    1. Open a Pull Request referencing this issue (e.g., Closes #66)
    2. Your PR will be reviewed by the grantFoxin maintainers

    Good luck! Track your progress on GrantFox.

  10. added a commit that references this issue on Aug 26, 2026
    766d890
  11. grantfox-oss commented on Aug 26, 2026

    @grantfox-oss
    Author

    🎉 This issue has been marked as completed on GrantFox as part of the Third Campaign campaign!

    @TCROWN10's PR #73 was approved and merged by @Uchechukwu-Ekezie.

    🏆 @TCROWN10: You earned 35 FoxPoints for this contribution! Your current tier: Explorer (379 total points). Track your full progress on GrantFox.

    👏 Great work, @TCROWN10! Keep contributing to grantFoxin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardThird CampaignCampaign: Third CampaignbugSomething isn't workingfrontendFrontend UIhelp wantedExtra attention is needed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions