fix some errors cause app crash

This commit is contained in:
Ren Amamiya
2023-08-19 08:56:19 +07:00
parent c85502e427
commit eda18f8c34
14 changed files with 265 additions and 253 deletions

View File

@@ -63,7 +63,12 @@ export function useNostr() {
}
// build user's network
const events = await ndk.fetchEvents({ kinds: [3], authors: [...follows] });
const events = await ndk.fetchEvents({
kinds: [3],
authors: [...follows],
limit: 300,
});
events.forEach((event: NDKEvent) => {
event.tags.forEach((tag) => {
if (tag[0] === 'p') lruNetwork.set(tag[1], tag[1]);
@@ -88,12 +93,11 @@ export function useNostr() {
try {
if (!ndk) return { status: 'failed', data: [], message: 'NDK instance not found' };
// setup nostr-fetch
const fetcher = NostrFetcher.withCustomPool(ndkAdapter(ndk));
const dbEventsEmpty = await db.isEventsEmpty();
let since: number;
if (dbEventsEmpty) {
if (dbEventsEmpty || db.account.last_login_at === 0) {
since = nHoursAgo(24);
} else {
since = db.account.last_login_at ?? nHoursAgo(24);
@@ -125,6 +129,7 @@ export function useNostr() {
event.id,
JSON.stringify(event),
event.pubkey,
event.kind,
root,
reply,
event.created_at

View File

@@ -1,19 +1,20 @@
import { NDKUserProfile } from '@nostr-dev-kit/ndk';
import { useQuery } from '@tanstack/react-query';
import { useNDK } from '@libs/ndk/provider';
export function useProfile(pubkey: string, fallback?: string) {
export function useProfile(pubkey: string, embed?: string) {
const { ndk } = useNDK();
const {
status,
data: user,
error,
isFetching,
} = useQuery(
['user', pubkey],
async () => {
if (!fallback) {
const user = ndk.getUser({ hexpubkey: pubkey });
if (!embed) {
const cleanPubkey = pubkey.replace('-', '');
const user = ndk.getUser({ hexpubkey: cleanPubkey });
await user.fetchProfile();
if (user.profile) {
user.profile.display_name = user.profile.displayName;
@@ -22,7 +23,7 @@ export function useProfile(pubkey: string, fallback?: string) {
throw new Error('User not found');
}
} else {
const profile = JSON.parse(fallback);
const profile: NDKUserProfile = JSON.parse(embed);
return profile;
}
},
@@ -35,5 +36,5 @@ export function useProfile(pubkey: string, fallback?: string) {
}
);
return { status, user, error, isFetching };
return { status, user, error };
}

View File

@@ -43,7 +43,6 @@ export function useImageUploader() {
if (res.ok) {
const url =
res.file?.metadata?.url ?? `https://void.cat/d/${res.file?.id}.${filetype}`;
console.log(url);
if (nip94) {
const tags = [