chore: fix fetching of user profile
This commit is contained in:
parent
4f9fdd19b0
commit
006ed7b548
@ -41,8 +41,7 @@ export interface NDKContextType {
|
||||
) => Promise<NDKEvent | null>
|
||||
findMetadata: (
|
||||
pubkey: string,
|
||||
opts?: NDKSubscriptionOptions,
|
||||
storeProfileEvent?: boolean
|
||||
opts?: NDKSubscriptionOptions
|
||||
) => Promise<NDKUserProfile | null>
|
||||
getNDKRelayList: (pubkey: Hexpubkey) => Promise<NDKRelayList>
|
||||
publish: (event: NDKEvent, explicitRelayUrls?: string[]) => Promise<string[]>
|
||||
@ -205,21 +204,17 @@ export const NDKContextProvider = ({ children }: { children: ReactNode }) => {
|
||||
*/
|
||||
const findMetadata = async (
|
||||
pubkey: string,
|
||||
opts?: NDKSubscriptionOptions,
|
||||
storeProfileEvent?: boolean
|
||||
opts?: NDKSubscriptionOptions
|
||||
): Promise<NDKUserProfile | null> => {
|
||||
const npub = hexToNpub(pubkey)
|
||||
|
||||
const user = new NDKUser({ npub })
|
||||
user.ndk = ndk
|
||||
|
||||
return await user.fetchProfile(
|
||||
{
|
||||
cacheUsage: NDKSubscriptionCacheUsage.PARALLEL,
|
||||
...(opts || {})
|
||||
},
|
||||
storeProfileEvent
|
||||
)
|
||||
return await user.fetchProfile({
|
||||
cacheUsage: NDKSubscriptionCacheUsage.PARALLEL,
|
||||
...(opts || {})
|
||||
})
|
||||
}
|
||||
|
||||
const getNDKRelayList = async (pubkey: Hexpubkey) => {
|
||||
@ -250,8 +245,7 @@ export const NDKContextProvider = ({ children }: { children: ReactNode }) => {
|
||||
ndkRelaySet = NDKRelaySet.fromRelayUrls(explicitRelayUrls, ndk)
|
||||
}
|
||||
|
||||
return event
|
||||
.publish(ndkRelaySet, 10000)
|
||||
return await Promise.race([event.publish(ndkRelaySet), timeout(3000)])
|
||||
.then((res) => {
|
||||
const relaysPublishedOn = Array.from(res)
|
||||
return relaysPublishedOn.map((relay) => relay.url)
|
||||
|
@ -25,9 +25,8 @@ export const useAuth = () => {
|
||||
const { getRelayInfo } = useDvm()
|
||||
const { findMetadata, getNDKRelayList } = useNDKContext()
|
||||
|
||||
const { auth: authState, relays: relaysState } = useAppSelector(
|
||||
(state) => state
|
||||
)
|
||||
const authState = useAppSelector((state) => state.auth)
|
||||
const relaysState = useAppSelector((state) => state.relays)
|
||||
|
||||
const checkSession = useCallback(() => {
|
||||
const savedAuthToken = getAuthToken()
|
||||
@ -66,7 +65,7 @@ export const useAuth = () => {
|
||||
const emptyMetadata = getEmptyMetadataEvent()
|
||||
|
||||
try {
|
||||
const profile = await findMetadata(pubkey, {}, true)
|
||||
const profile = await findMetadata(pubkey)
|
||||
|
||||
if (profile && profile.profileEvent) {
|
||||
const event: Event = JSON.parse(profile.profileEvent)
|
||||
|
@ -164,7 +164,7 @@ export const MainLayout = () => {
|
||||
if (loggedIn) {
|
||||
if (!loginMethod || !usersPubkey) return logout()
|
||||
|
||||
findMetadata(usersPubkey, {}, true).then((profile) => {
|
||||
findMetadata(usersPubkey).then((profile) => {
|
||||
if (profile && profile.profileEvent) {
|
||||
try {
|
||||
const event: Event = JSON.parse(profile.profileEvent)
|
||||
|
Loading…
Reference in New Issue
Block a user