1
0
forked from Kieran/snort

get profiles from ndk

This commit is contained in:
Martti Malmi 2023-12-23 16:53:14 +02:00
parent 85169ebe0c
commit 5bfcd858da
22 changed files with 47 additions and 52 deletions

View File

@ -1,10 +1,10 @@
import "./CashuNuts.css";
import { useEffect, useState } from "react";
import { FormattedMessage, FormattedNumber } from "react-intl";
import { useUserProfile } from "@snort/system-react";
import useLogin from "@/Hooks/useLogin";
import Icon from "@/Icons/Icon";
import useProfile from "@/Hooks/useProfile";
interface Token {
token: Array<{
@ -18,7 +18,7 @@ interface Token {
export default function CashuNuts({ token }: { token: string }) {
const { publicKey } = useLogin(s => ({ publicKey: s.publicKey }));
const profile = useUserProfile(publicKey);
const profile = useProfile(publicKey);
async function copyToken(e: React.MouseEvent<HTMLButtonElement>, token: string) {
e.stopPropagation();

View File

@ -1,13 +1,13 @@
import { NostrLink, NostrPrefix } from "@snort/system";
import { useUserProfile } from "@snort/system-react";
import DisplayName from "@/Element/User/DisplayName";
import { ProfileCard } from "@/Element/User/ProfileCard";
import { ProfileLink } from "@/Element/User/ProfileLink";
import { useCallback, useRef, useState } from "react";
import useProfile from "@/Hooks/useProfile";
export default function Mention({ link }: { link: NostrLink }) {
const profile = useUserProfile(link.id);
const profile = useProfile(link.id);
const [isHovering, setIsHovering] = useState(false);
const hoverTimeoutRef = useRef<NodeJS.Timeout | null>(null);

View File

@ -3,7 +3,7 @@ import { FormattedMessage, useIntl } from "react-intl";
import { useLongPress } from "use-long-press";
import { TaggedNostrEvent, ParsedZap, countLeadingZeros, NostrLink } from "@snort/system";
import { normalizeReaction } from "@snort/shared";
import { useUserProfile } from "@snort/system-react";
import useProfile from "@/hooks/useProfile";
import { Menu, MenuItem } from "@szhsin/react-menu";
import classNames from "classnames";
@ -53,7 +53,7 @@ export default function NoteFooter(props: NoteFooterProps) {
preferences: prefs,
readonly,
} = useLogin(s => ({ preferences: s.appData.item.preferences, publicKey: s.publicKey, readonly: s.readonly }));
const author = useUserProfile(ev.pubkey);
const author = useProfile(ev.pubkey);
const interactionCache = useInteractionCache(publicKey, ev.id);
const { publisher, system } = useEventPublisher();
const note = useNoteCreator(n => ({ show: n.show, replyTo: n.replyTo, update: n.update, quote: n.quote }));

View File

@ -8,7 +8,7 @@ import { eventLink, hexToBech32, getDisplayName } from "@/SnortUtils";
import useModeration from "@/Hooks/useModeration";
import { FormattedMessage } from "react-intl";
import Icon from "@/Icons/Icon";
import { useUserProfile } from "@snort/system-react";
import useProfile from "@/hooks/useProfile";
import { useInView } from "react-intersection-observer";
export interface NoteReactionProps {
@ -20,7 +20,7 @@ export default function NoteReaction(props: NoteReactionProps) {
const { data: ev } = props;
const { isMuted } = useModeration();
const { inView, ref } = useInView({ triggerOnce: true, rootMargin: "2000px" });
const profile = useUserProfile(inView ? ev.pubkey : "");
const profile = useProfile(inView ? ev.pubkey : "");
const refEvent = useMemo(() => {
if (ev) {

View File

@ -2,7 +2,7 @@ import { TaggedNostrEvent, ParsedZap, NostrLink } from "@snort/system";
import { LNURL } from "@snort/shared";
import { useState } from "react";
import { FormattedMessage, FormattedNumber, useIntl } from "react-intl";
import { useUserProfile } from "@snort/system-react";
import useProfile from "@/hooks/useProfile";
import useEventPublisher from "@/Hooks/useEventPublisher";
import { useWallet } from "@/Wallet";
@ -28,7 +28,7 @@ export default function Poll(props: PollProps) {
publicKey: myPubKey,
relays,
} = useLogin(s => ({ preferences: s.appData.item.preferences, publicKey: s.publicKey, relays: s.relays }));
const pollerProfile = useUserProfile(props.ev.pubkey);
const pollerProfile = useProfile(props.ev.pubkey);
const [tallyBy, setTallyBy] = useState<PollTally>("pubkeys");
const [error, setError] = useState("");
const [invoice, setInvoice] = useState("");

View File

@ -1,7 +1,7 @@
import "./ZapButton.css";
import { useState } from "react";
import { HexKey } from "@snort/system";
import { useUserProfile } from "@snort/system-react";
import useProfile from "@/hooks/useProfile";
import SendSats from "@/Element/SendSats";
import Icon from "@/Icons/Icon";
@ -18,7 +18,7 @@ const ZapButton = ({
children?: React.ReactNode;
event?: string;
}) => {
const profile = useUserProfile(pubkey);
const profile = useProfile(pubkey);
const [zap, setZap] = useState(false);
const service = lnurl ?? (profile?.lud16 || profile?.lud06);
if (!service) return null;

View File

@ -1,6 +1,6 @@
import SnortApi from "@/External/SnortApi";
import { getCurrentRefCode, getDisplayName } from "@/SnortUtils";
import { useUserProfile } from "@snort/system-react";
import useProfile from "@/hooks/useProfile";
import Lottie from "lottie-react";
import { useState, useEffect } from "react";
import { FormattedMessage } from "react-intl";
@ -18,7 +18,7 @@ const InviteModal = () => {
api.getRefCodeInfo(code).then(a => setPubkey(a.pubkey));
}
}, []);
const profile = useUserProfile(pubkey);
const profile = useProfile(pubkey);
if (!code) return;
function close() {

View File

@ -1,5 +1,5 @@
import { mapEventToProfile } from "@snort/system";
import { useUserProfile } from "@snort/system-react";
import useProfile from "@/hooks/useProfile";
import AccountName from "./AccountName";
import useLogin from "@/Hooks/useLogin";
@ -12,7 +12,7 @@ export default function ActiveAccount({ name = "", setAsPrimary = () => {} }) {
publicKey: s.publicKey,
readonly: s.readonly,
}));
const profile = useUserProfile(publicKey);
const profile = useProfile(publicKey);
const { publisher, system } = useEventPublisher();
async function saveProfile(nip05: string) {

View File

@ -17,7 +17,7 @@ import {
import AsyncButton from "@/Element/Button/AsyncButton";
import SendSats from "@/Element/SendSats";
import Copy from "@/Element/Copy";
import { useUserProfile } from "@snort/system-react";
import useProfile from "@/hooks/useProfile";
import useEventPublisher from "@/Hooks/useEventPublisher";
import { debounce } from "@/SnortUtils";
import useLogin from "@/Hooks/useLogin";
@ -43,7 +43,7 @@ export default function Nip5Service(props: Nip05ServiceProps) {
const { helpText = true } = props;
const { formatMessage } = useIntl();
const { publicKey } = useLogin(s => ({ publicKey: s.publicKey }));
const user = useUserProfile(publicKey);
const user = useProfile(publicKey);
const { publisher, system } = useEventPublisher();
const svc = useMemo(() => new ServiceProvider(props.service), [props.service]);
const [serviceConfig, setServiceConfig] = useState<ServiceConfig>();

View File

@ -4,7 +4,7 @@ import { HexKey } from "@snort/system";
import { getDisplayNameOrPlaceHolder } from "@/SnortUtils";
import classNames from "classnames";
import useProfile from "@/Hooks/useProfile";
import {NDKUserProfile} from "@nostr-dev-kit/ndk";
import { NDKUserProfile } from "@nostr-dev-kit/ndk";
interface DisplayNameProps {
pubkey: HexKey;

View File

@ -1,9 +1,9 @@
import "./Nip05.css";
import { HexKey } from "@snort/system";
import { useUserProfile } from "@snort/system-react";
import useProfile from "@/Hooks/useProfile";
export function useIsVerified(pubkey?: HexKey, bypassCheck?: boolean) {
const profile = useUserProfile(pubkey);
const profile = useProfile(pubkey);
return { isVerified: bypassCheck || profile?.isNostrAddressValid };
}

View File

@ -1,8 +1,9 @@
import { ReactNode, useContext } from "react";
import { Link, LinkProps } from "react-router-dom";
import { UserMetadata, NostrLink, NostrPrefix, MetadataCache } from "@snort/system";
import { NostrLink, NostrPrefix } from "@snort/system";
import { SnortContext } from "@snort/system-react";
import { randomSample } from "@/SnortUtils";
import { NDKUserProfile } from "@nostr-dev-kit/ndk";
export function ProfileLink({
pubkey,
@ -12,7 +13,7 @@ export function ProfileLink({
...others
}: {
pubkey: string;
user?: UserMetadata | MetadataCache;
user?: NDKUserProfile;
explicitLink?: string;
children?: ReactNode;
} & Omit<LinkProps, "to">) {

View File

@ -1,11 +1,12 @@
import "./ProfilePreview.css";
import { ReactNode } from "react";
import { HexKey, UserMetadata } from "@snort/system";
import { useUserProfile } from "@snort/system-react";
import { HexKey } from "@snort/system";
import { useInView } from "react-intersection-observer";
import ProfileImage from "@/Element/User/ProfileImage";
import FollowButton from "@/Element/User/FollowButton";
import useProfile from "@/Hooks/useProfile";
import { NDKUserProfile } from "@nostr-dev-kit/ndk";
export interface ProfilePreviewProps {
pubkey: HexKey;
@ -14,7 +15,7 @@ export interface ProfilePreviewProps {
linkToProfile?: boolean;
profileCards?: boolean;
};
profile?: UserMetadata;
profile?: NDKUserProfile;
actions?: ReactNode;
className?: string;
onClick?: (e: React.MouseEvent<HTMLDivElement>) => void;
@ -22,7 +23,7 @@ export interface ProfilePreviewProps {
export default function ProfilePreview(props: ProfilePreviewProps) {
const pubkey = props.pubkey;
const { ref, inView } = useInView({ triggerOnce: true });
const user = useUserProfile(inView ? pubkey : undefined);
const user = useProfile(inView ? pubkey : undefined);
const options = {
about: true,
...props.options,

View File

@ -1,11 +1,11 @@
import { HexKey } from "@snort/system";
import { useUserProfile } from "@snort/system-react";
import useProfile from "@/hooks/useProfile";
import { ProfileLink } from "./ProfileLink";
import DisplayName from "./DisplayName";
export default function Username({ pubkey, onLinkVisit }: { pubkey: HexKey; onLinkVisit(): void }) {
const user = useUserProfile(pubkey);
const user = useProfile(pubkey);
return user ? (
<ProfileLink pubkey={pubkey} onClick={onLinkVisit} user={user}>

View File

@ -5,7 +5,7 @@ import Icon from "@/Icons/Icon";
import { ProfileLink } from "@/Element/User/ProfileLink";
import { NoteCreatorButton } from "@/Element/Event/Create/NoteCreatorButton";
import classNames from "classnames";
import { useUserProfile } from "@snort/system-react";
import useProfile from "@/hooks/useProfile";
import Avatar from "@/Element/User/Avatar";
import { useIntl } from "react-intl";
@ -37,7 +37,7 @@ const Footer = () => {
publicKey: s.publicKey,
readonly: s.readonly,
}));
const profile = useUserProfile(publicKey);
const profile = useProfile(publicKey);
const { formatMessage } = useIntl();
const readOnlyIcon = readonly && (

View File

@ -4,7 +4,7 @@ import Icon from "@/Icons/Icon";
import { ProfileLink } from "../../Element/User/ProfileLink";
import Avatar from "../../Element/User/Avatar";
import useLogin from "../../Hooks/useLogin";
import { useUserProfile } from "@snort/system-react";
import useProfile from "@/hooks/useProfile";
import { NoteCreatorButton } from "../../Element/Event/Create/NoteCreatorButton";
import { FormattedMessage, useIntl } from "react-intl";
import classNames from "classnames";
@ -78,7 +78,7 @@ export default function NavSidebar({ narrow = false }) {
subscriptions: s.subscriptions,
readonly: s.readonly,
}));
const profile = useUserProfile(publicKey);
const profile = useProfile(publicKey);
const navigate = useNavigate();
const { publisher } = useEventPublisher();
const sub = getCurrentSubscription(subscriptions);

View File

@ -2,7 +2,7 @@ import "./Notifications.css";
import { Suspense, lazy, useEffect, useMemo, useState, useSyncExternalStore } from "react";
import { EventExt, EventKind, NostrEvent, NostrLink, NostrPrefix, TaggedNostrEvent, parseZap } from "@snort/system";
import { unwrap } from "@snort/shared";
import { useEventFeed, useUserProfile } from "@snort/system-react";
import { useEventFeed } from "@snort/system-react";
import { useInView } from "react-intersection-observer";
import { FormattedMessage, useIntl } from "react-intl";
import { useNavigate } from "react-router-dom";
@ -20,6 +20,7 @@ import { LiveEvent } from "@/Element/LiveEvent";
import ProfilePreview from "@/Element/User/ProfilePreview";
import { ShowMoreInView } from "@/Element/Event/ShowMore";
import PageSpinner from "@/Element/PageSpinner";
import useProfile from "@/Hooks/useProfile";
const NotificationGraph = lazy(() => import("@/Pages/Notifications/NotificationChart"));
function notificationContext(ev: TaggedNostrEvent) {
@ -133,7 +134,7 @@ function NotificationGroup({ evs, onClick }: { evs: Array<TaggedNostrEvent>; onC
}),
);
const firstPubkey = pubkeys[0];
const firstPubkeyProfile = useUserProfile(inView ? (firstPubkey === "anon" ? "" : firstPubkey) : "");
const firstPubkeyProfile = useProfile(inView ? (firstPubkey === "anon" ? "" : firstPubkey) : "");
const context = notificationContext(evs[0]);
const totalZaps = zaps.reduce((acc, v) => acc + v.amount, 0);

View File

@ -2,14 +2,7 @@ import "./ProfilePage.css";
import { useEffect, useState } from "react";
import { FormattedMessage } from "react-intl";
import { Link, useLocation, useNavigate, useParams } from "react-router-dom";
import {
encodeTLVEntries,
EventKind,
NostrLink,
NostrPrefix,
TLVEntryType,
tryParseNostrLink,
} from "@snort/system";
import { encodeTLVEntries, EventKind, NostrLink, NostrPrefix, TLVEntryType, tryParseNostrLink } from "@snort/system";
import { fetchNip05Pubkey, LNURL } from "@snort/shared";
import { findTag, getLinkReactions, hexToBech32, parseId, unwrap } from "@/SnortUtils";
@ -55,7 +48,7 @@ import { UserWebsiteLink } from "@/Element/User/UserWebsiteLink";
import { useMuteList, usePinList } from "@/Hooks/useLists";
import FollowedBy from "@/Element/User/FollowedBy";
import useProfile from "@/Hooks/useProfile";
import {NDKUserProfile} from "@nostr-dev-kit/ndk";
import { NDKUserProfile } from "@nostr-dev-kit/ndk";
interface ProfilePageProps {
id?: string;

View File

@ -2,7 +2,7 @@ import "./ZapPool.css";
import { useMemo, useSyncExternalStore } from "react";
import { FormattedMessage, FormattedNumber } from "react-intl";
import { useUserProfile } from "@snort/system-react";
import useProfile from "@/hooks/useProfile";
import { SnortPubKey } from "@/Const";
import ProfilePreview from "@/Element/User/ProfilePreview";
@ -24,7 +24,7 @@ const DataProviders = [
export function ZapPoolTarget({ target }: { target: ZapPoolRecipient }) {
if (!ZapPoolController) return;
const login = useLogin();
const profile = useUserProfile(target.pubkey);
const profile = useProfile(target.pubkey);
const hasAddress = profile?.lud16 || profile?.lud06;
const defaultZapMount = Math.ceil(login.appData.item.preferences.defaultZapAmount * (target.split / 100));
return (

View File

@ -2,7 +2,7 @@ import "./Profile.css";
import { useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";
import { mapEventToProfile } from "@snort/system";
import { useUserProfile } from "@snort/system-react";
import useProfile from "@/hooks/useProfile";
import useEventPublisher from "@/Hooks/useEventPublisher";
import { openFile, debounce } from "@/SnortUtils";
@ -27,7 +27,7 @@ export default function ProfileSettings(props: ProfileSettingsProps) {
const navigate = useNavigate();
const { formatMessage } = useIntl();
const { publicKey: id, readonly } = useLogin(s => ({ publicKey: s.publicKey, readonly: s.readonly }));
const user = useUserProfile(id ?? "");
const user = useProfile(id ?? "");
const { publisher, system } = useEventPublisher();
const uploader = useFileUpload();
const [error, setError] = useState<Error>();

View File

@ -16,12 +16,11 @@ import {
NostrEvent,
MetadataCache,
NostrLink,
UserMetadata,
} from "@snort/system";
import { isHex, isOffline } from "@snort/shared";
import { Birthday, Day } from "@/Const";
import AnimalName from "@/Element/User/AnimalName";
import {NDKUser, NDKUserProfile} from "@nostr-dev-kit/ndk";
import { NDKUserProfile } from "@nostr-dev-kit/ndk";
export const sha256 = (str: string | Uint8Array): u256 => {
return utils.bytesToHex(hash(str));

View File

@ -1,6 +1,6 @@
import "./TaskList.css";
import { Fragment, useSyncExternalStore } from "react";
import { useUserProfile } from "@snort/system-react";
import useProfile from "@/hooks/useProfile";
import useLogin from "@/Hooks/useLogin";
import Icon from "@/Icons/Icon";
@ -38,7 +38,7 @@ class TaskStore extends ExternalStore<Array<UITask>> {
const AllTasks = new TaskStore();
export const TaskList = () => {
const session = useLogin();
const user = useUserProfile(session.publicKey);
const user = useProfile(session.publicKey);
const tasks = useSyncExternalStore(
c => AllTasks.hook(c),
() => AllTasks.snapshot(),