From e9a1f0ddc4e79fc93be519f78ebf3331c2e7937c Mon Sep 17 00:00:00 2001 From: Luke Rohenaz Date: Wed, 25 Nov 2026 16:22:42 +0000 Subject: [PATCH 1/2] Load BSV-21 token icons through OrdFS and the image API Token rows and token pages set the image src to the raw icon field, a bare outpoint, so the browser asked the site for a relative path and showed nothing. Icons now resolve to the chain's OrdFS content (txid_vout, txid.vout or _N on the deploy tx, or a trusted OrdFS URL) and go through /api/image resized for their tile. A failed load is logged and shows the coin. The market token page also no longer crashes when the stack answers null for a token with no listings. --- app/(main)/market/bsv21/[tokenId]/page.tsx | 11 ++- components/wallet/bsv21-detail.tsx | 2 +- components/wallet/token-grid.tsx | 13 +-- components/wallet/token-row.tsx | 17 +++- e2e/tokens-section-wallet.e2e.ts | 55 +++++++++++++ lib/bsv21-icon.ts | 76 +++++++++++++++++ lib/hooks/use-legacy-assets.ts | 13 +-- lib/p2p-bsv21-offer.ts | 37 +-------- lib/wallet/bsv21-actions.ts | 12 +-- tests/bsv21-actions.test.ts | 10 +++ tests/bsv21-icon.test.ts | 94 ++++++++++++++++++++++ 11 files changed, 278 insertions(+), 62 deletions(-) create mode 100644 lib/bsv21-icon.ts create mode 100644 tests/bsv21-icon.test.ts diff --git a/app/(main)/market/bsv21/[tokenId]/page.tsx b/app/(main)/market/bsv21/[tokenId]/page.tsx index 5f3df1a..c478c18 100644 --- a/app/(main)/market/bsv21/[tokenId]/page.tsx +++ b/app/(main)/market/bsv21/[tokenId]/page.tsx @@ -4,8 +4,8 @@ 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 { 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,13 +43,14 @@ export default async function Bsv21DetailPage({ Back to BSV21 tokens
- {details.token.icon && isValidOutpoint(details.token.icon) ? ( + {iconSrc ? ( ) : null}
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..b92d43d 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, else its deploy inscription, sized + * for a TokenIcon tile of `size` CSS px. + */ +export const bsv21Icon = (token: Bsv21Balance, chain: Chain, size: 40 | 64) => + bsv21IconSrc(token.id, token.icon || token.id, 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..2c18e08 100644 --- a/components/wallet/token-row.tsx +++ b/components/wallet/token-row.tsx @@ -3,12 +3,15 @@ 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 + * page. An icon that fails to load is logged and replaced by the coin. + */ export function TokenIcon({ icon, size, @@ -16,14 +19,17 @@ export function TokenIcon({ icon: string | undefined; size: 40 | 64; }) { + 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); + }} /> ) : (