fix bug with checkHandleAvailability
This commit is contained in:
@@ -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})
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user