Skip to content

feat(payments): EN-124 Add latest balances command#102

Merged
Quentin-David-24 merged 4 commits into
mainfrom
feat/EN-124-latest-balances-cmd
Apr 28, 2026
Merged

feat(payments): EN-124 Add latest balances command#102
Quentin-David-24 merged 4 commits into
mainfrom
feat/EN-124-latest-balances-cmd

Conversation

@Quentin-David-24
Copy link
Copy Markdown
Contributor

No description provided.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 18, 2025

Warning

Rate limit exceeded

@Quentin-David-24 has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 26 minutes and 43 seconds before requesting another review.

To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7ea2a223-cd22-45f3-a4d8-2f9cb8e8bbc4

📥 Commits

Reviewing files that changed from the base of the PR and between f8fd23f and 589ab04.

📒 Files selected for processing (2)
  • cmd/payments/pools/latest_balances.go
  • cmd/payments/pools/root.go

Walkthrough

A new CLI command for retrieving latest pool balances has been added. It initializes a controller, determines the Payments API version, calls the appropriate version-specific endpoint (v1/v2 or v3), processes the response data, and renders results in a table format using pterm.

Changes

Cohort / File(s) Summary
New Pool Balances Command
cmd/payments/pools/latest_balances.go
Implements NewLatestBalancesCommand() with LatestBalancesStore and LatestBalancesController types. Handles version-specific API calls to retrieve pool balances, maps responses into shared structures, and renders tabular output with Asset and Amount columns.
Command Registration
cmd/payments/pools/root.go
Registers the new latest balances command as a subcommand of the pools root command.

Sequence Diagram

sequenceDiagram
    participant User as User/CLI
    participant Cmd as LatestBalancesCommand
    participant Ver as Version Resolver
    participant API as Payments API
    participant Store as LatestBalancesStore
    participant Out as Output Renderer

    User->>Cmd: Execute balances command
    Cmd->>Ver: Get Payments API version
    Ver-->>Cmd: Return version (v1/v2 or v3)
    
    alt API v1/v2
        Cmd->>API: GetPoolBalancesLatest (v1)
        API-->>Cmd: PoolBalancesResponse
        Cmd->>Cmd: Validate StatusCode < 300
        Cmd->>Store: Store response data
    else API v3
        Cmd->>API: GetPoolBalancesLatest (v3)
        API-->>Cmd: V3 balance items
        Cmd->>Cmd: Map v3 items to shared structure
        Cmd->>Store: Store mapped balances
    end
    
    Cmd->>Out: Render table (Asset, Amount columns)
    Out-->>User: Display pool balances
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 Hop, hop! A new command springs to life,
Pool balances revealed without strife,
From API versions one, two, and three,
Data flows swift as a rabbit's decree,
In tables displayed, for all eyes to see!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ❓ Inconclusive No description was provided by the author; the pull request lacks context about the changes, motivation, or implementation details. Add a pull request description explaining the purpose of the latest balances command, how it works, and any relevant implementation notes.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main change: adding a latest balances command to the payments module, with a specific reference to ticket EN-124.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/EN-124-latest-balances-cmd

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.

@Quentin-David-24 Quentin-David-24 marked this pull request as ready for review April 28, 2026 08:17
@Quentin-David-24 Quentin-David-24 requested a review from a team as a code owner April 28, 2026 08:17
Copy link
Copy Markdown
Contributor

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@cmd/payments/pools/latest_balances.go`:
- Around line 97-107: The code pre-allocates poolBalances with length
len(*v3Balances) and then uses append, producing leading zero-value entries;
change the allocation and population so you don't append into a pre-sized
slice—either create poolBalances with make([]shared.PoolBalance, 0,
len(*v3Balances)) and keep using append, or iterate with for i, v3Balance :=
range *v3Balances and assign directly to poolBalances[i] after allocating with
make([]shared.PoolBalance, len(*v3Balances)); update the block that references
v3Balances, poolBalances, shared.PoolBalance and the assignment to
c.store.Balances accordingly.
- Around line 13-14: Update the import statements in
cmd/payments/pools/latest_balances.go to use the v3 module path: replace
"github.com/formancehq/fctl/cmd/payments/versions" with
"github.com/formancehq/fctl/v3/cmd/payments/versions" and replace fctl
"github.com/formancehq/fctl/pkg" with fctl "github.com/formancehq/fctl/v3/pkg"
so the package paths match the module declared in go.mod and align with other
files (affects the import block at the top of latest_balances.go).
- Around line 126-133: NewLatestBalancesCommand() currently declares the CLI
verb "balances <poolID>" which collides with NewBalancesCommand(); change the
command name string in NewLatestBalancesCommand() from "balances <poolID>" to
"latest-balances <poolID>" (and update any brief description if desired) so the
registered child commands under the "pools" parent are unique; locate the
declaration inside NewLatestBalancesCommand() and replace the command literal to
resolve the naming collision.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 33d6cfb9-0cb7-4e1f-8fc2-36e5e692fddb

📥 Commits

Reviewing files that changed from the base of the PR and between be4e110 and f8fd23f.

📒 Files selected for processing (2)
  • cmd/payments/pools/latest_balances.go
  • cmd/payments/pools/root.go

Comment thread cmd/payments/pools/latest_balances.go Outdated
Comment thread cmd/payments/pools/latest_balances.go
Comment thread cmd/payments/pools/latest_balances.go
@fguery
Copy link
Copy Markdown
Contributor

fguery commented Apr 28, 2026

Coderabbit comments are not bad, but beside that LGTM :)

@Quentin-David-24 Quentin-David-24 merged commit e9a7648 into main Apr 28, 2026
5 checks passed
@Quentin-David-24 Quentin-David-24 deleted the feat/EN-124-latest-balances-cmd branch April 28, 2026 09:08
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