diff --git a/src/pages/login/index.tsx b/src/pages/login/index.tsx index 87e2ecf..0938cf7 100644 --- a/src/pages/login/index.tsx +++ b/src/pages/login/index.tsx @@ -109,6 +109,12 @@ export const Login = () => { setIsLoading(true) + const displayError = (message: string) => { + toast.error(message) + setIsLoading(false) + setLoadingSpinnerDesc('') + } + if (inputValue.includes('@')) { const nip05Profile = await nip05.queryProfile(inputValue).catch((err) => { toast.error('An error occurred while querying nip05 profile: ' + err) @@ -128,16 +134,14 @@ export const Login = () => { }) if (!metadataEvent) { - toast.error('metadata not found!') - return + return displayError('metadata not found!') } const metadataContent = metadataController.extractProfileMetadataContent(metadataEvent) if (!metadataContent?.nip05) { - toast.error('nip05 not present in metadata') - return + return displayError('nip05 not present in metadata') } const nip05Profile = await nip05.queryProfile(inputValue).catch((err) => { @@ -147,8 +151,9 @@ export const Login = () => { if (nip05Profile) { if (nip05Profile.pubkey !== pubkey) { - toast.error('pubkey in nip05 does not match with provided npub') - return + return displayError( + 'pubkey in nip05 does not match with provided npub' + ) } relays = nip05Profile.relays @@ -156,13 +161,11 @@ export const Login = () => { } if (!relays || relays.length === 0) { - toast.error('No relay found for nsecbunker') - return + return displayError('No relay found for nsecbunker') } if (!pubkey) { - toast.error('pubkey not found') - return + return displayError('pubkey not found') } setLoadingSpinnerDesc('Initializing nsecBunker')