Skip to content

refactor: stop extending Axios in HttpService, expect an instance instead #1733

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

jzsfkzm
Copy link
Contributor

@jzsfkzm jzsfkzm commented Jul 24, 2025

closes #1424

Summary by CodeRabbit

  • Refactor
    • Unified all HTTP service classes to use pre-configured Axios instances instead of configuration objects.
    • Centralized Axios instance creation and interceptor management across backend and frontend services.
    • Updated service constructors and dependency injection to accept Axios instances, simplifying service instantiation and configuration.
    • Improved analytics tracking for specific API responses by consolidating response interceptors.
    • No changes to user-facing features or interfaces.

@jzsfkzm jzsfkzm requested a review from a team as a code owner July 24, 2025 13:54
Copy link

coderabbitai bot commented Jul 24, 2025

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

This change refactors all HTTP service classes to use dependency injection of pre-configured Axios instances instead of extending or constructing Axios directly. Service constructors and dependency injection containers are updated accordingly, and related test setups, React hooks, and interceptors are adjusted to reference the encapsulated Axios instance. No exported entity signatures are changed except for service constructors.

Changes

File(s) Change Summary
apps/api/src/chain/services/block-http/block-http.service.spec.ts Test updated to instantiate service with explicit Axios instance.
apps/api/src/core/providers/http-sdk.provider.ts,
apps/notifications/...provider.ts
Service registration updated to inject Axios instance via axios.create() instead of config object.
apps/deploy-web/src/components/turnstile/Turnstile.tsx,
.../useBalancesQuery.ts,
.../useGrantsQuery.ts
Updated to reference .axios property for interceptors and URI checks.
apps/deploy-web/src/context/ServicesProvider/ServicesProvider.tsx AuthzHttpService now receives Axios instance from DI container.
apps/deploy-web/src/services/app-di-container/app-di-container.ts Refactored DI container: centralizes Axios instance creation/configuration, updates all service factories.
apps/deploy-web/src/services/http/http-browser.service.ts UserProviderService now receives Axios instance in constructor.
apps/deploy-web/src/services/managed-wallet-http/managed-wallet-http.service.ts Constructor now takes an Axios instance instead of config object.
apps/deploy-web/src/services/user-provider/user-provider.service.ts Constructor now takes Axios instance, updates interceptor setup accordingly.
packages/http-sdk/src/http/http.service.ts HttpService now encapsulates Axios instance via composition, exposes HTTP methods delegating to it.
packages/http-sdk/src/*/*.ts (e.g., auth-http.service.ts, balance-http.service.ts, etc.) All HTTP service classes updated: constructors now accept Axios instance or removed if redundant.
packages/http-sdk/src/coin-gecko/coin-gecko-http.service.ts,
cosmos-http.service.ts,
node-http.service.ts
Constructors updated to accept Axios instance and apply retry logic to it.
packages/http-sdk/src/tx-http/tx-http.service.ts Constructor updated: Axios instance is now first parameter, followed by registry.

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant DIContainer
    participant AxiosFactory
    participant Service

    App->>DIContainer: Request Service (e.g., UserHttpService)
    DIContainer->>AxiosFactory: Create or retrieve AxiosInstance
    AxiosFactory-->>DIContainer: AxiosInstance
    DIContainer->>Service: Instantiate Service(AxiosInstance)
    Service-->>DIContainer: Service instance
    DIContainer-->>App: Return Service instance
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Possibly related PRs

Suggested reviewers

  • stalniy

Poem

A hop, a skip, a code refactor leap—
Now Axios is tamed, its config runs deep.
No longer we inherit, but inject with care,
Services now lighter, with less to declare.
With every request, our code feels more neat—
A rabbit’s delight in this DI feat! 🐇✨

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (1)
apps/deploy-web/src/services/app-di-container/app-di-container.ts (1)

66-80: Consider extracting analytics configuration for better maintainability

The analytics interceptors work correctly, but the hardcoded URL patterns and event names could be extracted to constants for better maintainability.

Consider extracting the analytics configuration:

const ANALYTICS_ENDPOINTS = {
  ANONYMOUS_USER: "/v1/anonymous-users",
  TRIAL_START: "v1/start-trial"
} as const;

const ANALYTICS_EVENTS = {
  ANONYMOUS_USER_CREATED: {
    name: "anonymous_user_created",
    category: "user",
    label: "Anonymous User Created"
  },
  TRIAL_STARTED: {
    name: "trial_started", 
    category: "billing",
    label: "Trial Started"
  }
} as const;

Then use these constants in the interceptors for better maintainability and type safety.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 37acfee and 46fb207.

📒 Files selected for processing (31)
  • apps/api/src/chain/services/block-http/block-http.service.spec.ts (2 hunks)
  • apps/api/src/core/providers/http-sdk.provider.ts (2 hunks)
  • apps/deploy-web/src/components/turnstile/Turnstile.tsx (1 hunks)
  • apps/deploy-web/src/context/ServicesProvider/ServicesProvider.tsx (1 hunks)
  • apps/deploy-web/src/queries/useBalancesQuery.ts (1 hunks)
  • apps/deploy-web/src/queries/useGrantsQuery.ts (3 hunks)
  • apps/deploy-web/src/services/app-di-container/app-di-container.ts (4 hunks)
  • apps/deploy-web/src/services/http/http-browser.service.ts (1 hunks)
  • apps/deploy-web/src/services/managed-wallet-http/managed-wallet-http.service.ts (1 hunks)
  • apps/deploy-web/src/services/user-provider/user-provider.service.ts (1 hunks)
  • apps/notifications/src/modules/alert/providers/http-sdk.provider.ts (2 hunks)
  • packages/http-sdk/src/api-http/api-http.service.ts (0 hunks)
  • packages/http-sdk/src/auth/auth-http.service.ts (0 hunks)
  • packages/http-sdk/src/authz/authz-http.service.ts (0 hunks)
  • packages/http-sdk/src/balance/balance-http.service.ts (0 hunks)
  • packages/http-sdk/src/bid/bid-http.service.ts (0 hunks)
  • packages/http-sdk/src/block/block-http.service.ts (0 hunks)
  • packages/http-sdk/src/coin-gecko/coin-gecko-http.service.ts (2 hunks)
  • packages/http-sdk/src/cosmos/cosmos-http.service.ts (2 hunks)
  • packages/http-sdk/src/deployment-setting/deployment-setting-http.service.ts (0 hunks)
  • packages/http-sdk/src/deployment/deployment-http.service.ts (1 hunks)
  • packages/http-sdk/src/git-hub/git-hub-http.service.ts (0 hunks)
  • packages/http-sdk/src/http/http.service.ts (1 hunks)
  • packages/http-sdk/src/lease/lease-http.service.ts (0 hunks)
  • packages/http-sdk/src/node/node-http.service.ts (2 hunks)
  • packages/http-sdk/src/provider/provider-http.service.ts (0 hunks)
  • packages/http-sdk/src/stripe/stripe.service.ts (0 hunks)
  • packages/http-sdk/src/template/template-http.service.ts (0 hunks)
  • packages/http-sdk/src/tx-http/tx-http.service.ts (2 hunks)
  • packages/http-sdk/src/usage/usage-http.service.ts (0 hunks)
  • packages/http-sdk/src/user-http/user-http.service.ts (2 hunks)
💤 Files with no reviewable changes (13)
  • packages/http-sdk/src/stripe/stripe.service.ts
  • packages/http-sdk/src/block/block-http.service.ts
  • packages/http-sdk/src/provider/provider-http.service.ts
  • packages/http-sdk/src/authz/authz-http.service.ts
  • packages/http-sdk/src/api-http/api-http.service.ts
  • packages/http-sdk/src/template/template-http.service.ts
  • packages/http-sdk/src/usage/usage-http.service.ts
  • packages/http-sdk/src/auth/auth-http.service.ts
  • packages/http-sdk/src/bid/bid-http.service.ts
  • packages/http-sdk/src/git-hub/git-hub-http.service.ts
  • packages/http-sdk/src/deployment-setting/deployment-setting-http.service.ts
  • packages/http-sdk/src/balance/balance-http.service.ts
  • packages/http-sdk/src/lease/lease-http.service.ts
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/general.mdc)

Never use type any or cast to type any. Always define the proper TypeScript types.

Files:

  • apps/api/src/chain/services/block-http/block-http.service.spec.ts
  • apps/deploy-web/src/components/turnstile/Turnstile.tsx
  • apps/notifications/src/modules/alert/providers/http-sdk.provider.ts
  • apps/deploy-web/src/queries/useBalancesQuery.ts
  • apps/deploy-web/src/services/http/http-browser.service.ts
  • packages/http-sdk/src/coin-gecko/coin-gecko-http.service.ts
  • apps/deploy-web/src/queries/useGrantsQuery.ts
  • apps/deploy-web/src/services/user-provider/user-provider.service.ts
  • apps/deploy-web/src/services/managed-wallet-http/managed-wallet-http.service.ts
  • apps/deploy-web/src/context/ServicesProvider/ServicesProvider.tsx
  • packages/http-sdk/src/cosmos/cosmos-http.service.ts
  • packages/http-sdk/src/deployment/deployment-http.service.ts
  • apps/api/src/core/providers/http-sdk.provider.ts
  • packages/http-sdk/src/node/node-http.service.ts
  • packages/http-sdk/src/tx-http/tx-http.service.ts
  • packages/http-sdk/src/user-http/user-http.service.ts
  • packages/http-sdk/src/http/http.service.ts
  • apps/deploy-web/src/services/app-di-container/app-di-container.ts
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/general.mdc)

**/*.{js,jsx,ts,tsx}: Never use deprecated methods from libraries.
Don't add unnecessary comments to the code

