| 824 | } |
| 825 | |
| 826 | function ResolutionMonitorBadge({ eventId }: { eventId: string }) { |
| 827 | const { t } = useI18n(); |
| 828 | const [status, setStatus] = useState<{ sourceType: string; lastCheckedAt: string | null } | null>(null); |
| 829 | const [renderNow] = useState(() => Date.now()); |
| 830 | |
| 831 | useEffect(() => { |
| 832 | fetch(`/api/resolution-alerts?marketId=${eventId}`) |
| 833 | .then((r) => r.json()) |
| 834 | .then((data) => { if (data.monitor) setStatus(data.monitor); }) |
| 835 | .catch(() => {}); |
| 836 | }, [eventId]); |
| 837 | |
| 838 | if (!status) return null; |
| 839 | |
| 840 | const isMonitored = ["known_feed", "price_feed", "sports_feed"].includes(status.sourceType); |
| 841 | if (isMonitored) { |
| 842 | const ago = status.lastCheckedAt |
| 843 | ? `${Math.round((renderNow - new Date(status.lastCheckedAt).getTime()) / 60_000)}m ago` |
| 844 | : "pending"; |
| 845 | const monitorKey = status.sourceType === "price_feed" ? "detail.priceMonitored" : status.sourceType === "sports_feed" ? "detail.sportsMonitored" : "detail.rssMonitored"; |
| 846 | return ( |
| 847 | <span className="ml-2 text-[10px] text-[#22c55e]/70"> |
| 848 | {t(monitorKey, { ago })} |
| 849 | </span> |
| 850 | ); |
| 851 | } |
| 852 | |
| 853 | return ( |
| 854 | <span className="ml-2 text-[10px] text-[var(--text-ghost)]"> |
| 855 | {t("detail.notMonitorable")} |
| 856 | </span> |
| 857 | ); |
| 858 | } |