From 7532081076d036ef65bd3bbfdcc14cdf1aa295e7 Mon Sep 17 00:00:00 2001 From: squirrel <47972284+zksquirrel@users.noreply.github.com> Date: Sun, 24 Nov 2024 16:06:54 +0000 Subject: [PATCH] Update ShieldedPoolDashboard.tsx --- src/app/dashboard/ShieldedPoolDashboard.tsx | 259 +++----------------- 1 file changed, 40 insertions(+), 219 deletions(-) diff --git a/src/app/dashboard/ShieldedPoolDashboard.tsx b/src/app/dashboard/ShieldedPoolDashboard.tsx index 4983bfd..f23b056 100644 --- a/src/app/dashboard/ShieldedPoolDashboard.tsx +++ b/src/app/dashboard/ShieldedPoolDashboard.tsx @@ -4,6 +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 useExportDashboardAsPNG from "@/hooks/useExportDashboardAsPNG"; import dynamic from "next/dynamic"; @@ -27,7 +28,7 @@ const orchardUrl = "https://raw.githubusercontent.com/ZecHub/zechub-wiki/main/public/data/orchard_supply.json"; const hashrateUrl = "https://raw.githubusercontent.com/ZecHub/zechub-wiki/main/public/data/hashrate.json"; - + const txsummaryUrl = "https://raw.githubusercontent.com/ZecHub/zechub-wiki/main/public/data/transaction_summary.json"; @@ -150,7 +151,6 @@ async function getShieldedTxCount(): Promise { return null; } const data = await response.json(); - // Get the latest data entry and handle missing fields by defaulting to zero const latestData = data[data.length - 1] || {}; return { sapling: latestData.sapling || 0, @@ -165,18 +165,17 @@ async function getShieldedTxCount(): Promise { const ShieldedPoolDashboard = () => { const [selectedPool, setSelectedPool] = useState("default"); - const [blockchainInfo, setBlockchainInfo] = useState(null); + const [blockchainInfo, setBlockchainInfo] = useState( + null + ); const [circulation, setCirculation] = useState(null); const [sproutSupply, setSproutSupply] = useState(null); 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 [shieldedTxCount, setShieldedTxCount] = useState( + null + ); const { divChartRef, handleSaveToPng } = useExportDashboardAsPNG(); @@ -207,73 +206,14 @@ const ShieldedPoolDashboard = () => { getShieldedTxCount().then((data) => setShieldedTxCount(data ?? { sapling: 0, orchard: 0, timestamp: "N/A" }) ); - }, []); - useEffect(() => { - const fetchData = async () => { - const data = await getSupplyData(getDataUrl()); - setLastUpdated(data[data.length - 1]?.timestamp?.split("T")[0] || "N/A"); - }; - fetchData(); - }, [selectedPool]); - - const getDataUrl = () => { - switch (selectedPool) { - case "sprout": - return sproutUrl; - case "sapling": - return saplingUrl; - case "orchard": - return orchardUrl; - case "hashrate": - return hashrateUrl; - default: - return defaultUrl; - } - }; - - const getDataColor = () => { - switch (selectedPool) { - case "sprout": - return "#A020F0"; - case "sapling": - return "#FFA500"; - case "orchard": - return "#32CD32"; - default: - return "url(#area-background-gradient)"; - } - }; - 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; - } - }; - - const handleCumulativeChange = (checked: boolean) => { - setCumulativeCheck(checked); - }; - - const handleFilterChange = (checked: boolean) => { - setfilterSpamCheck(checked); + (orchardSupply?.supply ?? 0) + ); }; if (!blockchainInfo) { @@ -282,17 +222,12 @@ const ShieldedPoolDashboard = () => { return (
-

{selectedToolName}

+

Shielded Supply Chart (ZEC)

- +
- {selectedTool === 'supply' && ( - - )} - {selectedTool === 'transaction' && ( - - )} +
@@ -308,152 +243,38 @@ const ShieldedPoolDashboard = () => { sproutSupply, saplingSupply, orchardSupply, - }, selectedTool) + }) } />
- {selectedTool === 'supply' && ( -
+
-
-
- -
-
-
-
-
-
-
-
- )} - {selectedTool === 'transaction' && ( -
-
-
-
-
-
-
-
-
- -
-
- -
-
-
- )} - -
-
-

Market Cap

-

${blockchainInfo.market_cap_usd?.toLocaleString()}

-
-
-

ZEC in Circulation

-

{circulation?.toLocaleString() ?? "N/A"} ZEC

-
-
-

Market Price (USD)

-

${blockchainInfo.market_price_usd?.toFixed(2)}

-
-
-

Market Price (BTC)

-

{blockchainInfo.market_price_btc}

-
-
-

Blocks

-

{blockchainInfo.blocks?.toLocaleString()}

-
-
-

24h Transactions

-

{blockchainInfo.transactions_24h?.toLocaleString()}

-
-
-

Nodes

-

{blockchainInfo.nodes}

+
-
-

Shielded TX (24h)

-

- {shieldedTxCount - ? `Sapling: ${shieldedTxCount?.sapling?.toLocaleString()} | Orchard: ${shieldedTxCount.orchard?.toLocaleString()}` - : "N/A"} -

+
+