MCPcopy Create free account
hub / github.com/AmazingAng/PolyWorld / SmartMoneyPanel

Function SmartMoneyPanel

src/components/SmartMoneyPanel.tsx:40–183  ·  view source on GitHub ↗
({
  smartTrades,
  markets,
  walletFilter,
  onClearFilter,
  onSelectMarket,
  onSelectWallet,
}: SmartMoneyPanelProps)

Source from the content-addressed store, hash-verified

38type SmartMoneyTab = "trades" | "flow" | "signals";
39
40export default function SmartMoneyPanel({
41 smartTrades,
42 markets,
43 walletFilter,
44 onClearFilter,
45 onSelectMarket,
46 onSelectWallet,
47}: SmartMoneyPanelProps) {
48 const { t } = useI18n();
49 const [tab, setTab] = useState<SmartMoneyTab>("trades");
50 const [flows, setFlows] = useState<CategoryFlow[]>([]);
51 const [flowLoading, setFlowLoading] = useState(false);
52 const [newTradeThreshold] = useState(() => Date.now() - 60_000);
53
54 const fetchFlows = useCallback(async () => {
55 try {
56 const res = await fetch("/api/smart-money?view=flow");
57 if (!res.ok) return;
58 const data = await res.json();
59 if (data.flows) setFlows(data.flows);
60 } catch { /* non-critical */ }
61 setFlowLoading(false);
62 }, []);
63
64 const handleTabChange = useCallback((nextTab: SmartMoneyTab) => {
65 setTab(nextTab);
66 if (nextTab === "flow" && flows.length === 0) {
67 setFlowLoading(true);
68 void fetchFlows();
69 }
70 }, [fetchFlows, flows.length]);
71
72 useEffect(() => {
73 if (tab !== "flow") return;
74 const iv = setInterval(() => {
75 void fetchFlows();
76 }, 120_000);
77 return () => clearInterval(iv);
78 }, [fetchFlows, tab]);
79
80 const filteredTrades = useMemo(() => {
81 if (!walletFilter) return smartTrades;
82 return smartTrades.filter(
83 (tr) => tr.wallet.toLowerCase() === walletFilter.toLowerCase()
84 );
85 }, [smartTrades, walletFilter]);
86
87 return (
88 <div className="font-mono">
89 {/* Tab bar */}
90 <div className="flex items-center gap-0.5 mb-2">
91 {(["trades", "flow", "signals"] as SmartMoneyTab[]).map((tabId) => (
92 <button
93 key={tabId}
94 onClick={() => handleTabChange(tabId)}
95 className={`px-2 py-0.5 text-[10px] font-mono transition-colors ${
96 tab === tabId
97 ? "text-[var(--text)] bg-[var(--surface-hover)]"

Callers

nothing calls this directly

Calls 5

useI18nFunction · 0.90
formatVolumeFunction · 0.90
tradeKeyFunction · 0.85
truncAddrFunction · 0.70
timeAgoFunction · 0.70

Tested by

no test coverage detected