use top level await for some functions

This commit is contained in:
Ren Amamiya
2023-04-23 12:15:04 +07:00
parent ac6fb3cb55
commit 97c45a8c8f
11 changed files with 270 additions and 271 deletions

View File

@@ -1,10 +1,8 @@
import { RelayContext } from '@components/relaysProvider';
import { createPleb } from '@utils/storage';
import useLocalStorage from '@rehooks/local-storage';
import { fetch } from '@tauri-apps/api/http';
import { useCallback, useContext, useEffect, useMemo, useState } from 'react';
import { useCallback, useEffect, useMemo, useState } from 'react';
export const fetchProfileMetadata = async (pubkey: string) => {
const result = await fetch(`https://rbr.bio/${pubkey}/metadata.json`, {
@@ -15,7 +13,6 @@ export const fetchProfileMetadata = async (pubkey: string) => {
};
export const useProfileMetadata = (pubkey: string) => {
const [pool, relays]: any = useContext(RelayContext);
const [activeAccount]: any = useLocalStorage('account', {});
const [plebs] = useLocalStorage('plebs', []);
const [profile, setProfile] = useState(null);
@@ -40,16 +37,11 @@ export const useProfileMetadata = (pubkey: string) => {
return createPleb(pubkey, metadata);
}, []);
const fetchProfileFromRelays = useCallback(async (pubkey: string) => {
const result = await pool.fetchAndCacheMetadata(pubkey, relays);
return result;
}, []);
useEffect(() => {
let ignore = false;
if (!cacheProfile && !ignore) {
fetchProfileFromRelays(pubkey)
fetchProfileMetadata(pubkey)
.then((res: any) => {
// update state
setProfile(JSON.parse(res.content));