Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort receive accounts in swap section #16265

Merged
merged 1 commit into from
Feb 18, 2025
Merged

Conversation

enjojoy
Copy link
Contributor

@enjojoy enjojoy commented Jan 8, 2025

Description

Sort accounts by account type and account index

Related Issue

Resolve #14879

Screenshots:

Screenshot 2025-01-08 at 14 46 56 Screenshot 2025-01-08 at 14 59 52

@enjojoy enjojoy changed the title fix(suite): swap accounts sort Sort receive accounts in swap section Jan 8, 2025
Copy link

github-actions bot commented Jan 8, 2025

🚀 Expo preview is ready!

  • Project → trezor-suite-preview
  • Platforms → android, ios
  • Scheme → trezorsuitelite
  • Runtime Version → 26
  • More info

Learn more about 𝝠 Expo Github Action

@enjojoy enjojoy marked this pull request as ready for review January 9, 2025 09:10
@enjojoy enjojoy requested review from tomasklim and izmy January 9, 2025 09:11
@tomasklim tomasklim requested a review from izmy February 7, 2025 16:43
@tomasklim tomasklim force-pushed the fix/swap-accounts-sort branch from 9a1c653 to dcaa91d Compare February 17, 2025 15:10
Copy link

coderabbitai bot commented Feb 17, 2025

Walkthrough

The changes update both the test suite and the account filtering logic. In the test file, expected results have been revised to include legacy accounts for Ethereum and Bitcoin under specific conditions such as debug mode and coin join exclusions. The modifications include removing expectations for certain account types and including legacy accounts instead. In the main account filtering implementation, a new helper function consolidates the conditions for account inclusion, and the filtered accounts are now sorted using the newly added sortByCoin utility imported from ./accountUtils. The overall filtering criteria based on device state, network, account type, and visibility remain intact while introducing the additional sorting step. No changes were made to the declarations of exported or public entities.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between baff029 and dcaa91d.

📒 Files selected for processing (2)
  • suite-common/wallet-utils/src/__tests__/filterReceiveAccounts.test.ts (2 hunks)
  • suite-common/wallet-utils/src/filterReceiveAccounts.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: run-desktop-tests (@group=wallet, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=other, trezor-user-env-unix)
  • GitHub Check: run-desktop-tests (@group=passphrase, trezor-user-env-unix)
  • GitHub Check: EAS Update
  • GitHub Check: run-desktop-tests (@group=settings, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: build-web
  • GitHub Check: prepare_android_test_app
  • GitHub Check: run-desktop-tests (@group=device-management, trezor-user-env-unix)
  • GitHub Check: Analyze with CodeQL (javascript)
  • GitHub Check: build-web
  • GitHub Check: run-desktop-tests (@group=suite, trezor-user-env-unix)
  • GitHub Check: Setup and Cache Dependencies
🔇 Additional comments (5)
suite-common/wallet-utils/src/filterReceiveAccounts.ts (3)

5-5: LGTM!

The import of sortByCoin is correctly added to support the new sorting functionality.


43-48: LGTM! Good refactoring.

The new helper function improves code readability by consolidating related filtering conditions into a single, well-named function.


50-50:

❓ Verification inconclusive

Verify that the sorting order matches the Suite's sidebar implementation.

Based on the past review comments, there is an existing account sorting order in the Suite's sidebar. Please verify that sortByCoin follows the same order:

  1. normal (BTC, ETH, SOL,...)
  2. taproot (BTC)
  3. segwit (BTC)
  4. coinjoin (BTC)
  5. ledger (ETH, SOL)
  6. legacy (BTC, ETH)
  7. imported (mobile)

🏁 Script executed:

#!/bin/bash
# Description: Verify the implementation of sortByCoin function

# Search for the sortByCoin implementation
ast-grep --pattern $'export const sortByCoin = ($$$) => {
  $$$
}'

Length of output: 67


I'll run an additional search for the sortByCoin definition to better verify its implementation. The previous AST-based search returned no output, so I'll now search the repository for any occurrence of sortByCoin to locate its definition.

Please run the above script and share the output so we can verify whether the implementation matches the Suite's sidebar account sorting order.


🏁 Script executed:

[run_scripts]
#!/bin/bash
# Searching for any occurrence of "sortByCoin" in the repository using ripgrep
rg -i "sortByCoin" .

Length of output: 1834


Sorting Order Verification

Please ensure that the implementation of sortByCoin in suite-common/wallet-utils/src/accountUtils.ts strictly follows the established account order matching the Suite's sidebar:

  • Normal (BTC, ETH, SOL, …)
  • Taproot (BTC)
  • Segwit (BTC)
  • Coinjoin (BTC)
  • Ledger (ETH, SOL)
  • Legacy (BTC, ETH)
  • Imported (mobile)

Although the automated search located the function and its various usages, we were unable to extract the detailed implementation via AST search. Verify manually (or via further testing) that the sorting logic in sortByCoin indeed conforms to the above order—especially by cross-checking:

  • The implementation in suite-common/wallet-utils/src/accountUtils.ts
  • The tests in suite-common/wallet-utils/src/__tests__/accountUtils.test.ts
  • The actual account ordering in the Suite's sidebar
suite-common/wallet-utils/src/__tests__/filterReceiveAccounts.test.ts (2)

81-83: Verify the order of accounts in the test case.

The order of accounts in the expected results should match the sorting order implemented in sortByCoin. Currently, the order is:

  1. normal
  2. ledger
  3. legacy

Please verify that this matches the intended sorting order.


102-105: Verify the order of accounts in the BTC network test case.

The order of accounts in the expected results should match the sorting order implemented in sortByCoin. Currently, the order is:

  1. ledger
  2. taproot
  3. segwit
  4. legacy

Based on the past review comments, Bitcoiners prefer a different order:

  1. taproot
  2. segwit
  3. legacy
  4. ledger

Please update the test case to match the preferred order.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@tomasklim tomasklim merged commit 3f232b6 into develop Feb 18, 2025
32 checks passed
@tomasklim tomasklim deleted the fix/swap-accounts-sort branch February 18, 2025 07:47
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.

Trading - when swapping receive accounts list is not organised by account number
3 participants