Files:

  • apps/api/src/chain/services/block-http/block-http.service.spec.ts
  • apps/deploy-web/src/components/turnstile/Turnstile.tsx
  • apps/notifications/src/modules/alert/providers/http-sdk.provider.ts
  • apps/deploy-web/src/queries/useBalancesQuery.ts
  • apps/deploy-web/src/services/http/http-browser.service.ts
  • packages/http-sdk/src/coin-gecko/coin-gecko-http.service.ts
  • apps/deploy-web/src/queries/useGrantsQuery.ts
  • apps/deploy-web/src/services/user-provider/user-provider.service.ts
  • apps/deploy-web/src/services/managed-wallet-http/managed-wallet-http.service.ts
  • apps/deploy-web/src/context/ServicesProvider/ServicesProvider.tsx
  • packages/http-sdk/src/cosmos/cosmos-http.service.ts
  • packages/http-sdk/src/deployment/deployment-http.service.ts
  • apps/api/src/core/providers/http-sdk.provider.ts
  • packages/http-sdk/src/node/node-http.service.ts
  • packages/http-sdk/src/tx-http/tx-http.service.ts
  • packages/http-sdk/src/user-http/user-http.service.ts
  • packages/http-sdk/src/http/http.service.ts
  • apps/deploy-web/src/services/app-di-container/app-di-container.ts
