cyberia/research/events/client/src/shared/lib/formatTicketPriceRange.ts

import { formatUsdt } from "@/shared/lib/money/usdt";

/**
 * Ticket price range as returned from the API.
 * The API returns { [key: string]: string | null } where values are micro-units (USDT 6 decimals).
 */
type ApiTicketPriceRange = {
  [key: string]: string | null;
};

/**
 * Formats the ticket price range for display.
 * Shows "<min>" format.
 * Returns null if no tickets are available (all categories sold out).
 *
 * @param priceRange - Object containing min and max prices from API
 * @returns Formatted price string with currency symbol, or null if unavailable
 */
export function formatTicketPriceRange(
  priceRange: ApiTicketPriceRange | undefined,
): string | null {
  if (!priceRange) {
    return null;
  }

  const min = priceRange.min;

  // All categories sold out
  if (min == null) {
    return null;
  }

  return formatUsdt(BigInt(min));
}

/**
 * Gets a simple display string for the ticket price range without currency symbol.
 * Used when the currency symbol is displayed separately.
 *
 * @param priceRange - Object containing min and max prices from API
 * @returns Formatted price string (e.g., "50"), or null if unavailable
 */
export function getTicketPriceRangeDisplay(
  priceRange: ApiTicketPriceRange | undefined,
): string | null {
  if (!priceRange) {
    return null;
  }

  const min = priceRange.min;

  // All categories sold out
  if (min == null) {
    return null;
  }

  return formatUsdt(BigInt(min));
}

Graph