about summary refs log tree commit diff
path: root/src/state/ageAssurance/index.tsx
diff options
context:
space:
mode:
authorEric Bailey <git@esb.lol>2025-07-18 14:21:23 -0500
committerGitHub <noreply@github.com>2025-07-18 14:21:23 -0500
commit0995e81b58925139dc2a16f98c613fcf2bba84d5 (patch)
tree0d875e29e3ed02a19847151e67beac84d456be91 /src/state/ageAssurance/index.tsx
parent6a15679fb118dd07fe869311e6d3c4721c221b58 (diff)
downloadvoidsky-0995e81b58925139dc2a16f98c613fcf2bba84d5.tar.zst
Age assurance tweaks (#8671)
* Refetch state while in pending status

* Add success state to redirect, just have user close, nicer experience

* Stop refetching after pending
Diffstat (limited to 'src/state/ageAssurance/index.tsx')
-rw-r--r--src/state/ageAssurance/index.tsx22
1 files changed, 21 insertions, 1 deletions
diff --git a/src/state/ageAssurance/index.tsx b/src/state/ageAssurance/index.tsx
index eded74773..3451b1139 100644
--- a/src/state/ageAssurance/index.tsx
+++ b/src/state/ageAssurance/index.tsx
@@ -1,4 +1,4 @@
-import {createContext, useContext, useMemo} from 'react'
+import {createContext, useContext, useMemo, useState} from 'react'
 import {type AppBskyUnspeccedDefs} from '@atproto/api'
 import {useQuery} from '@tanstack/react-query'
 
@@ -46,6 +46,7 @@ export function Provider({children}: {children: React.ReactNode}) {
   const {geolocation} = useGeolocation()
   const isAgeAssuranceEnabled = useIsAgeAssuranceEnabled()
   const getAndRegisterPushToken = useGetAndRegisterPushToken()
+  const [refetchWhilePending, setRefetchWhilePending] = useState(false)
 
   const {data, isFetched, refetch} = useQuery({
     /**
@@ -56,6 +57,7 @@ export function Provider({children}: {children: React.ReactNode}) {
      * However, it only needs to run if AA is enabled.
      */
     enabled: isAgeAssuranceEnabled,
+    refetchOnWindowFocus: refetchWhilePending,
     queryKey: createAgeAssuranceQueryKey(agent.session?.did ?? 'never'),
     async queryFn() {
       if (!agent.session) return null
@@ -109,6 +111,24 @@ export function Provider({children}: {children: React.ReactNode}) {
     return ctx
   }, [isFetched, data, isAgeAssuranceEnabled])
 
+  if (
+    !!ageAssuranceContext.lastInitiatedAt &&
+    ageAssuranceContext.status === 'pending' &&
+    !refetchWhilePending
+  ) {
+    /*
+     * If we have a pending state, we want to refetch on window focus to ensure
+     * that we get the latest state when the user returns to the app.
+     */
+    setRefetchWhilePending(true)
+  } else if (
+    !!ageAssuranceContext.lastInitiatedAt &&
+    ageAssuranceContext.status !== 'pending' &&
+    refetchWhilePending
+  ) {
+    setRefetchWhilePending(false)
+  }
+
   const ageAssuranceAPIContext = useMemo<AgeAssuranceAPIContextType>(
     () => ({
       refetch,