Skip to content

fix: add pot_balance to p2p/me and keep one userbalance failure shape - #229

Open
helloscoopa wants to merge 1 commit into
mainfrom
scoopa/p2p-me-pot-balance
Open

helloscoopa wants to merge 1 commit into
mainfrom
scoopa/p2p-me-pot-balance

Conversation

@helloscoopa

@helloscoopa helloscoopa commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

What

Follow-up to #226. These commits were pushed to that branch after it merged, so they never landed:

  • GET /api/v1/p2p/me returns pot_balance next to its spendable balance, from the same read. app-frontend#132 (merged) reads it, so the sell and send sheets can say "· 4,500 in savings pots" from one live response. Without it the app shows no pot note there, but limits are still right.
  • /api/v1/userbalance bad requests (invalid JSON / Telegram ID) now use the same failure shape as the other errors (success: false, pots: [], zero balances). They keep HTTP 400 and the error field the DCA backend reads first. This addresses CodeRabbit's outside-diff note on feat: return spendable and pot balances from userbalance #226.

Docs: docs/dca-backend-integration.md §6.2.
Tests: TestUserBalanceBadRequestShape, TestWriteBalanceFailureHasNoErrorField.


Generated by Claude Code

Summary by CodeRabbit

  • New Features
    • P2P account details now include the total amount held in savings pots as pot_balance.
    • Invalid balance requests return HTTP 400 with an error message and a consistent failure response.
  • Documentation
    • Clarified that the regular balance excludes savings pots and pot_balance shows the amount held in pots.

…2p/me

The invalid JSON / Telegram ID answers now use the same shape as other
failures (success false, pots []), keeping 400 and the error field callers
read. /api/v1/p2p/me also returns pot_balance next to the spendable
balance, so the app can explain a limit from one live read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FBZc7gWkW4RodtHSrGXGQq
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Changes: P2P pot balance

Layer / File(s) Summary
Add pot balance to the P2P response
internal/api/p2p.go, docs/dca-backend-integration.md
meBody retrieves the sender’s total pot balance, returns an error if the lookup fails, and includes the value as pot_balance. The API example describes balance as excluding savings pots and documents pot_balance.

User balance error responses

Layer / File(s) Summary
Standardize user balance failure responses
internal/api/user_balance.go, internal/api/user_balance_test.go
Malformed JSON and nonpositive Telegram IDs return HTTP 400 with the failure response shape and an error field. Balance-read failures use HTTP 200 and omit error. Tests cover both response shapes.

Possibly related issues

  • bitcoindeepa/bot#183 — The issue concerns inconsistent user_balance.go error response shapes and retaining the error field. This change updates the same endpoint’s bad-request response shape and keeps that field.

Suggested reviewers: xbuddhi, claude, rayaanr

Change: Feature

Merge Risk: Minimal · up to 031f1

The change adds the pot balance to the P2P response and makes userbalance bad-request errors consistent, and it is low risk. In rare cases a pot note may briefly disagree with the spendable balance, and the next request corrects it.

Security architecture risk: Low · up to 031f1

The savings-pot total is returned through existing authenticated routes. A second lookup can make an otherwise successful balance request fail, or return two figures that reflect different moments. Payment checks and wallet creation are unchanged.

Retained concerns

  • Low · reliability · observed: The second savings-pot query makes the entire P2P balance response depend on a display field. If that query fails after spendable balance was computed, the endpoint discards the balance and limits and returns HTTP 503. Wallet initialization preserves its success status and creation flag, but drops the balance and limits through its existing fallback.
Security review details

Security Blast Radius

  • observed — The P2P service credential can now read the explicit savings-pot aggregate for any bot wallet it was already allowed to name with a signed user header, subject to the network allowlist when configured. The response adds neither individual pot records nor wallet credentials.

Trust Boundaries and Controls

  • observed — Wallet initialization still requires both service authentication and Telegram identity verification. User balance retains its separate wallet-signature and network controls; the changed malformed-input branches return fixed messages before looking up any account.

Resilience and Maintainability Implications

  • observed — Wallet creation or reuse is decided before balance enrichment. The existing per-user lock and initialized-wallet check govern concurrent initialization and retries; failure of the added query neither re-enters creation nor changes the reported creation outcome.

Hardening Proposals

  • proposed — Return the pot subtotal already used to calculate spendable balance. This removes the extra failure point and makes the two fields agree on the pot subtotal without implying an atomic snapshot across the wallet and pot stores.
Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d1c0a0fa-8941-4d37-b38b-6eab2732bad4
Commits

Reviewing files that changed from the base of the PR and between a373d1c and 031f151.

Files selected for processing: 4

  • docs/dca-backend-integration.md
  • internal/api/p2p.go
  • internal/api/user_balance.go
  • internal/api/user_balance_test.go

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

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.

2 participants