From 3f7ac9e2d4518ef419a018f63110c442c64b0edd Mon Sep 17 00:00:00 2001 From: Martti Malmi Date: Fri, 6 Oct 2023 15:03:18 +0300 Subject: [PATCH] if username@{NIP05_DOMAIN} valid, change profile page url to /username --- .../app/src/Pages/Profile/ProfilePage.tsx | 33 +++- packages/app/src/Pages/Profile/ProfileTab.tsx | 172 +++++++++--------- 2 files changed, 109 insertions(+), 96 deletions(-) diff --git a/packages/app/src/Pages/Profile/ProfilePage.tsx b/packages/app/src/Pages/Profile/ProfilePage.tsx index 67ae1e62..da23fc3e 100644 --- a/packages/app/src/Pages/Profile/ProfilePage.tsx +++ b/packages/app/src/Pages/Profile/ProfilePage.tsx @@ -2,14 +2,7 @@ import "./ProfilePage.css"; import { useEffect, useState } from "react"; import FormattedMessage from "Element/FormattedMessage"; import { useNavigate, useParams } from "react-router-dom"; -import { - encodeTLV, - encodeTLVEntries, - EventKind, - NostrPrefix, - TLVEntryType, - tryParseNostrLink, -} from "@snort/system"; +import { encodeTLV, encodeTLVEntries, EventKind, NostrPrefix, TLVEntryType, tryParseNostrLink } from "@snort/system"; import { LNURL } from "@snort/shared"; import { useUserProfile } from "@snort/system-react"; @@ -28,7 +21,7 @@ import Avatar from "Element/User/Avatar"; import Timeline from "Element/Feed/Timeline"; import Text from "Element/Text"; import SendSats from "Element/SendSats"; -import Nip05 from "Element/User/Nip05"; +import Nip05, { useIsVerified } from "Element/User/Nip05"; import Copy from "Element/Copy"; import ProfileImage from "Element/User/ProfileImage"; import BlockList from "Element/User/BlockList"; @@ -55,7 +48,7 @@ import ProfileTab, { FollowsTab, ProfileTabType, RelaysTab, - ZapsProfileTab + ZapsProfileTab, } from "Pages/Profile/ProfileTab"; export default function ProfilePage() { @@ -71,6 +64,7 @@ export default function ProfilePage() { const [modalImage, setModalImage] = useState(""); const aboutText = user?.about || ""; const npub = !id?.startsWith(NostrPrefix.PublicKey) ? hexToBech32(NostrPrefix.PublicKey, id || undefined) : id; + const { isVerified } = useIsVerified(user?.pubkey || ""); const lnurl = (() => { try { @@ -139,6 +133,25 @@ export default function ProfilePage() { return inner(); } + useEffect(() => { + const replaceWith = (username: string) => { + const current = window.location.pathname; + const npub = hexToBech32(NostrPrefix.PublicKey, user?.pubkey); + if (current.endsWith(`/${npub}`)) { + window.history.replaceState?.(null, "", `/${username}`); + } + }; + if (user?.nip05) { + if (user.nip05.endsWith(`@${process.env.NIP05_DOMAIN}`)) { + const username = user.nip05?.replace(`@${process.env.NIP05_DOMAIN}`, ""); + replaceWith(username); + } else { + // do we want this? would need to support urls with dots like /fiatjaf.com + // replaceWith(user.nip05?.replace(/^_@/, "")); + } + } + }, [isVerified, user?.pubkey]); + function username() { return ( <> diff --git a/packages/app/src/Pages/Profile/ProfileTab.tsx b/packages/app/src/Pages/Profile/ProfileTab.tsx index f4e53478..c03a536a 100644 --- a/packages/app/src/Pages/Profile/ProfileTab.tsx +++ b/packages/app/src/Pages/Profile/ProfileTab.tsx @@ -1,7 +1,7 @@ import useZapsFeed from "../../Feed/ZapsFeed"; import FormattedMessage from "../../Element/FormattedMessage"; import messages from "../messages"; -import {formatShort} from "../../Number"; +import { formatShort } from "../../Number"; import useFollowersFeed from "../../Feed/FollowersFeed"; import FollowsList from "../../Element/User/FollowListBase"; import useFollowsFeed from "../../Feed/FollowsFeed"; @@ -10,8 +10,8 @@ import RelaysMetadata from "../../Element/Relay/RelaysMetadata"; import useBookmarkFeed from "../../Feed/BookmarkFeed"; import Bookmarks from "../../Element/Bookmarks"; import Icon from "../../Icons/Icon"; -import {Tab} from "../../Element/Tabs"; -import {EventKind, HexKey, NostrLink, NostrPrefix} from "@snort/system"; +import { Tab } from "../../Element/Tabs"; +import { EventKind, HexKey, NostrLink, NostrPrefix } from "@snort/system"; import { default as ZapElement } from "Element/Event/Zap"; export enum ProfileTabType { @@ -68,87 +68,87 @@ export function BookMarksTab({ id }: { id: HexKey }) { } const ProfileTab = { - Notes: { - text: ( - <> - - - - ), - value: ProfileTabType.NOTES, - }, - Reactions: { - text: ( - <> - - - - ), - value: ProfileTabType.REACTIONS, - }, - Followers: { - text: ( - <> - - - - ), - value: ProfileTabType.FOLLOWERS, - }, - Follows: { - text: ( - <> - - - - ), - value: ProfileTabType.FOLLOWS, - }, - Zaps: { - text: ( - <> - - - - ), - value: ProfileTabType.ZAPS, - }, - Muted: { - text: ( - <> - - - - ), - value: ProfileTabType.MUTED, - }, - Blocked: { - text: ( - <> - - - - ), - value: ProfileTabType.BLOCKED, - }, - Relays: { - text: ( - <> - - - - ), - value: ProfileTabType.RELAYS, - }, - Bookmarks: { - text: ( - <> - - - - ), - value: ProfileTabType.BOOKMARKS, - }, - } as { [key: string]: Tab }; + Notes: { + text: ( + <> + + + + ), + value: ProfileTabType.NOTES, + }, + Reactions: { + text: ( + <> + + + + ), + value: ProfileTabType.REACTIONS, + }, + Followers: { + text: ( + <> + + + + ), + value: ProfileTabType.FOLLOWERS, + }, + Follows: { + text: ( + <> + + + + ), + value: ProfileTabType.FOLLOWS, + }, + Zaps: { + text: ( + <> + + + + ), + value: ProfileTabType.ZAPS, + }, + Muted: { + text: ( + <> + + + + ), + value: ProfileTabType.MUTED, + }, + Blocked: { + text: ( + <> + + + + ), + value: ProfileTabType.BLOCKED, + }, + Relays: { + text: ( + <> + + + + ), + value: ProfileTabType.RELAYS, + }, + Bookmarks: { + text: ( + <> + + + + ), + value: ProfileTabType.BOOKMARKS, + }, +} as { [key: string]: Tab }; -export default ProfileTab; \ No newline at end of file +export default ProfileTab;