if username@{NIP05_DOMAIN} valid, change profile page url to /username
This commit is contained in:
parent
9f5d467745
commit
3f7ac9e2d4
@ -2,14 +2,7 @@ import "./ProfilePage.css";
|
|||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import FormattedMessage from "Element/FormattedMessage";
|
import FormattedMessage from "Element/FormattedMessage";
|
||||||
import { useNavigate, useParams } from "react-router-dom";
|
import { useNavigate, useParams } from "react-router-dom";
|
||||||
import {
|
import { encodeTLV, encodeTLVEntries, EventKind, NostrPrefix, TLVEntryType, tryParseNostrLink } from "@snort/system";
|
||||||
encodeTLV,
|
|
||||||
encodeTLVEntries,
|
|
||||||
EventKind,
|
|
||||||
NostrPrefix,
|
|
||||||
TLVEntryType,
|
|
||||||
tryParseNostrLink,
|
|
||||||
} from "@snort/system";
|
|
||||||
import { LNURL } from "@snort/shared";
|
import { LNURL } from "@snort/shared";
|
||||||
import { useUserProfile } from "@snort/system-react";
|
import { useUserProfile } from "@snort/system-react";
|
||||||
|
|
||||||
@ -28,7 +21,7 @@ import Avatar from "Element/User/Avatar";
|
|||||||
import Timeline from "Element/Feed/Timeline";
|
import Timeline from "Element/Feed/Timeline";
|
||||||
import Text from "Element/Text";
|
import Text from "Element/Text";
|
||||||
import SendSats from "Element/SendSats";
|
import SendSats from "Element/SendSats";
|
||||||
import Nip05 from "Element/User/Nip05";
|
import Nip05, { useIsVerified } from "Element/User/Nip05";
|
||||||
import Copy from "Element/Copy";
|
import Copy from "Element/Copy";
|
||||||
import ProfileImage from "Element/User/ProfileImage";
|
import ProfileImage from "Element/User/ProfileImage";
|
||||||
import BlockList from "Element/User/BlockList";
|
import BlockList from "Element/User/BlockList";
|
||||||
@ -55,7 +48,7 @@ import ProfileTab, {
|
|||||||
FollowsTab,
|
FollowsTab,
|
||||||
ProfileTabType,
|
ProfileTabType,
|
||||||
RelaysTab,
|
RelaysTab,
|
||||||
ZapsProfileTab
|
ZapsProfileTab,
|
||||||
} from "Pages/Profile/ProfileTab";
|
} from "Pages/Profile/ProfileTab";
|
||||||
|
|
||||||
export default function ProfilePage() {
|
export default function ProfilePage() {
|
||||||
@ -71,6 +64,7 @@ export default function ProfilePage() {
|
|||||||
const [modalImage, setModalImage] = useState<string>("");
|
const [modalImage, setModalImage] = useState<string>("");
|
||||||
const aboutText = user?.about || "";
|
const aboutText = user?.about || "";
|
||||||
const npub = !id?.startsWith(NostrPrefix.PublicKey) ? hexToBech32(NostrPrefix.PublicKey, id || undefined) : id;
|
const npub = !id?.startsWith(NostrPrefix.PublicKey) ? hexToBech32(NostrPrefix.PublicKey, id || undefined) : id;
|
||||||
|
const { isVerified } = useIsVerified(user?.pubkey || "");
|
||||||
|
|
||||||
const lnurl = (() => {
|
const lnurl = (() => {
|
||||||
try {
|
try {
|
||||||
@ -139,6 +133,25 @@ export default function ProfilePage() {
|
|||||||
return inner();
|
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() {
|
function username() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import useZapsFeed from "../../Feed/ZapsFeed";
|
import useZapsFeed from "../../Feed/ZapsFeed";
|
||||||
import FormattedMessage from "../../Element/FormattedMessage";
|
import FormattedMessage from "../../Element/FormattedMessage";
|
||||||
import messages from "../messages";
|
import messages from "../messages";
|
||||||
import {formatShort} from "../../Number";
|
import { formatShort } from "../../Number";
|
||||||
import useFollowersFeed from "../../Feed/FollowersFeed";
|
import useFollowersFeed from "../../Feed/FollowersFeed";
|
||||||
import FollowsList from "../../Element/User/FollowListBase";
|
import FollowsList from "../../Element/User/FollowListBase";
|
||||||
import useFollowsFeed from "../../Feed/FollowsFeed";
|
import useFollowsFeed from "../../Feed/FollowsFeed";
|
||||||
@ -10,8 +10,8 @@ import RelaysMetadata from "../../Element/Relay/RelaysMetadata";
|
|||||||
import useBookmarkFeed from "../../Feed/BookmarkFeed";
|
import useBookmarkFeed from "../../Feed/BookmarkFeed";
|
||||||
import Bookmarks from "../../Element/Bookmarks";
|
import Bookmarks from "../../Element/Bookmarks";
|
||||||
import Icon from "../../Icons/Icon";
|
import Icon from "../../Icons/Icon";
|
||||||
import {Tab} from "../../Element/Tabs";
|
import { Tab } from "../../Element/Tabs";
|
||||||
import {EventKind, HexKey, NostrLink, NostrPrefix} from "@snort/system";
|
import { EventKind, HexKey, NostrLink, NostrPrefix } from "@snort/system";
|
||||||
import { default as ZapElement } from "Element/Event/Zap";
|
import { default as ZapElement } from "Element/Event/Zap";
|
||||||
|
|
||||||
export enum ProfileTabType {
|
export enum ProfileTabType {
|
||||||
@ -68,87 +68,87 @@ export function BookMarksTab({ id }: { id: HexKey }) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const ProfileTab = {
|
const ProfileTab = {
|
||||||
Notes: {
|
Notes: {
|
||||||
text: (
|
text: (
|
||||||
<>
|
<>
|
||||||
<Icon name="pencil" size={16} />
|
<Icon name="pencil" size={16} />
|
||||||
<FormattedMessage defaultMessage="Notes" />
|
<FormattedMessage defaultMessage="Notes" />
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
value: ProfileTabType.NOTES,
|
value: ProfileTabType.NOTES,
|
||||||
},
|
},
|
||||||
Reactions: {
|
Reactions: {
|
||||||
text: (
|
text: (
|
||||||
<>
|
<>
|
||||||
<Icon name="reaction" size={16} />
|
<Icon name="reaction" size={16} />
|
||||||
<FormattedMessage defaultMessage="Reactions" />
|
<FormattedMessage defaultMessage="Reactions" />
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
value: ProfileTabType.REACTIONS,
|
value: ProfileTabType.REACTIONS,
|
||||||
},
|
},
|
||||||
Followers: {
|
Followers: {
|
||||||
text: (
|
text: (
|
||||||
<>
|
<>
|
||||||
<Icon name="user-v2" size={16} />
|
<Icon name="user-v2" size={16} />
|
||||||
<FormattedMessage defaultMessage="Followers" />
|
<FormattedMessage defaultMessage="Followers" />
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
value: ProfileTabType.FOLLOWERS,
|
value: ProfileTabType.FOLLOWERS,
|
||||||
},
|
},
|
||||||
Follows: {
|
Follows: {
|
||||||
text: (
|
text: (
|
||||||
<>
|
<>
|
||||||
<Icon name="stars" size={16} />
|
<Icon name="stars" size={16} />
|
||||||
<FormattedMessage defaultMessage="Follows" />
|
<FormattedMessage defaultMessage="Follows" />
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
value: ProfileTabType.FOLLOWS,
|
value: ProfileTabType.FOLLOWS,
|
||||||
},
|
},
|
||||||
Zaps: {
|
Zaps: {
|
||||||
text: (
|
text: (
|
||||||
<>
|
<>
|
||||||
<Icon name="zap-solid" size={16} />
|
<Icon name="zap-solid" size={16} />
|
||||||
<FormattedMessage defaultMessage="Zaps" />
|
<FormattedMessage defaultMessage="Zaps" />
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
value: ProfileTabType.ZAPS,
|
value: ProfileTabType.ZAPS,
|
||||||
},
|
},
|
||||||
Muted: {
|
Muted: {
|
||||||
text: (
|
text: (
|
||||||
<>
|
<>
|
||||||
<Icon name="mute" size={16} />
|
<Icon name="mute" size={16} />
|
||||||
<FormattedMessage defaultMessage="Muted" />
|
<FormattedMessage defaultMessage="Muted" />
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
value: ProfileTabType.MUTED,
|
value: ProfileTabType.MUTED,
|
||||||
},
|
},
|
||||||
Blocked: {
|
Blocked: {
|
||||||
text: (
|
text: (
|
||||||
<>
|
<>
|
||||||
<Icon name="block" size={16} />
|
<Icon name="block" size={16} />
|
||||||
<FormattedMessage defaultMessage="Blocked" />
|
<FormattedMessage defaultMessage="Blocked" />
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
value: ProfileTabType.BLOCKED,
|
value: ProfileTabType.BLOCKED,
|
||||||
},
|
},
|
||||||
Relays: {
|
Relays: {
|
||||||
text: (
|
text: (
|
||||||
<>
|
<>
|
||||||
<Icon name="wifi" size={16} />
|
<Icon name="wifi" size={16} />
|
||||||
<FormattedMessage defaultMessage="Relays" />
|
<FormattedMessage defaultMessage="Relays" />
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
value: ProfileTabType.RELAYS,
|
value: ProfileTabType.RELAYS,
|
||||||
},
|
},
|
||||||
Bookmarks: {
|
Bookmarks: {
|
||||||
text: (
|
text: (
|
||||||
<>
|
<>
|
||||||
<Icon name="bookmark-solid" size={16} />
|
<Icon name="bookmark-solid" size={16} />
|
||||||
<FormattedMessage defaultMessage="Bookmarks" />
|
<FormattedMessage defaultMessage="Bookmarks" />
|
||||||
</>
|
</>
|
||||||
),
|
),
|
||||||
value: ProfileTabType.BOOKMARKS,
|
value: ProfileTabType.BOOKMARKS,
|
||||||
},
|
},
|
||||||
} as { [key: string]: Tab };
|
} as { [key: string]: Tab };
|
||||||
|
|
||||||
export default ProfileTab;
|
export default ProfileTab;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user