Fix variant pricing: resolve reverse prices from *-holo fields, hide unpriced rows

TCGdex publishes reverse-holo prices in avg-holo when a card has no holo
variant (e.g. swsh2-83: reverse=true, holo=false, avg-reverse absent).
Variant rows are now shown only when a real price exists, and collection
pricing resolves Reverse via avg-reverse ?? avg-holo ?? avg.
This commit is contained in:
2026-07-29 00:40:41 +02:00
parent 0c6fa47c84
commit ccf6ddad40
2 changed files with 29 additions and 7 deletions
+9 -1
View File
@@ -35,7 +35,15 @@ export async function priceCollectionCards(
const cardmarket = detail?.pricing?.cardmarket;
if (cardmarket) {
const priceKey = variantPriceMap[card.variant ?? ""] ?? "avg";
price = cardmarket[priceKey] ?? cardmarket.avg ?? 0;
// TCGdex quirk: reverse prices may live in the *-holo
// fields when the card has no holo variant
price =
cardmarket[priceKey] ??
(card.variant === "Reverse"
? cardmarket["avg-holo"]
: undefined) ??
cardmarket.avg ??
0;
}
return { ...card, price, totalPrice: price };
}),
+19 -5
View File
@@ -53,16 +53,30 @@ const availableVariants = card.variants
const variantPrices: { label: string; price: number }[] = [];
// Always include the base avg price (0 when no Cardmarket data)
variantPrices.push({ label: "Base", price: cardmarket?.avg ?? 0 });
// TCGdex quirk: when a card has a reverse variant but no holo variant,
// the reverse price is published in the *-holo fields (avg-reverse absent)
const priceKeyFor = (variant: string): string => {
if (variant === "reverse" && card.variants?.holo === false) {
return cardmarket?.["avg-reverse"] != null
? "avg-reverse"
: "avg-holo";
}
return variantPriceMap[variant];
};
// Add prices for each available variant
// Base price row, only when actually priced
if (cardmarket?.avg != null) {
variantPrices.push({ label: "Base", price: cardmarket.avg });
}
// Variant rows, only when the price actually exists
for (const variant of availableVariants) {
if (variant === "normal") continue; // normal uses the base avg, already added
const priceKey = variantPriceMap[variant];
const price = cardmarket?.[priceKey] ?? 0;
const price = cardmarket?.[priceKeyFor(variant)];
if (price != null) {
variantPrices.push({ label: variantLabels[variant] ?? variant, price });
}
}
// Determine which tabs have content
const hasAttacks = card.attacks && card.attacks.length > 0;