diff --git a/app/(app)/(profile)/[npub]/page.tsx b/app/(app)/(profile)/[npub]/page.tsx index 1843108..2849b23 100644 --- a/app/(app)/(profile)/[npub]/page.tsx +++ b/app/(app)/(profile)/[npub]/page.tsx @@ -39,7 +39,7 @@ export default function ProfilePage({
- {!!profile.banner && ( + {!!profile?.banner && (
- {profile.image ? ( + {profile?.image ? (

- {profile.displayName ?? profile.name ?? truncateText(npub)} + {profile?.displayName ?? profile?.name ?? truncateText(npub)}

- {!!profile.nip05 && ( + {!!profile?.nip05 && ( )}
- {!!profile.name &&

{profile.name}

} - {!!profile.name && !!profile.nip05 && ( + {!!profile?.name &&

{profile.name}

} + {!!profile?.name && !!profile.nip05 && ( <>
ยท

{profile.nip05}

@@ -100,7 +100,7 @@ export default function ProfilePage({ )}
- {!!profile.about && ( + {!!profile?.about && (

{profile.about}

diff --git a/app/_providers/ndk/context/Users.ts b/app/_providers/ndk/context/Users.ts index 7d2a6e7..4450e8e 100644 --- a/app/_providers/ndk/context/Users.ts +++ b/app/_providers/ndk/context/Users.ts @@ -54,8 +54,9 @@ export const Users = (ndk: NDK | undefined) => { } function getProfile(id: string) { - if (users[id]) { - return users[id].profile!; + const user = users[id]; + if (user) { + return user.profile; } else { fetchUser(id); } diff --git a/app/_providers/ndk/context/index.tsx b/app/_providers/ndk/context/index.tsx index b900ba4..48bb8be 100644 --- a/app/_providers/ndk/context/index.tsx +++ b/app/_providers/ndk/context/index.tsx @@ -56,8 +56,8 @@ interface NDKContext { } | undefined, ) => Promise; - getUser: (_: string) => NDKUser; - getProfile: (_: string) => NDKUserProfile; + getUser: (_: string) => NDKUser | undefined; + getProfile: (_: string) => NDKUserProfile | undefined; } const NDKContext = createContext({ diff --git a/app/_providers/ndk/utils/notes.ts b/app/_providers/ndk/utils/notes.ts index b43d7cc..7b20ef1 100644 --- a/app/_providers/ndk/utils/notes.ts +++ b/app/_providers/ndk/utils/notes.ts @@ -46,7 +46,7 @@ export const parseContent = ({ // Convert legacy mentions to bech32 entities const mentionMatch = text.match(/^#\[(\d+)\]/i); - if (mentionMatch) { + if (mentionMatch && mentionMatch[1]) { const i = parseInt(mentionMatch[1]); if (tags[i]) { diff --git a/bun.lockb b/bun.lockb index 1d4bd33..cc3693e 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/components/CreatorCard/index.tsx b/components/CreatorCard/index.tsx index 20ecb43..d0c83c4 100644 --- a/components/CreatorCard/index.tsx +++ b/components/CreatorCard/index.tsx @@ -13,7 +13,7 @@ import { BANNER } from "@/constants/app"; import { getNameToShow } from "@/lib/utils"; type CreatorCardProps = { - profile: NDKUserProfile; + profile?: NDKUserProfile; npub: string; recentWork: { id: string; diff --git a/components/KindCard/1.tsx b/components/KindCard/1.tsx index b362f95..5764c7f 100644 --- a/components/KindCard/1.tsx +++ b/components/KindCard/1.tsx @@ -10,7 +10,7 @@ import { toast } from "sonner"; export default function Kind1(props: Event) { const { content, pubkey, tags } = props; - const r = getTagsValues("r", tags); + const r = getTagsValues("r", tags).filter(Boolean); const npub = nip19.npubEncode(pubkey); return ( diff --git a/components/KindCard/30023.tsx b/components/KindCard/30023.tsx index 3f65e15..7b839c2 100644 --- a/components/KindCard/30023.tsx +++ b/components/KindCard/30023.tsx @@ -8,7 +8,9 @@ import { removeDuplicates } from "@/lib/utils"; export default function Kind30023({ content, pubkey, tags }: Event) { const title = getTagValues("title", tags); const summary = getTagValues("summary", tags); - const contentTags = removeDuplicates(getTagsValues("t", tags)); + const contentTags = removeDuplicates(getTagsValues("t", tags)).filter( + Boolean, + ); return ( diff --git a/components/KindCard/components/ProfileHeader.tsx b/components/KindCard/components/ProfileHeader.tsx index d7b1e1a..bcfcfe4 100644 --- a/components/KindCard/components/ProfileHeader.tsx +++ b/components/KindCard/components/ProfileHeader.tsx @@ -14,7 +14,7 @@ export default function ProfileHeader({ pubkey }: ProfileHeaderProps) { return ( - + {getTwoLetters({ npub, profile })} @@ -23,7 +23,7 @@ export default function ProfileHeader({ pubkey }: ProfileHeaderProps) { {getNameToShow({ npub, profile })} - {!!profile.nip05 && } + {!!profile?.nip05 && }
); diff --git a/components/TextRendering/index.tsx b/components/TextRendering/index.tsx index 427e384..7e54f83 100644 --- a/components/TextRendering/index.tsx +++ b/components/TextRendering/index.tsx @@ -50,12 +50,16 @@ const RenderText = ({ text }: { text?: string }) => { // specialElement = {specialValuesArray[index]}; } else if (specialValuesArray[index]?.match(nostrPrefixRegex)) { const mention = specialValuesArray[index]?.split(":")[1]; - if (mention.startsWith("nprofile") || mention.startsWith("npub")) { + if ( + mention && + (mention.startsWith("nprofile") || mention.startsWith("npub")) + ) { specialElement = ; } else if ( - mention.startsWith("nevent") || - mention.startsWith("note") || - mention.startsWith("naddr") + mention && + (mention.startsWith("nevent") || + mention.startsWith("note") || + mention.startsWith("naddr")) ) { specialElement = ; } diff --git a/lib/hooks/useCurrentUser.ts b/lib/hooks/useCurrentUser.ts index 5065c3b..c923ffe 100644 --- a/lib/hooks/useCurrentUser.ts +++ b/lib/hooks/useCurrentUser.ts @@ -64,9 +64,11 @@ export default function useCurrentUser() { window.location.reload(); } function handleUpdateUser(userInfo: string) { + const userObject = UserSchema.safeParse(JSON.parse(userInfo)); + if (!userObject.success) return; const parsedData = UserSchema.safeParse({ ...currentUser, - ...JSON.parse(userInfo), + ...userObject, }); if (parsedData.success) { updateCurrentUser({ diff --git a/lib/hooks/useLocalStorage.ts b/lib/hooks/useLocalStorage.ts index 28a292c..85cab1c 100644 --- a/lib/hooks/useLocalStorage.ts +++ b/lib/hooks/useLocalStorage.ts @@ -12,7 +12,7 @@ function useLocalStorage(key: string, initialValue: T) { // Get from local storage by key const item = window.localStorage.getItem(key); // Parse stored json or if none return initialValue - return item ? JSON.parse(item) : initialValue; + return item ? (JSON.parse(item) as T) : initialValue; } catch (error) { // If error also return initialValue console.log(error); diff --git a/lib/nostr/utils.ts b/lib/nostr/utils.ts index a654bc9..105a15f 100644 --- a/lib/nostr/utils.ts +++ b/lib/nostr/utils.ts @@ -14,12 +14,12 @@ export function nip19ToTag(nip19Id: string): string[] | undefined { case "nprofile": tag = ["e", decoded.data.pubkey]; if (decoded.data.relays && decoded.data.relays.length > 0) - tag.push(decoded.data.relays[0]); + tag.push(decoded.data.relays[0] as string); return tag; case "nevent": tag = ["e", decoded.data.id]; if (decoded.data.relays && decoded.data.relays.length > 0) - tag.push(decoded.data.relays[0]); + tag.push(decoded.data.relays[0] as string); return tag; case "naddr": tag = [ @@ -27,7 +27,7 @@ export function nip19ToTag(nip19Id: string): string[] | undefined { `${decoded.data.kind}:${decoded.data.pubkey}:${decoded.data.identifier}`, ]; if (decoded.data.relays && decoded.data.relays.length > 0) { - tag.push(decoded.data.relays[0]); + tag.push(decoded.data.relays[0] as string); } return tag; } @@ -35,12 +35,12 @@ export function nip19ToTag(nip19Id: string): string[] | undefined { export function aTagToNip19(aTag: string[]): string { if (aTag[0] !== "a") throw new Error("Not an a tag"); - const tagIdSplit = aTag[1].split(":"); + const tagIdSplit = aTag[1]!.split(":"); return nip19.naddrEncode({ - kind: parseInt(tagIdSplit[0]), - pubkey: tagIdSplit[1], - identifier: tagIdSplit[2], + kind: parseInt(tagIdSplit[0] as string), + pubkey: tagIdSplit[1] as string, + identifier: tagIdSplit[2] as string, }); } export const getTagValues = (name: string, tags: string[][]) => { diff --git a/package.json b/package.json index c3fa5e7..1df0dee 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ }, "devDependencies": { "@tailwindcss/typography": "^0.5.10", + "@total-typescript/ts-reset": "^0.5.1", "@types/crypto-js": "^4.1.2", "@types/node": "^20", "@types/ramda": "^0.29.6", diff --git a/reset.d.ts b/reset.d.ts new file mode 100644 index 0000000..a3d4a03 --- /dev/null +++ b/reset.d.ts @@ -0,0 +1 @@ +import "@total-typescript/ts-reset"; diff --git a/tsconfig.json b/tsconfig.json index a84e8ed..7aa020b 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,6 +14,7 @@ "isolatedModules": true, "jsx": "preserve", "incremental": true, + "noUncheckedIndexedAccess": true, "plugins": [ { "name": "next"