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): add Solana message system feature for stake, unstake and claim #17381

Merged
merged 1 commit into from
Mar 4, 2025

Conversation

izmy
Copy link
Contributor

@izmy izmy commented Mar 4, 2025

Description

Created features for

  • sol.staking.stake
  • sol.staking.unstake
  • sol.staking.claim

I also rewrote useMessageSystemStaking hook in a more generic way.

Related Issue

Resolve #17321

@izmy izmy requested a review from MiroslavProchazka March 4, 2025 12:30
@izmy izmy requested review from tomasklim and matejkriz as code owners March 4, 2025 12:30
@izmy izmy self-assigned this Mar 4, 2025
Copy link

coderabbitai bot commented Mar 4, 2025

Walkthrough

The changes update multiple components to pass the current account’s network symbol into the useMessageSystemStaking hook. In the Claim, Stake, and Unstake modals and related components, the hook’s invocation now receives a parameter (either selectedAccount.network.symbol or account?.symbol) instead of being called without an argument. Related modifications include adding Redux selectors to retrieve the selected account and casting it to a typed object where necessary. The useMessageSystemStaking hook itself is updated to accept an optional network symbol, incorporating a new type for available network symbols and conditionally assigning feature values for staking, unstaking, and claiming. Additionally, the message system types have been refactored by replacing flat staking properties with a nested object structure that organizes actions under stake, unstake, and claim with specific keys for Ethereum and Solana, alongside revised type definitions.


📜 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 dcac848 and 625185a.

