Skip to content

Commit

Permalink
fix(wallet-mobile): Do not show notifications on wallet selection screen
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljscript committed Feb 13, 2025
1 parent 89a8ddc commit 463b4ed
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import {useNavigation} from '@react-navigation/native'
import {isString} from '@yoroi/common'
import {useNotificationManager} from '@yoroi/notifications'
import {Notifications} from '@yoroi/types'
import * as React from 'react'
import {useMemo} from 'react'

import {isWalletSelectionRoute} from '../../../kernel/navigation'
import {useNotificationDisplaySettings} from '../../Settings/useCases/changeWalletSettings/Notifications/NotificationsDisplaySettings'
import {useWalletManager} from '../../WalletManager/context/WalletManagerProvider'
import {NotificationPopup} from './common/NotificationPopup'
Expand Down Expand Up @@ -37,11 +40,14 @@ export const NotificationUIHandler = () => {
const useCollectNewNotifications = ({enabled}: {enabled: boolean}) => {
const manager = useNotificationManager()
const walletManager = useWalletManager()
const selectedWalletId = walletManager.selected.wallet?.id ?? ''
const selectedWalletId = walletManager.selected.wallet?.id ?? null
const [events, setEvents] = React.useState<Notifications.Event[]>([])
const navigator = useNavigation()
const navigatorState = navigator.getState()
const isWalletSelectionScreen = React.useMemo(() => isWalletSelectionRoute(navigatorState), [navigatorState])

React.useEffect(() => {
if (!enabled) return
if (!enabled || !isString(selectedWalletId) || isWalletSelectionScreen) return
const pushEvent = (event: Notifications.Event) => {
setEvents((e) => [...e, event])
}
Expand All @@ -58,7 +64,7 @@ const useCollectNewNotifications = ({enabled}: {enabled: boolean}) => {
return () => {
subscription.unsubscribe()
}
}, [manager, setEvents, selectedWalletId, enabled])
}, [manager, setEvents, selectedWalletId, enabled, isWalletSelectionScreen])

const removeEvent = (id: number) => {
setEvents((e) => e.filter((ev) => ev.id !== id))
Expand Down
11 changes: 11 additions & 0 deletions apps/wallet-mobile/src/kernel/navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -654,3 +654,14 @@ const getFocusedRouteName = (state: Partial<NavigationState> | NavigationState['

return [name]
}

export const isWalletSelectionRoute = (state: Partial<NavigationState> | NavigationState['routes'][0]['state']) => {
const routes = getFocusedRouteName(state)
const manageWalletsRoute: keyof AppRoutes = 'manage-wallets'
const walletSelectionRoute: keyof WalletStackRoutes = 'wallet-selection'

return (
(routes.length === 1 && routes[0] === manageWalletsRoute) ||
(routes.length === 2 && routes[1] === walletSelectionRoute)
)
}

0 comments on commit 463b4ed

Please sign in to comment.