**/*.spec.{ts,tsx}

📄 CodeRabbit Inference Engine (.cursor/rules/no-jest-mock.mdc)

Don't use jest.mock() to mock dependencies in test files. Instead, use jest-mock-extended to create mocks and pass mocks as dependencies to the service under test.

**/*.spec.{ts,tsx}: Use setup function instead of beforeEach in test files
setup function must be at the bottom of the root describe block in test files
setup function creates an object under test and returns it
setup function should accept a single parameter with inline type definition
Don't use shared state in setup function
Don't specify return type of setup function

Files:

  • apps/api/src/chain/services/block-http/block-http.service.spec.ts
🧠 Learnings (19)
📓 Common learnings
Learnt from: jzsfkzm
PR: akash-network/console#1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:0-0
Timestamp: 2025-05-28T20:42:58.200Z
Learning: The user successfully implemented CosmosHttpService with retry logic using axiosRetry, exponential backoff, and proper error handling for Cosmos API calls, replacing direct axios usage in StatsService.
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-07-21T08:24:27.953Z
Learning: Applies to apps/{deploy-web,provider-console}/**/*.spec.tsx : Use `queryBy` methods instead of `getBy` methods in test expectations in `.spec.tsx` files
Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/no-jest-mock.mdc:0-0
Timestamp: 2025-07-21T08:24:24.269Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't use `jest.mock()` to mock dependencies in test files. Instead, use `jest-mock-extended` to create mocks and pass mocks as dependencies to the service under test.
apps/api/src/chain/services/block-http/block-http.service.spec.ts (6)

Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/no-jest-mock.mdc:0-0
Timestamp: 2025-07-21T08:24:24.269Z
Learning: Applies to **/*.spec.{ts,tsx} : Don't use jest.mock() to mock dependencies in test files. Instead, use jest-mock-extended to create mocks and pass mocks as dependencies to the service under test.

Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : Use setup function instead of beforeEach in test files

Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-07-21T08:24:27.953Z
Learning: Applies to apps/{deploy-web,provider-console}/**/*.spec.tsx : Use queryBy methods instead of getBy methods in test expectations in .spec.tsx files

Learnt from: jzsfkzm
PR: #1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:0-0
Timestamp: 2025-05-28T20:42:58.200Z
Learning: The user successfully implemented CosmosHttpService with retry logic using axiosRetry, exponential backoff, and proper error handling for Cosmos API calls, replacing direct axios usage in StatsService.

Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : setup function creates an object under test and returns it

Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/setup-instead-of-before-each.mdc:0-0
Timestamp: 2025-07-21T08:25:07.474Z
Learning: Applies to **/*.spec.{ts,tsx} : setup function should accept a single parameter with inline type definition

apps/deploy-web/src/components/turnstile/Turnstile.tsx (1)

Learnt from: jzsfkzm
PR: #1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:0-0
Timestamp: 2025-05-28T20:42:58.200Z
Learning: The user successfully implemented CosmosHttpService with retry logic using axiosRetry, exponential backoff, and proper error handling for Cosmos API calls, replacing direct axios usage in StatsService.

apps/notifications/src/modules/alert/providers/http-sdk.provider.ts (3)

Learnt from: jzsfkzm
PR: #1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:0-0
Timestamp: 2025-05-28T20:42:58.200Z
Learning: The user successfully implemented CosmosHttpService with retry logic using axiosRetry, exponential backoff, and proper error handling for Cosmos API calls, replacing direct axios usage in StatsService.

Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-07-21T08:24:27.953Z
Learning: Applies to apps/{deploy-web,provider-console}/**/*.spec.tsx : Use queryBy methods instead of getBy methods in test expectations in .spec.tsx files

Learnt from: baktun14
PR: #1428
File: apps/api/src/deployment/controllers/deployment/deployment.controller.ts:0-0
Timestamp: 2025-06-03T15:06:34.211Z
Learning: The getByOwnerAndDseq method in apps/api/src/deployment/controllers/deployment/deployment.controller.ts is intentionally public without the @Protected decorator because it serves public blockchain data from an indexer, following the pattern of public blockchain APIs.

