fix bug with checkHandleAvailability
This commit is contained in:
@@ -22,7 +22,6 @@ import {
|
|||||||
checkHandleAvailability,
|
checkHandleAvailability,
|
||||||
useHandleAvailabilityQuery,
|
useHandleAvailabilityQuery,
|
||||||
} from '#/state/queries/handle-availability'
|
} from '#/state/queries/handle-availability'
|
||||||
import {useAgent} from '#/state/session'
|
|
||||||
import {ScreenTransition} from '#/screens/Login/ScreenTransition'
|
import {ScreenTransition} from '#/screens/Login/ScreenTransition'
|
||||||
import {useSignupContext} from '#/screens/Signup/state'
|
import {useSignupContext} from '#/screens/Signup/state'
|
||||||
import {atoms as a, native, useTheme} from '#/alf'
|
import {atoms as a, native, useTheme} from '#/alf'
|
||||||
@@ -39,7 +38,6 @@ export function StepHandle() {
|
|||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const t = useTheme()
|
const t = useTheme()
|
||||||
const {state, dispatch} = useSignupContext()
|
const {state, dispatch} = useSignupContext()
|
||||||
const agent = useAgent()
|
|
||||||
const [draftValue, setDraftValue] = useState(state.handle)
|
const [draftValue, setDraftValue] = useState(state.handle)
|
||||||
const isNextLoading = useThrottledValue(state.isLoading, 500)
|
const isNextLoading = useThrottledValue(state.isLoading, 500)
|
||||||
|
|
||||||
@@ -58,8 +56,6 @@ export function StepHandle() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
const onNextPress = async () => {
|
const onNextPress = async () => {
|
||||||
if (!isHandleAvailable?.available) return
|
|
||||||
|
|
||||||
const handle = draftValue.trim()
|
const handle = draftValue.trim()
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'setHandle',
|
type: 'setHandle',
|
||||||
@@ -74,8 +70,7 @@ export function StepHandle() {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const {available: handleAvailable} = await checkHandleAvailability(
|
const {available: handleAvailable} = await checkHandleAvailability(
|
||||||
agent,
|
createFullHandle(handle, state.userDomain),
|
||||||
handle,
|
|
||||||
state.serviceDescription?.did ?? 'UNKNOWN',
|
state.serviceDescription?.did ?? 'UNKNOWN',
|
||||||
{typeahead: false},
|
{typeahead: false},
|
||||||
)
|
)
|
||||||
@@ -88,6 +83,11 @@ export function StepHandle() {
|
|||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
} catch (error) {
|
||||||
|
logger.error('Failed to check handle availability on next press', {
|
||||||
|
safeMessage: error,
|
||||||
|
})
|
||||||
|
// do nothing on error, let them pass
|
||||||
} finally {
|
} finally {
|
||||||
dispatch({type: 'setIsLoading', value: false})
|
dispatch({type: 'setIsLoading', value: false})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
import {useMemo} from 'react'
|
|
||||||
import {Agent, ComAtprotoTempCheckHandleAvailability} from '@atproto/api'
|
import {Agent, ComAtprotoTempCheckHandleAvailability} from '@atproto/api'
|
||||||
import {useQuery} from '@tanstack/react-query'
|
import {useQuery} from '@tanstack/react-query'
|
||||||
|
|
||||||
@@ -38,13 +37,6 @@ export function useHandleAvailabilityQuery(
|
|||||||
) {
|
) {
|
||||||
const name = username.trim()
|
const name = username.trim()
|
||||||
const debouncedHandle = useDebouncedValue(name, debounceDelayMs)
|
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 {
|
return {
|
||||||
enabled: enabled && name === debouncedHandle,
|
enabled: enabled && name === debouncedHandle,
|
||||||
@@ -57,7 +49,7 @@ export function useHandleAvailabilityQuery(
|
|||||||
),
|
),
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
const handle = createFullHandle(name, serviceDomain)
|
const handle = createFullHandle(name, serviceDomain)
|
||||||
return await checkHandleAvailability(agent, handle, serviceDid, {
|
return await checkHandleAvailability(handle, serviceDid, {
|
||||||
email,
|
email,
|
||||||
birthDate,
|
birthDate,
|
||||||
typeahead: true,
|
typeahead: true,
|
||||||
@@ -68,7 +60,6 @@ export function useHandleAvailabilityQuery(
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function checkHandleAvailability(
|
export async function checkHandleAvailability(
|
||||||
agent: Agent,
|
|
||||||
handle: string,
|
handle: string,
|
||||||
serviceDid: string,
|
serviceDid: string,
|
||||||
{
|
{
|
||||||
@@ -82,6 +73,7 @@ export async function checkHandleAvailability(
|
|||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
if (serviceDid === BSKY_SERVICE_DID) {
|
if (serviceDid === BSKY_SERVICE_DID) {
|
||||||
|
const agent = new Agent({service: BSKY_SERVICE})
|
||||||
// entryway has a special API for handle availability
|
// entryway has a special API for handle availability
|
||||||
const {data} = await agent.com.atproto.temp.checkHandleAvailability({
|
const {data} = await agent.com.atproto.temp.checkHandleAvailability({
|
||||||
handle,
|
handle,
|
||||||
@@ -116,6 +108,7 @@ export async function checkHandleAvailability(
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 3rd party PDSes won't have this API so just try and resolve the handle
|
// 3rd party PDSes won't have this API so just try and resolve the handle
|
||||||
|
const agent = new Agent({service: PUBLIC_BSKY_SERVICE})
|
||||||
try {
|
try {
|
||||||
const res = await agent.resolveHandle({
|
const res = await agent.resolveHandle({
|
||||||
handle,
|
handle,
|
||||||
|
|||||||
Reference in New Issue
Block a user