From 897daaa1fa57a587b5562fd9c94526dd22485b65 Mon Sep 17 00:00:00 2001 From: enes Date: Thu, 10 Oct 2024 13:56:08 +0200 Subject: [PATCH] feat: handle root _@ users on add counterpart --- src/pages/create/index.tsx | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/src/pages/create/index.tsx b/src/pages/create/index.tsx index 90d359b..3374a08 100644 --- a/src/pages/create/index.tsx +++ b/src/pages/create/index.tsx @@ -246,17 +246,22 @@ export const CreatePage = () => { const input = userInput.toLowerCase() if (input.startsWith('npub')) { - const pubkey = npubToHex(input) - if (pubkey) { - addUser(pubkey) - setUserInput('') - } else { - setError('Provided npub is not valid. Please enter correct npub.') - } - return + return handleAddNpubUser(input) } 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) setLoadingSpinnerDesc('Querying for nip05') const nip05Profile = await queryNip05(input) @@ -279,7 +284,16 @@ export const CreatePage = () => { 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) => {