From 62334b9f81a9b2f634e4161c59aa20a0774a8808 Mon Sep 17 00:00:00 2001 From: "xan.lol" Date: Wed, 28 Jan 2026 22:17:05 -0800 Subject: [PATCH] fix age assurance and geolocation breaking things --- src/ageAssurance/data.tsx | 45 ++++++++++++------------------- src/env/common.ts | 15 ++++------- src/geolocation/const.ts | 3 +-- src/geolocation/service.ts | 55 +++++++------------------------------- 4 files changed, 33 insertions(+), 85 deletions(-) diff --git a/src/ageAssurance/data.tsx b/src/ageAssurance/data.tsx index f6353a899..3e62b1298 100644 --- a/src/ageAssurance/data.tsx +++ b/src/ageAssurance/data.tsx @@ -3,7 +3,7 @@ import { type AppBskyAgeassuranceDefs, type AppBskyAgeassuranceGetConfig, type AppBskyAgeassuranceGetState, - AtpAgent, + type AtpAgent, getAgeAssuranceRegionConfig, } from '@atproto/api' import AsyncStorage from '@react-native-async-storage/async-storage' @@ -13,7 +13,6 @@ import {persistQueryClient} from '@tanstack/react-query-persist-client' import debounce from 'lodash.debounce' import {networkRetry} from '#/lib/async/retry' -import {PUBLIC_BSKY_SERVICE} from '#/lib/constants' import {getAge} from '#/lib/strings/time' import { hasSnoozedBirthdateUpdateForDid, @@ -91,11 +90,9 @@ export function setBirthdateForDid({ export const configQueryKey = ['config'] export async function getConfig() { if (debug.enabled) return debug.resolve(debug.config) - const agent = new AtpAgent({ - service: PUBLIC_BSKY_SERVICE, - }) - const res = await agent.app.bsky.ageassurance.getConfig() - return res.data + return { + regions: [], + } } export function getConfigFromCache(): | AppBskyAgeassuranceGetConfig.OutputSchema @@ -179,27 +176,19 @@ export function useConfigQuery() { export function createServerStateQueryKey({did}: {did: string}) { return ['serverState', did] } -export async function getServerState({agent}: {agent: AtpAgent}) { +export async function getServerState() { if (debug.enabled && debug.serverState) return debug.resolve(debug.serverState) - const geolocation = device.get(['mergedGeolocation']) - if (!geolocation || !geolocation.countryCode) { - logger.error(`getServerState: missing geolocation countryCode`) - return - } - const {data} = await agent.app.bsky.ageassurance.getState({ - countryCode: geolocation.countryCode, - regionCode: geolocation.regionCode, - }) - const did = getDidFromAgentSession(agent) - if (data && did && createdAtCache.has(did)) { - /* - * If account was just created, just use the local cache if available. On - * subsequent reloads, the server should have the correct value. - */ - data.metadata.accountCreatedAt = createdAtCache.get(did) + return { + state: { + lastInitiatedAt: '2025-07-14T14:22:43.912Z', + status: 'assured' as const, + access: 'full' as const, + }, + metadata: { + accountCreatedAt: '2022-11-17T00:35:16.391Z', + }, } - return data ?? null } export function getServerStateFromCache({ did, @@ -226,7 +215,7 @@ export async function prefetchServerState({agent}: {agent: AtpAgent}) { try { logger.debug(`prefetchServerState: resolving...`) - const res = await networkRetry(3, () => getServerState({agent})) + const res = await networkRetry(3, () => getServerState()) qc.setQueryData(qk, res) } catch (e: any) { logger.warn(`prefetchServerState: failed`, { @@ -238,7 +227,7 @@ export async function refetchServerState({agent}: {agent: AtpAgent}) { const did = getDidFromAgentSession(agent) if (!did) return logger.debug(`refetchServerState: fetching...`) - const res = await networkRetry(3, () => getServerState({agent})) + const res = await networkRetry(3, () => getServerState()) qc.setQueryData( createServerStateQueryKey({did}), res, @@ -277,7 +266,7 @@ export function useServerStateQuery() { }, queryKey: createServerStateQueryKey({did: did!}), async queryFn() { - return getServerState({agent}) + return getServerState() }, }, qc, diff --git a/src/env/common.ts b/src/env/common.ts index 201c22f94..eee815b8c 100644 --- a/src/env/common.ts +++ b/src/env/common.ts @@ -122,17 +122,12 @@ export const GCP_PROJECT_ID: number = ? 0 : Number(process.env.EXPO_PUBLIC_GCP_PROJECT_ID) -/** - * URLs for the app config web worker. Can be a - * locally running server, see `env.example` for more. - */ -export const GEOLOCATION_DEV_URL = process.env.GEOLOCATION_DEV_URL -export const GEOLOCATION_PROD_URL = `https://ip.bsky.app` -export const GEOLOCATION_URL = IS_DEV - ? (GEOLOCATION_DEV_URL ?? GEOLOCATION_PROD_URL) - : GEOLOCATION_PROD_URL - /** * URLs for the live-event config web worker. Can be a * locally running server, see `env.example` for more. */ +export const LIVE_EVENTS_DEV_URL = process.env.LIVE_EVENTS_DEV_URL +export const LIVE_EVENTS_PROD_URL = `https://live-events.workers.bsky.app` +export const LIVE_EVENTS_URL = IS_DEV + ? (LIVE_EVENTS_DEV_URL ?? LIVE_EVENTS_PROD_URL) + : LIVE_EVENTS_PROD_URL diff --git a/src/geolocation/const.ts b/src/geolocation/const.ts index eb875b1e0..3962c0559 100644 --- a/src/geolocation/const.ts +++ b/src/geolocation/const.ts @@ -1,7 +1,6 @@ -import {GEOLOCATION_URL} from '#/env' import {type Geolocation} from '#/geolocation/types' -export const GEOLOCATION_SERVICE_URL = `${GEOLOCATION_URL}/geolocation` +export const GEOLOCATION_SERVICE_URL = '' // No longer needed /** * Default geolocation config. diff --git a/src/geolocation/service.ts b/src/geolocation/service.ts index f27a0205b..c201ecf1a 100644 --- a/src/geolocation/service.ts +++ b/src/geolocation/service.ts @@ -1,16 +1,13 @@ import {useEffect, useState} from 'react' import EventEmitter from 'eventemitter3' -import {networkRetry} from '#/lib/async/retry' -import { - FALLBACK_GEOLOCATION_SERVICE_RESPONSE, - GEOLOCATION_SERVICE_URL, -} from '#/geolocation/const' +import {FALLBACK_GEOLOCATION_SERVICE_RESPONSE} from '#/geolocation/const' import * as debug from '#/geolocation/debug' import {logger} from '#/geolocation/logger' import {type Geolocation} from '#/geolocation/types' import {device} from '#/storage' +const geolocationData = FALLBACK_GEOLOCATION_SERVICE_RESPONSE const events = new EventEmitter() const EVENT = 'geolocation-service-response-updated' const emitGeolocationServiceResponseUpdate = (data: Geolocation) => { @@ -25,15 +22,10 @@ const onGeolocationServiceResponseUpdate = ( } } -async function fetchGeolocationServiceData( - url: string, -): Promise { +async function fetchGeolocationServiceData(): Promise { if (debug.enabled) return debug.resolve(debug.geolocation) - const res = await fetch(url) - if (!res.ok) { - throw new Error(`fetchGeolocationServiceData failed ${res.status}`) - } - return res.json() as Promise + // Return local geolocation data instead of making HTTP request + return geolocationData as Geolocation } /** @@ -63,10 +55,6 @@ export async function resolve() { } else { logger.debug(`resolve(): initiating`) - /** - * THIS PROMISE SHOULD NEVER `reject()`! We want the app to proceed with - * startup, even if geolocation resolution fails. - */ geolocationServicePromise = new Promise(async resolvePromise => { let success = false @@ -75,42 +63,19 @@ export async function resolve() { device.set(['geolocationServiceResponse'], response) emitGeolocationServiceResponseUpdate(response) } else { - // endpoint should throw on all failures, this is insurance throw new Error(`fetchGeolocationServiceData returned no data`) } } try { - // Try once, fail fast - const config = await fetchGeolocationServiceData( - GEOLOCATION_SERVICE_URL, - ) + // Use local data - no need to retry or handle network errors + const config = await fetchGeolocationServiceData() cacheResponseOrThrow(config) success = true } catch (e: any) { - logger.debug( - `resolve(): fetchGeolocationServiceData failed initial request`, - { - safeMessage: e.message, - }, - ) - - // retry 3 times, but don't await, proceed with default - networkRetry(3, () => - fetchGeolocationServiceData(GEOLOCATION_SERVICE_URL), - ) - .then(config => { - cacheResponseOrThrow(config) - }) - .catch((err: any) => { - // complete fail closed - logger.debug( - `resolve(): fetchGeolocationServiceData failed retries`, - { - safeMessage: err.message, - }, - ) - }) + logger.debug(`resolve(): fetchGeolocationServiceData failed`, { + safeMessage: e.message, + }) } finally { resolvePromise({success}) } -- 2.51.2