From 2917baa12e37989f33391aa07b21c45efe88bf16 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Tue, 5 Aug 2025 11:57:06 +0300 Subject: [PATCH] fix bug with checkHandleAvailability --- src/screens/Signup/StepHandle.tsx | 12 ++++++------ src/state/queries/handle-availability.ts | 13 +++---------- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/screens/Signup/StepHandle.tsx b/src/screens/Signup/StepHandle.tsx index 4065dbea59..b55ef717ea 100644 --- a/src/screens/Signup/StepHandle.tsx +++ b/src/screens/Signup/StepHandle.tsx @@ -22,7 +22,6 @@ import { checkHandleAvailability, useHandleAvailabilityQuery, } from '#/state/queries/handle-availability' -import {useAgent} from '#/state/session' import {ScreenTransition} from '#/screens/Login/ScreenTransition' import {useSignupContext} from '#/screens/Signup/state' import {atoms as a, native, useTheme} from '#/alf' @@ -39,7 +38,6 @@ export function StepHandle() { const {_} = useLingui() const t = useTheme() const {state, dispatch} = useSignupContext() - const agent = useAgent() const [draftValue, setDraftValue] = useState(state.handle) const isNextLoading = useThrottledValue(state.isLoading, 500) @@ -58,8 +56,6 @@ export function StepHandle() { }) const onNextPress = async () => { - if (!isHandleAvailable?.available) return - const handle = draftValue.trim() dispatch({ type: 'setHandle', @@ -74,8 +70,7 @@ export function StepHandle() { try { const {available: handleAvailable} = await checkHandleAvailability( - agent, - handle, + createFullHandle(handle, state.userDomain), state.serviceDescription?.did ?? 'UNKNOWN', {typeahead: false}, ) @@ -88,6 +83,11 @@ export function StepHandle() { }) return } + } catch (error) { + logger.error('Failed to check handle availability on next press', { + safeMessage: error, + }) + // do nothing on error, let them pass } finally { dispatch({type: 'setIsLoading', value: false}) } diff --git a/src/state/queries/handle-availability.ts b/src/state/queries/handle-availability.ts index 3951ad35e5..140e5de35b 100644 --- a/src/state/queries/handle-availability.ts +++ b/src/state/queries/handle-availability.ts @@ -1,4 +1,3 @@ -import {useMemo} from 'react' import {Agent, ComAtprotoTempCheckHandleAvailability} from '@atproto/api' import {useQuery} from '@tanstack/react-query' @@ -38,13 +37,6 @@ export function useHandleAvailabilityQuery( ) { const name = username.trim() const debouncedHandle = useDebouncedValue(name, debounceDelayMs) - const agent = useMemo(() => { - if (serviceDid === BSKY_SERVICE_DID) { - return new Agent({service: BSKY_SERVICE}) - } else { - return new Agent({service: PUBLIC_BSKY_SERVICE}) - } - }, [serviceDid]) return { enabled: enabled && name === debouncedHandle, @@ -57,7 +49,7 @@ export function useHandleAvailabilityQuery( ), queryFn: async () => { const handle = createFullHandle(name, serviceDomain) - return await checkHandleAvailability(agent, handle, serviceDid, { + return await checkHandleAvailability(handle, serviceDid, { email, birthDate, typeahead: true, @@ -68,7 +60,6 @@ export function useHandleAvailabilityQuery( } export async function checkHandleAvailability( - agent: Agent, handle: string, serviceDid: string, { @@ -82,6 +73,7 @@ export async function checkHandleAvailability( }, ) { if (serviceDid === BSKY_SERVICE_DID) { + const agent = new Agent({service: BSKY_SERVICE}) // entryway has a special API for handle availability const {data} = await agent.com.atproto.temp.checkHandleAvailability({ handle, @@ -116,6 +108,7 @@ export async function checkHandleAvailability( } } else { // 3rd party PDSes won't have this API so just try and resolve the handle + const agent = new Agent({service: PUBLIC_BSKY_SERVICE}) try { const res = await agent.resolveHandle({ handle,