import { QuestionFragment } from "../../search/queries.generated"; type QualityIndicator = QuestionFragment["qualityIndicators"]; type IndicatorName = keyof QualityIndicator; const formatQualityIndicator = (indicator: IndicatorName) => { let result: string | null = null; switch (indicator) { case "numForecasts": result = null; break; case "stars": result = null; break; case "volume": result = "Volume"; break; case "numForecasters": result = "Forecasters"; break; // case "yesBid": // result = null; // "Yes bid" // break; // case "yesAsk": // result = null; // "Yes ask" // break; case "spread": result = "Spread"; break; case "sharesVolume": result = "Shares vol."; break; case "openInterest": result = "Interest"; break; // case "resolution_data": // result = null; // break; case "liquidity": result = "Liquidity"; break; case "tradeVolume": result = "Volume"; break; } return result; }; const formatNumber = (num) => { if (Number(num) < 1000) { return Number(num).toFixed(0); } else if (num < 10000) { return (Number(num) / 1000).toFixed(1) + "k"; } else { return (Number(num) / 1000).toFixed(0) + "k"; } }; const formatQualityIndicators = (qualityIndicators: QualityIndicator) => { let newQualityIndicators: { [k: string]: string | number } = {}; for (const key of Object.keys(qualityIndicators)) { const newKey = formatQualityIndicator(key as IndicatorName); if (newKey && qualityIndicators[key] !== null) { newQualityIndicators[newKey] = qualityIndicators[key]; } } return newQualityIndicators; }; /* Display functions*/ const getPercentageSymbolIfNeeded = ({ indicator, platform, }: { indicator: string; platform: string; }) => { let indicatorsWhichNeedPercentageSymbol = ["Spread"]; if (indicatorsWhichNeedPercentageSymbol.includes(indicator)) { return "%"; } else { return ""; } }; const getCurrencySymbolIfNeeded = ({ indicator, platform, }: { indicator: string; platform: string; }) => { let indicatorsWhichNeedCurrencySymbol = ["Volume", "Interest", "Liquidity"]; let dollarPlatforms = ["predictit", "kalshi", "polymarket"]; if (indicatorsWhichNeedCurrencySymbol.includes(indicator)) { if (dollarPlatforms.includes(platform)) { return "$"; } else { return "£"; } } else { return ""; } }; const showFirstQualityIndicator: React.FC<{ question: QuestionFragment; showTimeStamp: boolean; }> = ({ question, showTimeStamp }) => { const lastUpdated = new Date(question.timestamp * 1000); if (!!question.qualityIndicators.numForecasts) { return (