apps/deploy-web/src/queries/useBalancesQuery.ts (3)

Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-07-21T08:24:27.953Z
Learning: Applies to apps/{deploy-web,provider-console}/**/*.spec.tsx : Use queryBy methods instead of getBy methods in test expectations in .spec.tsx files

Learnt from: jzsfkzm
PR: #1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:0-0
Timestamp: 2025-05-28T20:42:58.200Z
Learning: The user successfully implemented CosmosHttpService with retry logic using axiosRetry, exponential backoff, and proper error handling for Cosmos API calls, replacing direct axios usage in StatsService.

Learnt from: stalniy
PR: #1660
File: apps/deploy-web/src/components/alerts/DeploymentAlertsContainer/DeploymentAlertsContainer.spec.tsx:54-56
Timestamp: 2025-07-11T10:46:43.711Z
Learning: In apps/{deploy-web,provider-console}/**/*.spec.tsx files: Use getBy methods instead of queryBy methods when testing element presence with toBeInTheDocument() because getBy throws an error and shows DOM state when element is not found, providing better debugging information than queryBy which returns null.

apps/deploy-web/src/services/http/http-browser.service.ts (2)

Learnt from: jzsfkzm
PR: #1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:0-0
Timestamp: 2025-05-28T20:42:58.200Z
Learning: The user successfully implemented CosmosHttpService with retry logic using axiosRetry, exponential backoff, and proper error handling for Cosmos API calls, replacing direct axios usage in StatsService.

Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-07-21T08:24:27.953Z
Learning: Applies to apps/{deploy-web,provider-console}/**/*.spec.tsx : Use queryBy methods instead of getBy methods in test expectations in .spec.tsx files

packages/http-sdk/src/coin-gecko/coin-gecko-http.service.ts (2)

Learnt from: jzsfkzm
PR: #1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:0-0
Timestamp: 2025-05-28T20:42:58.200Z
Learning: The user successfully implemented CosmosHttpService with retry logic using axiosRetry, exponential backoff, and proper error handling for Cosmos API calls, replacing direct axios usage in StatsService.

Learnt from: jzsfkzm
PR: #1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:245-248
Timestamp: 2025-05-28T20:33:02.123Z
Learning: The user has implemented retry logic for Cosmos API calls in a dedicated CosmosHttpService, addressing resilience concerns for external API interactions.

apps/deploy-web/src/queries/useGrantsQuery.ts (3)

Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-07-21T08:24:27.953Z
Learning: Applies to apps/{deploy-web,provider-console}/**/*.spec.tsx : Use queryBy methods instead of getBy methods in test expectations in .spec.tsx files

Learnt from: stalniy
PR: #1660
File: apps/deploy-web/src/components/alerts/DeploymentAlertsContainer/DeploymentAlertsContainer.spec.tsx:54-56
Timestamp: 2025-07-11T10:46:43.711Z
Learning: In apps/{deploy-web,provider-console}/**/*.spec.tsx files: Use getBy methods instead of queryBy methods when testing element presence with toBeInTheDocument() because getBy throws an error and shows DOM state when element is not found, providing better debugging information than queryBy which returns null.

Learnt from: jzsfkzm
PR: #1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:0-0
Timestamp: 2025-05-28T20:42:58.200Z
Learning: The user successfully implemented CosmosHttpService with retry logic using axiosRetry, exponential backoff, and proper error handling for Cosmos API calls, replacing direct axios usage in StatsService.

apps/deploy-web/src/services/user-provider/user-provider.service.ts (2)

Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-07-21T08:24:27.953Z
Learning: Applies to apps/{deploy-web,provider-console}/**/*.spec.tsx : Use queryBy methods instead of getBy methods in test expectations in .spec.tsx files

Learnt from: jzsfkzm
PR: #1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:0-0
Timestamp: 2025-05-28T20:42:58.200Z
Learning: The user successfully implemented CosmosHttpService with retry logic using axiosRetry, exponential backoff, and proper error handling for Cosmos API calls, replacing direct axios usage in StatsService.

apps/deploy-web/src/services/managed-wallet-http/managed-wallet-http.service.ts (1)

Learnt from: jzsfkzm
PR: #1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:0-0
Timestamp: 2025-05-28T20:42:58.200Z
Learning: The user successfully implemented CosmosHttpService with retry logic using axiosRetry, exponential backoff, and proper error handling for Cosmos API calls, replacing direct axios usage in StatsService.

apps/deploy-web/src/context/ServicesProvider/ServicesProvider.tsx (2)

Learnt from: jzsfkzm
PR: #1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:0-0
Timestamp: 2025-05-28T20:42:58.200Z
Learning: The user successfully implemented CosmosHttpService with retry logic using axiosRetry, exponential backoff, and proper error handling for Cosmos API calls, replacing direct axios usage in StatsService.

Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-07-21T08:24:27.953Z
Learning: Applies to apps/{deploy-web,provider-console}/**/*.spec.tsx : Use queryBy methods instead of getBy methods in test expectations in .spec.tsx files

