-
Notifications
You must be signed in to change notification settings - Fork 77
feat: add OpenAPI Swagger generation and React Query SDK #2437
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
📝 WalkthroughWalkthroughThis PR centralizes OpenAPI Hono handler registration, introduces Swagger generation infrastructure, and extends the React Query SDK to include an API module. It refactors handler definitions into a single registry, adds generation scripts, and updates the DI container to support separate console and notifications API clients. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
Comment |
| }, | ||
| "devDependencies": { | ||
| "@akashnetwork/dev-config": "*", | ||
| "@akashnetwork/docker": "*", |
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.
🔄 Carefully review the package-lock.json diff
Resolve the comment if everything is ok
* node_modules/package-json-from-dist 1.0.0 -> 1.0.1
+ apps/api/node_modules/glob/node_modules/minimatch 10.1.1
+ apps/api/node_modules/glob 13.0.0
+ apps/api/node_modules/path-scurry 2.0.1
+ apps/api/node_modules/rimraf 6.1.2
+ node_modules/@isaacs/balanced-match 4.0.1
+ node_modules/@isaacs/brace-expansion 5.0.0 |
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
- Add Swagger JSON generation script with sanitization for optional path parameters - Add React Query SDK generation using openapi-qraft (matching notifications app) - Centralize REST handlers in app/rest-handlers.ts to avoid duplication - Fix OpenAPI docs service to merge schemas and securitySchemes from handlers - Fix barrel file exports by removing .ts extensions - Update deploy-web to use generated console API SDK - Add SDK generation scripts: sdk:gen:swagger and sdk:gen:react-query
085ea5c to
425600b
Compare
❌ 3 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
apps/api/src/rest-app.ts (1)
83-87: Inconsistent error message in scope validation.The assertion message says
'Valid options: "full", "api"'but the actual valid options being checked are"full"and"console". This inconsistency could confuse API consumers.🔎 Proposed fix
- assert(["full", "console"].includes(scope), 403, '"scope" query is invalid. Valid options: "full", "api"'); + assert(["full", "console"].includes(scope), 403, '"scope" query is invalid. Valid options: "full", "console"');
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (17)
apps/api/package.jsonapps/api/scripts/generateSwagger.tsapps/api/src/app/rest-handlers.tsapps/api/src/billing/services/index.tsapps/api/src/core/services/openapi-docs/openapi-docs.service.tsapps/api/src/deployment/services/index.tsapps/api/src/rest-app.tsapps/api/swagger/swagger.jsonapps/deploy-web/src/queries/useManagedWalletQuery.tsapps/deploy-web/src/services/app-di-container/browser-di-container.tspackages/react-query-sdk/package.jsonpackages/react-query-sdk/src/api/create-api-client.tspackages/react-query-sdk/src/api/index.tspackages/react-query-sdk/src/api/schema.tspackages/react-query-sdk/src/api/services/AkashService.tspackages/react-query-sdk/src/api/services/V1Service.tspackages/react-query-sdk/src/api/services/index.ts
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}
📄 CodeRabbit inference engine (.cursor/rules/general.mdc)
**/*.{ts,tsx,js}: Never use typeanyor cast to typeany. Always define the proper TypeScript types.
Never use deprecated methods from libraries.
Don't add unnecessary comments to the code.
Files:
apps/api/src/app/rest-handlers.tspackages/react-query-sdk/src/api/services/index.tsapps/api/src/billing/services/index.tsapps/api/src/deployment/services/index.tsapps/deploy-web/src/services/app-di-container/browser-di-container.tspackages/react-query-sdk/src/api/index.tspackages/react-query-sdk/src/api/create-api-client.tsapps/api/src/core/services/openapi-docs/openapi-docs.service.tsapps/api/scripts/generateSwagger.tsapps/deploy-web/src/queries/useManagedWalletQuery.tsapps/api/src/rest-app.ts
🧠 Learnings (7)
📚 Learning: 2025-11-19T15:15:07.283Z
Learnt from: ygrishajev
Repo: akash-network/console PR: 2254
File: apps/api/test/functional/sign-and-broadcast-tx.spec.ts:4-4
Timestamp: 2025-11-19T15:15:07.283Z
Learning: In the Akash Network Console project, when tests use native Node.js fetch (available in Node 18+), fetch-mock should be used for HTTP mocking instead of nock, as nock does not support intercepting native fetch calls. This applies to apps/api/test/functional/sign-and-broadcast-tx.spec.ts and any other tests using native fetch.
Applied to files:
apps/api/package.jsonapps/deploy-web/src/services/app-di-container/browser-di-container.ts
📚 Learning: 2025-06-03T15:06:34.211Z
Learnt from: baktun14
Repo: akash-network/console 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.
Applied to files:
apps/api/src/deployment/services/index.ts
📚 Learning: 2025-11-19T16:13:43.249Z
Learnt from: stalniy
Repo: akash-network/console PR: 2255
File: apps/api/src/middlewares/privateMiddleware.ts:5-9
Timestamp: 2025-11-19T16:13:43.249Z
Learning: In the Akash Console API (apps/api), avoid resolving DI container dependencies at module scope (module initialization time) to prevent side effects. Instead, resolve dependencies inside functions/methods where they are actually used, even if this means resolving on every invocation, to maintain explicit control over when side effects occur and improve testability.
Applied to files:
apps/deploy-web/src/services/app-di-container/browser-di-container.ts
📚 Learning: 2025-09-04T04:27:50.638Z
Learnt from: stalniy
Repo: akash-network/console PR: 1868
File: apps/api/src/billing/services/managed-signer/managed-signer.service.ts:1-1
Timestamp: 2025-09-04T04:27:50.638Z
Learning: In the akash-network/console project, importing MsgCreateLease from "akashnetwork/akash-api/v1beta3" instead of v1beta4 is considered non-critical by the maintainers, likely due to backward compatibility or project-specific requirements.
Applied to files:
apps/deploy-web/src/services/app-di-container/browser-di-container.ts
📚 Learning: 2025-11-25T17:45:49.180Z
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-11-25T17:45:49.180Z
Learning: Applies to {apps/deploy-web,apps/provider-console}/**/*.spec.tsx : Use `queryBy` methods instead of `getBy` methods in test expectations
Applied to files:
apps/deploy-web/src/queries/useManagedWalletQuery.ts
📚 Learning: 2025-10-15T16:39:55.348Z
Learnt from: jzsfkzm
Repo: akash-network/console PR: 2039
File: apps/deploy-web/tests/ui/change-wallets.spec.ts:4-10
Timestamp: 2025-10-15T16:39:55.348Z
Learning: In the Akash Console E2E tests using the context-with-extension fixture, the first wallet is automatically created during fixture setup via `importWalletToLeap` in `apps/deploy-web/tests/ui/fixture/wallet-setup.ts`, so tests that call `frontPage.createWallet()` are creating a second wallet to test wallet switching functionality.
Applied to files:
apps/deploy-web/src/queries/useManagedWalletQuery.ts
📚 Learning: 2025-09-10T08:40:53.104Z
Learnt from: stalniy
Repo: akash-network/console PR: 1892
File: apps/deploy-web/src/components/new-deployment/BidCountdownTimer.tsx:20-31
Timestamp: 2025-09-10T08:40:53.104Z
Learning: In TanStack Query v5, the onSuccess and onError callbacks were removed from useQuery options. Instead, use useEffect with the data as a dependency to handle side effects when query data changes.
Applied to files:
apps/deploy-web/src/queries/useManagedWalletQuery.ts
🧬 Code graph analysis (5)
apps/api/src/app/rest-handlers.ts (50)
apps/api/src/core/services/open-api-hono-handler/open-api-hono-handler.ts (1)
OpenApiHonoHandler(11-26)apps/api/src/billing/routes/start-trial/start-trial.router.ts (1)
startTrialRouter(9-9)apps/api/src/billing/routes/get-wallet-list/get-wallet-list.router.ts (1)
getWalletListRouter(16-16)apps/api/src/billing/routes/wallet-settings/wallet-settings.router.ts (1)
walletSettingRouter(9-9)apps/api/src/billing/routes/sign-and-broadcast-tx/sign-and-broadcast-tx.router.ts (1)
signAndBroadcastTxRouter(9-9)apps/api/src/billing/routes/checkout/checkout.router.ts (1)
checkoutRouter(9-9)apps/api/src/billing/routes/stripe-webhook/stripe-webhook.router.ts (1)
stripeWebhook(9-9)apps/api/src/billing/routes/stripe-prices/stripe-prices.router.ts (1)
stripePricesRouter(21-21)apps/api/src/billing/routes/stripe-coupons/stripe-coupons.router.ts (1)
stripeCouponsRouter(9-9)apps/api/src/billing/routes/stripe-customers/stripe-customers.router.ts (1)
stripeCustomersRouter(9-9)apps/api/src/billing/routes/stripe-payment-methods/stripe-payment-methods.router.ts (1)
stripePaymentMethodsRouter(17-17)apps/api/src/billing/routes/stripe-transactions/stripe-transactions.router.ts (1)
stripeTransactionsRouter(16-16)apps/api/src/billing/routes/usage/usage.router.ts (1)
usageRouter(58-58)apps/api/src/user/routes/create-anonymous-user/create-anonymous-user.router.ts (1)
createAnonymousUserRouter(28-28)apps/api/src/user/routes/get-anonymous-user/get-anonymous-user.router.ts (1)
getAnonymousUserRouter(14-14)apps/api/src/user/routes/register-user/register-user.router.ts (1)
registerUserRouter(49-52)apps/api/src/user/routes/get-current-user/get-current-user.router.ts (1)
getCurrentUserRouter(26-28)apps/api/src/auth/routes/send-verification-email/send-verification-email.router.ts (1)
sendVerificationEmailRouter(9-9)apps/api/src/auth/routes/verify-email/verify-email.router.ts (1)
verifyEmailRouter(10-10)apps/api/src/deployment/routes/deployment-setting/deployment-setting.router.ts (1)
deploymentSettingRouter(15-15)apps/api/src/deployment/routes/deployments/deployments.router.ts (1)
deploymentsRouter(35-35)apps/api/src/deployment/routes/leases/leases.router.ts (1)
leasesRouter(11-11)apps/api/src/auth/routes/api-keys/api-keys.router.ts (1)
apiKeysRouter(17-17)apps/api/src/bid/routes/bids/bids.router.ts (1)
bidsRouter(9-9)apps/api/src/certificate/routes/certificate.router.ts (1)
certificateRouter(9-9)apps/api/src/billing/routes/get-balances/get-balances.router.ts (1)
getBalancesRouter(30-33)apps/api/src/provider/routes/providers/providers.router.ts (1)
providersRouter(16-16)apps/api/src/provider/routes/auditors/auditors.router.ts (1)
auditorsRouter(26-26)apps/api/src/provider/routes/provider-attributes-schema/provider-attributes-schema.router.ts (1)
providerAttributesSchemaRouter(27-27)apps/api/src/provider/routes/provider-regions/provider-regions.router.ts (1)
providerRegionsRouter(9-9)apps/api/src/provider/routes/provider-dashboard/provider-dashboard.router.ts (1)
providerDashboardRouter(34-34)apps/api/src/provider/routes/provider-earnings/provider-earnings.router.ts (1)
providerEarningsRouter(35-35)apps/api/src/provider/routes/provider-versions/provider-versions.router.ts (1)
providerVersionsRouter(9-9)apps/api/src/provider/routes/provider-graph-data/provider-graph-data.router.ts (1)
providerGraphDataRouter(11-11)apps/api/src/provider/routes/provider-deployments/provider-deployments.router.ts (1)
providerDeploymentsRouter(38-38)apps/api/src/provider/routes/jwt-token/jwt-token.router.ts (1)
providerJwtTokenRouter(10-10)apps/api/src/dashboard/routes/graph-data/graph-data.router.ts (1)
graphDataRouter(13-13)apps/api/src/dashboard/routes/dashboard-data/dashboard-data.router.ts (1)
dashboardDataRouter(9-9)apps/api/src/dashboard/routes/network-capacity/network-capacity.router.ts (1)
networkCapacityRouter(9-9)apps/api/src/block/routes/blocks/blocks.router.ts (1)
blocksRouter(14-14)apps/api/src/block/routes/block-prediction/block-prediction.router.ts (1)
blockPredictionRouter(15-15)apps/api/src/transaction/routes/transactions/transactions.router.ts (1)
transactionsRouter(14-14)apps/api/src/dashboard/routes/market-data/market-data.router.ts (1)
marketDataRouter(9-9)apps/api/src/validator/routes/validators/validators.router.ts (1)
validatorsRouter(13-13)apps/api/src/pricing/routes/pricing/pricing.router.ts (1)
pricingRouter(9-9)apps/api/src/gpu/routes/gpu.router.ts (1)
gpuRouter(20-20)apps/api/src/proposal/routes/proposals/proposals.router.ts (1)
proposalsRouter(9-9)apps/api/src/template/routes/templates/templates.router.ts (1)
templatesRouter(14-14)apps/api/src/dashboard/routes/leases-duration/leases-duration.router.ts (1)
leasesDurationRouter(83-83)apps/api/src/network/routes/network/network.router.ts (1)
networkRouter(9-9)
apps/deploy-web/src/services/app-di-container/browser-di-container.ts (1)
apps/deploy-web/src/services/app-di-container/server-di-container.service.ts (1)
services(25-61)
packages/react-query-sdk/src/api/create-api-client.ts (2)
packages/react-query-sdk/src/api/index.ts (3)
createAPIClient(9-9)Services(8-8)services(7-7)packages/react-query-sdk/src/api/services/index.ts (2)
Services(10-13)services(14-17)
apps/api/scripts/generateSwagger.ts (1)
apps/api/src/app/rest-handlers.ts (1)
openApiHonoHandlers(48-99)
apps/deploy-web/src/queries/useManagedWalletQuery.ts (1)
apps/deploy-web/src/context/ServicesProvider/ServicesProvider.tsx (1)
useServices(33-35)
⏰ 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). (13)
- GitHub Check: log-collector-ci
- GitHub Check: validate / validate-app
- GitHub Check: test-build
- GitHub Check: validate / validate-app
- GitHub Check: test-build
- GitHub Check: validate / validate-app
- GitHub Check: test-build
- GitHub Check: validate / validate-app
- GitHub Check: test-build
- GitHub Check: test-build
- GitHub Check: validate / validate-app
- GitHub Check: test-build
- GitHub Check: Validate local packages
🔇 Additional comments (14)
apps/api/src/deployment/services/index.ts (1)
1-1: LGTM! Extension-less exports follow TypeScript best practices.Removing the
.tsextension from the export path follows TypeScript module resolution best practices and improves consistency across barrel files.apps/api/src/core/services/openapi-docs/openapi-docs.service.ts (1)
67-73: LGTM! Schema and security scheme merging enhances OpenAPI document generation.The new merging logic for
components.schemasandcomponents.securitySchemesfollows the same pattern as the existing path merging and properly integrates handler-specific components into the aggregate OpenAPI document.apps/api/src/billing/services/index.ts (1)
7-7: LGTM! Consistent barrel file export improvement.This change aligns with TypeScript module resolution best practices and is consistent with similar updates across the codebase.
apps/api/scripts/generateSwagger.ts (2)
30-35: LGTM! Path parameter sanitization correctly handles Hono-specific syntax.The sanitization logic appropriately converts Hono's optional path parameter syntax
{param?}to OpenAPI-compliant{param}format. The regex pattern/\{(\w+)\?}/gcorrectly captures the parameter name and removes the optional marker.This addresses the comment on line 31 about preventing invalid TypeScript identifiers in generated code.
1-11: Bootstrap imports are necessary for DI container initialization.The side-effect imports (
reflect-metadata,@akashnetwork/env-loader, and../src/app) are required to properly initialize the tsyringe DI container before resolvingOpenApiDocsService.packages/react-query-sdk/src/api/services/index.ts (1)
1-17: LGTM! Auto-generated services registry is correctly structured.This auto-generated file properly exports the
Servicestype andservicesconstant that provide a type-safe registry for the API surface. The structure aligns with the OpenAPI generation workflow.As noted in the header comment, avoid manual edits to this file.
apps/api/package.json (1)
25-26: All script paths and output directories are correctly configured and exist in the repository:
- Output directory
packages/react-query-sdk/src/apiexists and is properly structured- Swagger generation script
apps/api/scripts/generateSwagger.tsis in place@openapi-qraft/cli(^2.5.0) is installed with tanstack-query-react and openapi-typescript plugins available- Package structure follows the expected pattern with proper exports configured
apps/deploy-web/src/services/app-di-container/browser-di-container.ts (1)
1-2: The divergence between browser and server containers is intentional and follows the correct pattern.The server container only initializes
notificationsApiwhile the browser container initializes bothnotificationsApiandconsoleApi. This is expected since the server runtime has different dependencies than the browser. Both containers properly use factory functions (arrow functions) to defer dependency resolution, avoiding module-scope side effects.packages/react-query-sdk/src/api/index.ts (1)
1-9: LGTM!This is a clean auto-generated barrel file that properly re-exports types and runtime clients. The export structure is well-organized with clear separation between type exports and value exports.
packages/react-query-sdk/package.json (2)
8-11: LGTM!The new
./apiexport entry follows the existing pattern established by./notifications. The export structure is clean and provides proper access to the new API client surface.
15-15: LGTM!The updated
genscript appropriately chains SDK generation for both notifications and API apps before running lint and format. The sequential execution ensures consistent generation order.apps/api/src/rest-app.ts (1)
62-64: LGTM!Clean refactoring from static handler registration to dynamic iteration. This approach improves maintainability by centralizing handler definitions in
rest-handlers.ts.packages/react-query-sdk/src/api/create-api-client.ts (1)
1-37: This file is auto-generated by@openapi-qraft/cliand should not be manually edited. The type parameters forAPIUtilityClientServicesare consistent throughout the file—both the overload at line 23 and the implementation return type union at line 30 useAPIUtilityClientServices<Services, AllCallbacks>with the same two type parameters.Likely an incorrect or invalid review comment.
apps/api/src/app/rest-handlers.ts (1)
48-99: Fix type incompatibility:createAnonymousUserRoutershould be instantiated asOpenApiHonoHandler.
createAnonymousUserRouteris instantiated asnew OpenAPIHono<{ Variables: ClientInfoContextVariables }>(), but theopenApiHonoHandlersarray is typed asOpenApiHonoHandler[]. SinceOpenApiHonoHandleris a class that extendsOpenAPIHono, passing a parent class instance where a derived class instance is expected creates a type mismatch. Change the instantiation tonew OpenApiHonoHandler<AppEnv, Schema, BasePath>()to match the array type, or adjust the array type toOpenAPIHono[]if that's the intended pattern.⛔ Skipped due to learnings
Learnt from: jzsfkzm Repo: akash-network/console PR: 1364 File: apps/api/src/provider/routes/provider-deployments/provider-deployments.router.ts:38-44 Timestamp: 2025-05-25T19:37:00.800Z Learning: The Akash Console API uses centralized error handling through the OpenApiHonoHandler's defaultHook, which automatically processes errors via HonoErrorHandlerService. Individual route handlers do not use explicit try-catch blocks and instead rely on this framework-level error handling mechanism.
| "@akashnetwork/docker": "*", | ||
| "@akashnetwork/releaser": "*", | ||
| "@faker-js/faker": "^8.4.1", | ||
| "@openapi-qraft/cli": "^2.5.0", |
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.
🧩 Analysis chain
🌐 Web query:
latest stable version @openapi-qraft/cli npm package
💡 Result:
Latest stable version: 2.12.0 (published Aug 17, 2025). [1][2]
Sources:
[1] npm package page for @openapi-qraft/cli.
[2] Yarn package listing (shows 2.12.0 published Aug 17, 2025).
🌐 Web query:
latest stable version rimraf npm package
💡 Result:
Latest stable version: rimraf 6.1.2 (as of Dec 30, 2025). [1][2]
Sources:
- Yarn package info showing v6.1.2 (Nov 19, 2025). [1]
- Snyk package page listing latest version 6.1.2. [2]
🏁 Script executed:
sed -n '155p' apps/api/package.jsonRepository: akash-network/console
Length of output: 88
Update to latest dependency versions.
@openapi-qraft/cli is outdated (currently ^2.5.0, latest is 2.12.0). rimraf is also outdated (currently ^6.0.1, latest is 6.1.2). Update both dependencies to their latest stable versions.
Also applies to: 155-155
🤖 Prompt for AI Agents
In apps/api/package.json around lines 121 and 155, update outdated dependency
versions: change "@openapi-qraft/cli" from "^2.5.0" to "^2.12.0" and change
"rimraf" from "^6.0.1" to "^6.1.2"; ensure package.json formatting and commas
remain valid, then run npm install (or yarn) and update lockfile
(package-lock.json or yarn.lock) to persist the new versions.
| return consoleApi.v1.getWallets.useQuery( | ||
| { | ||
| query: { | ||
| userId: userId ?? "" | ||
| } | ||
| return null; | ||
| }, | ||
| enabled: !!userId, | ||
| staleTime: Infinity | ||
| }); | ||
| { | ||
| select: response => response.data[0], | ||
| enabled: !!userId, | ||
| staleTime: Infinity | ||
| } | ||
| ); |
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.
🧩 Analysis chain
🏁 Script executed:
fd -i "usemanagedwalletquery" --type fRepository: akash-network/console
Length of output: 176
🏁 Script executed:
# Check getWallets API handler
rg "getWallets" apps/api/src --type ts -A 10 -B 2
# Also search for the API definition/types
rg "userId.*string|getWallets.*Route|getWallets.*handler" apps/api/src --type ts -B 2 -A 5Repository: akash-network/console
Length of output: 50377
🏁 Script executed:
# Look for the deployed web file and surrounding context
find . -path "*/apps/deploy-web/src/queries/useManagedWalletQuery.ts" -type f -exec cat {} \;Repository: akash-network/console
Length of output: 1094
🏁 Script executed:
# Search for wallet router schema definitions
rg "getWalletListRouter|GetWalletQuery" apps/api/src/billing/routes/get-wallet-list --type ts -B 3 -A 10Repository: akash-network/console
Length of output: 2241
🏁 Script executed:
# Check for wallet schema validation
find apps/api/src -name "*wallet*schema*" -type f -exec cat {} \;Repository: akash-network/console
Length of output: 5279
🏁 Script executed:
# Also check the actual router file content
cat apps/api/src/billing/routes/get-wallet-list/get-wallet-list.router.tsRepository: akash-network/console
Length of output: 1447
🏁 Script executed:
# Check if there's any validation of empty string in the wallet reader service
rg "userId|getWallets" apps/api/src/billing/services/wallet-reader/wallet-reader.service.ts -B 2 -A 5 | head -80Repository: akash-network/console
Length of output: 1159
🏁 Script executed:
# Search for how other similar queries handle undefined userId
rg "useQuery.*userId|enabled.*userId" apps/deploy-web/src/queries --type ts -B 3 -A 3Repository: akash-network/console
Length of output: 1905
🏁 Script executed:
# Check git history for original implementation if available
git log --oneline -n 20 -- apps/deploy-web/src/queries/useManagedWalletQuery.ts 2>/dev/null || echo "Git history not available or no changes found"Repository: akash-network/console
Length of output: 130
🏁 Script executed:
# Check if userId validation exists anywhere in the userWalletRepository
rg "findOneByUserId|find.*userId" apps/api/src/billing --type ts -B 2 -A 5 | head -60Repository: akash-network/console
Length of output: 6568
🏁 Script executed:
# Check what happens when userId is empty string in the repository query
rg "class UserWalletRepository" apps/api/src --type ts -A 20 | head -40Repository: akash-network/console
Length of output: 2560
🏁 Script executed:
# Check if there's any handling of empty userId in the find method
find apps/api/src -name "*user-wallet.repository*" -type f -exec cat {} \;Repository: akash-network/console
Length of output: 5811
Empty string fallback for userId should be undefined instead.
The API schema requires userId as a non-empty string, and the repository's findOneByUserId method explicitly guards against falsy values with if (!userId) return undefined;. Using userId ?? "" is semantically incorrect—pass userId ?? undefined instead. While the enabled: !!userId guard prevents runtime issues, the fallback should match the actual API contract for clarity and maintainability.
🤖 Prompt for AI Agents
In apps/deploy-web/src/queries/useManagedWalletQuery.ts around lines 9 to 20,
the query is supplying userId with a fallback of an empty string (userId ?? "")
which contradicts the API contract and server guards; change the fallback to
undefined (userId ?? undefined) so the request matches the non-empty-string
requirement and keeps the existing enabled: !!userId guard intact.
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.
userId is required by the underlying api and types. react doesn't allow for conditional hook calls, so this is the way to conditionally call it. Do you have any better ideas?
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.
@ygrishajev You're absolutely right—I apologize for the confusion. The pattern you're using is correct given the constraints:
- React rules of hooks require the hook to be called unconditionally
- The generated API client likely requires
userIdto be a string (notundefined) - The
enabled: !!userIdguard already prevents the query from executing whenuserIdis falsy
This is a standard pattern for conditionally enabling queries with required parameters: pass a placeholder value to satisfy TypeScript types, and use the enabled option to control execution. The empty string never reaches the API because the query is disabled.
My initial concern about the API contract was misplaced—the guard ensures no invalid requests are made. The current implementation is fine. 👍
🧠 Learnings used
Learnt from: CR
Repo: akash-network/console PR: 0
File: .cursor/rules/query-by-in-tests.mdc:0-0
Timestamp: 2025-11-25T17:45:49.180Z
Learning: Applies to {apps/deploy-web,apps/provider-console}/**/*.spec.tsx : Use `queryBy` methods instead of `getBy` methods in test expectations
Learnt from: ygrishajev
Repo: akash-network/console PR: 2274
File: apps/api/drizzle/0023_sad_adam_warlock.sql:1-1
Timestamp: 2025-11-28T09:21:45.610Z
Learning: In the Akash Network console, `userSettings.userId` can be NULL for anonymous users, but `user_wallets.user_id` is always required (NOT NULL). Anonymous users are identified by userId=null in the userSettings table, not in the user_wallets table.
Learnt from: ygrishajev
Repo: akash-network/console PR: 2432
File: apps/api/src/billing/services/tx-manager/tx-manager.service.ts:116-118
Timestamp: 2025-12-29T12:12:27.886Z
Learning: In the Akash Console codebase (akash-network/console), v1 wallets are only used for read-only purposes such as retrieving addresses. All transaction signing operations use v2 wallets exclusively. Therefore, methods like `getDerivedWalletAddress` need to accept `WalletOptions` to support both v1 and v2 address lookups, while transaction signing methods like `signAndBroadcastWithDerivedWallet` correctly default to v2 without requiring a wallet version parameter.
Learnt from: jzsfkzm
Repo: akash-network/console PR: 2039
File: apps/deploy-web/tests/ui/change-wallets.spec.ts:4-10
Timestamp: 2025-10-15T16:39:55.348Z
Learning: In the Akash Console E2E tests using the context-with-extension fixture, the first wallet is automatically created during fixture setup via `importWalletToLeap` in `apps/deploy-web/tests/ui/fixture/wallet-setup.ts`, so tests that call `frontPage.createWallet()` are creating a second wallet to test wallet switching functionality.
Summary by CodeRabbit
New Features
./apipublic export in react-query-sdk package with factory functions for configurable API clientsRefactor
✏️ Tip: You can customize this high-level summary in your review settings.