feat: add GET /users/me/balance endpoint#77
feat: add GET /users/me/balance endpoint#77Mmesolove wants to merge 3 commits intoPi-Defi-world:mainfrom
Conversation
Expose user on-chain Stellar balances so the frontend can display real ACBU and XLM balances instead of placeholder dashes. - Add getBalance handler to userController.ts - Register GET /me/balance route in userRoutes.ts - Return acbu_balance, xlm_balance, and full balances array - Respects STELLAR_ACBU_ASSET_ISSUER env var for custom asset
📝 WalkthroughWalkthroughAdds a new authenticated GET /users/me/balance endpoint (controller + route) that reads a user’s Stellar address from the DB, queries the Stellar account via Changes
Sequence DiagramsequenceDiagram
participant Client as Client
participant Auth as "Auth Middleware"
participant Controller as "getBalance Controller"
participant DB as Prisma
participant Stellar as "stellarClient"
Client->>Auth: GET /users/me/balance (API key)
Auth-->>Controller: req.apiKey.userId
Controller->>DB: fetch user by id -> stellarAddress
DB-->>Controller: user { stellarAddress }
Controller->>Stellar: stellarClient.getAccount(stellarAddress)
Stellar-->>Controller: account { balances }
Controller->>Controller: compute acbu_balance & xlm_balance
Controller-->>Client: 200 { acbu_balance, xlm_balance, balances }
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
|
please review |
|
@Mmesolove Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/controllers/userController.ts`:
- Line 580: Wrap the call to stellarClient.getAccount in a try/catch inside the
userController code path that calls it; if stellarClient.getAccount throws,
catch the error and rethrow an AppError (e.g., new AppError("Stellar account not
found or unfunded", 404, { cause: err })) so the global error handler can
produce the proper client response—use the symbols stellarClient.getAccount and
AppError to locate where to add the try/catch and ensure the original error is
preserved as the cause or included in the AppError message.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 83f4f4d3-d418-42e8-937a-0b421d17bd63
📒 Files selected for processing (2)
src/controllers/userController.tssrc/routes/userRoutes.ts
|
@Mmesolove cl failed |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
src/jobs/walletActivationJob.ts (3)
3-3: Unused variable and formatting issue.
myVariableis declared but never used. If intentional placeholder code, it should be removed. Prettier also expects double quotes.♻️ Proposed fix
-const myVariable = 'value';🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/jobs/walletActivationJob.ts` at line 3, Remove the unused placeholder variable myVariable from walletActivationJob.ts (or use it meaningfully if intended); if it was meant to be placeholder, delete the declaration to avoid lint/unused-variable errors and update any remaining string literals to use double quotes to satisfy Prettier formatting rules.
9-10: Unused variable and formatting issue.
anotherVariableis declared but never used. Prettier expects double quotes and a trailing newline.♻️ Proposed fix
-// Another comment here -const anotherVariable = 'anotherValue';🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/jobs/walletActivationJob.ts` around lines 9 - 10, Remove the unused declaration anotherVariable (delete the line "const anotherVariable = 'anotherValue';") and reformat the file to use double quotes and ensure a trailing newline so the file ends with a newline; this fixes the unused-variable warning and satisfies Prettier's double-quote and newline rules.
1-1: Unused import and formatting issue.
someFunctionis imported but never used. Additionally, ESLint/Prettier flags single quotes—use double quotes per project style.♻️ Proposed fix
-import { someFunction } from 'some-library';If the import is actually needed, update to:
-import { someFunction } from 'some-library'; +import { someFunction } from "some-library";🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/jobs/walletActivationJob.ts` at line 1, Remove the unused import someFunction from the top of walletActivationJob.ts (or if it is actually required, use it where intended) and update the import string to use double quotes instead of single quotes to satisfy project formatting; ensure no other unused imports remain and run the linter/formatter to confirm the fix.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/jobs/walletActivationJob.ts`:
- Around line 1-10: The file removed the RabbitMQ consumer export
startWalletActivationConsumer causing startup failure and breaking the wallet
activation flow (sendXlmToActivate has no callers); restore the original
consumer implementation and export startWalletActivationConsumer (or
alternatively remove its import/call in src/index.ts), ensuring the consumer
subscribes to the activation queue and invokes
walletActivationService.sendXlmToActivate (or the existing walletActivationJob)
when messages arrive so KYC-paid wallets receive XLM; keep the
walletActivationJob export if used elsewhere and ensure
startWalletActivationConsumer is exported from this module.
---
Nitpick comments:
In `@src/jobs/walletActivationJob.ts`:
- Line 3: Remove the unused placeholder variable myVariable from
walletActivationJob.ts (or use it meaningfully if intended); if it was meant to
be placeholder, delete the declaration to avoid lint/unused-variable errors and
update any remaining string literals to use double quotes to satisfy Prettier
formatting rules.
- Around line 9-10: Remove the unused declaration anotherVariable (delete the
line "const anotherVariable = 'anotherValue';") and reformat the file to use
double quotes and ensure a trailing newline so the file ends with a newline;
this fixes the unused-variable warning and satisfies Prettier's double-quote and
newline rules.
- Line 1: Remove the unused import someFunction from the top of
walletActivationJob.ts (or if it is actually required, use it where intended)
and update the import string to use double quotes instead of single quotes to
satisfy project formatting; ensure no other unused imports remain and run the
linter/formatter to confirm the fix.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 21dd9e1d-032e-4115-9acc-e3b36aedda40
📒 Files selected for processing (1)
src/jobs/walletActivationJob.ts
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/jobs/walletActivationJob.ts`:
- Around line 1-3: The file contains unresolved git merge conflict markers and
stray placeholder imports that break parsing; remove all conflict markers (e.g.,
"=======", branch labels and the placeholder "feature/get-users-me-balance"
import) and restore only the original startWalletActivationConsumer
implementation so src/index.ts can import it; ensure the QUEUE reference is
defined by adding const QUEUE = QUEUES.WALLET_ACTIVATION before
startWalletActivationConsumer or replace QUEUE with QUEUES.WALLET_ACTIVATION
directly, and remove the extraneous trailing "main" marker.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: a0ca40b0-39cb-4bff-a319-adcfb58419b7
📒 Files selected for processing (1)
src/jobs/walletActivationJob.ts
|
@Mmesolove cl failed |
|
@Mmesolove resolve |
|
Please merge |
Closes #44
Expose user on-chain Stellar balances so the frontend can display real ACBU and XLM balances instead of placeholder dashes.
Add getBalance handler to userController.ts
Register GET /me/balance route in userRoutes.ts
Return acbu_balance, xlm_balance, and full balances array
Respects STELLAR_ACBU_ASSET_ISSUER env var for custom asset
Summary by CodeRabbit
New Features
Chores