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

Update Expo linking, simplify popup deeplink callback #16769

Merged
merged 2 commits into from
Feb 5, 2025

Conversation

martykan
Copy link
Member

@martykan martykan commented Feb 3, 2025

Description

There was an issue in expo-linking on iOS that was fixed in the latest version expo/expo#33031

This PR also refactors the logic around expo-linking to use their useURL hook instead of manual callbacks.

Copy link

coderabbitai bot commented Feb 3, 2025

Walkthrough

The changes involve modifications to the useConnectPopupNavigation.ts hook, specifically the removal of the navigateToConnectPopup function and its associated logic. The navigation logic has been integrated into a single useEffect hook that directly utilizes the current URL from Linking.useURL(). The previous implementation that awaited the initial URL through Linking.getInitialURL() has been removed, simplifying the URL handling. The checks for the feature flag and URL validity are now performed within the same effect, and the subscription to URL events via Linking.addEventListener has been eliminated. Additionally, the expo-linking dependency has been updated to version ^7.0.5 across multiple package.json files, reflecting a minor version upgrade without altering other configurations.

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

🪧 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 bot commented Feb 3, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@martykan martykan added the no-project This label is used to specify that PR doesn't need to be added to a project label Feb 3, 2025
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-connect-popup/src/hooks/useConnectPopupNavigation.ts (2)

31-32: Track device connection/unlock state handling.

The TODO comments highlight an important edge case that needs to be addressed. Similar patterns exist in other modals (biometrics, coin enabled) that could serve as references.

Would you like me to:

  1. Create an issue to track this technical debt?
  2. Generate a proposal for handling device connection/unlock states based on existing modal patterns?

39-44: Consider enhancing error handling and readability.

While the implementation is cleaner, consider these improvements:

  1. Combine the early returns for better readability
  2. Add error handling for URL parsing
  3. Memoize the navigation callback

Here's a suggested implementation:

 useEffect(() => {
-    if (!featureFlagEnabled) return;
-    if (!url || !isConnectPopupUrl(url)) return;
-    const parsedUrl = Linking.parse(url);
-    navigation.navigate(RootStackRoutes.ConnectPopup, { parsedUrl });
+    if (!featureFlagEnabled || !url || !isConnectPopupUrl(url)) return;
+    
+    try {
+        const parsedUrl = Linking.parse(url);
+        navigation.navigate(RootStackRoutes.ConnectPopup, { parsedUrl });
+    } catch (error) {
+        console.error('Failed to parse Connect Popup URL:', error);
+    }
 }, [url, navigation, featureFlagEnabled]);
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between c8f5f48 and dc05200.

📒 Files selected for processing (1)
  • suite-native/module-connect-popup/src/hooks/useConnectPopupNavigation.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Unit Tests
  • GitHub Check: Releases revision Checks
  • GitHub Check: Other Checks
  • GitHub Check: Type Checking
  • GitHub Check: Linting and formatting
  • GitHub Check: Build libs for publishing
  • GitHub Check: prepare_android_test_app
  • GitHub Check: Analyze with CodeQL (javascript)
🔇 Additional comments (2)
suite-native/module-connect-popup/src/hooks/useConnectPopupNavigation.ts (2)

1-29: LGTM! Well-structured imports and robust URL validation.

The imports are well-organized, types are properly defined, and the URL validation logic effectively handles both development and production environments.


37-37: LGTM! Good use of the useURL hook.

Using Linking.useURL() simplifies the URL handling by leveraging React's built-in state management.

@martykan martykan force-pushed the chore/mobile-connect-popup-linking-logic branch from dc05200 to 09dac31 Compare February 3, 2025 15:17
@martykan martykan marked this pull request as ready for review February 3, 2025 15:18
@martykan martykan requested review from a team and mroz22 as code owners February 3, 2025 15:18
@martykan martykan changed the title chore(suite-native): mobile connect popup simplify deeplink callback Update Expo linking, simplify popup deeplink callback Feb 3, 2025
Copy link

github-actions bot commented Feb 3, 2025

🚀 Expo preview is ready!

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

Learn more about 𝝠 Expo Github Action

@martykan martykan removed the no-project This label is used to specify that PR doesn't need to be added to a project label Feb 3, 2025
@martykan martykan force-pushed the chore/mobile-connect-popup-linking-logic branch from 09dac31 to cbca225 Compare February 5, 2025 11:10
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-connect-popup/src/hooks/useConnectPopupNavigation.ts (1)

42-47: Consider enhancing error reporting.

While the try-catch implementation is good, consider using a proper error tracking solution instead of just console.warn for better visibility of issues in production.

-            console.warn('Invalid deeplink URL', { error, url });
+            // Use your error tracking solution (e.g., Sentry)
+            reportError(new Error('Invalid deeplink URL'), { error, url });
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 09dac31 and cbca225.

📒 Files selected for processing (1)
  • suite-native/module-connect-popup/src/hooks/useConnectPopupNavigation.ts (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (16)
  • GitHub Check: build-deploy
  • GitHub Check: build-deploy
  • GitHub Check: run-desktop-tests (@group=wallet, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: EAS Update
  • GitHub Check: run-desktop-tests (@group=settings, trezor-user-env-unix bitcoin-regtest)
  • GitHub Check: transport-e2e-test
  • GitHub Check: run-desktop-tests (@group=device-management, trezor-user-env-unix)
  • GitHub Check: build
  • GitHub Check: prepare_android_test_app
  • GitHub Check: build-web
  • GitHub Check: run-desktop-tests (@group=suite, trezor-user-env-unix)
  • GitHub Check: build-web
  • GitHub Check: test
  • GitHub Check: Setup and Cache Dependencies
  • GitHub Check: Analyze with CodeQL (javascript)
  • GitHub Check: Socket Security: Pull Request Alerts
🔇 Additional comments (2)
suite-native/module-connect-popup/src/hooks/useConnectPopupNavigation.ts (2)

37-37: LGTM! Good simplification using the useURL hook.

The change to use Linking.useURL() effectively simplifies the URL handling by automatically managing both initial URLs and subsequent URL changes.


39-48: Verify edge cases and optimize URL validation.

Based on previous concerns about edge cases:

  1. Verify the behavior when rapidly receiving multiple URLs.
  2. Consider validating the URL before checking the feature flag for better performance.
     useEffect(() => {
-        if (!featureFlagEnabled) return;
-        if (!url || !isConnectPopupUrl(url)) return;
+        if (!url) return;
+        if (!isConnectPopupUrl(url)) return;
+        if (!featureFlagEnabled) return;
         try {
             const parsedUrl = Linking.parse(url);
             navigation.navigate(RootStackRoutes.ConnectPopup, { parsedUrl });

Let's verify the behavior with multiple URLs:

@martykan martykan enabled auto-merge (rebase) February 5, 2025 11:24
@martykan martykan merged commit 1b30739 into develop Feb 5, 2025
69 of 77 checks passed
@martykan martykan deleted the chore/mobile-connect-popup-linking-logic branch February 5, 2025 11:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 🎯 To do
Development

Successfully merging this pull request may close these issues.

2 participants