fix: counterpart search NIP05 glitching
All checks were successful
Open PR on Staging / audit_and_check (pull_request) Successful in 44s
All checks were successful
Open PR on Staging / audit_and_check (pull_request) Successful in 44s
This commit is contained in:
parent
69efd9e09d
commit
0fd0f26fc7
@ -148,6 +148,17 @@ export const CreatePage = () => {
|
|||||||
[setUserInput]
|
[setUserInput]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const handleSearchUserNip05 = async (
|
||||||
|
nip05: string
|
||||||
|
): Promise<string | null> => {
|
||||||
|
const { pubkey } = await queryNip05(nip05).catch((err) => {
|
||||||
|
console.error(err)
|
||||||
|
return { pubkey: null }
|
||||||
|
})
|
||||||
|
|
||||||
|
return pubkey
|
||||||
|
}
|
||||||
|
|
||||||
const handleSearchUsers = async (searchValue?: string) => {
|
const handleSearchUsers = async (searchValue?: string) => {
|
||||||
const searchString = searchValue || userSearchInput || undefined
|
const searchString = searchValue || userSearchInput || undefined
|
||||||
|
|
||||||
@ -224,7 +235,9 @@ export const CreatePage = () => {
|
|||||||
})
|
})
|
||||||
}, [foundUsers])
|
}, [foundUsers])
|
||||||
|
|
||||||
const handleInputKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
|
const handleInputKeyDown = async (
|
||||||
|
event: React.KeyboardEvent<HTMLDivElement>
|
||||||
|
) => {
|
||||||
if (
|
if (
|
||||||
event.code === KeyboardCode.Enter ||
|
event.code === KeyboardCode.Enter ||
|
||||||
event.code === KeyboardCode.NumpadEnter
|
event.code === KeyboardCode.NumpadEnter
|
||||||
@ -238,11 +251,22 @@ export const CreatePage = () => {
|
|||||||
} else {
|
} else {
|
||||||
// Otherwize if search already provided some results, user must manually click the search button
|
// Otherwize if search already provided some results, user must manually click the search button
|
||||||
if (!foundUsers.length) {
|
if (!foundUsers.length) {
|
||||||
|
// If it's NIP05 send request to .well-known
|
||||||
|
if (userSearchInput.includes('@')) {
|
||||||
|
const pubkey = await handleSearchUserNip05(userSearchInput)
|
||||||
|
|
||||||
|
if (pubkey) {
|
||||||
|
setUserInput(userSearchInput)
|
||||||
|
} else {
|
||||||
|
toast.error(`No user found with the NIP05: ${userSearchInput}`)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
handleSearchUsers()
|
handleSearchUsers()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedFiles) {
|
if (selectedFiles) {
|
||||||
@ -959,19 +983,6 @@ export const CreatePage = () => {
|
|||||||
} else {
|
} else {
|
||||||
disarmAddOnEnter()
|
disarmAddOnEnter()
|
||||||
}
|
}
|
||||||
} else if (value.includes('@')) {
|
|
||||||
// Seems like it's nip05 format
|
|
||||||
const { pubkey } = await queryNip05(value).catch((err) => {
|
|
||||||
console.error(err)
|
|
||||||
return { pubkey: null }
|
|
||||||
})
|
|
||||||
|
|
||||||
if (pubkey) {
|
|
||||||
// Arm the manual user npub add after enter is hit, we don't want to trigger search
|
|
||||||
setPastedUserNpubOrNip05(hexToNpub(pubkey))
|
|
||||||
} else {
|
|
||||||
disarmAddOnEnter()
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Disarm the add user on enter hit, and trigger search after 1 second
|
// Disarm the add user on enter hit, and trigger search after 1 second
|
||||||
disarmAddOnEnter()
|
disarmAddOnEnter()
|
||||||
|
Loading…
Reference in New Issue
Block a user