diff --git a/src/app/dashboard/ShieldedPoolDashboard.tsx b/src/app/dashboard/ShieldedPoolDashboard.tsx index 4b9f224..61e4590 100644 --- a/src/app/dashboard/ShieldedPoolDashboard.tsx +++ b/src/app/dashboard/ShieldedPoolDashboard.tsx @@ -4,7 +4,7 @@ import { useEffect, useState } from "react"; import Button from "@/components/Button/Button"; import Checkbox from "@/components/Checkbox/Checkbox"; import Tools from "@/components/tools"; -import ZecToZatsConverter from "@/components/Converter/ZecToZatsConverter"; // Import Zec to Zats Converter +import ZecToZatsConverter from "@/components/Converter/ZecToZatsConverter"; import useExportDashboardAsPNG from "@/hooks/useExportDashboardAsPNG"; import dynamic from "next/dynamic"; @@ -81,6 +81,68 @@ interface ShieldedTxCount { timestamp: string; } +async function getBlockchainData(): Promise { + try { + const response = await fetch( + "https://api.blockchair.com/zcash/stats?key=A___8A4ebOe3KJT9bqiiOHWnJbCLpDUZ" + ); + if (!response.ok) { + console.error("Failed to fetch blockchain data:", response.statusText); + return null; + } + const data = await response.json(); + return data.data as BlockchainInfo; + } catch (error) { + console.error("Error fetching blockchain data:", error); + return null; + } +} + +async function getBlockchainInfo(): Promise { + try { + const response = await fetch(blockchainInfoUrl, { mode: "cors" }); + if (!response.ok) { + console.error("Failed to fetch blockchain info:", response.statusText); + return null; + } + const data = await response.json(); + return data.chainSupply?.chainValue ?? null; + } catch (error) { + console.error("Error fetching blockchain info:", error); + return null; + } +} + +async function getSupplyData(url: string): Promise { + try { + const response = await fetch(url); + if (!response.ok) { + console.error("Failed to fetch supply data:", response.statusText); + return []; + } + const data = await response.json(); + return data as SupplyData[]; + } catch (error) { + console.error("Error fetching supply data:", error); + return []; + } +} + +async function getLastUpdatedDate(): Promise { + try { + const response = await fetch(apiUrl); + if (!response.ok) { + console.error("Failed to fetch last updated date:", response.statusText); + return "N/A"; + } + const data = await response.json(); + return data[0]?.commit?.committer?.date ?? "N/A"; + } catch (error) { + console.error("Error fetching last updated date:", error); + return "N/A"; + } +} + const ShieldedPoolDashboard = () => { const [selectedPool, setSelectedPool] = useState("default"); const [blockchainInfo, setBlockchainInfo] = useState( @@ -91,15 +153,11 @@ const ShieldedPoolDashboard = () => { const [saplingSupply, setSaplingSupply] = useState(null); const [orchardSupply, setOrchardSupply] = useState(null); const [lastUpdated, setLastUpdated] = useState(null); - const [shieldedTxCount, setShieldedTxCount] = - useState(null); const [selectedTool, setSelectedTool] = useState("supply"); const [selectedToolName, setSelectedToolName] = useState( "Shielded Supply Chart (ZEC)" ); - const [cumulativeCheck, setCumulativeCheck] = useState(true); - const [filterSpamCheck, setFilterSpamCheck] = useState(false); const { divChartRef, handleSaveToPng } = useExportDashboardAsPNG(); @@ -111,8 +169,6 @@ const ShieldedPoolDashboard = () => { return saplingUrl; case "orchard": return orchardUrl; - case "hashrate": - return hashrateUrl; default: return defaultUrl; } @@ -132,112 +188,110 @@ const ShieldedPoolDashboard = () => { }; const getTotalShieldedSupply = () => { - const totalSupply = + return ( (sproutSupply?.supply ?? 0) + (saplingSupply?.supply ?? 0) + - (orchardSupply?.supply ?? 0); - return totalSupply; - }; - - const handleToolChange = (tool: string) => { - setSelectedTool(tool); - switch (tool) { - case "supply": - setSelectedPool("default"); - setSelectedToolName("Shielded Supply Chart (ZEC)"); - break; - case "transaction": - setSelectedPool("default"); - setSelectedToolName("Shielded Transactions Chart (ZEC)"); - break; - } + (orchardSupply?.supply ?? 0) + ); }; useEffect(() => { - const fetchLastUpdatedDate = async () => { + const fetchBlockchainInfo = async () => { + try { + const response = await fetch(defaultUrl); + const data = await response.json(); + setBlockchainInfo(data); + } catch (error) { + console.error("Error fetching blockchain info:", error); + } + }; + + const fetchLastUpdated = async () => { try { const response = await fetch(apiUrl); - if (!response.ok) { - console.error("Failed to fetch last updated date:", response.statusText); - setLastUpdated("N/A"); - return; - } const data = await response.json(); setLastUpdated(data[0]?.commit?.committer?.date ?? "N/A"); } catch (error) { console.error("Error fetching last updated date:", error); - setLastUpdated("N/A"); } }; - fetchLastUpdatedDate(); + fetchBlockchainInfo(); + fetchLastUpdated(); }, []); return (

{selectedToolName}

- + setSelectedTool(tool)} />
{selectedTool === "supply" && ( - + )} {selectedTool === "transaction" && ( )}
- + Last updated:{" "} {lastUpdated ? new Date(lastUpdated).toLocaleDateString() : "N/A"}
- {selectedTool === "supply" && ( -
-
-
-
- -
+ +
+
+
+ +
+
- )} +
); };