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:
@@ -35,7 +35,15 @@ export async function priceCollectionCards(
|
|||||||
const cardmarket = detail?.pricing?.cardmarket;
|
const cardmarket = detail?.pricing?.cardmarket;
|
||||||
if (cardmarket) {
|
if (cardmarket) {
|
||||||
const priceKey = variantPriceMap[card.variant ?? ""] ?? "avg";
|
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 };
|
return { ...card, price, totalPrice: price };
|
||||||
}),
|
}),
|
||||||
|
|||||||
@@ -53,16 +53,30 @@ const availableVariants = card.variants
|
|||||||
|
|
||||||
const variantPrices: { label: string; price: number }[] = [];
|
const variantPrices: { label: string; price: number }[] = [];
|
||||||
|
|
||||||
// Always include the base avg price (0 when no Cardmarket data)
|
// TCGdex quirk: when a card has a reverse variant but no holo variant,
|
||||||
variantPrices.push({ label: "Base", price: cardmarket?.avg ?? 0 });
|
// 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) {
|
for (const variant of availableVariants) {
|
||||||
if (variant === "normal") continue; // normal uses the base avg, already added
|
if (variant === "normal") continue; // normal uses the base avg, already added
|
||||||
const priceKey = variantPriceMap[variant];
|
const price = cardmarket?.[priceKeyFor(variant)];
|
||||||
const price = cardmarket?.[priceKey] ?? 0;
|
if (price != null) {
|
||||||
variantPrices.push({ label: variantLabels[variant] ?? variant, price });
|
variantPrices.push({ label: variantLabels[variant] ?? variant, price });
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Determine which tabs have content
|
// Determine which tabs have content
|
||||||
const hasAttacks = card.attacks && card.attacks.length > 0;
|
const hasAttacks = card.attacks && card.attacks.length > 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user