fully support nip05
This commit is contained in:
@@ -1,38 +1,28 @@
|
||||
import { createPleb, getPleb } from "@libs/storage";
|
||||
import { RelayContext } from "@shared/relayProvider";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { nip19 } from "nostr-tools";
|
||||
import { useContext } from "react";
|
||||
|
||||
export function useProfile(id: string) {
|
||||
export function useProfile(pubkey: string) {
|
||||
const ndk = useContext(RelayContext);
|
||||
const {
|
||||
status,
|
||||
data: user,
|
||||
error,
|
||||
isFetching,
|
||||
} = useQuery(["user", id], async () => {
|
||||
let npub: string;
|
||||
|
||||
if (id.substring(0, 4) === "npub") {
|
||||
npub = id;
|
||||
} else {
|
||||
npub = nip19.npubEncode(id);
|
||||
}
|
||||
|
||||
const current = Math.floor(Date.now() / 1000);
|
||||
const result = await getPleb(npub);
|
||||
|
||||
if (result && parseInt(result.created_at) + 86400 >= current) {
|
||||
return result;
|
||||
} else {
|
||||
const user = ndk.getUser({ npub });
|
||||
} = useQuery(
|
||||
["user", pubkey],
|
||||
async () => {
|
||||
const user = ndk.getUser({ hexpubkey: pubkey });
|
||||
await user.fetchProfile();
|
||||
await createPleb(id, user.profile);
|
||||
|
||||
return user.profile;
|
||||
}
|
||||
});
|
||||
},
|
||||
{
|
||||
staleTime: Infinity,
|
||||
refetchOnWindowFocus: false,
|
||||
refetchOnReconnect: false,
|
||||
},
|
||||
);
|
||||
|
||||
return { status, user, error, isFetching };
|
||||
}
|
||||
|
||||
@@ -24,6 +24,9 @@ export function useSocial() {
|
||||
},
|
||||
{
|
||||
enabled: account ? true : false,
|
||||
refetchOnReconnect: false,
|
||||
refetchOnMount: false,
|
||||
refetchOnWindowFocus: false,
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user