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

Solana staking view only #17296

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open

Solana staking view only #17296

wants to merge 2 commits into from

Conversation

vytick
Copy link
Contributor

@vytick vytick commented Feb 27, 2025

  • show staking for solana
  • updated text for solana stake activating
  • show rewards per epoch similar to desktop

Related Issue

Resolve #16370

Screenshots:

@vytick vytick added mobile Suite Lite issues and PRs solana staking labels Feb 27, 2025
@trezor trezor deleted a comment from coderabbitai bot Feb 27, 2025
@vytick vytick marked this pull request as ready for review February 27, 2025 23:11
@vytick vytick requested a review from a team as a code owner February 27, 2025 23:11
@vytick vytick requested a review from Nodonisko February 27, 2025 23:11
Copy link

coderabbitai bot commented Feb 27, 2025

Walkthrough

The pull request extends support for Solana staking across multiple modules. A new function is added to compute the total Solana cryptocurrency balance by combining the account's formatted balance with its staking balance. Localization entries for staking-related text are introduced in the internationalization file. Component changes adjust properties and styling based on the network symbol, enabling dynamic alert messages and titles for pending stakes. The selectors have been expanded to include Solana data, with modifications to handle staking balance, pending state, rewards, APY, and device account filtering for Solana accounts. Additionally, a new file containing dedicated Solana staking selectors is added, and the list of recognized staking coins is updated to include Solana symbols. These changes integrate Solana-specific logic alongside existing Ethereum staking functionalities.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
  • @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 (3)
suite-native/module-staking-management/src/components/StakePendingCard.tsx (2)

36-37: Consider a more descriptive helper name.

While isSolana works, you might rename it to something like isSolanaNetwork for added clarity, especially if more symbols or custom checks are expected in the future.


70-75: Function naming could be more explicit.

getTitle is generic. Using something like getPendingStakeTitle or getStakePendingCardTitle might better convey its purpose.

suite-native/staking/src/selectors.ts (1)

162-163: Hardcoded return for Solana confirmation.

Returning false for Solana stake confirmations is valid for now but consider a future scenario where Solana confirmation might become relevant or track different stake states.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0598bb8 and 0be1914.

📒 Files selected for processing (7)
  • suite-common/wallet-utils/src/solanaStakingUtils.ts (1 hunks)
  • suite-native/intl/src/en.ts (1 hunks)
  • suite-native/module-staking-management/src/components/StakePendingCard.tsx (5 hunks)
  • suite-native/module-staking-management/src/components/StakingBalancesOverviewCard.tsx (2 hunks)
  • suite-native/staking/src/selectors.ts (11 hunks)
  • suite-native/staking/src/solanaStakingSelectors.ts (1 hunks)
  • suite-native/staking/src/utils.ts (1 hunks)
🔇 Additional comments (24)
suite-native/module-staking-management/src/components/StakingBalancesOverviewCard.tsx (2)

70-74: Good implementation of network-specific rewards title

This change nicely accommodates Solana's different rewards mechanism by conditionally displaying "Rewards per Epoch" for Solana networks, which is more accurate than the generic "Rewards" label used for other networks.


108-108: Clean implementation using the conditional title

The component now correctly uses the dynamically determined rewards title based on the network symbol.

suite-common/wallet-utils/src/solanaStakingUtils.ts (1)

85-89: Good implementation of total balance calculation for Solana

This new function properly combines the account's formatted balance with its staking balance, correctly handling the case when staking balance is null by defaulting to 0.

The implementation is straightforward and follows the pattern of other utility functions in this file. The use of BigNumber ensures precise calculations without floating-point issues.

suite-native/intl/src/en.ts (2)

1247-1247: Appropriate addition of Solana-specific rewards label

Adding "Rewards per Epoch" is appropriate for Solana's epoch-based rewards system.


1254-1255: Clear labels for Solana stake activation status

These additions provide clear and descriptive labels for the stake activation process in Solana, which differs from other networks.

suite-native/staking/src/utils.ts (1)

4-4: Correctly expanded staking coins to include Solana

The stakingCoins constant has been properly updated to include 'sol' and 'dsol', allowing the application to recognize and support Solana staking functionality.

This is a necessary change to enable the view-only staking functionality for Solana networks mentioned in the PR objectives.

suite-native/module-staking-management/src/components/StakePendingCard.tsx (4)

19-22: Type definition looks good.

The newly added StakePendingCardProps type is clear and self-explanatory, properly capturing the required props.


38-46: Logic appears sound.

The getCardAlertProps function correctly returns consistent alertTitle and alertVariant values for Solana vs. other networks. The structure is clean and straightforward.


55-59: Solana activation messaging is correctly handled.

Switching the alert title for Solana via isSolana(symbol) is properly differentiated, aligning with the unique activation flow.


99-100: Appropriate usage of useMemo.

Memoizing the alert props based on symbol and staking statuses helps avoid unnecessary render calculations.

suite-native/staking/src/solanaStakingSelectors.ts (8)

1-18: Imports and setup look good.

Utilizing createWeakMapSelector and pulling state interfaces from shared modules lays a solid foundation for the Solana staking selectors.


21-35: Account filtering logic seems correct.

Filtering visible device accounts specifically for the solana network and confirming the existence of Solana staking accounts is a clean approach. This ensures only relevant Solana accounts appear downstream.


37-46: Efficient memoized selector.

selectSolStakingAccountsInfoByAccountKey is well-structured. Using createWeakMapSelector ensures consistent performance by caching results per account instance.


48-64: Clear pending stake detection.

selectSolanaIsStakePendingByAccountKey accurately checks for any positive pending stake or unstake amounts, returning a boolean. This mirrors typical Solana staking logic.


66-74: APY selection aligns with existing patterns.

The selector fetches pool statistics via selectPoolStatsApyData. Just ensure that any protocol or network APY mismatches are handled gracefully.


76-90: Staked balance calculation is correct.

Combining staked, claimable, and pending amounts into a single BigNumber result is standard. This avoids floating-point pitfalls.


92-108: Expected rewards calculation is well-structured.

calculateSolanaStakingReward is used appropriately. This design cleanly accommodates changes in future reward logic or new constraints.


110-120: Total stake pending retrieval is straightforward.

selectSolanaTotalStakePendingByAccountKey returning '0' for non-staking or missing data is consistent with typical selector conventions.

suite-native/staking/src/selectors.ts (6)

2-11: Expanded imports for Solana.

Bringing in additional selectors and utilities for sol and dsol is a proper step toward unifying staking logic for multiple networks.


23-28: New Solana staking selector references.

Importing from solanaStakingSelectors seamlessly integrates the Solana-specific logic while preserving clarity for other networks.


48-50: Solana accounts now included in device account selection.

Allowing sol and dsol within selectDeviceAccountsWithStaking ensures consistent user interface support for Solana-based staking.


72-78: Accurate handling of Solana balance.

getSolanaCryptoBalanceWithStaking merges staked and main balances accurately, aligning with the established pattern for other staking coins.


110-111: Excellent Solana integration throughout.

In all these updated function switches—selectAccountHasStaking, selectIsStakePendingByAccountKey, selectStakedBalanceByAccountKey, selectRewardsBalanceByAccountKey, selectTotalStakePendingByAccountKey—the approach is consistent with the existing pattern for Ethereum. The uniform logic ensures minimal fragmentation across different networks.

Also applies to: 136-137, 198-199, 224-226, 251-252


179-179: Directly returning APY data.

Simplifying selectAPYByAccountKey for plan synergy with the pool stats API is elegant. It ensures a single source of truth for yield data.

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

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 solana staking
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sol staking - view only
1 participant