From fb3878389de6fd87f13b7bb9aeb5aa2e93253d88 Mon Sep 17 00:00:00 2001 From: Yana Date: Fri, 14 Feb 2025 19:16:43 +0200 Subject: [PATCH] WIP --- explorer-nextjs/src/app/api/index.tsx | 4 +- explorer-nextjs/src/app/api/urls.ts | 2 + .../landingPageComponents/NoiseCard.tsx | 56 ++++++++++++++++--- .../src/components/nodeTable/NodeTable.tsx | 2 +- .../nymNodePageComponents/NodeRewardsCard.tsx | 3 +- 5 files changed, 54 insertions(+), 13 deletions(-) diff --git a/explorer-nextjs/src/app/api/index.tsx b/explorer-nextjs/src/app/api/index.tsx index 72da24e86b..91d8e9f408 100644 --- a/explorer-nextjs/src/app/api/index.tsx +++ b/explorer-nextjs/src/app/api/index.tsx @@ -16,7 +16,7 @@ import { CURRENT_EPOCH_REWARDS, DATA_OBSERVATORY_BALANCES_URL, DATA_OBSERVATORY_NODES_URL, - HARBOURMASTER_API_MIXNODES_STATS, + NS_API_MIXNODES_STATS, NYM_ACCOUNT_ADDRESS, NYM_NODES, NYM_PRICES_API, @@ -176,7 +176,7 @@ export const fetchOriginalStake = async (address: string): Promise => { }; export const fetchNoise = async (): Promise => { - const response = await fetch(HARBOURMASTER_API_MIXNODES_STATS, { + const response = await fetch(NS_API_MIXNODES_STATS, { headers: { Accept: "application/json", "Content-Type": "application/json; charset=utf-8", diff --git a/explorer-nextjs/src/app/api/urls.ts b/explorer-nextjs/src/app/api/urls.ts index aa0862c9d5..c00d145759 100644 --- a/explorer-nextjs/src/app/api/urls.ts +++ b/explorer-nextjs/src/app/api/urls.ts @@ -2,6 +2,8 @@ export const NYM_NODES = "https://explorer.nymtech.net/api/v1/tmp/unstable/nym-nodes"; export const HARBOURMASTER_API_MIXNODES_STATS = "https://harbourmaster.nymtech.net/v2/mixnodes/stats"; +export const NS_API_MIXNODES_STATS = + "https://mainnet-node-status-api.nymtech.cc/v2/mixnodes/stats"; export const CURRENT_EPOCH = "https://validator.nymtech.net/api/v1/epoch/current"; export const CURRENT_EPOCH_REWARDS = diff --git a/explorer-nextjs/src/components/landingPageComponents/NoiseCard.tsx b/explorer-nextjs/src/components/landingPageComponents/NoiseCard.tsx index b10b0511b0..2a15d05934 100644 --- a/explorer-nextjs/src/components/landingPageComponents/NoiseCard.tsx +++ b/explorer-nextjs/src/components/landingPageComponents/NoiseCard.tsx @@ -40,11 +40,44 @@ export const NoiseCard = () => { const todaysData = data[data.length - 1]; const yesterdaysData = data[data.length - 2]; + const filterData = ( + data: IPacketsAndStakingData[], + cutoffDateStr = "2025-02-11", + ): IPacketsAndStakingData[] => { + const cutoffDate = new Date(cutoffDateStr); + + return data.filter((entry) => new Date(entry.date_utc) >= cutoffDate); + }; + + console.log("filterData :>> ", filterData(data)); + const noiseLast24H = todaysData.total_packets_sent + todaysData.total_packets_received; const noisePrevious24H = yesterdaysData.total_packets_sent + yesterdaysData.total_packets_received; + const formatNoiseVolume = (packets: number): string => { + if (packets < 0) { + throw new Error("Packets cannot be negative"); + } + + const BYTES_PER_PACKET = 2048; + const totalBytes = packets * BYTES_PER_PACKET; + const units = ["B", "KB", "MB", "GB", "TB", "PB"]; + + let size = totalBytes; + let unitIndex = 0; + + // Convert to the most appropriate unit + for (; size >= 1024 && unitIndex < units.length - 1; unitIndex++) { + size /= 1024; + } + + return `${size.toFixed(2)} ${units[unitIndex]}`; + }; + + const formatedNoiseVolume = formatNoiseVolume(noiseLast24H); + const calculatePercentageChange = (last24H: number, previous24H: number) => { if (previous24H === 0) { return previous24H; @@ -59,23 +92,28 @@ export const NoiseCard = () => { const noiseLast24HFormatted = formatBigNum(noiseLast24H)?.toString() || ""; - const noiseLineGraphData = data.map((item: IPacketsAndStakingData) => { - return { - date_utc: item.date_utc, - numericData: item.total_packets_sent + item.total_packets_received, - }; - }); + const noiseLineGraphData = filterData(data).map( + (item: IPacketsAndStakingData) => { + return { + date_utc: item.date_utc, + numericData: item.total_packets_sent + item.total_packets_received, + }; + }, + ); return ( - + {noiseLast24HFormatted} - + + ({formatedNoiseVolume}) + + 0} diff --git a/explorer-nextjs/src/components/nodeTable/NodeTable.tsx b/explorer-nextjs/src/components/nodeTable/NodeTable.tsx index 85cec9762a..7760368098 100644 --- a/explorer-nextjs/src/components/nodeTable/NodeTable.tsx +++ b/explorer-nextjs/src/components/nodeTable/NodeTable.tsx @@ -206,7 +206,7 @@ const NodeTable = ({ nodes }: { nodes: MappedNymNodes }) => { Header: Qlt of Service, Cell: ({ row }) => ( - {row.original.qualityOfService}% + {row.original.qualityOfService.toFixed()}% ), }, diff --git a/explorer-nextjs/src/components/nymNodePageComponents/NodeRewardsCard.tsx b/explorer-nextjs/src/components/nymNodePageComponents/NodeRewardsCard.tsx index 097e31e6f8..cb57cd3e82 100644 --- a/explorer-nextjs/src/components/nymNodePageComponents/NodeRewardsCard.tsx +++ b/explorer-nextjs/src/components/nymNodePageComponents/NodeRewardsCard.tsx @@ -61,10 +61,11 @@ export const NodeRewardsCard = ({ id }: INodeRewardsCardProps) => { // Extract reward details const rewardDetails: RewardingDetails = nodeInfo.rewarding_details; + console.log("rewardDetails :>> ", rewardDetails); // Calculated data const operatorRewards = Number(rewardDetails.operator) / 1_000_000; - const operatorRewardsFormated = `${operatorRewards} NYM`; + const operatorRewardsFormated = `${operatorRewards.toFixed(2)} NYM`; const profitMarginPercent = Number(rewardDetails.cost_params.profit_margin_percent) * 100;