celo-poll/app/poll/[id]/layout.tsx
2025-12-08 16:31:30 +03:00

90 lines
2.7 KiB
TypeScript

import { Metadata } from 'next'
import { getPollById } from '@/lib/db/polls'
import { getCurrentNetwork, BLOCK_EXPLORER_URL } from '@/lib/celo'
type Props = {
params: Promise<{ id: string }>
}
export async function generateMetadata({ params }: Props): Promise<Metadata> {
const { id } = await params
const poll = await getPollById(id)
if (!poll) {
return {
title: 'Poll Not Found - PollCelo',
description: 'The poll you\'re looking for doesn\'t exist.',
}
}
const appUrl = process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:3000'
const ogImageUrl = `${appUrl}/api/og?pollId=${poll.id}`
const pollUrl = `${appUrl}/poll/${poll.id}`
const totalVotes = poll.options.reduce((sum, opt) => sum + opt.votes, 0)
const timeUntilClose = poll.endTime - Date.now()
const hoursUntilClose = Math.max(0, Math.floor(timeUntilClose / (1000 * 60 * 60)))
const statusText = poll.status === 'active'
? `🟢 Live - ${hoursUntilClose}h left`
: '🔴 Closed'
return {
title: `${poll.question} - PollCelo`,
description: poll.description || `Vote with cUSD and win rewards! ${totalVotes} votes • ${statusText}`,
keywords: ['poll', 'prediction', 'cUSD', 'celo', 'voting', 'rewards'],
// Open Graph
openGraph: {
title: poll.question,
description: poll.description || 'Vote with cUSD and win rewards!',
images: [ogImageUrl],
url: pollUrl,
type: 'website',
siteName: 'PollCelo',
},
// Twitter Card
twitter: {
card: 'summary_large_image',
title: poll.question,
description: poll.description || 'Vote with cUSD and win rewards!',
images: [ogImageUrl],
creator: '@pollcelo',
},
// FarCastor Mini App Metadata
other: {
"fc:miniapp": JSON.stringify({
version: "1",
imageUrl: ogImageUrl,
button: {
title: poll.status === 'active' ? "Vote Now" : "View Results",
action: {
type: "launch_frame",
name: "PollCelo",
url: pollUrl,
splashImageUrl: `${appUrl}/icon.png`,
splashBackgroundColor: "#10B981"
}
}
}),
// Poll-specific data (JSON)
'pollcelo:poll:id': poll.id,
'pollcelo:poll:status': poll.status,
'pollcelo:poll:total_votes': totalVotes.toString(),
'pollcelo:poll:total_pot': poll.totalPot.toString(),
'pollcelo:poll:ends_at': poll.endTime.toString(),
'pollcelo:network': getCurrentNetwork().name,
},
}
}
export default function PollLayout({ children }: { children: React.ReactNode }) {
return (
<div className="min-h-screen bg-gray-50">
{children}
</div>
)
}