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): Mobile Trade: Legal notice and safety #17011

Merged
merged 1 commit into from
Feb 17, 2025

Conversation

jbazant
Copy link
Contributor

@jbazant jbazant commented Feb 14, 2025

Description

Related Issue

Resolve #16993

Screenshots:

Screenshot 2025-02-14 at 16 13 01

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

coderabbitai bot commented Feb 14, 2025

Walkthrough

The pull request implements several updates across the trading module. A new legal section is added to the translations, providing detailed legal and security information related to cryptocurrency transactions. Two new UI components, Confirmation and LegalSheet, have been introduced to manage user confirmation and display legal details through a bottom sheet interface. To support these components, new hooks such as useBottomSheetControls and useTradeConfirmationControls have been added, and the existing useTradeSheetControls hook has been refactored to delegate visibility management. A test suite has also been included to ensure the proper behavior of the bottom sheet controls. Additionally, the TradingScreen component has been updated to replace a placeholder button with the new Confirmation component, adjusting the user interaction flow in the trading environment.


📜 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 dd23d05 and 9e29731.

📒 Files selected for processing (8)
  • suite-native/intl/src/en.ts (1 hunks)
  • suite-native/module-trading/src/components/buy/Confirmation.tsx (1 hunks)
  • suite-native/module-trading/src/components/buy/LegalSheet.tsx (1 hunks)
  • suite-native/module-trading/src/hooks/__tests__/useBottomSheetControls.test.ts (1 hunks)
  • suite-native/module-trading/src/hooks/useBottomSheetControls.ts (1 hunks)
  • suite-native/module-trading/src/hooks/useTradeConfirmationControls.ts (1 hunks)
  • suite-native/module-trading/src/hooks/useTradeSheetControls.ts (1 hunks)
  • suite-native/module-trading/src/screens/TradingScreen.tsx (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • suite-native/module-trading/src/hooks/useBottomSheetControls.ts
  • suite-native/module-trading/src/components/buy/Confirmation.tsx
  • suite-native/module-trading/src/hooks/tests/useBottomSheetControls.test.ts
  • suite-native/module-trading/src/screens/TradingScreen.tsx
  • suite-native/module-trading/src/components/buy/LegalSheet.tsx
  • suite-native/module-trading/src/hooks/useTradeConfirmationControls.ts
  • suite-native/module-trading/src/hooks/useTradeSheetControls.ts
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: EAS Update
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: Analyze with CodeQL (javascript)
  • GitHub Check: prepare_android_test_app
🔇 Additional comments (5)
suite-native/intl/src/en.ts (5)

1359-1376: Well-structured legal and security content.

The new legalSheet section effectively organizes critical information into distinct categories (security, partners, legal) with clear headers and detailed explanations.

Some notable strengths:

  • Clear separation of concerns between security, partner, and legal information
  • Comprehensive coverage of key risks and responsibilities
  • Effective use of template literals for dynamic provider name integration

1362-1368: Strong security-first messaging.

The security section effectively communicates critical security information:

  • Warns about potential scams
  • Emphasizes identity verification requirements
  • Clearly states transaction finality

1369-1370: Clear partner relationship disclosure.

The partners section effectively clarifies the relationship between Invity and the trade provider, helping users understand the service governance model.


1371-1375: Comprehensive legal disclaimers.

The legal section effectively covers:

  • Prohibited activities
  • Terms of Service compliance
  • Regional regulatory variations
  • Associated risks

1360-1360:

✅ Verification successful

Verify template literal interpolation.

The code uses template literals with tradeProviderName. Let's verify that this variable is properly passed and handled.

Also applies to: 1370-1370


🏁 Script executed:

#!/bin/bash
# Search for components that use these translations to verify proper variable passing
rg -A 5 "legalSheet.*title|legalSheet.*infoPartners"

Length of output: 1251


Template Literal Interpolation Verified

The translation string in suite-native/intl/src/en.ts (lines 1360 and 1370) that uses {tradeProviderName} is correctly handled. The search output confirms that components (specifically in suite-native/module-trading/src/components/buy/LegalSheet.tsx) are passing the tradeProviderName variable via the Translation component for both the title and infoPartners fields.

  • Verified that the tradeProviderName variable is properly passed in the Translation component.
  • Confirmed that the interpolation syntax in the language file matches the usage pattern in the consuming component.

No further changes are necessary.

✨ 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: 1

🧹 Nitpick comments (6)
suite-native/module-trading/src/hooks/useBottomSheetControls.ts (1)

3-19: LGTM! Consider adding animation state.

The implementation is clean and follows React best practices. Consider enhancing it with animation state management for smoother transitions.

Add animation state management:

 export const useBottomSheetControls = () => {
     const [isSheetVisible, setIsSheetVisible] = useState(false);
+    const [isAnimating, setIsAnimating] = useState(false);
 
     const showSheet = useCallback(() => {
+        setIsAnimating(true);
         setIsSheetVisible(true);
     }, []);
 
     const hideSheet = useCallback(() => {
+        setIsAnimating(true);
         setIsSheetVisible(false);
     }, []);
 
+    const onAnimationComplete = useCallback(() => {
+        setIsAnimating(false);
+    }, []);
 
     return {
         isSheetVisible,
+        isAnimating,
         showSheet,
         hideSheet,
+        onAnimationComplete,
     };
 };
suite-native/module-trading/src/components/buy/Confirmation.tsx (2)

13-15: Add accessibility attributes to the button.

Enhance the button's accessibility by adding appropriate ARIA attributes and role.

-            <Button onPress={showSheet} disabled={!isConfirmationEnabled}>
+            <Button
+                onPress={showSheet}
+                disabled={!isConfirmationEnabled}
+                accessibilityRole="button"
+                accessibilityLabel={<Translation id="moduleTrading.tradingScreen.continueButtonA11yLabel" />}
+                accessibilityHint={<Translation id="moduleTrading.tradingScreen.continueButtonA11yHint" />}
+            >

7-23: Add error handling for edge cases.

Consider handling edge cases such as:

  • Network errors when loading provider data
  • State transitions during sheet visibility changes
  • Disabled state feedback
 export const Confirmation = () => {
     const { isConfirmationEnabled, showSheet, hideSheet, isSheetVisible, tradeProviderName } =
         useTradeConfirmationControls();
+    const [error, setError] = useState<Error | null>(null);
+
+    const handleShowSheet = async () => {
+        try {
+            await showSheet();
+        } catch (err) {
+            setError(err instanceof Error ? err : new Error('Failed to show sheet'));
+        }
+    };

     return (
         <>
+            {error && (
+                <Text variant="error">
+                    <Translation
+                        id="moduleTrading.tradingScreen.error"
+                        values={{ message: error.message }}
+                    />
+                </Text>
+            )}
             <Button
-                onPress={showSheet}
+                onPress={handleShowSheet}
                 disabled={!isConfirmationEnabled}
             >
                 <Translation id="moduleTrading.tradingScreen.continueButton" />
             </Button>
suite-native/module-trading/src/hooks/__tests__/useBottomSheetControls.test.ts (1)

5-34: Test coverage looks good but could be enhanced.

The tests effectively cover the basic functionality of the bottom sheet controls:

  • Default state
  • Show sheet
  • Hide sheet after show

Consider adding tests for:

  • Error handling scenarios
  • Edge cases like multiple show/hide calls
  • State persistence between renders
suite-native/module-trading/src/components/buy/LegalSheet.tsx (2)

12-16: Consider enhancing accessibility for helper components.

The Subheader and Info components should include proper accessibility attributes for screen readers.

 const Subheader = ({ children }: { children: ReactNode }) => (
-    <Text variant="highlight" color="textDefault">
+    <Text variant="highlight" color="textDefault" accessibilityRole="header">
         {children}
     </Text>
 );

 const Info = ({ children }: { children: ReactNode }) => (
-    <HStack>
+    <HStack accessibilityRole="text">
         <Box flex={0}>
             <Text>{'\u2022'}</Text>
         </Box>

Also applies to: 18-29


31-82: Well-structured legal notice implementation.

The component effectively organizes legal information into distinct sections with proper spacing and visual hierarchy. The use of translation keys ensures proper internationalization.

A few suggestions for improvement:

  1. Consider adding a loading state for the sheet
  2. Add error boundaries for translation key failures
  3. Consider adding analytics for user interactions
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 8304a7b and bc9cd82.

📒 Files selected for processing (8)
  • suite-native/intl/src/en.ts (1 hunks)
  • suite-native/module-trading/src/components/buy/Confirmation.tsx (1 hunks)
  • suite-native/module-trading/src/components/buy/LegalSheet.tsx (1 hunks)
  • suite-native/module-trading/src/hooks/__tests__/useBottomSheetControls.test.ts (1 hunks)
  • suite-native/module-trading/src/hooks/useBottomSheetControls.ts (1 hunks)
  • suite-native/module-trading/src/hooks/useTradeConfirmationControls.ts (1 hunks)
  • suite-native/module-trading/src/hooks/useTradeSheetControls.ts (1 hunks)
  • suite-native/module-trading/src/screens/TradingScreen.tsx (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
suite-native/module-trading/src/screens/TradingScreen.tsx (1)
Learnt from: jbazant
PR: trezor/trezor-suite#16829
File: suite-native/module-trading/src/screens/TradingScreen.tsx:31-43
Timestamp: 2025-02-04T19:21:55.211Z
Learning: In React Native components, when implementing visual stubs or UI mockups, it's acceptable to use inline hardcoded values that will be replaced with real data in future commits. These temporary values don't need to be extracted into constants.
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: EAS Update
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: Analyze with CodeQL (javascript)
  • GitHub Check: prepare_android_test_app
🔇 Additional comments (4)
suite-native/module-trading/src/hooks/useTradeSheetControls.ts (1)

5-14: LGTM! Well-structured refactoring.

The refactoring improves code organization by delegating visibility management to useBottomSheetControls while maintaining type safety through generics.

suite-native/module-trading/src/screens/TradingScreen.tsx (1)

1-1: LGTM! Good improvement to the trading screen.

The changes enhance the UI by replacing the placeholder button with a proper legal confirmation component, which aligns well with the PR's objectives of improving legal compliance and safety features.

Also applies to: 7-7, 19-19

suite-native/module-trading/src/components/buy/LegalSheet.tsx (1)

6-10: Props interface is well-defined.

The props interface clearly defines the required properties and includes proper typing for the optional tradeProviderName.

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

1359-1376: Legal translations are well-structured but require legal review.

The translations effectively cover important legal aspects:

  • Security warnings
  • Partner relationships
  • Legal notices
  • Transaction finality
  • Regulatory compliance

However, these translations contain important legal statements that should be reviewed by legal counsel to ensure accuracy and compliance across jurisdictions.

Please ensure:

  1. Legal team has reviewed and approved all legal statements
  2. Translations maintain legal meaning when localized to other languages
  3. Compliance with financial regulations in target markets

Copy link

github-actions bot commented Feb 14, 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

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-native/module-trading/src/components/buy/LegalSheet.tsx (2)

12-22: Consider enhancing helper components with explicit prop types.

While the components are well-structured, consider these improvements:

  1. Define explicit prop types interfaces for better maintainability
  2. Consider moving to separate files if these components are reused elsewhere
+interface SubheaderProps {
+    children: ReactNode;
+}
-const Subheader = ({ children }: { children: ReactNode }) => (
+const Subheader = ({ children }: SubheaderProps) => (

+interface InfoProps {
+    children: ReactNode;
+}
-const Info = ({ children }: { children: ReactNode }) => (
+const Info = ({ children }: InfoProps) => (

31-73: Consider enhancing accessibility and user experience.

The legal information is well-structured, but consider these improvements:

  1. Add aria-labels for better screen reader support
  2. Consider adding a "Read more" or expand/collapse functionality for long text
-        <VStack spacing="sp12" paddingHorizontal="sp12">
+        <VStack 
+            spacing="sp12" 
+            paddingHorizontal="sp12"
+            role="region"
+            aria-label={<Translation id="moduleTrading.legalSheet.ariaLabel" />}
+        >
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bc9cd82 and dd23d05.

📒 Files selected for processing (1)
  • suite-native/module-trading/src/components/buy/LegalSheet.tsx (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (4)
  • GitHub Check: EAS Update
  • GitHub Check: prepare_android_test_app
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: Analyze with CodeQL (javascript)
🔇 Additional comments (2)
suite-native/module-trading/src/components/buy/LegalSheet.tsx (2)

1-10: LGTM! Well-structured imports and type definitions.

The imports are appropriate, and the LegalSheetProps type is well-defined with clear purpose.


24-75:

❓ Verification inconclusive

Verify the translation keys and button behavior.

The component structure is clean and well-organized. However, there are a few points to verify:

  1. The continue button uses a translation key from tradingScreen instead of legalSheet
  2. The collapsable prop's behavior should be documented

Let's verify the translation keys are properly defined:


🏁 Script executed:

#!/bin/bash
# Check if all translation keys are defined
rg -A 1 "moduleTrading\.legalSheet\." suite-native/intl/src/
rg "moduleTrading\.tradingScreen\.continueButton" suite-native/intl/src/

Length of output: 137


Action Required: Confirm Translation Keys and Document collapsable Behavior

The LegalSheet component is cleanly structured; however, two issues need your attention:

  • Translation Key Verification: The continue button uses the key moduleTrading.tradingScreen.continueButton while other keys come from moduleTrading.legalSheet.*. Please manually verify that this discrepancy is intentional and that the corresponding key is correctly defined in your internationalization files.
  • collapsable Prop Documentation: The behavior of the collapsable prop on the BottomSheet component isn’t immediately clear. Consider adding documentation (or verifying existing documentation) to clarify its intended functionality.

Please review these points to ensure consistency and clarity in the component behavior.

Copy link
Contributor

@vytick vytick left a comment

Choose a reason for hiding this comment

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

🚀

@jbazant
Copy link
Contributor Author

jbazant commented Feb 14, 2025

/rebase

Copy link

@trezor-ci trezor-ci force-pushed the 16993-Mobile-Trade-Legal-notice-and-safety branch from dd23d05 to 9e29731 Compare February 14, 2025 16:41
@jbazant jbazant merged commit 51efb6c into develop Feb 17, 2025
16 checks passed
@jbazant jbazant deleted the 16993-Mobile-Trade-Legal-notice-and-safety branch February 17, 2025 05:50
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
None yet
Development

Successfully merging this pull request may close these issues.

Mobile Trade: Legal notice and safety
2 participants