diff --git a/app/(main)/market/bsv21/[tokenId]/page.tsx b/app/(main)/market/bsv21/[tokenId]/page.tsx index 5f3df1a..2978fa7 100644 --- a/app/(main)/market/bsv21/[tokenId]/page.tsx +++ b/app/(main)/market/bsv21/[tokenId]/page.tsx @@ -2,10 +2,10 @@ import { ArrowLeft } from "lucide-react"; import type { Metadata } from "next"; import Link from "next/link"; import { notFound } from "next/navigation"; -import ImageWithFallback from "@/components/image-with-fallback"; import { Bsv21DetailClient } from "@/components/market/bsv21-detail-client"; -import { createStackServices, stackContentUrl } from "@/lib/stack"; -import { isValidOutpoint } from "@/lib/validation"; +import { TokenIcon } from "@/components/wallet/token-row"; +import { bsv21IconSrc } from "@/lib/bsv21-icon"; +import { createStackServices } from "@/lib/stack"; import { formatBsv21Amount, getBsv21Listings, @@ -31,6 +31,8 @@ export default async function Bsv21DetailPage({ const decimals = Number.parseInt(details.token.dec ?? "0", 10); const symbol = details.token.sym || tokenId.slice(0, 8); const overlayFee = safeOverlayFee(details); + // Shown at 80px; ask the image API for 2x. + const iconSrc = bsv21IconSrc(tokenId, details.token.icon, 160); return (
@@ -41,15 +43,7 @@ export default async function Bsv21DetailPage({ Back to BSV21 tokens
- {details.token.icon && isValidOutpoint(details.token.icon) ? ( - - ) : null} +

{symbol}

diff --git a/app/api/image/route.ts b/app/api/image/route.ts index be7235e..a92e113 100644 --- a/app/api/image/route.ts +++ b/app/api/image/route.ts @@ -22,7 +22,7 @@ import { lookup } from "node:dns/promises"; import { ImageProtocols } from "bitcoin-image"; import { type NextRequest, NextResponse } from "next/server"; import sharp from "sharp"; -import { reportDiagnostic } from "@/lib/runtime-diagnostics"; +import { reportFailure } from "@/lib/runtime-diagnostics"; /** * SSRF protection: block requests to private/reserved IP ranges. @@ -246,23 +246,24 @@ export async function GET(request: NextRequest) { "X-Cache": "MISS", }, }); - } catch { - const diagnostic = reportDiagnostic({ - category: "route", - code: "route.unexpected", - operation: "api.image", - recoverable: true, - context: { route: "/api/image", retryable: true }, - }); - // Fallback error image - return new NextResponse( - `Image Error`, + } catch (error) { + // A 502, not a placeholder image: the page's onError must see the + // failure so it can show its own fallback. + const diagnostic = reportFailure( + { + category: "route", + code: "route.unexpected", + operation: "api.image", + recoverable: true, + context: { route: "/api/image", retryable: true }, + }, + error, + ); + return NextResponse.json( + { error: "Could not process the image" }, { - status: 200, - headers: { - "Content-Type": "image/svg+xml", - "X-Correlation-ID": diagnostic.correlationId, - }, + status: 502, + headers: { "X-Correlation-ID": diagnostic.correlationId }, }, ); } diff --git a/components/wallet/bsv21-detail.tsx b/components/wallet/bsv21-detail.tsx index 9b4d4c0..605e25f 100644 --- a/components/wallet/bsv21-detail.tsx +++ b/components/wallet/bsv21-detail.tsx @@ -222,7 +222,7 @@ export default function Bsv21Detail({ tokenId }: { tokenId: string }) { ) : null} } - icon={bsv21Icon(token, chain)} + icon={bsv21Icon(token, chain, 64)} id={token.id} idLabel="Token ID" status={ diff --git a/components/wallet/token-grid.tsx b/components/wallet/token-grid.tsx index 5c2c711..4a8d705 100644 --- a/components/wallet/token-grid.tsx +++ b/components/wallet/token-grid.tsx @@ -21,9 +21,9 @@ import { SoundDialog, } from "@/components/ui/sound-dialog"; import { useSound } from "@/hooks/use-sound"; +import { bsv21IconSrc } from "@/lib/bsv21-icon"; import type { Chain } from "@/lib/chain-endpoints"; import { useBsv21Availability } from "@/lib/hooks/use-stack-features"; -import { getOrdinalThumbnail } from "@/lib/image-utils"; import { reportDiagnostic } from "@/lib/runtime-diagnostics"; import { type AssetSurfaceState, @@ -75,9 +75,12 @@ export function Bsv21Unreadable({ state }: { state: AssetSurfaceState }) { ); } -/** A BSV-21 token's icon, else its deploy inscription's thumbnail. */ -export const bsv21Icon = (token: Bsv21Balance, chain: Chain) => - token.icon || getOrdinalThumbnail(token.id, 100, chain); +/** + * A BSV-21 token's icon through OrdFS, sized for a TokenIcon tile of `size` + * CSS px. No icon shows the coin: the deploy inscription is BSV-20 JSON. + */ +export const bsv21Icon = (token: Bsv21Balance, chain: Chain, size: 40 | 64) => + bsv21IconSrc(token.id, token.icon, size * 2, chain); /** Says why BSV-21 sends, mints and creates are off, once the stack has answered. */ export function Bsv21UnavailableNotice() { @@ -388,7 +391,7 @@ export default function TokenGrid() { amount={formatBsv21Amount(bsv21Spendable(token), token.dec)} caption={shortOutpoint(token.id)} href={tokenDetailHref("bsv21", token.id)} - icon={bsv21Icon(token, chain)} + icon={bsv21Icon(token, chain, 40)} key={token.id} ticker={bsv21Ticker(token)} /> diff --git a/components/wallet/token-row.tsx b/components/wallet/token-row.tsx index 9080073..e67bdd9 100644 --- a/components/wallet/token-row.tsx +++ b/components/wallet/token-row.tsx @@ -3,27 +3,39 @@ import { ChevronRight, Coins } from "lucide-react"; import Image from "next/image"; import Link from "next/link"; -import type { ReactNode } from "react"; +import { type ReactNode, useState } from "react"; import { Skeleton } from "@/components/ui/skeleton"; import { useSound } from "@/hooks/use-sound"; import { cn } from "@/lib/utils"; -/** A token's icon, else a coin, in a rounded tile: 40px in a row, 64 on its page. */ +/** + * A token's icon, else a coin, in a rounded tile: 40px in a row, 64 on its + * wallet page, 80 on its market page. An icon that fails to load is logged + * and replaced by the coin. + */ export function TokenIcon({ icon, size, }: { icon: string | undefined; - size: 40 | 64; + size: 40 | 64 | 80; }) { + const [failedSrc, setFailedSrc] = useState(null); + const showImage = Boolean(icon) && failedSrc !== icon; return (
- {icon ? ( + {icon && showImage ? ( { + console.error("[token-icon] image failed to load", { src: icon }); + setFailedSrc(icon); + }} /> ) : (