Skip to content

fix: backgroundlock path state #337

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
9 changes: 7 additions & 2 deletions apps/easypid/src/app/+native-intent.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'fast-text-encoding'

import { TypedArrayEncoder } from '@credo-ts/core'
import { appScheme } from '@easypid/constants'
import { parseInvitationUrl } from '@package/agent'
import { deeplinkSchemes } from '@package/app'
Expand Down Expand Up @@ -57,14 +58,18 @@ export async function redirectSystemPath({ path, initial }: { path: string; init
}

if (redirectPath) {
// Always make the user authenticate first when opening with a deeplink
const encodedRedirect = TypedArrayEncoder.toBase64URL(TypedArrayEncoder.fromString(redirectPath))
const newPath = `/authenticate?redirectAfterUnlock=${encodedRedirect}`

// NOTE: it somehow doesn't handle the intent if the app is already open
// so we replace the router to the path. I think it can break easily though if e.g.
// the wallet is locked in the background. Not sure how to proceed, this is best effort fix
if (!initial) {
router.replace(redirectPath)
router.replace(newPath)
return null
}
return redirectPath
return newPath
}

void Haptics.notificationAsync(Haptics.NotificationFeedbackType.Error)
Expand Down
8 changes: 8 additions & 0 deletions apps/easypid/src/app/authenticate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ export default function Authenticate() {
const isLoading =
secureUnlock.state === 'acquired-wallet-key' || (secureUnlock.state === 'locked' && secureUnlock.isUnlocking)

// If there is a redirectAfterUnlock param, we require the user to authenticate again
// biome-ignore lint/correctness/useExhaustiveDependencies: only check on component mount
useEffect(() => {
if (secureUnlock.state === 'unlocked' && redirectAfterUnlock) {
secureUnlock.lock()
}
}, [])

// After resetting the wallet, we want to avoid prompting for face id immediately
// So we add an artificial delay
useEffect(() => {
Expand Down
10 changes: 9 additions & 1 deletion apps/easypid/src/features/menu/FunkeMenuScreen.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type React from 'react'

import { useSecureUnlock } from '@easypid/agent'
import { useFeatureFlag } from '@easypid/hooks/useFeatureFlag'
import { useWalletReset } from '@easypid/hooks/useWalletReset'
import { useCredentialByCategory } from '@package/agent/src/hooks/useCredentialByCategory'
Expand Down Expand Up @@ -62,13 +63,19 @@ export function FunkeMenuScreen() {
const { handleScroll, isScrolledByOffset, scrollEventThrottle } = useScrollViewPosition()
const onResetWallet = useWalletReset()
const { withHaptics } = useHaptics()

const secureUnlock = useSecureUnlock()
const { credential, isLoading } = useCredentialByCategory('DE-PID')
const hasEidCardFeatureFlag = useFeatureFlag('EID_CARD')

const handleFeedback = withHaptics(() => Linking.openURL('mailto:[email protected]?subject=Feedback on the Wallet'))
const handlePush = (path: string) => withHaptics(() => router.push(path))

const handleLock = () => {
if (secureUnlock.state === 'unlocked') {
secureUnlock.lock()
}
}

return (
<FlexPage gap="$0" paddingHorizontal="$0">
<HeaderContainer isScrolledByOffset={isScrolledByOffset} title="Menu" />
Expand Down Expand Up @@ -117,6 +124,7 @@ export function FunkeMenuScreen() {
icon={<HeroIcons.InformationCircleFilled />}
label="About this wallet"
/>
<MenuListItem onPress={handleLock} action="none" icon={<HeroIcons.LockClosedFilled />} label="Lock app" />
<MenuListItem
variant="danger"
onPress={onResetWallet}
Expand Down
10 changes: 9 additions & 1 deletion packages/app/src/components/TextBackButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,16 @@ export function TextBackButton() {
const router = useRouter()
const { withHaptics } = useHaptics()

const handleBack = () => {
if (router.canGoBack()) {
router.back()
} else {
router.replace('/')
}
}

return (
<Button.Text color="$primary-500" fontWeight="$semiBold" onPress={withHaptics(() => router.back())} scaleOnPress>
<Button.Text color="$primary-500" fontWeight="$semiBold" onPress={withHaptics(handleBack)} scaleOnPress>
<HeroIcons.ArrowLeft mr={-4} color="$primary-500" strokeWidth={2} size={20} /> Back
</Button.Text>
)
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/provider/BackgroundLockProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { PropsWithChildren } from 'react'

import { useSecureUnlock } from '@package/secure-store/secure-wallet-key/SecureUnlockProvider'
import { useSecureUnlock } from '@easypid/agent'
import { useRouter } from 'expo-router'
import { useEffect, useRef } from 'react'
import { AppState, type AppStateStatus } from 'react-native'
Expand Down