diff --git a/lib/types/farcaster-types.js b/lib/types/farcaster-types.js --- a/lib/types/farcaster-types.js +++ b/lib/types/farcaster-types.js @@ -17,6 +17,7 @@ export type NeynarUser = { +fid: number, +username: string, + +pfp_url: string, ... }; diff --git a/lib/utils/fc-cache.js b/lib/utils/fc-cache.js --- a/lib/utils/fc-cache.js +++ b/lib/utils/fc-cache.js @@ -56,10 +56,13 @@ const fetchFarcasterUsernamesPromise = (async () => { let farcasterUsernames: $ReadOnlyArray; try { - farcasterUsernames = await Promise.race([ - this.client.getFarcasterUsernames(needFetch), + const farcasterUsers = await Promise.race([ + this.client.getFarcasterUsers(needFetch), throwOnTimeout(`usernames for ${JSON.stringify(needFetch)}`), ]); + farcasterUsernames = farcasterUsers.map( + farcasterUser => farcasterUser?.username, + ); } catch (e) { console.log(e); farcasterUsernames = new Array(needFetch.length).fill(null); diff --git a/lib/utils/neynar-client.js b/lib/utils/neynar-client.js --- a/lib/utils/neynar-client.js +++ b/lib/utils/neynar-client.js @@ -37,6 +37,11 @@ +channel: NeynarChannel, }; +export type FarcasterUser = { + +username: string, + +pfpURL: string, +}; + const neynarBaseURL = 'https://api.neynar.com/'; const neynarURLs = { '1': `${neynarBaseURL}v1/farcaster/`, @@ -193,11 +198,11 @@ } } - async getFarcasterUsernames( + async getFarcasterUsers( fids: $ReadOnlyArray, - ): Promise> { + ): Promise> { const fidsLeft = [...fids]; - const results: Array = []; + const results: Array = []; do { // Neynar API allows querying 100 at a time const batch = fidsLeft.splice(0, 100); @@ -221,7 +226,11 @@ for (const fid of batch) { const neynarUser = neynarUserMap.get(parseInt(fid)); - results.push(neynarUser ? neynarUser.username : null); + results.push( + neynarUser + ? { username: neynarUser.username, pfpURL: neynarUser.pfp_url } + : null, + ); } } catch (error) { console.log(