packages/http-sdk/src/cosmos/cosmos-http.service.ts (2)

Learnt from: jzsfkzm
PR: #1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:0-0
Timestamp: 2025-05-28T20:42:58.200Z
Learning: The user successfully implemented CosmosHttpService with retry logic using axiosRetry, exponential backoff, and proper error handling for Cosmos API calls, replacing direct axios usage in StatsService.

Learnt from: jzsfkzm
PR: #1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:245-248
Timestamp: 2025-05-28T20:33:02.123Z
Learning: The user has implemented retry logic for Cosmos API calls in a dedicated CosmosHttpService, addressing resilience concerns for external API interactions.

packages/http-sdk/src/deployment/deployment-http.service.ts (3)

Learnt from: baktun14
PR: #1428
File: apps/api/src/deployment/controllers/deployment/deployment.controller.ts:0-0
Timestamp: 2025-06-03T15:06:34.211Z
Learning: The getByOwnerAndDseq method in apps/api/src/deployment/controllers/deployment/deployment.controller.ts is intentionally public without the @Protected decorator because it serves public blockchain data from an indexer, following the pattern of public blockchain APIs.

Learnt from: jzsfkzm
PR: #1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:0-0
Timestamp: 2025-05-28T20:42:58.200Z
Learning: The user successfully implemented CosmosHttpService with retry logic using axiosRetry, exponential backoff, and proper error handling for Cosmos API calls, replacing direct axios usage in StatsService.

Learnt from: CR
PR: akash-network/console#0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-07-21T08:24:27.953Z
Learning: Applies to apps/{deploy-web,provider-console}/**/*.spec.tsx : Use queryBy methods instead of getBy methods in test expectations in .spec.tsx files

apps/api/src/core/providers/http-sdk.provider.ts (1)

Learnt from: jzsfkzm
PR: #1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:0-0
Timestamp: 2025-05-28T20:42:58.200Z
Learning: The user successfully implemented CosmosHttpService with retry logic using axiosRetry, exponential backoff, and proper error handling for Cosmos API calls, replacing direct axios usage in StatsService.

packages/http-sdk/src/node/node-http.service.ts (2)

Learnt from: jzsfkzm
PR: #1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:0-0
Timestamp: 2025-05-28T20:42:58.200Z
Learning: The user successfully implemented CosmosHttpService with retry logic using axiosRetry, exponential backoff, and proper error handling for Cosmos API calls, replacing direct axios usage in StatsService.

Learnt from: jzsfkzm
PR: #1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:245-248
Timestamp: 2025-05-28T20:33:02.123Z
Learning: The user has implemented retry logic for Cosmos API calls in a dedicated CosmosHttpService, addressing resilience concerns for external API interactions.

packages/http-sdk/src/tx-http/tx-http.service.ts (1)

Learnt from: jzsfkzm
PR: #1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:0-0
Timestamp: 2025-05-28T20:42:58.200Z
Learning: The user successfully implemented CosmosHttpService with retry logic using axiosRetry, exponential backoff, and proper error handling for Cosmos API calls, replacing direct axios usage in StatsService.

packages/http-sdk/src/user-http/user-http.service.ts (1)

Learnt from: jzsfkzm
PR: #1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:0-0
Timestamp: 2025-05-28T20:42:58.200Z
Learning: The user successfully implemented CosmosHttpService with retry logic using axiosRetry, exponential backoff, and proper error handling for Cosmos API calls, replacing direct axios usage in StatsService.

packages/http-sdk/src/http/http.service.ts (1)

Learnt from: jzsfkzm
PR: #1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:0-0
Timestamp: 2025-05-28T20:42:58.200Z
Learning: The user successfully implemented CosmosHttpService with retry logic using axiosRetry, exponential backoff, and proper error handling for Cosmos API calls, replacing direct axios usage in StatsService.

apps/deploy-web/src/services/app-di-container/app-di-container.ts (1)

Learnt from: jzsfkzm
PR: #1372
File: apps/api/src/dashboard/services/stats/stats.service.ts:0-0
Timestamp: 2025-05-28T20:42:58.200Z
Learning: The user successfully implemented CosmosHttpService with retry logic using axiosRetry, exponential backoff, and proper error handling for Cosmos API calls, replacing direct axios usage in StatsService.

🧬 Code Graph Analysis (8)
apps/api/src/chain/services/block-http/block-http.service.spec.ts (1)
packages/http-sdk/src/http/http.service.ts (1)
  • axios (30-32)
apps/deploy-web/src/services/http/http-browser.service.ts (2)
apps/deploy-web/src/services/user-provider/user-provider.service.ts (1)
  • UserProviderService (7-26)
apps/deploy-web/src/services/http/http-server.service.ts (1)
  • services (22-32)
packages/http-sdk/src/coin-gecko/coin-gecko-http.service.ts (1)
packages/http-sdk/src/http/http.service.ts (1)
  • axios (30-32)
