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

feat(suite-native): persist favourite trade assets #17169

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

vytick
Copy link
Contributor

@vytick vytick commented Feb 22, 2025

  • persist favourite trade assets
  • make favourite and all trade lists complementary

Related Issue

Followup to #16991

Screenshots:

Simulator.Screen.Recording.-.iPhone.16.-.2025-02-22.at.16.27.34.mp4

@vytick vytick added the mobile Suite Lite issues and PRs label Feb 22, 2025
@vytick vytick requested a review from a team as a code owner February 22, 2025 15:29
@vytick vytick requested a review from jbazant February 22, 2025 15:31
Copy link

🚀 Expo preview is ready!

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

Learn more about 𝝠 Expo Github Action

Copy link

coderabbitai bot commented Feb 24, 2025

Walkthrough

This pull request introduces modifications across multiple modules. In the component responsible for displaying tradeable assets, the logic for determining favorite assets has been refactored. The import of helper functions and the selector used for favorites has been updated, and the asset list is now dynamically categorized into favorites and non-favorites using a reduction over the assets array. In the trading slice, a helper function for generating favorite asset keys has been changed from private to exported, allowing broader reuse. Additionally, the state management has been enhanced with the introduction of a persisted reducer for trading, ensuring that the favorites state is maintained across sessions by persisting it under a defined key and version.

✨ 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.

Copy link

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

🧹 Nitpick comments (1)
suite-native/module-trading/src/components/general/TradeableAssetsSheet/TradeableAssetsSheet.tsx (1)

81-93: Consider extracting the reducer function for better reusability.

While the current implementation is efficient, the reducer function could be extracted to improve reusability and testability.

+const categorizeAssets = (favourites: Record<string, TradeableAsset>) => (
+    acc: { favouriteData: TradeableAsset[]; allData: TradeableAsset[] },
+    asset: TradeableAsset,
+) => {
+    const key = getTradeableAssetFavouriteKey(asset);
+    if (favourites[key]) {
+        acc.favouriteData.push(asset);
+    } else {
+        acc.allData.push(asset);
+    }
+    return acc;
+};

 const listData = useMemo(() => {
-    const { favouriteData, allData } = mockAssets.reduce(
-        (acc, a) => {
-            const key = getTradeableAssetFavouriteKey(a);
-            if (favourites[key]) {
-                acc.favouriteData.push(a);
-            } else {
-                acc.allData.push(a);
-            }
-
-            return acc;
-        },
-        { favouriteData: [] as TradeableAsset[], allData: [] as TradeableAsset[] },
-    );
+    const { favouriteData, allData } = mockAssets.reduce(
+        categorizeAssets(favourites),
+        { favouriteData: [] as TradeableAsset[], allData: [] as TradeableAsset[] },
+    );
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 446fc4e and 7a43ed8.

📒 Files selected for processing (3)
  • suite-native/module-trading/src/components/general/TradeableAssetsSheet/TradeableAssetsSheet.tsx (2 hunks)
  • suite-native/module-trading/src/tradingSlice.ts (1 hunks)
  • suite-native/state/src/reducers.ts (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
suite-native/module-trading/src/components/general/TradeableAssetsSheet/TradeableAssetsSheet.tsx (2)
Learnt from: jbazant
PR: trezor/trezor-suite#16668
File: suite-native/module-trading/src/components/TradeableAssetsSheet/TradeableAssetsSheet.tsx:0-0
Timestamp: 2025-02-04T13:18:21.530Z
Learning: The mock data arrays in `suite-native/module-trading/src/components/TradeableAssetsSheet/TradeableAssetsSheet.tsx` are intentionally used as visual stubs and will be replaced with real data fetching in future commits.
Learnt from: jbazant
PR: trezor/trezor-suite#16668
File: suite-native/module-trading/src/components/general/TradeableAssetsSheet/TradeableAssetsFilterTabs.tsx:17-28
Timestamp: 2025-02-04T13:18:46.084Z
Learning: The mock data in TradeableAssetsFilterTabs.tsx is part of a visual stub and will be replaced with dynamic data in future commits.
🔇 Additional comments (3)
suite-native/state/src/reducers.ts (1)

78-83: LGTM! Well-structured persistence implementation.

The implementation follows the established pattern of other persisted reducers in the file, correctly specifying the persisted keys and version, and properly integrating with the existing wallet reducers.

Also applies to: 94-94

suite-native/module-trading/src/tradingSlice.ts (1)

34-35: LGTM! Clean and efficient key generation function.

The exported function follows a consistent pattern for generating unique keys, combining the asset's symbol and contract address when available. The implementation is simple, efficient, and reusable across components.

suite-native/module-trading/src/components/general/TradeableAssetsSheet/TradeableAssetsSheet.tsx (1)

7-7: LGTM! Efficient data processing implementation.

The refactored implementation efficiently categorizes assets using reduce, maintaining a clean separation between favorites and all assets. The useMemo dependency is correctly updated to reflect the changes.

Also applies to: 78-112

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mobile Suite Lite issues and PRs
Projects
Status: 🏃‍♀️ In progress
Development

Successfully merging this pull request may close these issues.

1 participant