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

fix(suite): fixed staking in sidebar #17525

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

Conversation

TomasBoda
Copy link
Contributor

Description

Staking in sidebar is shown only if non-zero balance is staked or there is stake/unstake/claim pending or the claim is ready.

Related Issue

Resolve #16864

Screenshots:

Ethereum #1 staking is shown because the claim is ready:

Screenshot 2025-03-10 at 15 04 06

Ethereum #2 staking is hidden because there is no staked balance and no other condition is met:

Screenshot 2025-03-10 at 15 04 27

@TomasBoda TomasBoda self-assigned this Mar 10, 2025
@TomasBoda TomasBoda requested a review from tomasklim March 10, 2025 14:07
Copy link

coderabbitai bot commented Mar 10, 2025

Walkthrough

The changes update the logic used to determine if staking details should be displayed in the AccountSection component. The previous implementation, which relied on separate selectors for Ethereum and Solana staking statuses, has been removed. Instead, the component now uses the selectAccountIsStakingActive selector to check if staking is active for the account. The logic for the isStakeShown variable has been simplified, directly reflecting the result of this new selector. Additionally, a new selector, selectAnyAccountIsStakingActive, has been introduced in other components to enhance the determination of staking status across accounts. The rendering logic in various components, including AssetCard, AssetRow, and EthStakingDashboard, has been updated to utilize these selectors, allowing for more streamlined and dynamic user interfaces based on the staking status. A new utility function, isAccountStakingActive, has also been added to support these changes.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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
Member

@tomasklim tomasklim left a comment

Choose a reason for hiding this comment

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

    const hasEthStaked = useSelector(state => selectEthAccountHasStaked(state, account.key));
    const hasSolStaked = useSelector(state => selectSolAccountHasStaked(state, account.key));

Previously it was decided based on this logic which is used also on other places, it would be great to have it unified all over the places so that it does not happen that there is staking in sidebar but you see "staking welcome screen" or vice versa

Screenshot 2025-03-12 at 11 23 55

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 (2)
suite-common/wallet-core/src/stake/stakeUtils.ts (2)

17-23: Consider adding JSDoc comments for better documentation.

While the code is clear, adding JSDoc comments would improve maintainability by documenting the purpose of the function, its parameters, and return value.

