-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
854 additions
and
157 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
# docs | ||
|
||
## 0.3.13 | ||
|
||
### Patch Changes | ||
|
||
- Updated dependencies [86e03b9] | ||
- [email protected] | ||
|
||
## 0.3.12 | ||
|
||
### Patch Changes | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
packages/debugger/app/components/frame-app-debugger-view-profile-dialog.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* eslint-disable @next/next/no-img-element */ | ||
import React from "react"; | ||
import { | ||
Dialog, | ||
DialogContent, | ||
DialogTitle, | ||
DialogDescription, | ||
} from "@/components/ui/dialog"; | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { z } from "zod"; | ||
import { Loader2Icon, TriangleAlertIcon } from "lucide-react"; | ||
import Image from "next/image"; | ||
|
||
type UserDetails = { | ||
username: string; | ||
pfp_url: string; | ||
profile: { | ||
bio: { | ||
text: string; | ||
}; | ||
}; | ||
follower_count: number; | ||
following_count: number; | ||
}; | ||
|
||
type FrameAppDebuggerViewProfileDialogProps = { | ||
fid: number; | ||
onDismiss: () => void; | ||
}; | ||
|
||
const UserDetailsSchema = z.object({ | ||
username: z.string(), | ||
pfp_url: z.string().url(), | ||
profile: z.object({ | ||
bio: z.object({ | ||
text: z.string(), | ||
}), | ||
}), | ||
follower_count: z.number().int(), | ||
following_count: z.number().int(), | ||
}); | ||
|
||
async function fetchUser(fid: number): Promise<UserDetails> { | ||
const response = await fetch(`/farcaster/user/${fid}`); | ||
|
||
if (!response.ok) { | ||
throw new Error("Network response was not ok"); | ||
} | ||
|
||
const data = await response.json(); | ||
|
||
return UserDetailsSchema.parse(data); | ||
} | ||
|
||
export function FrameAppDebuggerViewProfileDialog({ | ||
fid, | ||
onDismiss, | ||
}: FrameAppDebuggerViewProfileDialogProps) { | ||
const query = useQuery({ | ||
queryKey: ["user", fid], | ||
queryFn: () => fetchUser(fid), | ||
}); | ||
|
||
return ( | ||
<Dialog open={true} onOpenChange={onDismiss}> | ||
<DialogContent> | ||
<DialogTitle>Profile Details</DialogTitle> | ||
{query.isLoading && ( | ||
<DialogDescription className="flex items-center justify-center"> | ||
<Loader2Icon className="animate-spin" /> | ||
</DialogDescription> | ||
)} | ||
{query.isError && ( | ||
<DialogDescription className="flex flex-col items-center justify-center text-red-500"> | ||
<TriangleAlertIcon className="mb-2 w-6 h-6" /> | ||
<span className="font-semibold">Unexpected error occurred</span> | ||
</DialogDescription> | ||
)} | ||
{query.isSuccess && ( | ||
<DialogDescription className="flex flex-col gap-2 items-center justify-center"> | ||
<div className="flex items-center"> | ||
<div className="aspect-square h-[80px] w-[80px] rounded-full overflow-hidden"> | ||
<img | ||
className="w-full h-full object-contain" | ||
src={query.data.pfp_url} | ||
alt={query.data.username} | ||
width={80} | ||
/> | ||
</div> | ||
</div> | ||
<strong className="text-lg">{query.data.username}</strong> | ||
<div className="grid grid-cols-2 gap-4 text-sm text-gray-500 text-center"> | ||
<div> | ||
<strong>{formatCount(query.data.follower_count)}</strong>{" "} | ||
followers | ||
</div> | ||
<div> | ||
<strong>{formatCount(query.data.following_count)}</strong>{" "} | ||
following | ||
</div> | ||
</div> | ||
<span>{query.data.profile.bio.text}</span> | ||
</DialogDescription> | ||
)} | ||
</DialogContent> | ||
</Dialog> | ||
); | ||
} | ||
|
||
function formatCount(count: number): string { | ||
if (count < 1000) { | ||
return count.toString(); | ||
} else if (count >= 1000 && count < 1000000) { | ||
return (count / 1000).toFixed(1) + "K"; | ||
} | ||
|
||
return (count / 1000000).toFixed(1) + "M"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import type { NextRequest } from "next/server"; | ||
import { z } from "zod"; | ||
|
||
const validator = z.object({ | ||
fid: z.coerce.number().int().positive(), | ||
}); | ||
|
||
export async function GET( | ||
_: NextRequest, | ||
{ params }: { params: { fid: string } } | ||
) { | ||
try { | ||
const { fid } = validator.parse(params); | ||
|
||
const url = new URL("https://api.neynar.com/v2/farcaster/user/bulk"); | ||
|
||
url.searchParams.set("fids", fid.toString()); | ||
|
||
const response = await fetch(url, { | ||
headers: { | ||
accept: "application/json", | ||
"x-api-key": "NEYNAR_FRAMES_JS", | ||
}, | ||
}); | ||
|
||
if (!response.ok) { | ||
if (response.status === 404) { | ||
return Response.json({ error: "User not found" }, { status: 404 }); | ||
} | ||
|
||
throw new Error(`Unexpected response: ${response.status}`); | ||
} | ||
|
||
const data = await response.json(); | ||
|
||
return Response.json(data.users[0]); | ||
} catch (e) { | ||
if (e instanceof z.ZodError) { | ||
return Response.json({ error: e.errors }, { status: 400 }); | ||
} | ||
|
||
throw e; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { sha512 } from "@noble/hashes/sha512"; | ||
import { etc, getPublicKey, sign, verify } from "@noble/ed25519"; | ||
|
||
if (!etc.sha512Sync) { | ||
etc.sha512Sync = (...m: Uint8Array[]) => sha512(etc.concatBytes(...m)); | ||
} | ||
|
||
export { getPublicKey, sign, verify }; |
Oops, something went wrong.