feat: handle root _@ users on add counterpart
All checks were successful
Open PR on Staging / audit_and_check (pull_request) Successful in 35s

This commit is contained in:
enes 2024-10-10 13:56:08 +02:00
parent 7f5fd4534f
commit 897daaa1fa

View File

@ -246,17 +246,22 @@ export const CreatePage = () => {
const input = userInput.toLowerCase() const input = userInput.toLowerCase()
if (input.startsWith('npub')) { if (input.startsWith('npub')) {
const pubkey = npubToHex(input) return handleAddNpubUser(input)
if (pubkey) {
addUser(pubkey)
setUserInput('')
} else {
setError('Provided npub is not valid. Please enter correct npub.')
}
return
} }
if (input.includes('@')) { if (input.includes('@')) {
return await handleAddNip05User(input)
}
// If the user enters the domain (w/o @) assume it's the "root" and append _@
// https://github.com/nostr-protocol/nips/blob/master/05.md#showing-just-the-domain-as-an-identifier
if (input.includes('.')) {
return await handleAddNip05User(`_@${input}`)
}
setError('Invalid input! Make sure to provide correct npub or nip05.')
async function handleAddNip05User(input: string) {
setIsLoading(true) setIsLoading(true)
setLoadingSpinnerDesc('Querying for nip05') setLoadingSpinnerDesc('Querying for nip05')
const nip05Profile = await queryNip05(input) const nip05Profile = await queryNip05(input)
@ -279,7 +284,16 @@ export const CreatePage = () => {
return return
} }
setError('Invalid input! Make sure to provide correct npub or nip05.') function handleAddNpubUser(input: string) {
const pubkey = npubToHex(input)
if (pubkey) {
addUser(pubkey)
setUserInput('')
} else {
setError('Provided npub is not valid. Please enter correct npub.')
}
return
}
} }
const handleUserRoleChange = (role: UserRole, pubkey: string) => { const handleUserRoleChange = (role: UserRole, pubkey: string) => {