+/**
+ * Determines if an account is actively participating in staking.
+ * An account is considered active if:
+ * - It has a deposited balance, or
+ * - It has pending stake/unstake/claim operations, or
+ * - It has funds ready to claim
+ *
+ * @param account - The account to check for staking activity
+ * @param claimTransactions - List of claim transactions to check for pending status
+ * @returns True if the account is actively participating in staking, false otherwise
+ */
 export const isAccountStakingActive = (
     account: Account | null,
     claimTransactions: WalletAccountTransaction[],
 ) => {

25-25: Consider adding a comment explaining the purpose of pendingClaimTxs.

Adding a brief comment would clarify why we're filtering for pending claim transactions and how they're used in determining if a claim is pending.

-    const pendingClaimTxs = claimTransactions.filter(tx => isPending(tx));
+    // Filter for pending claim transactions to determine if a claim operation is in progress
+    const pendingClaimTxs = claimTransactions.filter(tx => isPending(tx));
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 520f221 and 688998d.

📒 Files selected for processing (10)
  • packages/suite/src/components/wallet/WalletLayout/AccountsMenu/AccountSection.tsx (2 hunks)
  • packages/suite/src/views/dashboard/AssetsView/AssetCard/AssetCard.tsx (3 hunks)
  • packages/suite/src/views/dashboard/AssetsView/AssetTable/AssetRow.tsx (4 hunks)
  • packages/suite/src/views/dashboard/AssetsView/assetsViewUtils.ts (1 hunks)
  • packages/suite/src/views/wallet/staking/components/EthStakingDashboard/components/EthStakingDashboard.tsx (3 hunks)
  • packages/suite/src/views/wallet/staking/components/SolStakingDashboard/SolStakingDashboard.tsx (2 hunks)
  • packages/suite/src/views/wallet/staking/components/SolStakingDashboard/components/Rewards/RewardsList.tsx (3 hunks)
  • packages/suite/src/views/wallet/staking/components/StakingDashboard/StakingDashboard.tsx (1 hunks)
  • suite-common/wallet-core/src/stake/stakeUtils.ts (1 hunks)
  • suite-common/wallet-core/src/transactions/transactionsReducer.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/suite/src/components/wallet/WalletLayout/AccountsMenu/AccountSection.tsx
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: EAS Update
  • GitHub Check: prepare_android_test_app
  • GitHub Check: Analyze with CodeQL (javascript)
  • GitHub Check: build-web
  • GitHub Check: Setup and Cache Dependencies
🔇 Additional comments (30)
packages/suite/src/views/dashboard/AssetsView/assetsViewUtils.ts (2)

43-45: Improved variable naming for better semantics.

The renamed variable hasAccountsWithStakingBalance better reflects its purpose - it indicates the presence of accounts with staking balance rather than making a rendering decision. This enhances code readability and aligns with the PR's goal of clearly identifying when staking should be displayed.


51-51: LGTM - consistent variable name update.

The return object properly uses the renamed variable, maintaining consistency throughout the function.

packages/suite/src/views/wallet/staking/components/SolStakingDashboard/components/Rewards/RewardsList.tsx (3)

4-4: Appropriate new selector import.

The import of selectAccountIsStakingActive aligns with the PR's goal of refining staking visibility logic.


53-53: Correctly implementing the staking active check.

Using the selector with useSelector hook is the right approach to determine if staking is active for the specific account.


55-61: Improved conditional rendering logic.

This change properly implements the PR requirement by:

  1. Only showing the RewardsEmpty component when staking is active but there are no rewards
  2. Returning null when staking is not active

This ensures that staking UI elements are only displayed when relevant to the user.

packages/suite/src/views/wallet/staking/components/StakingDashboard/StakingDashboard.tsx (1)

22-22: Simplified component rendering.

Removing conditional logic from this component is appropriate since the responsibility for determining whether to show staking content has been moved to the parent components. This maintains the single responsibility principle and makes the component more focused.

packages/suite/src/views/wallet/staking/components/SolStakingDashboard/SolStakingDashboard.tsx (3)

3-7: Well-organized imports.

The imports have been properly reorganized to include the new selectAccountIsStakingActive selector.


40-40: Correctly implementing the staking active check.

Using the new selector to determine if staking is active for the current account aligns perfectly with the PR objective.


47-81: Well-implemented conditional rendering.

This change perfectly implements the PR's goal by:

  1. Only showing the staking dashboard when staking is active
  2. Showing an EmptyStakingCard when staking is not active

The conditional structure is clear and easy to understand, making the code maintainable.

packages/suite/src/views/wallet/staking/components/EthStakingDashboard/components/EthStakingDashboard.tsx (3)

6-6: Good addition of new imports

The imports for selectAccountIsStakingActive and EmptyStakingCard are correctly added to support the conditional rendering of staking UI elements.

Also applies to: 27-27


72-72: Well-implemented staking status check

Good use of the selector to determine if staking is active for the account, which will help control when staking information is displayed.


79-117: Excellent conditional rendering implementation

The conditional rendering logic improves the user experience by showing either the full staking dashboard when staking is active or an empty state when it's not. This aligns perfectly with the PR objective to only show staking information under specific conditions.

packages/suite/src/views/dashboard/AssetsView/AssetCard/AssetCard.tsx (5)

10-10: Good addition of the selector import

The import of selectAnyAccountIsStakingActive is correctly added to determine if any accounts associated with the asset are actively staking.


130-132: Well-implemented staking status check

Good use of the selector to determine if any of the staking accounts for this asset are active, which will help control when staking information is displayed in the asset card.


134-147: Clear renaming of variables

The renaming from shouldRenderStakingRow to hasAccountsWithStakingBalance makes the code more readable and better reflects what the variable represents - a check for accounts with balances rather than a UI rendering decision.


148-148: Good implementation of the rendering condition

The new shouldRenderStaking variable combines both balance check and active staking status, which correctly implements the PR requirement to only show staking information under specific conditions.


192-201: Updated rendering logic improves UX

The conditional rendering of AssetCardTokensAndStakingInfo using both staking status and presence of tokens enhances the user experience by only showing relevant information, which aligns with the PR objectives.

suite-common/wallet-core/src/transactions/transactionsReducer.ts (3)

40-40: Good import of the utility function

The import of isAccountStakingActive utility function is appropriately added to support the new selectors.


386-389: Well-implemented account staking selector

The new selectAccountIsStakingActive selector correctly uses the utility function to determine if a specific account is actively staking, which is essential for the conditional UI rendering in other components.


391-405: Excellent implementation of the aggregated staking selector

The selectAnyAccountIsStakingActive selector efficiently processes multiple accounts to determine if any are actively staking. The implementation follows good practices:

  1. Correctly maps accounts to their transactions
  2. Filters for claim transactions
  3. Uses the utility function to check each account's staking status
  4. Returns a boolean indicating if any account is active

This implementation enables proper conditional rendering of staking UI elements across multiple components.

packages/suite/src/views/dashboard/AssetsView/AssetTable/AssetRow.tsx (6)

9-9: Good addition of the selector import

The import of selectAnyAccountIsStakingActive is correctly added to determine if any accounts associated with the asset are actively staking.


87-89: Well-implemented staking status check

Good use of the selector to determine if any of the staking accounts for this asset are active, which helps control when staking information is displayed in the asset row.


91-104: Clear renaming of variables

The renaming from shouldRenderStakingRow to hasAccountsWithStakingBalance makes the code more readable and better reflects what the variable represents - a check for accounts with balances rather than a UI rendering decision.


105-105: Good implementation of the rendering condition

The new shouldRenderStaking variable combines both balance check and active staking status, which correctly implements the PR requirement to only show staking information under specific conditions.


113-114: Consistent update to dashed line position logic

Good update to the $dashedLinePosition property to use the new shouldRenderStaking variable, maintaining visual consistency with the new rendering logic.


193-199: Updated rendering logic improves UX

The conditional rendering of AssetStakingRow using the new shouldRenderStaking condition enhances the user experience by only showing staking information when it's relevant, which aligns with the PR objectives.

suite-common/wallet-core/src/stake/stakeUtils.ts (4)

9-33: Well-implemented staking activity check function.

This new utility function isAccountStakingActive provides a comprehensive check for whether an account is active in staking, aligning with the PR objective to display staking in the sidebar only under specific conditions. The function correctly handles various scenarios:

  • Properly validates account existence and staking support
  • Checks for deposited balance
  • Detects pending stake/unstake/claim operations
  • Identifies if claiming is available

The use of BigNumber for comparisons is appropriate for financial calculations to avoid floating-point precision issues.


13-15: Good defensive programming with early returns.

These early return conditions appropriately handle edge cases (null account or unsupported network) before proceeding with the main logic, improving both code readability and performance.


29-29: Verify logic for determining pending claims.

The condition for isClaimPending checks both claimableAmount > 0 AND pendingClaimTxs.length > 0. Please confirm this is intentional - a claim is only considered pending when there's a claimable amount AND there are pending claim transactions.


32-32: Return statement aligns well with PR objectives.

The return statement effectively implements the requirements specified in the PR objectives, showing staking information only when there's a non-zero staked balance, pending operations, or claim availability.

Copy link

github-actions bot commented Mar 12, 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

@TomasBoda TomasBoda marked this pull request as draft March 12, 2025 15:30
@TomasBoda TomasBoda force-pushed the fix/sidebar-staking branch from 9bfc7ee to 4456fb2 Compare March 12, 2025 15:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants