This commit is contained in:
2023-12-04 13:36:16 +07:00
parent 4093821fd0
commit 8795923443
2 changed files with 33 additions and 24 deletions

View File

@@ -64,14 +64,17 @@ export const NDKInstance = () => {
const bunker = !!parseInt(bunkerSetting); const bunker = !!parseInt(bunkerSetting);
const outbox = !!parseInt(outboxSetting); const outbox = !!parseInt(outboxSetting);
// #TODO: user can config outbox relays
const outboxRelayUrls = normalizeRelayUrlSet(['wss://purplepag.es/']);
const tauriAdapter = new NDKCacheAdapterTauri(db); const tauriAdapter = new NDKCacheAdapterTauri(db);
const instance = new NDK({ const instance = new NDK({
explicitRelayUrls, explicitRelayUrls,
cacheAdapter: tauriAdapter, outboxRelayUrls,
outboxRelayUrls: ['wss://purplepag.es'],
enableOutboxModel: outbox, enableOutboxModel: outbox,
autoConnectUserRelays: true, autoConnectUserRelays: true,
autoFetchUserMutelist: true, autoFetchUserMutelist: true,
cacheAdapter: tauriAdapter,
// clientName: 'Lume', // clientName: 'Lume',
// clientNip89: '', // clientNip89: '',
}); });

View File

@@ -1,11 +1,10 @@
import { NDKUserProfile } from '@nostr-dev-kit/ndk'; import { NDKUserProfile } from '@nostr-dev-kit/ndk';
import { useQuery, useQueryClient } from '@tanstack/react-query'; import { useQuery } from '@tanstack/react-query';
import { nip19 } from 'nostr-tools'; import { nip19 } from 'nostr-tools';
import { useNDK } from '@libs/ndk/provider'; import { useNDK } from '@libs/ndk/provider';
export function useProfile(pubkey: string, embed?: string) { export function useProfile(pubkey: string, embed?: string) {
const queryClient = useQueryClient();
const { ndk } = useNDK(); const { ndk } = useNDK();
const { const {
isFetching, isFetching,
@@ -14,6 +13,7 @@ export function useProfile(pubkey: string, embed?: string) {
} = useQuery({ } = useQuery({
queryKey: ['user', pubkey], queryKey: ['user', pubkey],
queryFn: async () => { queryFn: async () => {
try {
// parse data from nostr.band api // parse data from nostr.band api
if (embed) { if (embed) {
const profile: NDKUserProfile = JSON.parse(embed); const profile: NDKUserProfile = JSON.parse(embed);
@@ -36,9 +36,15 @@ export function useProfile(pubkey: string, embed?: string) {
throw new Error( throw new Error(
`Cannot get metadata for ${pubkey}, will be retry after 10 seconds` `Cannot get metadata for ${pubkey}, will be retry after 10 seconds`
); );
return profile; return profile;
} catch (e) {
console.error(e);
throw new Error(
`Cannot get metadata for ${pubkey}, will be retry after 10 seconds`
);
}
}, },
initialData: () => queryClient.getQueryData(['user', pubkey]) as NDKUserProfile,
refetchOnWindowFocus: false, refetchOnWindowFocus: false,
refetchOnReconnect: false, refetchOnReconnect: false,
retry: 2, retry: 2,