feat(payments): EN-124 Add latest balances command#102
Conversation
|
Warning Rate limit exceeded
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 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 configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughA 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
Sequence DiagramsequenceDiagram
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ 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 |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
cmd/payments/pools/latest_balances.gocmd/payments/pools/root.go
|
Coderabbit comments are not bad, but beside that LGTM :) |
No description provided.