-
Notifications
You must be signed in to change notification settings - Fork 71
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
base: main
Are you sure you want to change the base?
Conversation
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThis 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
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
Estimated code review effort🎯 4 (Complex) | ⏱️ ~40 minutes Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed 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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 maintainabilityThe 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
📒 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, usejest-mock-extended
to create mocks and pass mocks as dependencies to the service under test.
**/*.spec.{ts,tsx}
: Usesetup
function instead ofbeforeEach
in test files
setup
function must be at the bottom of the rootdescribe
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 insetup
function
Don't specify return type ofsetup
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 viaaxios.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 theservices.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 usethis.axios.getUri()
, which accesses the method through the encapsulated Axios instance rather than directly on the service. This aligns with the refactoredHttpService
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 theDeploymentHttpService
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 theLeaseHttpService
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()
todi.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 viasuper(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
toauthzHttpService.axios.defaults.baseURL
correctly reflect the new encapsulation where the Axios instance is accessed via theaxios
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 theAxiosInstance
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 castingthis
, 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 unusedAxiosRequestConfig
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 ofthis.interceptors.request
, which aligns with the new architecture whereHttpService
encapsulates an Axios instancepackages/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 compositionThe 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 implementationThe
getAxiosInstance
factory method correctly merges configurations while avoiding header contamination between instances by destructuring defaults.
84-92
: Service instantiations correctly updatedAll 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
beforeEach(() => { | ||
blockHttpService = new BlockHttpServiceCommon(); | ||
blockHttpService = new BlockHttpServiceCommon(axios.create()); | ||
service = new BlockHttpService(blockHttpService); | ||
}); |
There was a problem hiding this comment.
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.
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); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
46fb207
to
3f6bd4d
Compare
3f6bd4d
to
dd54ba9
Compare
WoW @jzsfkzm it's a challenging task. Don't push it so hard though but I appreciate that you started it. Because 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 |
closes #1424
Summary by CodeRabbit