Skip to content

Commit 28dcd4f

Browse files
authored
fix: update basic frame template (#523)
1 parent e456e74 commit 28dcd4f

4 files changed

Lines changed: 80 additions & 102 deletions

File tree

templates/express/src/entry-server.tsx

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,30 @@ const frames = createFrames({
1414
],
1515
});
1616

17-
export const handleRequest = frames(async ctx => {
17+
export const handleRequest = frames(async (ctx) => {
18+
if (!ctx.message) {
19+
return {
20+
image: (
21+
<div>
22+
This is the initial frame which will be shown before the user has
23+
interacted with the frame.
24+
</div>
25+
),
26+
buttons: [<Button action="post">Say hello</Button>],
27+
};
28+
}
29+
30+
if (!ctx.message.isValid) {
31+
throw new Error("Invalid message");
32+
}
33+
1834
return {
19-
image: ctx.message ? (
20-
<div
21-
style={{
22-
display: "flex",
23-
flexDirection: "column",
24-
}}
25-
>
26-
GM, {ctx.message.requesterUserData?.displayName}! Your FID is{" "}
35+
image: (
36+
<div>
37+
Hello {ctx.message.requesterUserData?.displayName}! Your FID is{" "}
2738
{ctx.message.requesterFid}
28-
{", "}
29-
{ctx.message.requesterFid < 20_000
30-
? "you're OG!"
31-
: "welcome to the Farcaster!"}
32-
</div>
33-
) : (
34-
<div
35-
style={{
36-
display: "flex",
37-
flexDirection: "column",
38-
}}
39-
>
40-
Say GM
4139
</div>
4240
),
43-
buttons: !ctx.url.searchParams.has("saidGm")
44-
? [
45-
<Button action="post" key="1" target={{ query: { saidGm: true } }}>
46-
Say GM
47-
</Button>,
48-
]
49-
: [],
41+
buttons: [],
5042
};
5143
});

templates/hono/src/server.tsx

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,31 @@ const frames = createFrames({
1818
],
1919
});
2020

21-
const handleRequest = frames(async ctx => {
21+
const handleRequest = frames(async (ctx) => {
22+
if (!ctx.message) {
23+
return {
24+
image: (
25+
<div>
26+
This is the initial frame which will be shown before the user has
27+
interacted with the frame.
28+
</div>
29+
),
30+
buttons: [<Button action="post">Say hello</Button>],
31+
};
32+
}
33+
34+
if (!ctx.message.isValid) {
35+
throw new Error("Invalid message");
36+
}
37+
2238
return {
23-
image: ctx.message ? (
24-
<div
25-
style={{
26-
display: "flex",
27-
flexDirection: "column",
28-
}}
29-
>
30-
GM, {ctx.message.requesterUserData?.displayName}! Your FID is{" "}
39+
image: (
40+
<div>
41+
Hello {ctx.message.requesterUserData?.displayName}! Your FID is{" "}
3142
{ctx.message.requesterFid}
32-
{", "}
33-
{ctx.message.requesterFid < 20_000
34-
? "you're OG!"
35-
: "welcome to the Farcaster!"}
36-
</div>
37-
) : (
38-
<div
39-
style={{
40-
display: "flex",
41-
flexDirection: "column",
42-
}}
43-
>
44-
Say GM
4543
</div>
4644
),
47-
buttons: !ctx.url.searchParams.has("saidGm")
48-
? [
49-
<Button action="post" key="1" target={{ query: { saidGm: true } }}>
50-
Say GM
51-
</Button>,
52-
]
53-
: [],
45+
buttons: [],
5446
};
5547
});
5648

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { farcasterHubContext } from "frames.js/middleware";
2+
import { createFrames } from "frames.js/next";
3+
4+
export const frames = createFrames({
5+
basePath: "/frames",
6+
middleware: [
7+
farcasterHubContext({
8+
// remove if you aren't using @frames.js/debugger or you just don't want to use the debugger hub
9+
...(process.env.NODE_ENV === "production"
10+
? {}
11+
: {
12+
hubHttpUrl: "http://localhost:3010/hub",
13+
}),
14+
}),
15+
],
16+
});

templates/next/app/frames/route.tsx

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,31 @@
1-
import { farcasterHubContext } from "frames.js/middleware";
2-
import { createFrames, Button } from "frames.js/next";
3-
4-
const frames = createFrames({
5-
basePath: '/frames',
6-
middleware: [
7-
farcasterHubContext({
8-
// remove if you aren't using @frames.js/debugger or you just don't want to use the debugger hub
9-
...(process.env.NODE_ENV === "production"
10-
? {}
11-
: {
12-
hubHttpUrl: "http://localhost:3010/hub",
13-
}),
14-
}),
15-
],
16-
});
1+
import { Button } from "frames.js/next";
2+
import { frames } from "./frames";
173

184
const handleRequest = frames(async (ctx) => {
5+
if (!ctx.message) {
6+
return {
7+
image: (
8+
<div>
9+
This is the initial frame which will be shown before the user has
10+
interacted with the frame.
11+
</div>
12+
),
13+
buttons: [<Button action="post">Say hello</Button>],
14+
};
15+
}
16+
17+
if (!ctx.message.isValid) {
18+
throw new Error("Invalid message");
19+
}
20+
1921
return {
20-
image: ctx.message ? (
21-
<div
22-
style={{
23-
display: "flex",
24-
flexDirection: "column",
25-
}}
26-
>
27-
GM, {ctx.message.requesterUserData?.displayName}! Your FID is{" "}
22+
image: (
23+
<div>
24+
Hello {ctx.message.requesterUserData?.displayName}! Your FID is{" "}
2825
{ctx.message.requesterFid}
29-
{", "}
30-
{ctx.message.requesterFid < 20_000
31-
? "you're OG!"
32-
: "welcome to the Farcaster!"}
33-
</div>
34-
) : (
35-
<div
36-
style={{
37-
display: "flex",
38-
flexDirection: "column",
39-
}}
40-
>
41-
Say GM
4226
</div>
4327
),
44-
buttons: !ctx.url.searchParams.has("saidGm")
45-
? [
46-
<Button action="post" target={{ query: { saidGm: true } }}>
47-
Say GM
48-
</Button>,
49-
]
50-
: [],
28+
buttons: [],
5129
};
5230
});
5331

0 commit comments

Comments
 (0)