Skip to content

Commit

Permalink
fix: push to home on background lock (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
janrtvld authored Nov 27, 2024
1 parent 319e00f commit 6d5e2f1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/app/src/provider/BackgroundLockProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import type { PropsWithChildren } from 'react'

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

const BACKGROUND_TIME_THRESHOLD = 30000 // 30 seconds
const BACKGROUND_TIME_THRESHOLD = 60000 // 60 seconds

export function BackgroundLockProvider({ children }: PropsWithChildren) {
const router = useRouter()
const secureUnlock = useSecureUnlock()
const backgroundTimeRef = useRef<Date | null>(null)

Expand All @@ -22,6 +24,7 @@ export function BackgroundLockProvider({ children }: PropsWithChildren) {
if (timeInBackground > BACKGROUND_TIME_THRESHOLD && secureUnlock.state === 'unlocked') {
console.log('App was in background for more than 30 seconds, locking')
secureUnlock.lock()
router.replace('/authenticate')
}
backgroundTimeRef.current = null
}
Expand All @@ -33,7 +36,7 @@ export function BackgroundLockProvider({ children }: PropsWithChildren) {
return () => {
subscription.remove()
}
}, [secureUnlock])
}, [secureUnlock, router])

return <>{children}</>
}

0 comments on commit 6d5e2f1

Please sign in to comment.