Skip to content

Conversation

@zahorodnyi
Copy link
Collaborator

@zahorodnyi zahorodnyi commented Jan 13, 2026

Rework swap table display logic to use the comfy-table crate and move display logic to separate crate
FIx: #45

@zahorodnyi zahorodnyi requested a review from KyrylR as a code owner January 13, 2026 12:42
@zahorodnyi zahorodnyi self-assigned this Jan 13, 2026
@zahorodnyi zahorodnyi added the greptile Mark this PR to be reviewed by Greptile label Jan 13, 2026
@zahorodnyi
Copy link
Collaborator Author

@greptile review the PR according to the CONTRIBUTION.md

@greptile-apps
Copy link

greptile-apps bot commented Jan 13, 2026

Greptile Overview

Greptile Summary

This PR successfully refactors the swap table display logic to use the comfy-table crate, achieving better alignment and consistency with other CLI table displays in the codebase.

Key Changes:

  • Moved three swap-related data structs (LocalSwapData, LocalCancellableSwap, LocalWithdrawableSwap) from function-local scope to module level in swap.rs
  • Created three new display structs (ActiveSwapDisplay, CancellableSwapDisplay, WithdrawableSwapDisplay) with pre-formatted string fields
  • Implemented builder functions (build_active_swaps_displays, build_cancellable_swaps_displays, build_withdrawable_swaps_displays) to transform business logic structs into display structs
  • Added TableData trait implementations for the new display structs in tables.rs
  • Replaced manual table formatting (using println! with format strings and dashes) with the unified render_table function that uses comfy-table

Architectural Benefits:

  • Separation of Concerns: Business logic (data collection) is now separate from presentation logic (display formatting)
  • Consistency: All swap tables now use the same rendering mechanism as other tables in the CLI (options, positions, etc.)
  • Maintainability: Table formatting changes can be made in one place (tables.rs) rather than scattered across command implementations
  • Testability: Display logic is now in separate, testable builder functions

Functional Correctness:

  • All original data is preserved and displayed correctly
  • Empty state handling remains unchanged (errors before attempting to display)
  • Column headers and data alignment match the original format
  • The distinction between SwapDisplay (for browsing remote swaps) and ActiveSwapDisplay (for taking local swaps) is maintained correctly

This refactoring addresses issue #45 by fixing table alignment issues and provides a cleaner, more maintainable codebase.

Confidence Score: 5/5

  • This PR is safe to merge with no identified risks
  • After thorough analysis of both changed files, commit history, and related codebase context, no logic errors, security vulnerabilities, or functional issues were found. The refactoring maintains exact functional parity with the original code while improving code organization and consistency. All data transformations are correct, error handling is preserved, and the changes follow existing patterns in the codebase. The single logical commit adheres to the repository's commit guidelines.
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
crates/cli-client/src/cli/swap.rs 5/5 Refactored swap table display logic by moving structs to module level, creating dedicated display structs with pre-formatted strings, and implementing builder functions to transform data
crates/cli-client/src/cli/tables.rs 5/5 Added TableData implementations and display functions for three new swap display structs, following existing patterns

Sequence Diagram

sequenceDiagram
    participant User
    participant swap.rs
    participant Builder Functions
    participant Display Structs
    participant tables.rs
    participant comfy-table

    User->>swap.rs: Execute swap command (take/cancel/withdraw)
    swap.rs->>swap.rs: Collect LocalSwapData/LocalCancellableSwap/LocalWithdrawableSwap
    swap.rs->>Builder Functions: build_*_displays(local_data)
    Builder Functions->>Builder Functions: Format strings (format_settlement_asset, truncate_with_ellipsis, etc.)
    Builder Functions->>Display Structs: Create ActiveSwapDisplay/CancellableSwapDisplay/WithdrawableSwapDisplay
    Display Structs-->>Builder Functions: Return Vec<DisplayStruct>
    Builder Functions-->>swap.rs: Return displays
    swap.rs->>tables.rs: display_*_table(displays)
    tables.rs->>tables.rs: TableData::get_header()
    tables.rs->>tables.rs: TableData::to_row() for each item
    tables.rs->>comfy-table: render_table()
    comfy-table->>User: Formatted table output
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 file reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@zahorodnyi zahorodnyi force-pushed the fix/alignment-in-swap-tables branch from 4c033b0 to 6ef701f Compare January 13, 2026 13:10
@zahorodnyi
Copy link
Collaborator Author

@greptile review the PR according to the CONTRIBUTION.md

@zahorodnyi zahorodnyi closed this Jan 13, 2026
@zahorodnyi zahorodnyi reopened this Jan 13, 2026
Copy link
Collaborator

@KyrylR KyrylR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK b4009e9

@KyrylR KyrylR merged commit bbdd34d into main Jan 13, 2026
1 check passed
@KyrylR KyrylR deleted the fix/alignment-in-swap-tables branch January 13, 2026 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

greptile Mark this PR to be reviewed by Greptile

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rework swap tables display to use the comfy-table crate

3 participants