Skip to content

Commit

Permalink
update endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
hellno committed Oct 24, 2023
1 parent 9e4b800 commit dd96850
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 159 deletions.
30 changes: 22 additions & 8 deletions src/common/components/ProfileHoverCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import {
AvatarFallback,
AvatarImage,
} from "@/components/ui/avatar";
import { UserNeynarV2Type, fetchUserProfile } from '../helpers/neynar';
import { UserNeynarV1Type, fetchUserProfile } from '../helpers/neynar';
// import { Button } from '@/components/ui/button';
import { openWindow } from '../helpers/navigation';
import { Loading } from './Loading';
import { Button } from '@/components/ui/button';

const ProfileHoverCard = ({ userFid, username }: { userFid: string, username: string }) => {
const [profile, setProfile] = useState<UserNeynarV2Type | null>(null);
const [profile, setProfile] = useState<UserNeynarV1Type | null>(null);

useEffect(() => {
const getData = async () => {
Expand All @@ -29,20 +30,33 @@ const ProfileHoverCard = ({ userFid, username }: { userFid: string, username: st
openWindow(`https://warpcast.com/${profile?.username || username}`);
}

const updateFollowStatus = (following: boolean | undefined) => async () => {
if (following === undefined) return;

}

// console.log('profile', profile);

return (
<HoverCard openDelay={0.1}>
<HoverCardTrigger onClick={onClick}>{username}</HoverCardTrigger>
<HoverCardContent onClick={onClick} className="overflow-hidden">
<div className="space-y-2">
<div className="flex flex-row justify-between">
<Avatar>
<AvatarImage src={profile?.pfp_url} />
<AvatarImage src={profile?.pfp.url} />
<AvatarFallback>{username.slice(1, 2)}</AvatarFallback>
</Avatar>
{/* <Button className="rounded-sm">Follow</Button> */}
{/* <Button
className="rounded-sm group"
onClick={(e) => {e.stopPropagation(); updateFollowStatus(profile?.viewerContext.following)}}
>
<span className="block group-hover:hidden">{profile?.viewerContext.following ? "Following" : "Follow"}</span>
<span className="hidden group-hover:block group-hover:text-red-600">Unfollow</span>
</Button> */}
</div>
<div>
<h2 className="text-md font-semibold">{profile?.display_name}</h2>
<h2 className="text-md font-semibold">{profile?.displayName}</h2>
<h3 className="text-sm font-regular">{username}</h3>
</div>
{profile ? (
Expand All @@ -52,18 +66,18 @@ const ProfileHoverCard = ({ userFid, username }: { userFid: string, username: st
</p>
<div className="flex items-center pt-2 text-sm text-muted-foreground">
<span className="font-semibold text-foreground">
{profile?.following_count}
{profile?.followingCount}
&nbsp;
</span>
following
<span className="ml-2 font-semibold text-foreground">
{profile?.follower_count}
{profile?.followerCount}
&nbsp;
</span>
followers
</div>
</>
): <Loading />}
) : <Loading />}
</div>
</HoverCardContent>
</HoverCard>
Expand Down
147 changes: 2 additions & 145 deletions src/common/helpers/farcaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,148 +217,5 @@ export const publishReaction = async ({ authorFid, privateKey, reactionBody }: P
};



///// EXAMPLES GO BELOW

/**
* Example 1: A cast with no mentions
*
* "This is a cast with no mentions"
*/

// const cast = await makeCastAdd(
// castBody,
// dataOptions,
// ed25519Signer,
// );
// castResults.push(cast);

// /**
// * Example 2: A cast with mentions
// *
// * "@dwr and @v are big fans of @farcaster"
// */
// const castWithMentions = await makeCastAdd(
// {
// text: " and are big fans of ",
// embeds: [],
// embedsDeprecated: [],
// mentions: [3, 2, 1],
// mentionsPositions: [0, 5, 22],
// },
// dataOptions,
// ed25519Signer,
// );
// castResults.push(castWithMentions);

// /**
// * Example 3: A cast with mentions and an attachment
// *
// * "Hey @dwr, check this out!"
// */
// const castWithMentionsAndAttachment = await makeCastAdd(
// {
// text: "Hey , check this out!",
// embeds: [{ url: "https://farcaster.xyz" }],
// embedsDeprecated: [],
// mentions: [3],
// mentionsPositions: [4],
// },
// dataOptions,
// ed25519Signer,
// );
// castResults.push(castWithMentionsAndAttachment);

// /**
// * Example 4: A cast with mentions and an attachment, and a link in the text
// *
// * "Hey @dwr, check out https://farcaster.xyz!"
// */
// const castWithMentionsAttachmentLink = await makeCastAdd(
// {
// text: "Hey , check out https://farcaster.xyz!",
// embeds: [{ url: "https://farcaster.xyz" }],
// embedsDeprecated: [],
// mentions: [3],
// mentionsPositions: [4],
// },
// dataOptions,
// ed25519Signer,
// );
// castResults.push(castWithMentionsAttachmentLink);

// /**
// * Example 5: A cast with multiple mentions
// *
// * "You can mention @v multiple times: @v @v @v"
// */

// const castWithMultipleMentions = await makeCastAdd(
// {
// text: "You can mention multiple times: ",
// embeds: [],
// embedsDeprecated: [],
// mentions: [2, 2, 2, 2],
// mentionsPositions: [16, 33, 34, 35],
// },
// dataOptions,
// ed25519Signer,
// );
// castResults.push(castWithMultipleMentions);

// /**
// * Example 6: A cast with emoji and mentions
// *
// * "🤓@farcaster can mention immediately after emoji"
// */
// const castWithEmojiAndMentions = await makeCastAdd(
// {
// text: "🤓 can mention immediately after emoji",
// embeds: [],
// embedsDeprecated: [],
// mentions: [1],
// mentionsPositions: [4],
// },
// dataOptions,
// ed25519Signer,
// );
// castResults.push(castWithEmojiAndMentions);

// /**
// * Example 7: A cast with emoji and a link in the text and an attachment
// *
// * "🤓https://url-after-unicode.com can include URL immediately after emoji"
// */

// const castWithEmojiLinkAttachmnent = await makeCastAdd(
// {
// text: "🤓https://url-after-unicode.com can include URL immediately after emoji",
// embeds: [{ url: "https://url-after-unicode.com" }],
// embedsDeprecated: [],
// mentions: [],
// mentionsPositions: [],
// },
// dataOptions,
// ed25519Signer,
// );
// castResults.push(castWithEmojiLinkAttachmnent);

// /**
// * Example 7: A cast that replies to a URL
// *
// * "I think this is a great protocol 🚀"
// */

// const castReplyingToAUrl = await makeCastAdd(
// {
// text: "I think this is a great protocol 🚀",
// embeds: [],
// embedsDeprecated: [],
// mentions: [],
// mentionsPositions: [],
// parentUrl: "https://www.farcaster.xyz/",
// },
// dataOptions,
// ed25519Signer,
// );
// castResults.push(castReplyingToAUrl);
const addFollow = async (followerFid: number, followingFid: number, privateKey: string) => {
}
17 changes: 11 additions & 6 deletions src/common/helpers/neynar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,17 @@ export const getNeynarUserSearchEndpoint = (viewerFid?: string): string => {
return neynarEndpoint;
}

export const fetchUserProfile = async (userFid: string, username: string): Promise<UserNeynarV2Type | null> => {
const endpoint = getNeynarUserSearchEndpoint(userFid) + `&q=${username}`;
return axios.get(endpoint)
export const fetchUserProfile = async (userFid: string, username: string): Promise<UserNeynarV1Type | null> => {
const options = {
method: 'GET',
url: 'https://api.neynar.com/v1/farcaster/user-by-username',
params: { username, viewerFid: userFid },
headers: { accept: 'application/json', api_key: 'NEYNAR_API_DOCS' }
};
// const endpoint = getNeynarUserSearchEndpoint(userFid) + `&q=${username}`;
return axios.request(options)
.then(response => {
const users = response.data.result.users as UserNeynarV2Type[];
return users.length > 0 ? users[0] : null;
return response.data.result.user as UserNeynarV1Type;
})
.catch(error => {
console.error(error);
Expand All @@ -148,7 +153,7 @@ export const fetchCasts = async (castHashes: { hash: string }[]): Promise<CastTy
});
}

type UserNeynarV1Type = {
export type UserNeynarV1Type = {
fid: number;
custodyAddress: string;
username: string;
Expand Down

0 comments on commit dd96850

Please sign in to comment.