/* eslint-disable import/no-unused-modules */ import { ImageResponse } from '@vercel/og' import React from 'react' import { WATERMARK_URL } from '../../../constants' import getColor from '../../../utils/getColor' import getFont from '../../../utils/getFont' import getNetworkLogoUrl from '../../../utils/getNetworkLogoURL' import { getRequest } from '../../../utils/getRequest' import getToken from '../../../utils/getToken' export const onRequest: PagesFunction = async ({ params, request }) => { try { const origin = new URL(request.url).origin const { index } = params const networkName = String(index[0]) const tokenAddress = String(index[1]) const cacheUrl = origin + '/tokens/' + networkName + '/' + tokenAddress const data = await getRequest( cacheUrl, () => getToken(networkName, tokenAddress, cacheUrl), (data): data is NonNullable>> => Boolean(data.symbol && data.name) ) if (!data) { return new Response('Asset not found.', { status: 404 }) } const [fontData, palette] = await Promise.all([getFont(), getColor(data.ogImage)]) const networkLogo = getNetworkLogoUrl(networkName.toUpperCase()) // Capitalize name such that each word starts with a capital letter let words = data.name.split(' ') words = words.map((word) => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()) let name = words.join(' ') name = name.trim() return new ImageResponse( (
{data.ogImage ? ( {networkLogo != '' && ( )} ) : (
{data.name.slice(0, 3).toUpperCase()}
{networkLogo != '' && ( )}
)}
{name}
{data.symbol}
Uniswap
), { width: 1200, height: 630, fonts: [ { name: 'Inter', data: fontData, style: 'normal', }, ], } ) as Response } catch (error: any) { return new Response(error.message || error.toString(), { status: 500 }) } }