Skip to content

Commit

Permalink
update method
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcasey committed Nov 1, 2024
1 parent 39c1a01 commit 3371700
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions packages/farcaster/src/getFollowers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { log } from '@charmverse/core/log';
import * as http from '@packages/utils/http';

import type { FarcasterUser } from './interfaces';
Expand All @@ -17,20 +18,25 @@ export async function getFollowers(fid: number) {
let allUsers: FarcasterUser[] = [];
let cursor: string | undefined;

do {
const { next, users } = await http.GET<FollowersResponse>(
`${userApiUrl}?fid=${fid}&limit=100${cursor ? `&cursor=${cursor}` : ''}`,
{},
{
credentials: 'omit',
headers: {
'X-Api-Key': process.env.NEYNAR_API_KEY as string
try {
do {
const { next, users } = await http.GET<FollowersResponse>(
`${userApiUrl}?fid=${fid}&limit=100${cursor ? `&cursor=${cursor}` : ''}`,
{},
{
credentials: 'omit',
headers: {
'X-Api-Key': process.env.NEYNAR_API_KEY as string
}
}
}
);
);

allUsers = [...allUsers, ...users.map((user) => user.user)];
cursor = next?.cursor;
} while (cursor);
return allUsers;
allUsers = [...allUsers, ...users.map((user) => user.user)];
cursor = next?.cursor;
} while (cursor);
return allUsers;
} catch (error) {
log.error('Error fetching followers', { usersSoFar: allUsers.length, fid, cursor, error });
return allUsers;
}
}

0 comments on commit 3371700

Please sign in to comment.