packages/http-sdk/src/cosmos/cosmos-http.service.ts (1)
packages/http-sdk/src/http/http.service.ts (1)
  • axios (30-32)
apps/api/src/core/providers/http-sdk.provider.ts (5)
packages/http-sdk/src/http/http.service.ts (1)
  • axios (30-32)
apps/api/src/utils/constants.ts (2)
  • apiNodeUrl (19-19)
  • nodeApiBasePath (22-22)
packages/http-sdk/src/git-hub/git-hub-http.service.ts (1)
  • GitHubHttpService (50-66)
packages/http-sdk/src/coin-gecko/coin-gecko-http.service.ts (1)
  • CoinGeckoHttpService (10-24)
packages/http-sdk/src/node/node-http.service.ts (1)
  • NodeHttpService (10-29)
packages/http-sdk/src/node/node-http.service.ts (1)
packages/http-sdk/src/http/http.service.ts (1)
  • axios (30-32)
packages/http-sdk/src/tx-http/tx-http.service.ts (1)
packages/http-sdk/src/http/http.service.ts (1)
  • axios (30-32)
packages/http-sdk/src/user-http/user-http.service.ts (1)
packages/http-sdk/src/http/http.service.ts (1)
  • axios (30-32)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (8)
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: validate / validate-app
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: Validate local packages
🔇 Additional comments (32)
apps/api/src/chain/services/block-http/block-http.service.spec.ts (2)

5-5: LGTM: Axios import added for service instantiation.

The axios import is correctly added to support the refactored service constructor.


14-14: LGTM: Service instantiation correctly updated with Axios instance.

The BlockHttpServiceCommon constructor is properly updated to receive an Axios instance created via axios.create(), which aligns with the PR objective of using dependency injection instead of extending Axios.

apps/deploy-web/src/components/turnstile/Turnstile.tsx (2)

30-30: LGTM: Interceptor registration correctly updated for encapsulated Axios instance.

The response interceptor is properly registered on service.axios.interceptors.response instead of directly on the service, which aligns with the refactored architecture where services encapsulate an Axios instance.


33-33: LGTM: Interceptor cleanup correctly updated for encapsulated Axios instance.

The interceptor ejection properly uses service.axios.interceptors.response.eject(), maintaining consistency with the updated interceptor registration pattern.

apps/deploy-web/src/services/http/http-browser.service.ts (1)

22-22: LGTM: Service instantiation correctly updated with Axios dependency injection.

The UserProviderService constructor is properly updated to receive the services.defaultAxios instance, which aligns with the refactored architecture where services expect pre-configured Axios instances instead of plain configuration objects.

packages/http-sdk/src/deployment/deployment-http.service.ts (1)

154-154: LGTM: Method call correctly updated for encapsulated Axios instance.

The call to getUri is properly updated to use this.axios.getUri(), which accesses the method through the encapsulated Axios instance rather than directly on the service. This aligns with the refactored HttpService architecture.

apps/notifications/src/modules/alert/providers/http-sdk.provider.ts (3)

4-4: LGTM: Axios import added for service instantiation.

The axios import is correctly added to support creating Axios instances for the refactored service constructors.


13-17: LGTM: DeploymentHttpService provider correctly updated with Axios dependency injection.

The factory function properly creates an Axios instance with the configured baseURL and passes it to the DeploymentHttpService constructor, aligning with the refactored architecture that expects pre-configured Axios instances.


23-27: LGTM: LeaseHttpService provider correctly updated with Axios dependency injection.

The factory function properly creates an Axios instance with the configured baseURL and passes it to the LeaseHttpService constructor, maintaining consistency with the dependency injection pattern established in the refactor.

apps/deploy-web/src/queries/useBalancesQuery.ts (1)

13-13: LGTM! Correct property access pattern.

The change from di.authzHttpService.getUri() to di.authzHttpService.axios.getUri() correctly reflects the new encapsulation pattern where HTTP services now compose an Axios instance rather than extending it.

packages/http-sdk/src/user-http/user-http.service.ts (2)

1-1: LGTM! Correct import for the new constructor signature.

The AxiosInstance import is correctly added to support the refactored constructor that now expects an Axios instance.


28-30: LGTM! Constructor properly refactored for dependency injection.

The constructor correctly follows the new pattern by:

  • Accepting an AxiosInstance parameter instead of an optional config object
  • Passing the instance to the base HttpService class via super(axios)

This aligns with the broader refactor to use dependency injection of pre-configured Axios instances.

apps/deploy-web/src/queries/useGrantsQuery.ts (1)

20-20: LGTM! Consistent property access pattern across all hooks.

The changes from authzHttpService.defaults.baseURL to authzHttpService.axios.defaults.baseURL correctly reflect the new encapsulation where the Axios instance is accessed via the axios property. This is consistently applied across all three query hooks.

Also applies to: 32-32, 50-50

packages/http-sdk/src/node/node-http.service.ts (3)

1-1: LGTM! Import updated for new constructor signature.

