Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update basic frame template #523

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 21 additions & 29 deletions templates/express/src/entry-server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,38 +14,30 @@ const frames = createFrames({
],
});

export const handleRequest = frames(async ctx => {
export const handleRequest = frames(async (ctx) => {
if (!ctx.message) {
return {
image: (
<div>
This is the initial frame which will be shown before the user has
interacted with the frame.
</div>
),
buttons: [<Button action="post">Say hello</Button>],
};
}

if (!ctx.message.isValid) {
throw new Error("Invalid message");
}

return {
image: ctx.message ? (
<div
style={{
display: "flex",
flexDirection: "column",
}}
>
GM, {ctx.message.requesterUserData?.displayName}! Your FID is{" "}
image: (
<div>
Hello {ctx.message.requesterUserData?.displayName}! Your FID is{" "}
{ctx.message.requesterFid}
{", "}
{ctx.message.requesterFid < 20_000
? "you're OG!"
: "welcome to the Farcaster!"}
</div>
) : (
<div
style={{
display: "flex",
flexDirection: "column",
}}
>
Say GM
</div>
),
buttons: !ctx.url.searchParams.has("saidGm")
? [
<Button action="post" key="1" target={{ query: { saidGm: true } }}>
Say GM
</Button>,
]
: [],
buttons: [],
};
});
50 changes: 21 additions & 29 deletions templates/hono/src/server.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,39 +18,31 @@ const frames = createFrames({
],
});

const handleRequest = frames(async ctx => {
const handleRequest = frames(async (ctx) => {
if (!ctx.message) {
return {
image: (
<div>
This is the initial frame which will be shown before the user has
interacted with the frame.
</div>
),
buttons: [<Button action="post">Say hello</Button>],
};
}

if (!ctx.message.isValid) {
throw new Error("Invalid message");
}

return {
image: ctx.message ? (
<div
style={{
display: "flex",
flexDirection: "column",
}}
>
GM, {ctx.message.requesterUserData?.displayName}! Your FID is{" "}
image: (
<div>
Hello {ctx.message.requesterUserData?.displayName}! Your FID is{" "}
{ctx.message.requesterFid}
{", "}
{ctx.message.requesterFid < 20_000
? "you're OG!"
: "welcome to the Farcaster!"}
</div>
) : (
<div
style={{
display: "flex",
flexDirection: "column",
}}
>
Say GM
</div>
),
buttons: !ctx.url.searchParams.has("saidGm")
? [
<Button action="post" key="1" target={{ query: { saidGm: true } }}>
Say GM
</Button>,
]
: [],
buttons: [],
};
});

Expand Down
16 changes: 16 additions & 0 deletions templates/next/app/frames/frames.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { farcasterHubContext } from "frames.js/middleware";
import { createFrames } from "frames.js/next";

export const frames = createFrames({
basePath: "/frames",
middleware: [
farcasterHubContext({
// remove if you aren't using @frames.js/debugger or you just don't want to use the debugger hub
...(process.env.NODE_ENV === "production"
? {}
: {
hubHttpUrl: "http://localhost:3010/hub",
}),
}),
],
});
66 changes: 22 additions & 44 deletions templates/next/app/frames/route.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,31 @@
import { farcasterHubContext } from "frames.js/middleware";
import { createFrames, Button } from "frames.js/next";

const frames = createFrames({
basePath: '/frames',
middleware: [
farcasterHubContext({
// remove if you aren't using @frames.js/debugger or you just don't want to use the debugger hub
...(process.env.NODE_ENV === "production"
? {}
: {
hubHttpUrl: "http://localhost:3010/hub",
}),
}),
],
});
import { Button } from "frames.js/next";
import { frames } from "./frames";

const handleRequest = frames(async (ctx) => {
if (!ctx.message) {
return {
image: (
<div>
This is the initial frame which will be shown before the user has
interacted with the frame.
</div>
),
buttons: [<Button action="post">Say hello</Button>],
};
}

if (!ctx.message.isValid) {
throw new Error("Invalid message");
}

return {
image: ctx.message ? (
<div
style={{
display: "flex",
flexDirection: "column",
}}
>
GM, {ctx.message.requesterUserData?.displayName}! Your FID is{" "}
image: (
<div>
Hello {ctx.message.requesterUserData?.displayName}! Your FID is{" "}
{ctx.message.requesterFid}
{", "}
{ctx.message.requesterFid < 20_000
? "you're OG!"
: "welcome to the Farcaster!"}
</div>
) : (
<div
style={{
display: "flex",
flexDirection: "column",
}}
>
Say GM
</div>
),
buttons: !ctx.url.searchParams.has("saidGm")
? [
<Button action="post" target={{ query: { saidGm: true } }}>
Say GM
</Button>,
]
: [],
buttons: [],
};
});

Expand Down
Loading