feat: use saved frame manifest from build script

This commit is contained in:
lucas-neynar
2025-03-18 10:02:05 -07:00
parent 583054cefb
commit a66e219438
7 changed files with 102 additions and 33 deletions

View File

@@ -1,9 +1,9 @@
import { NextResponse } from 'next/server';
import { generateFarcasterMetadata } from '../../../lib/utils';
import { getFarcasterMetadata } from '../../../lib/utils';
export async function GET() {
try {
const config = await generateFarcasterMetadata();
const config = await getFarcasterMetadata();
return NextResponse.json(config);
} catch (error) {
console.error('Error generating metadata:', error);

View File

@@ -4,16 +4,15 @@ import App from "./app";
const appUrl = process.env.NEXT_PUBLIC_URL;
// frame preview metadata
// question: do we need metadata both in this file and in the .well-known/farcaster.json file?
const appName = process.env.NEXT_PUBLIC_FRAME_NAME || "Frames v2 Demo";
const appName = process.env.NEXT_PUBLIC_FRAME_NAME;
const splashImageUrl = process.env.NEXT_PUBLIC_FRAME_SPLASH_IMAGE_URL || `${appUrl}/splash.png`;
const iconUrl = process.env.NEXT_PUBLIC_FRAME_ICON_IMAGE_URL || `${appUrl}/icon.png`;
const frame = {
const framePreviewMetadata = {
version: "next",
imageUrl: `${appUrl}/opengraph-image`,
button: {
title: process.env.NEXT_PUBLIC_FRAME_BUTTON_TEXT || "Launch Frame",
title: process.env.NEXT_PUBLIC_FRAME_BUTTON_TEXT,
action: {
type: "launch_frame",
name: appName,
@@ -32,10 +31,10 @@ export async function generateMetadata(): Promise<Metadata> {
title: appName,
openGraph: {
title: appName,
description: process.env.NEXT_PUBLIC_FRAME_DESCRIPTION || "A Farcaster Frames v2 demo app.",
description: process.env.NEXT_PUBLIC_FRAME_DESCRIPTION,
},
other: {
"fc:frame": JSON.stringify(frame),
"fc:frame": JSON.stringify(framePreviewMetadata),
},
};
}

View File

@@ -1,9 +1,28 @@
import { clsx, type ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"
import { type ClassValue, clsx } from 'clsx';
import { twMerge } from 'tailwind-merge';
import { mnemonicToAccount } from 'viem/accounts';
interface FrameMetadata {
accountAssociation?: {
header: string;
payload: string;
signature: string;
};
frame: {
version: string;
name: string;
iconUrl: string;
homeUrl: string;
imageUrl: string;
buttonTitle: string;
splashImageUrl: string;
splashBackgroundColor: string;
webhookUrl: string;
};
}
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
return twMerge(clsx(inputs));
}
export function getSecretEnvVars() {
@@ -17,7 +36,18 @@ export function getSecretEnvVars() {
return { seedPhrase, fid };
}
export async function generateFarcasterMetadata() {
export async function getFarcasterMetadata(): Promise<FrameMetadata> {
// First check for FRAME_METADATA in .env and use that if it exists
if (process.env.FRAME_METADATA) {
try {
const metadata = JSON.parse(process.env.FRAME_METADATA);
console.log('Using pre-signed frame metadata from environment');
return metadata;
} catch (error) {
console.warn('Failed to parse FRAME_METADATA from environment:', error);
}
}
const appUrl = process.env.NEXT_PUBLIC_URL;
if (!appUrl) {
throw new Error('NEXT_PUBLIC_URL not configured');