Correctly removed unused AxiosRequestConfig and the AxiosInstance import supports the refactored constructor.


11-12: LGTM! Constructor properly refactored for dependency injection.

The constructor correctly follows the new pattern by accepting an AxiosInstance and passing it to the base class, consistent with the broader HttpService refactor.


14-18: LGTM! Retry logic correctly applied to injected Axios instance.

The retry configuration is now properly applied to the passed axios instance instead of casting this, which is cleaner and more explicit about which Axios instance is being configured.

apps/api/src/core/providers/http-sdk.provider.ts (3)

14-14: LGTM! Axios import added for instance creation.

The import is necessary to create Axios instances for the HTTP services, supporting the refactored dependency injection pattern.


30-30: LGTM! Services correctly instantiated with Axios instances.

The refactor from passing plain config objects to creating Axios instances with axios.create({ baseURL: apiNodeUrl }) properly implements the new dependency injection pattern for all services in the array.


32-34: LGTM! Individual services properly configured with Axios instances.

Each service is correctly instantiated with its own Axios instance created with the appropriate baseURL:

  • GitHubHttpService with GitHub raw content URL
  • CoinGeckoHttpService with CoinGecko API URL
  • NodeHttpService with the node API base path

This follows the consistent pattern of dependency injection with pre-configured Axios instances.

apps/deploy-web/src/context/ServicesProvider/ServicesProvider.tsx (1)

34-34: LGTM! Proper implementation of Axios instance injection.

The change correctly updates the AuthzHttpService instantiation to use a pre-configured Axios instance instead of passing configuration directly, aligning with the refactor objectives.

apps/deploy-web/src/services/managed-wallet-http/managed-wallet-http.service.ts (2)

3-3: LGTM! Proper type import for the refactor.

The addition of AxiosInstance import is necessary for the constructor parameter type change.


11-14: LGTM! Constructor correctly updated for dependency injection.

The constructor changes properly implement the refactor pattern:

  • Accepts AxiosInstance instead of configuration object
  • Correctly passes the instance to the superclass
  • Maintains existing functionality while improving architecture
packages/http-sdk/src/coin-gecko/coin-gecko-http.service.ts (2)

1-1: LGTM! Proper import cleanup for the refactor.

The import statement correctly adds AxiosInstance and removes the unused AxiosRequestConfig type, aligning with the new constructor signature.


11-19: LGTM! Constructor properly implements dependency injection pattern.

The constructor changes are well-implemented:

  • Accepts AxiosInstance parameter instead of config object
  • Correctly passes instance to superclass
  • Properly applies retry configuration to the provided instance
  • Maintains existing retry logic and error handling
apps/deploy-web/src/services/user-provider/user-provider.service.ts (2)

3-3: LGTM! Necessary import for constructor parameter type.

The addition of AxiosInstance import supports the constructor signature change.


8-12: LGTM! Constructor and interceptor setup correctly updated.

The changes properly implement the refactor:

  • Constructor accepts AxiosInstance parameter
  • Superclass receives the Axios instance correctly
  • Interceptor setup updated to use this.axios.interceptors.request instead of this.interceptors.request, which aligns with the new architecture where HttpService encapsulates an Axios instance
packages/http-sdk/src/cosmos/cosmos-http.service.ts (2)

1-1: LGTM! Import statement updated for the refactor.

The addition of AxiosInstance import is necessary for the new constructor parameter type.


27-35: LGTM! Constructor correctly implements dependency injection with retry logic.

The constructor changes are well-implemented:

  • Accepts AxiosInstance parameter following the refactor pattern
  • Correctly passes instance to superclass
  • Properly applies retry configuration to the provided instance
  • Maintains the existing exponential backoff and error condition logic that was previously implemented for Cosmos API resilience
packages/http-sdk/src/tx-http/tx-http.service.ts (1)

16-21: Constructor refactoring looks good!

The changes correctly implement dependency injection of the Axios instance and properly mark the registry as private readonly. The super constructor call is updated appropriately.

packages/http-sdk/src/http/http.service.ts (1)

1-5: Well-executed refactoring from inheritance to composition

The change from extending Axios to encapsulating an AxiosInstance is a good architectural improvement that follows dependency injection principles. The axios getter provides necessary access to the underlying instance for interceptor management.

Also applies to: 30-32

apps/deploy-web/src/services/app-di-container/app-di-container.ts (2)

32-39: Good factory pattern implementation

The getAxiosInstance factory method correctly merges configurations while avoiding header contamination between instances by destructuring defaults.


84-92: Service instantiations correctly updated

All HTTP services are properly instantiated with pre-configured Axios instances, maintaining consistency with the new dependency injection pattern. The managedWalletService correctly receives both dependencies.

Also applies to: 109-109

