Skip to content

feat: add GET /users/me/balance endpoint#77

Open
Mmesolove wants to merge 3 commits intoPi-Defi-world:mainfrom
Mmesolove:feature/get-users-me-balance
Open

feat: add GET /users/me/balance endpoint#77
Mmesolove wants to merge 3 commits intoPi-Defi-world:mainfrom
Mmesolove:feature/get-users-me-balance

Conversation

@Mmesolove
Copy link
Copy Markdown
Contributor

@Mmesolove Mmesolove commented Mar 25, 2026

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

    • Added an authenticated endpoint that returns a user’s Stellar balances (ACBU when available, XLM, and full balances array) with validation and proper error handling.
  • Chores

    • Removed the previous wallet-activation background consumer and replaced it with a placeholder job implementation.

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
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 25, 2026

📝 Walkthrough

Walkthrough

Adds 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 stellarClient, and returns acbu_balance, xlm_balance, and balances. Removes the RabbitMQ wallet activation consumer and replaces it with a placeholder job.

Changes

Cohort / File(s) Summary
Balance Controller
src/controllers/userController.ts
Added exported getBalance controller: validates req.apiKey.userId, loads user stellarAddress from Prisma, calls stellarClient.getAccount, computes acbu_balance (issued ACBU asset when issuer env set, else native fallback) and xlm_balance, and returns JSON { acbu_balance, xlm_balance, balances }.
Route Registration
src/routes/userRoutes.ts
Registered new authenticated route GET /me/balance pointing to getBalance (middleware order unchanged).
Wallet Activation Job
src/jobs/walletActivationJob.ts
Removed RabbitMQ consumer (startWalletActivationConsumer) that consumed WALLET_ACTIVATION and invoked activation transfer; replaced with exported async walletActivationJob placeholder and removed queue/assert/consumer logic and related imports.

Sequence Diagram

sequenceDiagram
    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 }
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐇 I hopped to the ledger, nose in the breeze,
I sniffed for ACBU and XLM in the trees,
I counted the balances, tallied each tune,
Sent back your totals beneath the moon 🌙✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning Changes to walletActivationJob.ts appear out of scope: the job was gutted (consumer removed, replaced with placeholder) but this is unrelated to the balance endpoint objective in issue #44. Remove changes to walletActivationJob.ts or explain their necessity. The balance endpoint can be delivered without removing the wallet activation consumer logic.
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title accurately describes the main change: adding a GET /users/me/balance endpoint, which is the primary objective.
Linked Issues check ✅ Passed The PR successfully implements the requirement from issue #44 by adding the GET /users/me/balance endpoint to expose real on-chain Stellar balances for the frontend.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@Mmesolove
Copy link
Copy Markdown
Contributor Author

please review

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 25, 2026

@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! 🚀

Learn more about application limits

Copy link
Copy Markdown

@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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between 777cc1e and 7ca9964.

📒 Files selected for processing (2)
  • src/controllers/userController.ts
  • src/routes/userRoutes.ts

@Junman140
Copy link
Copy Markdown
Member

@Mmesolove cl failed

Copy link
Copy Markdown

@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: 1

🧹 Nitpick comments (3)
src/jobs/walletActivationJob.ts (3)

3-3: Unused variable and formatting issue.

myVariable is 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.

anotherVariable is 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.

someFunction is 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

📥 Commits

Reviewing files that changed from the base of the PR and between 7ca9964 and aaf2dd0.

📒 Files selected for processing (1)
  • src/jobs/walletActivationJob.ts

Copy link
Copy Markdown

@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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between aaf2dd0 and 6ab370f.

📒 Files selected for processing (1)
  • src/jobs/walletActivationJob.ts

@Junman140
Copy link
Copy Markdown
Member

@Mmesolove cl failed

@Junman140
Copy link
Copy Markdown
Member

@Mmesolove resolve

@Mmesolove
Copy link
Copy Markdown
Contributor Author

Please merge

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.

Balance endpoint for frontend missing

2 participants