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

fix: deeplinking duplicate screens #38

Merged
merged 2 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions apps/expo/app/(home)/wallet.tsx

This file was deleted.

21 changes: 19 additions & 2 deletions apps/expo/app/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
import { Redirect } from 'expo-router'
import { XStack } from '@internal/ui'
import { WalletScreen } from 'app/features/wallet/WalletScreen'
import { Stack } from 'expo-router'
import { useSafeAreaInsets } from 'react-native-safe-area-context'

export default function Screen() {
return <Redirect href="/wallet" />
const { top } = useSafeAreaInsets()

return (
<>
<Stack.Screen
options={{
headerShown: true,
header: () => {
return <XStack h={top} bg="$grey-200" />
},
}}
/>
<WalletScreen />
</>
)
}
6 changes: 6 additions & 0 deletions apps/expo/utils/DeeplinkHandler.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ReactNode } from 'react'

import { QrTypes } from '@internal/agent'
import { useCredentialDataHandler } from 'app/hooks/useCredentialDataHandler'
import * as Linking from 'expo-linking'
import { useEffect, useState } from 'react'
Expand All @@ -8,6 +9,8 @@ interface DeeplinkHandlerProps {
children: ReactNode
}

const deeplinkSchemes = Object.values(QrTypes)

export const DeeplinkHandler = ({ children }: DeeplinkHandlerProps) => {
const url = Linking.useURL()
const [lastDeeplink, setLastDeeplink] = useState<string | null>(null)
Expand All @@ -16,6 +19,9 @@ export const DeeplinkHandler = ({ children }: DeeplinkHandlerProps) => {
useEffect(() => {
if (!url || url === lastDeeplink) return

// Ignore deeplinks that don't start with the schemes for credentials
if (!deeplinkSchemes.some((scheme) => url.startsWith(scheme))) return

setLastDeeplink(url)
void handleCredentialData(url)
}, [url])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export function CredentialNotificationScreen() {

const pushToWallet = () => {
router.back()
router.push('/wallet')
router.push('/')
}

useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export function PresentationNotificationScreen() {

const pushToWallet = () => {
router.back()
router.push('/wallet')
router.push('/')
}

useEffect(() => {
Expand Down