📒 Files selected for processing (8)
  • packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/ClaimModal/ClaimModal.tsx (1 hunks)
  • packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/StakeModal/StakeEthForm/StakeButton.tsx (1 hunks)
  • packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/UnstakeModal/UnstakeEthForm/UnstakeButton.tsx (1 hunks)
  • packages/suite/src/hooks/suite/useMessageSystemStaking.ts (1 hunks)
  • packages/suite/src/views/wallet/staking/components/StakingDashboard/components/ClaimCard.tsx (1 hunks)
  • packages/suite/src/views/wallet/staking/components/StakingDashboard/components/EmptyStakingCard.tsx (1 hunks)
  • packages/suite/src/views/wallet/staking/components/StakingDashboard/components/StakingCard.tsx (1 hunks)
  • suite-common/message-system/src/messageSystemTypes.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/suite/src/views/wallet/staking/components/StakingDashboard/components/EmptyStakingCard.tsx
  • packages/suite/src/views/wallet/staking/components/StakingDashboard/components/ClaimCard.tsx
  • packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/UnstakeModal/UnstakeEthForm/UnstakeButton.tsx
  • packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/ClaimModal/ClaimModal.tsx
  • packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/StakeModal/StakeEthForm/StakeButton.tsx
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: run-desktop-tests (@group=wallet, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: run-desktop-tests (@group=passphrase, trezor-user-env-unix)
  • GitHub Check: EAS Update
  • GitHub Check: build-web
  • GitHub Check: prepare_android_test_app
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: Analyze with CodeQL (javascript)
🔇 Additional comments (8)
packages/suite/src/views/wallet/staking/components/StakingDashboard/components/StakingCard.tsx (1)

90-90: Correctly passing network context to useMessageSystemStaking hook.

The modification ensures that the useMessageSystemStaking hook receives the current account's network symbol, allowing it to provide network-specific staking message content and disabled states. This change aligns with the PR objective of adding Solana message system features for staking operations.

suite-common/message-system/src/messageSystemTypes.ts (2)

21-34: Well-structured refactoring of staking feature organization.

The restructuring creates a more logical organization of staking features by grouping them first by action (stake, unstake, claim) and then by network (eth, sol). This hierarchical approach improves code maintainability and provides a clear, extensible pattern for adding more networks in the future.


43-50: Good implementation of recursive type extraction.

The ExtractFeatureValues<T> type recursively extracts leaf values from the nested Feature object structure, allowing the FeatureDomain type to properly capture all possible feature identifiers regardless of nesting depth. This is an elegant solution that works well with the new hierarchical structure.

packages/suite/src/hooks/suite/useMessageSystemStaking.ts (5)

6-6: Correctly importing NetworkSymbol type for hook parameter.

Adding this import is necessary to support the new parameter in the hook function signature.


12-18: Well-designed network type safety approach.

The implementation uses a combination of type restriction via Extract<NetworkSymbol, 'eth' | 'sol'> and runtime validation with availableNetworks.includes(networkSymbol) to ensure type safety. The availableNetworks array is constructed by gathering keys from all relevant feature objects, which provides a maintainable way to track supported networks.


19-19: Hook signature enhancement to support multiple networks.

The function signature now accepts an optional networkSymbol parameter, making the hook more flexible and reusable across different network contexts. This aligns perfectly with the PR objective of adding Solana message system features while maintaining existing Ethereum functionality.


22-29: Robust feature selection with proper null handling.

The code correctly handles the case when no network symbol is provided or when the provided symbol isn't supported. The conditional assignment of feature values based on the isAvailable flag ensures that appropriate defaults are used when necessary.


30-48: Safe selector usage with conditional feature existence checks.

All selectors are now wrapped with null checks (stake ? selectIsFeatureDisabled(...) : undefined) to handle cases where a feature might not be available for a particular network. This defensive programming approach prevents runtime errors when working with unsupported network types.

✨ 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 (2)
packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/UnstakeModal/UnstakeEthForm/UnstakeButton.tsx (1)

12-14: Consider adding error handling for missing selected account

While the component expects a selected account to be present (as shown by the type assertion), there's no explicit error handling if the account isn't properly loaded. Consider adding a guard clause to handle this edge case.

const selectedAccount = useSelector(
    state => state.wallet.selectedAccount,
) as SelectedAccountLoaded;
+ 
+ // Prevent rendering if no account is selected
+ if (!selectedAccount || selectedAccount.status !== 'loaded') {
+   return null;
+ }
suite-common/message-system/src/messageSystemTypes.ts (1)

23-34: Improved architecture for multi-network staking feature support

This restructuring of the Feature object from flat properties to a nested object structure provides better organization and scalability for supporting multiple blockchain networks. The new design allows for cleaner feature references by network type.

This approach will make it easier to add support for additional networks in the future without modifying the overall structure.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 50a7d60 and dcac848.

📒 Files selected for processing (7)
  • packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/ClaimModal/ClaimModal.tsx (1 hunks)
  • packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/StakeModal/StakeEthForm/StakeButton.tsx (1 hunks)
  • packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/UnstakeModal/UnstakeEthForm/UnstakeButton.tsx (1 hunks)
  • packages/suite/src/hooks/suite/useMessageSystemStaking.ts (1 hunks)
  • packages/suite/src/views/wallet/staking/components/StakingDashboard/components/ClaimCard.tsx (1 hunks)
  • packages/suite/src/views/wallet/staking/components/StakingDashboard/components/EmptyStakingCard.tsx (1 hunks)
  • suite-common/message-system/src/messageSystemTypes.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (11)
  • 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: run-desktop-tests (@group=settings, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: EAS Update
  • GitHub Check: run-desktop-tests (@group=device-management, trezor-user-env-unix)
  • GitHub Check: run-desktop-tests (@group=suite, trezor-user-env-unix)
  • GitHub Check: build-web
  • GitHub Check: prepare_android_test_app
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: Analyze with CodeQL (javascript)
🔇 Additional comments (17)
packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/ClaimModal/ClaimModal.tsx (1)

25-27: Network-aware message system support added - LGTM!

The change properly passes the selected account's network symbol to the useMessageSystemStaking hook, enabling network-specific claiming functionality. This enhancement aligns with the PR objective to add Solana message system support alongside existing Ethereum functionality.

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

31-31: Network-aware staking message system enabled - LGTM!

The update correctly passes the account symbol to the useMessageSystemStaking hook, enabling network-specific staking messages and controls. The optional chaining (account?.symbol) appropriately handles cases where the account might be undefined.

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

20-22: Network-aware claiming message system implemented - LGTM!

The update correctly passes the selected account's symbol to the useMessageSystemStaking hook, enabling network-specific claiming functionality. The optional chaining operator is appropriately used to handle potential undefined values.

packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/UnstakeModal/UnstakeEthForm/UnstakeButton.tsx (3)

1-1: Type import added for enhanced type safety - LGTM!

The SelectedAccountLoaded type import ensures proper typing for the selected account, which improves code safety and IDE support.


5-5: Added Redux selector support - LGTM!

Importing useSelector along with the existing useDevice hook enables access to Redux state for retrieving the currently selected account.


12-17: Network-aware unstaking message system implemented - LGTM!

These changes properly integrate the unstaking functionality with the network-specific message system:

  1. Retrieves the selected account from Redux state
  2. Casts it to the appropriate type for type safety
  3. Passes the network symbol to the useMessageSystemStaking hook

This enhancement fulfills the PR objective to add Solana message system features for unstaking operations.

suite-common/message-system/src/messageSystemTypes.ts (2)

43-48: Well-designed type utility for extracting nested feature values

The ExtractFeatureValues<T> type utility effectively handles recursive extraction of values from nested objects, providing strong type safety while accommodating the new structure.

This recursive type approach ensures that all feature values, regardless of nesting level, are properly typed and accessible.


50-50: Updated type definition matches the new feature structure

The FeatureDomain type now correctly uses the ExtractFeatureValues utility to extract all possible feature values from the restructured object.

This ensures type safety is maintained throughout the application when referencing feature domains.

packages/suite/src/hooks/suite/useMessageSystemStaking.ts (5)

12-17: Good type constraints and network availability checks

The AvailableNetworkSymbols type properly restricts the network symbols to only supported networks ('eth' and 'sol'). The availableNetworks constant efficiently aggregates all supported networks from the feature definitions.

This approach ensures type safety while maintaining a single source of truth for supported networks by deriving them directly from the Feature object keys.


19-19: Enhanced hook flexibility with optional network parameter

The function signature update appropriately makes the network symbol optional, allowing for backward compatibility while adding support for network-specific behavior.

This design choice supports both legacy code that doesn't pass a network symbol and new code that does.


22-28: Robust network availability checking and feature selection

The implementation correctly handles the case when a network symbol is provided and checks if it's available before attempting to use it, preventing potential runtime errors.

The type casting to AvailableNetworkSymbols is appropriate here since you've already validated that the network is included in the available networks list.


30-38: Improved selector implementation with null safety

The selectors now properly handle the case when a feature might be undefined, returning undefined instead of potentially causing runtime errors.

This defensive programming approach ensures the hook won't crash when used with unsupported networks.


40-48: Consistent null safety pattern across message content selectors

The message content selectors follow the same pattern as the disabled state selectors, maintaining consistency throughout the implementation.

This consistent approach makes the code more maintainable and predictable.

packages/suite/src/components/suite/modals/ReduxModal/UserContextModal/StakeModal/StakeEthForm/StakeButton.tsx (4)

1-1: Added proper type import for selected account

Importing the SelectedAccountLoaded type ensures type safety when working with the selected account.


5-5: Added useSelector hook import

The import has been updated to include the useSelector hook, which is needed to access the Redux state.


22-24: Passing network symbol to staking hook

The component now correctly passes the selected account's network symbol to the useMessageSystemStaking hook, enabling network-specific staking message behavior.

This ensures that the staking messages are contextually appropriate for the selected network (Ethereum or Solana).


12-14:

❓ Verification inconclusive

Verify type assertion safety

The code retrieves the selected account from Redux and asserts it as SelectedAccountLoaded. This assumes that a selected account is always loaded when this component is rendered.


🏁 Script executed:

#!/bin/bash
# Verify if the StakeButton component is only rendered when a selected account is loaded

# Check if there are any conditionals to ensure selected account is loaded before rendering this component
rg -A 5 -B 5 "StakeButton" --glob "*.tsx" | grep -i "selectedAccount"

# Check if there's any parent component that ensures the account is loaded
rg "<StakeButton" -A 2 -B 10 --glob "*.tsx" | grep -A 5 -B 5 -i "selectedAccount"

Length of output: 602


Action Required: Confirm Runtime Guard for Selected Account

It appears that our automated search did not reveal any explicit conditional checks (in StakeButton or its parent components) ensuring that a selected account is loaded before rendering this component. The code currently casts the retrieved state directly to SelectedAccountLoaded without verifying if the account is indeed available. Please manually verify that:

  • Any parent component or execution path guarantees a loaded selected account before rendering StakeButton.
  • If such a guarantee is absent, consider introducing runtime checks or conditional rendering to safely handle cases where no account is loaded.

Copy link

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

@izmy izmy force-pushed the feat/solana-message-system-staking branch from dcac848 to 625185a Compare March 4, 2025 13:16
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.

LGTM tested with

		{
            "conditions": [],
            "message": {
                "id": "12345",
                "priority": 93,
                "dismissible": false,
                "variant": "info",
                "category": ["feature"],
                "content": {
                    "en-GB": "123",
                    "en": "123",
                    "es": "123",
                    "cs": "123",
                    "ru": "123",
                    "ja": "123",
                    "hu": "123",
                    "it": "123",
                    "fr": "123",
                    "de": "123",
                    "tr": "123",
                    "pt": "123",
                    "uk": "123"
                },
                "feature": [
                    {
                        "domain": "sol.staking.stake",
                        "flag": false
                    }
                ]
            }
        },

Screenshot 2025-03-04 at 14 08 39
Screenshot 2025-03-04 at 14 12 24
Screenshot 2025-03-04 at 14 12 36

@tomasklim tomasklim merged commit 225a366 into develop Mar 4, 2025
28 of 30 checks passed
@tomasklim tomasklim deleted the feat/solana-message-system-staking branch March 4, 2025 13:23
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.

Add Solana staking message system kill switch
2 participants