Comment on lines 13 to 16
beforeEach(() => {
blockHttpService = new BlockHttpServiceCommon();
blockHttpService = new BlockHttpServiceCommon(axios.create());
service = new BlockHttpService(blockHttpService);
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Use setup function instead of beforeEach as per coding guidelines.

The coding guidelines specify using a setup function instead of beforeEach in test files. The setup function should be at the bottom of the root describe block and should create the object under test.

Apply this refactor to follow the coding guidelines:

-  beforeEach(() => {
-    blockHttpService = new BlockHttpServiceCommon(axios.create());
-    service = new BlockHttpService(blockHttpService);
-  });
+  it("should get current height", async () => {
+    const { service, blockHttpService } = setup();
+    const height = faker.number.int({ min: 1000000, max: 10000000 });
+    jest.spyOn(blockHttpService, "getCurrentHeight").mockResolvedValue(height);
+    const result = await service.getCurrentHeight();
+
+    expect(result).toBe(height);
+  });
+
+  function setup() {
+    const blockHttpService = new BlockHttpServiceCommon(axios.create());
+    const service = new BlockHttpService(blockHttpService);
+    return { service, blockHttpService };
+  }

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In apps/api/src/chain/services/block-http/block-http.service.spec.ts around
lines 13 to 16, replace the beforeEach block with a setup function as per coding
guidelines. Move the initialization of blockHttpService and service into a setup
function placed at the bottom of the root describe block, ensuring it returns or
sets up the object under test properly for use in the tests.

Comment on lines 10 to 28
get<T = any, R = AxiosResponse<T>>(...args: Parameters<AxiosInstance["get"]>): Promise<R> {
return this.axios.get(...args);
}

post<T = any, R = AxiosResponse<T>>(...args: Parameters<AxiosInstance["post"]>): Promise<R> {
return this.axios.post(...args);
}

patch<T = any, R = AxiosResponse<T>>(...args: Parameters<AxiosInstance["patch"]>): Promise<R> {
return this.axios.patch(...args);
}

put<T = any, R = AxiosResponse<T>>(...args: Parameters<AxiosInstance["put"]>): Promise<R> {
return this.axios.put(...args);
}

delete<T = any, R = AxiosResponse<T>>(...args: Parameters<AxiosInstance["delete"]>): Promise<R> {
return this.axios.delete(...args);
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove any type usage in HTTP method signatures

All HTTP methods use T = any as the default generic type, which violates the TypeScript best practices. The type parameter should not have a default value of any.

Apply this diff to fix the type issues:

-  get<T = any, R = AxiosResponse<T>>(...args: Parameters<AxiosInstance["get"]>): Promise<R> {
+  get<T = unknown, R = AxiosResponse<T>>(...args: Parameters<AxiosInstance["get"]>): Promise<R> {
     return this.axios.get(...args);
   }

-  post<T = any, R = AxiosResponse<T>>(...args: Parameters<AxiosInstance["post"]>): Promise<R> {
+  post<T = unknown, R = AxiosResponse<T>>(...args: Parameters<AxiosInstance["post"]>): Promise<R> {
     return this.axios.post(...args);
   }

-  patch<T = any, R = AxiosResponse<T>>(...args: Parameters<AxiosInstance["patch"]>): Promise<R> {
+  patch<T = unknown, R = AxiosResponse<T>>(...args: Parameters<AxiosInstance["patch"]>): Promise<R> {
     return this.axios.patch(...args);
   }

-  put<T = any, R = AxiosResponse<T>>(...args: Parameters<AxiosInstance["put"]>): Promise<R> {
+  put<T = unknown, R = AxiosResponse<T>>(...args: Parameters<AxiosInstance["put"]>): Promise<R> {
     return this.axios.put(...args);
   }

-  delete<T = any, R = AxiosResponse<T>>(...args: Parameters<AxiosInstance["delete"]>): Promise<R> {
+  delete<T = unknown, R = AxiosResponse<T>>(...args: Parameters<AxiosInstance["delete"]>): Promise<R> {
     return this.axios.delete(...args);
   }
🤖 Prompt for AI Agents
In packages/http-sdk/src/http/http.service.ts lines 10 to 28, the HTTP method
signatures use a default generic type of T = any, which is against TypeScript
best practices. Remove the default value of any from the generic type parameter
T in all HTTP methods so that T is a required type parameter without a default.
This change enforces explicit typing and improves type safety.

@jzsfkzm jzsfkzm marked this pull request as draft July 24, 2025 14:08
@jzsfkzm jzsfkzm force-pushed the refactor/1424-axios branch from 46fb207 to 3f6bd4d Compare July 24, 2025 14:22
@jzsfkzm jzsfkzm force-pushed the refactor/1424-axios branch from 3f6bd4d to dd54ba9 Compare July 24, 2025 15:25
@stalniy
Copy link
Contributor

stalniy commented Jul 24, 2025

WoW @jzsfkzm it's a challenging task. Don't push it so hard though but I appreciate that you started it. Because axiosRetry doesn't work with this custom axios classes and throws runtime error

Though it's something we need to do but there is also an alternative way. We need to fix first #1701 and then we could generate client from swagger doc. And most of this self-written stuff will be just removed and chain sdk related stuff will be hopefully replaced with chain sdk library. So, for now probably it makes sense to refactor only chain sdk related http classes

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.

Refactor http services
2 participants