Skip to content

feat(wallet-mobile): Add screen navigation for notification press#3919

Merged
stackchain merged 10 commits intodevelopfrom
feat/screen-navigation
May 8, 2025
Merged

feat(wallet-mobile): Add screen navigation for notification press#3919
stackchain merged 10 commits intodevelopfrom
feat/screen-navigation

Conversation

@michaeljscript
Copy link
Contributor

@michaeljscript michaeljscript commented Apr 18, 2025

Description / Change(s) / Related issue(s)

Add screen navigation for notification press

TODO

  • Add a handler to open a wallet screen
  • Add a handler to open a staking_center screen
  • Add a handler to open a swap screen
  • Add a handler to open a governance screen
  • Add a handler to open a discover screen
  • Confirm with product if we need to display a modal on the select wallet screen explaining the user that they need to select a wallet to perform the action
  • Refactor
  • Update documentation on Confluence, so the FCM payload matches what we have in documentation
Ticket

YV-401

Summary by CodeRabbit

  • New Features

    • Improved handling of notification-driven navigation, enabling the app to respond more intelligently when users interact with notifications.
    • Added support for deferred navigation to specific screens when opening the app from a notification.
    • Introduced a direct navigation method to the notifications screen.
    • Added navigation support for the swap feature with environment-specific handling.
  • Chores

    • Updated internal structure for notification initialization to improve maintainability.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Apr 18, 2025

Walkthrough

This change refactors notification handling and navigation integration within a mobile wallet application. The initialization of notifications is moved into a dedicated component within the navigation container. Notification action handling is updated to include navigation context, allowing for both immediate and deferred navigation actions based on the source of the notification (operating system or app). New helper functions are introduced to manage deferred navigation triggered by notifications. The navigation system is extended with a method for direct navigation to the notifications screen, and related type definitions are updated. Metadata for translation messages is also updated.

Changes

File(s) Change Summary
apps/wallet-mobile/src/AppNavigator.tsx Moved useInitNotifications call into a new NotificationContainer component, rendered inside the navigation container.
apps/wallet-mobile/src/features/Notifications/common/hooks.ts Modified initPushNotifications to accept walletNavigation and updated push notification event handling to pass navigation context to notification actions.
apps/wallet-mobile/src/features/Notifications/common/tools.ts Refactored triggerNotificationAction to accept an options object with navigation context and source; added helpers for deferred notification navigation; extracted internal navigation logic.
apps/wallet-mobile/src/features/Notifications/useCases/ViewNotificationHistory/ViewNotificationHistoryScreen.tsx Updated notification action handling to include navigation context and source in calls to triggerNotificationAction.
apps/wallet-mobile/src/features/WalletManager/useCases/SelectWalletFromListScreen/SelectWalletFromListScreen.tsx Enhanced wallet selection logic to handle deferred notification-driven navigation after wallet selection, using new helpers and navigation context.
apps/wallet-mobile/src/kernel/navigation.tsx Added navigateToNotifications and navigateToSwap methods to navigation hook and exported WalletNavigation type alias.
apps/wallet-mobile/translations/messages/src/AppNavigator.json Updated positional metadata for translation entries; no changes to message content.

Sequence Diagram(s)

sequenceDiagram
    participant OS
    participant AppNavigator
    participant NotificationContainer
    participant NotificationHooks
    participant WalletNavigation
    participant NotificationTools

    OS->>AppNavigator: Launch app / deliver notification
    AppNavigator->>NotificationContainer: Render
    NotificationContainer->>NotificationHooks: useInitNotifications({localEnabled, pushEnabled})
    NotificationHooks->>NotificationTools: initPushNotifications(walletNavigation)
    NotificationTools->>NotificationHooks: Register notification opened handler
    OS->>NotificationHooks: Notification opened event
    NotificationHooks->>NotificationTools: triggerNotificationAction({manager, id, walletNavigation, source: 'os'})
    NotificationTools->>WalletNavigation: (deferred or immediate navigation based on source)
