-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: update ui for visualizer's stats. Signed-off-by: Eugene Panteleymonchuk <[email protected]> * feat: update stats panel. Signed-off-by: Eugene Panteleymonchuk <[email protected]> * feat: update stats panel. update styles, use hook. Signed-off-by: Eugene Panteleymonchuk <[email protected]> * feat: create networkStats hook, update components to prevent rerender. Signed-off-by: Eugene Panteleymonchuk <[email protected]> --------- Signed-off-by: Eugene Panteleymonchuk <[email protected]> Co-authored-by: Begoña Álvarez de la Cruz <[email protected]>
- Loading branch information
1 parent
59655f3
commit fc127e1
Showing
7 changed files
with
139 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 10 additions & 21 deletions
31
client/src/features/visualizer-threejs/wrapper/StatsPanel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,18 @@ | ||
import React from "react"; | ||
import { useNetworkStats } from "~helpers/stardust/hooks/useNetworkStats"; | ||
|
||
export const StatsPanel: React.FC<{ readonly blocksCount: number; readonly network: string }> = ({ blocksCount, network }) => { | ||
const [blocksPerSecond, confirmedBlocksPerSecond, confirmedBlocksPerSecondPercent] = useNetworkStats(network); | ||
import React, { memo } from "react"; | ||
import { useNetworkStats } from "~helpers/nova/hooks/useNetworkStats"; | ||
|
||
export const StatsPanel = ({ network }: { network: string }) => { | ||
const [blocksPerSecond] = useNetworkStats(network); | ||
return ( | ||
<div className="stats-panel-container"> | ||
<div className="card stats-panel"> | ||
<div className="card--content"> | ||
<div className="stats-panel__info"> | ||
<div className="card--label">Blocks</div> | ||
<div className="card--value">{blocksCount}</div> | ||
</div> | ||
<div className="stats-panel__info"> | ||
<div className="card--label">BPS / CBPS</div> | ||
<div className="card--value"> | ||
{blocksPerSecond} / {confirmedBlocksPerSecond} | ||
</div> | ||
</div> | ||
<div className="stats-panel__info"> | ||
<div className="card--label">Referenced Rate</div> | ||
<div className="card--value">{confirmedBlocksPerSecondPercent}</div> | ||
</div> | ||
<div className="card"> | ||
<div className="stats-panel__info"> | ||
<div className="card--label">BPS</div> | ||
<div className="card--value green">{blocksPerSecond}</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default memo(StatsPanel); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { useEffect, useState } from "react"; | ||
import { useIsMounted } from "~helpers/hooks/useIsMounted"; | ||
import { ServiceFactory } from "~factories/serviceFactory"; | ||
import { NOVA } from "~models/config/protocolVersion"; | ||
import { NovaApiClient } from "~services/nova/novaApiClient"; | ||
|
||
/** | ||
* Periodicaly refresh network stats. | ||
* @param network The network in context. | ||
* @returns The network stats. | ||
*/ | ||
export function useNetworkStats(network: string): [string] { | ||
const isMounted = useIsMounted(); | ||
const [apiClient] = useState(ServiceFactory.get<NovaApiClient>(`api-client-${NOVA}`)); | ||
const [updateTimerId, setUpdateTimerId] = useState<NodeJS.Timer | null>(null); | ||
const [blocksPerSecond, setBlocksPerSecond] = useState<string>("--"); | ||
|
||
useEffect(() => { | ||
if (network) { | ||
updateNetworkStats(); | ||
} | ||
|
||
return () => { | ||
if (updateTimerId) { | ||
clearTimeout(updateTimerId); | ||
setUpdateTimerId(null); | ||
} | ||
}; | ||
}, [network]); | ||
|
||
const updateNetworkStats = () => { | ||
if (isMounted && apiClient && network) { | ||
apiClient | ||
.stats({ | ||
network, | ||
includeHistory: true, | ||
}) | ||
.then((ips) => { | ||
const itemsPerSecond = ips.itemsPerSecond ?? 0; | ||
setBlocksPerSecond(itemsPerSecond >= 0 ? itemsPerSecond.toFixed(2) : "--"); | ||
}) | ||
.catch((err) => { | ||
console.error(err); | ||
}) | ||
.finally(() => { | ||
setUpdateTimerId(setTimeout(async () => updateNetworkStats(), 4000)); | ||
}); | ||
} | ||
}; | ||
|
||
return [blocksPerSecond]; | ||
} |