feat(wallets): add GET /wallets/:id/balance endpoint for XLM balance and low-funds warning#521
Open
petahade wants to merge 1 commit into
Open
feat(wallets): add GET /wallets/:id/balance endpoint for XLM balance and low-funds warning#521petahade wants to merge 1 commit into
petahade wants to merge 1 commit into
Conversation
…checks Introduces a balance endpoint that queries Horizon for a wallet's native XLM balance and returns a low-funds warning flag to help callers avoid NFT mint failures caused by insufficient balance. - StellarService.getWalletBalance(): strict-error variant of getAccountBalance that throws BadRequestException for invalid addresses, NotFoundException for unfunded/non-existent Stellar accounts, and BadGatewayException for Horizon network failures; re-exports LOW_BALANCE_THRESHOLD_XLM (2.0) and WalletBalanceResult interface - WalletBalanceService: dedicated service (PrismaService + StellarService) that looks up the wallet by id+userId, guards against soft-deleted wallets, then delegates to getWalletBalance - WalletsController: new GET :id/balance route behind @Auth() + WalletOwnershipGuard with full Swagger docs and appropriate rate limit - WalletsModule: registers WalletBalanceService and exports it
|
@petahade 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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #361
Summary
Adds a
GET /wallets/:id/balanceendpoint that queries the Horizon API for a wallet's native XLM balance and returns awarningflag when funds are below the 2 XLM threshold that commonly causes NFT mint transaction failures.prepare-mintonwarning: falseto avoid wasting a Soroban simulation on an underfunded walletgetAccountBalance(which silently returns 0 on any error), the new path surfaces typed HTTP errors so the endpoint response always reflects the actual cause of failureChanged files
src/stellar/stellar.service.tsAdds
getWalletBalance(address)alongside the existinggetAccountBalance:400 Bad Request404 Not Found503 Service Unavailable(existing behaviour)502 Bad GatewayAlso exports
LOW_BALANCE_THRESHOLD_XLM = 2.0and theWalletBalanceResultinterface so they can be shared across the codebase.src/wallets/wallet-balance.service.ts(new)Single-responsibility service that owns the "look up wallet → fetch balance" flow:
PrismaService) — 404 if not found, wrong owner, or soft-deletedStellarService.getWalletBalance(wallet.address)Kept separate from
WalletManagementServiceto avoid introducing a new constructor dependency into a class whose test suite instantiates it directly without a mock forStellarService.src/wallets/wallets.controller.tsNew route injected from
WalletBalanceService:@Auth()(JWT, inherited from controller)@UseGuards(WalletOwnershipGuard)defaultthrottle key){ balance: number, warning: boolean }Full Swagger docs with per-status descriptions (200, 400, 401, 404, 502).
src/wallets/wallets.module.tsRegisters and exports
WalletBalanceService.Request / response
Error handling matrix
Wallet N not found(ownership guard)Wallet N not foundInvalid Stellar addressStellar account not found for address: G...Horizon request failed: <reason>Service unavailableArchitecture notes
getAccountBalance(existing) swallows all Horizon errors and returns 0 — appropriate for internal callers that treat 0 as "assume unfunded."getWalletBalance(new) is the strict variant for HTTP-facing callers that need to surface the actual failure reason. Both share the same circuit breaker config so they apply the same fault-tolerance policy.WalletBalanceServiceis intentionally separate fromWalletManagementServiceto keep constructor dependencies stable across the existing test suite. The service is thin enough that it doesn't warrant a separate module.