Loading

Possibly related PRs

  • Emurgo/yoroi#3918: Refactors notification initialization and extends notification action handling with navigation context, directly related to the changes in this PR.

Suggested reviewers

  • banklesss
  • stackchain

Poem

In the warren of code, a new path unfurled,
Notifications now know how to navigate the world!
With hops and with jumps, from OS or app,
Deferred or direct, we never lose track.
So here’s to the bunnies who keep things in sync—
With every new feature, we’re quicker than you think!
🐇✨


📜 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 d0c8bcc and 8380447.

📒 Files selected for processing (2)
  • apps/wallet-mobile/src/features/Notifications/common/tools.ts (3 hunks)
  • apps/wallet-mobile/src/kernel/navigation.tsx (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
apps/wallet-mobile/src/features/Notifications/common/tools.ts (3)
apps/wallet-mobile/src/kernel/navigation.tsx (1)
  • WalletNavigation (710-710)
apps/wallet-mobile/src/features/Notifications/common/storage.ts (1)
  • uiStorage (9-9)
packages/types/src/index.ts (1)
  • PushEvent (703-703)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: check
🔇 Additional comments (9)
apps/wallet-mobile/src/kernel/navigation.tsx (5)

14-15: LGTM: Imported hooks for enhanced navigation functionality.

The newly imported hooks (useSwap and useSelectedNetwork) are necessary for the new navigateToSwap functionality.


405-406: LGTM: Correctly initialized hooks within useWalletNavigation.

Both hooks are properly initialized within the hook function, following React patterns.


639-641: LGTM: Clean implementation of navigateToNotifications.

The function provides a simple and direct way to navigate to the notifications screen, which will be used by notification handling logic.


676-706: LGTM: Well-implemented navigateToSwap with appropriate conditional logic.

The implementation handles different scenarios well:

  1. Special case for Preprod network that shows a notice screen
  2. Form reset before navigation
  3. Optional token pre-selection

This comprehensive approach provides a good user experience.


710-710: LGTM: Useful type export for cross-file type safety.

Exporting the WalletNavigation type allows other files to properly type-check navigation objects, enhancing code robustness.

apps/wallet-mobile/src/features/Notifications/common/tools.ts (4)

2-3: LGTM: Appropriate imports for enhanced notification functionality.

Added imports support the new notification handling capabilities:

  • Type guards for runtime validation
  • Portfolio types for swap functionality
  • WalletNavigation type for navigation integration

Also applies to: 7-7


43-70: LGTM: Well-structured notification action handler with source differentiation.

The refactoring to use an options object improves readability and maintainability. The differentiation between OS notifications (source === 'os') and in-app notifications (source === 'app') allows for appropriate handling:

  • OS notifications store the action for deferred processing
  • In-app notifications navigate immediately

This approach correctly handles the different user experience flows.


72-79: LGTM: Useful utility functions for notification action persistence.

These functions provide a clean interface for managing the persisted notification actions:

  • clearNotificationInternalNavigationAction for cleanup
  • shouldHandleNotificationInternalNavigationAction for checking if action exists

The implementation uses persistent storage appropriately for cross-session state.


96-125: LGTM: Comprehensive navigation handler for different notification targets.

The handleInternalNavigation function properly handles all the required navigation targets:

  • wallet
  • staking_center
  • swap (including token pre-selection)
  • governance
  • discover

The conditional pushNotificationHistory parameter correctly controls whether to show the notifications history before final navigation, providing flexibility in the UX flow.

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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.

@codecov
Copy link

codecov bot commented Apr 18, 2025

Codecov Report

Attention: Patch coverage is 0% with 62 lines in your changes missing coverage. Please review.

Project coverage is 22.18%. Comparing base (55f1288) to head (8380447).
Report is 2 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3919      +/-   ##
===========================================
- Coverage    22.23%   22.18%   -0.06%     
===========================================
  Files         1140     1140              
  Lines        21764    21820      +56     
  Branches      3467     3480      +13     
===========================================
  Hits          4840     4840              
- Misses       16779    16835      +56     
  Partials       145      145              
Components Coverage Δ
@yoroi/api 100.00% <ø> (ø)
@yoroi/blockchains 100.00% <ø> (ø)
@yoroi/claim 100.00% <ø> (ø)
@yoroi/common 100.00% <ø> (ø)
@yoroi/dapp-connector 100.00% <ø> (ø)
@yoroi/exchange 100.00% <ø> (ø)
@yoroi/explorers 100.00% <ø> (ø)
@yoroi/identicon 100.00% <ø> (ø)
@yoroi/links 100.00% <ø> (ø)
@yoroi/notifications 100.00% <ø> (ø)
@yoroi/portfolio 100.00% <ø> (ø)
@yoroi/resolver 100.00% <ø> (ø)
@yoroi/setup-wallet 100.00% <ø> (ø)
@yoroi/staking 68.80% <ø> (ø)
@yoroi/swap 100.00% <ø> (ø)
@yoroi/theme 100.00% <ø> (ø)
@yoroi/transfer 100.00% <ø> (ø)
@yoroi/types ∅ <ø> (∅)
@yoroi/wallet-mobile 9.47% <0.00%> (-0.03%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jorbuedo jorbuedo marked this pull request as ready for review May 5, 2025 14:46
Copy link
Contributor

@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: 5

🧹 Nitpick comments (1)
apps/wallet-mobile/src/features/Notifications/common/tools.ts (1)

62-69: Distinguish internal-navigation storage key & encapsulate it

The literal 'triggerNotificationInternalNavigationAction' is repeated three times.
A single constant reduces the risk of typos and eases future refactors:

-      if (source === 'os') {
-        await uiStorage.setItem('triggerNotificationInternalNavigationAction', event.id)
+      if (source === 'os') {
+        await uiStorage.setItem(INTERNAL_NAV_KEY, event.id)
...
-  const id = await uiStorage.getItem('triggerNotificationInternalNavigationAction')
+  const id = await uiStorage.getItem(INTERNAL_NAV_KEY)
...
-  await uiStorage.removeItem('triggerNotificationInternalNavigationAction')
+  await uiStorage.removeItem(INTERNAL_NAV_KEY)

Define the key once at the top of the file:

const INTERNAL_NAV_KEY = 'triggerNotificationInternalNavigationAction' as const
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4b6e1f1 and 7eac11f.

📒 Files selected for processing (7)
  • apps/wallet-mobile/src/AppNavigator.tsx (2 hunks)
  • apps/wallet-mobile/src/features/Notifications/common/hooks.ts (3 hunks)
  • apps/wallet-mobile/src/features/Notifications/common/tools.ts (3 hunks)
  • apps/wallet-mobile/src/features/Notifications/useCases/ViewNotificationHistory/ViewNotificationHistoryScreen.tsx (2 hunks)
  • apps/wallet-mobile/src/features/WalletManager/useCases/SelectWalletFromListScreen/SelectWalletFromListScreen.tsx (3 hunks)
  • apps/wallet-mobile/src/kernel/navigation.tsx (2 hunks)
  • apps/wallet-mobile/translations/messages/src/AppNavigator.json (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
apps/wallet-mobile/src/features/Notifications/useCases/ViewNotificationHistory/ViewNotificationHistoryScreen.tsx (2)
apps/wallet-mobile/src/kernel/navigation.tsx (1)
  • useWalletNavigation (405-676)
apps/wallet-mobile/src/features/Notifications/common/tools.ts (1)
  • triggerNotificationAction (43-70)
apps/wallet-mobile/src/AppNavigator.tsx (1)
apps/wallet-mobile/src/features/Notifications/common/hooks.ts (1)
  • useInitNotifications (61-72)
apps/wallet-mobile/src/features/WalletManager/useCases/SelectWalletFromListScreen/SelectWalletFromListScreen.tsx (4)
apps/wallet-mobile/src/kernel/navigation.tsx (1)
  • useWalletNavigation (405-676)
packages/types/src/index.ts (1)
  • Meta (665-665)
apps/wallet-mobile/src/features/Notifications/common/tools.ts (2)
  • shouldHandleNotificationInternalNavigationAction (76-79)
  • handleNotificationInternalNavigationAction (81-94)
apps/wallet-mobile/src/features/Notifications/common/notification-manager.ts (1)
  • pushNotificationsManager (11-14)
apps/wallet-mobile/src/features/Notifications/common/hooks.ts (3)
apps/wallet-mobile/src/kernel/navigation.tsx (2)
  • WalletNavigation (678-678)
  • useWalletNavigation (405-676)
apps/wallet-mobile/src/features/Notifications/common/tools.ts (1)
  • triggerNotificationAction (43-70)
apps/wallet-mobile/src/features/Notifications/common/notification-manager.ts (1)
  • pushNotificationsManager (11-14)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: check
🔇 Additional comments (8)
apps/wallet-mobile/translations/messages/src/AppNavigator.json (1)

7-9: Line numbers updated correctly to match new component structure.

The metadata adjustments for translation messages accurately reflect the structural changes in the AppNavigator.tsx file, where the notification initialization was moved into a dedicated NotificationContainer component.

Also applies to: 12-14, 22-24, 27-29, 37-39, 42-44, 52-54, 57-59

apps/wallet-mobile/src/kernel/navigation.tsx (2)

639-641: Added navigation method to notifications screen.

The new navigateToNotifications method properly implements direct navigation to the notifications screen, which is essential for the notification-triggered navigation feature.


678-678: Added type definition for wallet navigation.

The WalletNavigation type definition provides proper type safety for the navigation object used throughout the notification handling system.

apps/wallet-mobile/src/AppNavigator.tsx (2)

120-120: Relocated notification initialization for proper navigation context.

Moving the NotificationContainer inside NavigationContainer ensures notifications have access to the navigation context.


243-246: Created dedicated component for notification initialization.

The new NotificationContainer component correctly encapsulates notification initialization logic, maintaining the same configuration while enabling proper integration with navigation context.

apps/wallet-mobile/src/features/Notifications/common/hooks.ts (1)

65-68: Trim unused dependency to avoid redundant effect resets

manager is not referenced inside this effect body, yet it appears in the dependency list.
React will not re-run the effect because walletNavigation is stable, but automated linting may complain and newcomers might wonder why it is there.

-  React.useEffect(
-    () => (pushEnabled ? initPushNotifications(walletNavigation) : undefined),
-    [walletNavigation, pushEnabled, manager],
-  )
+  React.useEffect(
+    () => (pushEnabled ? initPushNotifications(walletNavigation) : undefined),
+    [walletNavigation, pushEnabled],
+  )

[ suggest_nitpick ]

apps/wallet-mobile/src/features/Notifications/useCases/ViewNotificationHistory/ViewNotificationHistoryScreen.tsx (2)

15-15: Navigation integration looks good

Adding the useWalletNavigation hook here allows the notification component to properly navigate to different screens in response to notification actions. This matches the broader refactoring pattern seen in the codebase.

Also applies to: 32-32


39-41: Correctly implemented notification action handling

The updated triggerNotificationAction call properly passes the navigation context and identifies the source as 'app'. This ensures that when a user taps a notification within the app, it will directly handle navigation instead of deferring it through persistent storage, which is the correct behavior.

@jorbuedo
Copy link
Contributor

jorbuedo commented May 6, 2025

Screencast_20250506_123055.webm

@jorbuedo jorbuedo changed the title WIP feat(wallet-mobile): Add screen navigation for notification press feat(wallet-mobile): Add screen navigation for notification press May 6, 2025
@stackchain stackchain merged commit 393b745 into develop May 8, 2025
24 of 25 checks passed
@stackchain stackchain deleted the feat/screen-navigation branch May 8, 2025 09:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants