diff --git a/src/components/ProfileSection.tsx b/src/components/ProfileSection.tsx
index aa1b956..d6f8a4f 100644
--- a/src/components/ProfileSection.tsx
+++ b/src/components/ProfileSection.tsx
@@ -116,14 +116,20 @@ export const Profile = ({ pubkey }: ProfileProps) => {
})
}
+ // Try to encode
let profileRoute = appRoutes.home
- const hexPubkey = npubToHex(pubkey)
- if (hexPubkey) {
- profileRoute = getProfilePageRoute(
- nip19.nprofileEncode({
- pubkey: hexPubkey
- })
- )
+ let nprofile: string | undefined
+ try {
+ const hexPubkey = npubToHex(pubkey)
+ nprofile = hexPubkey
+ ? nip19.nprofileEncode({
+ pubkey: hexPubkey
+ })
+ : undefined
+ profileRoute = nprofile ? getProfilePageRoute(nprofile) : appRoutes.home
+ } catch (error) {
+ // Silently ignore and redirect to home
+ log(true, LogType.Error, 'Failed to encode profile.', error)
}
return (
@@ -148,7 +154,8 @@ export const Profile = ({ pubkey }: ProfileProps) => {
{displayName}
- {nip05 && (
+ {/* Nip05 can sometimes be an empty object '{}' which causes the error */}
+ {typeof nip05 === 'string' && (
{nip05}
)}
@@ -181,8 +188,12 @@ export const Profile = ({ pubkey }: ProfileProps) => {
-
- {lud16 && }
+ {typeof nprofile !== 'undefined' && (
+
+ )}
+ {typeof lud16 !== 'undefined' && (
+
+ )}
@@ -227,20 +238,16 @@ const posts: Post[] = [
]
type QRButtonWithPopUpProps = {
- pubkey: string
+ nprofile: string
}
export const ProfileQRButtonWithPopUp = ({
- pubkey
+ nprofile
}: QRButtonWithPopUpProps) => {
const [isOpen, setIsOpen] = useState(false)
useBodyScrollDisable(isOpen)
- const nprofile = nip19.nprofileEncode({
- pubkey
- })
-
const onQrCodeClicked = async () => {
const href = `https://njump.me/${nprofile}`
const a = document.createElement('a')
diff --git a/src/pages/profile.tsx b/src/pages/profile.tsx
index 0a1965b..84e2293 100644
--- a/src/pages/profile.tsx
+++ b/src/pages/profile.tsx
@@ -23,6 +23,8 @@ import { FilterOptions, ModDetails, UserRelaysType } from 'types'
import {
copyTextToClipboard,
DEFAULT_FILTER_OPTIONS,
+ log,
+ LogType,
now,
npubToHex,
scrollIntoView,
@@ -42,8 +44,8 @@ export const ProfilePage = () => {
: undefined
profilePubkey = value?.data.pubkey
} catch (error) {
- // Failed to decode the nprofile
// Silently ignore and redirect to home or logged in user
+ log(true, LogType.Error, 'Failed to decode nprofile.', error)
}
const scrollTargetRef = useRef(null)
diff --git a/src/pages/search.tsx b/src/pages/search.tsx
index 935b8e3..609e5cc 100644
--- a/src/pages/search.tsx
+++ b/src/pages/search.tsx
@@ -37,7 +37,8 @@ import {
isModDataComplete,
log,
LogType,
- scrollIntoView
+ scrollIntoView,
+ timeout
} from 'utils'
enum SearchKindEnum {
@@ -373,29 +374,38 @@ const UsersResult = ({
if (searchTerm === '') {
setProfiles([])
} else {
- const filter: NDKFilter = {
- kinds: [NDKKind.Metadata],
- search: searchTerm
+ const fetchProfiles = async () => {
+ setIsFetching(true)
+
+ const filter: NDKFilter = {
+ kinds: [NDKKind.Metadata],
+ search: searchTerm
+ }
+
+ const profiles = await Promise.race([
+ fetchEvents(filter),
+ timeout(10 * 1000)
+ ])
+ .then((events) => {
+ const results = events.map((event) => {
+ const ndkEvent = new NDKEvent(undefined, event)
+ const profile = profileFromEvent(ndkEvent)
+ return profile
+ })
+ return results
+ })
+ .catch((err) => {
+ log(true, LogType.Error, 'An error occurred in fetching users', err)
+ return []
+ })
+
+ setProfiles(profiles)
+ setIsFetching(false)
}
- setIsFetching(true)
- fetchEvents(filter)
- .then((events) => {
- const results = events.map((event) => {
- const ndkEvent = new NDKEvent(undefined, event)
- const profile = profileFromEvent(ndkEvent)
- return profile
- })
- setProfiles(results)
- })
- .catch((err) => {
- log(true, LogType.Error, 'An error occurred in fetching users', err)
- })
- .finally(() => {
- setIsFetching(false)
- })
+ fetchProfiles()
}
- }, [searchTerm, fetchEvents])
+ }, [fetchEvents, searchTerm])
const filteredProfiles = useMemo(() => {
let filtered = [...profiles]
diff --git a/src/pages/settings/profile.tsx b/src/pages/settings/profile.tsx
index 907d0f0..b553995 100644
--- a/src/pages/settings/profile.tsx
+++ b/src/pages/settings/profile.tsx
@@ -98,15 +98,15 @@ export const ProfileSettings = () => {
// In case user is not logged in clicking on profile link will navigate to homepage
let profileRoute = appRoutes.home
+ let nprofile: string | undefined
if (userState.auth && userState.user) {
const hexPubkey = npubToHex(userState.user.npub as string)
if (hexPubkey) {
- profileRoute = getProfilePageRoute(
- nip19.nprofileEncode({
- pubkey: hexPubkey
- })
- )
+ nprofile = nip19.nprofileEncode({
+ pubkey: hexPubkey
+ })
+ profileRoute = getProfilePageRoute(nprofile)
}
}
@@ -247,10 +247,8 @@ export const ProfileSettings = () => {
- {typeof userState.user?.pubkey === 'string' && (
-
+ {typeof nprofile !== 'undefined' && (
+
)}