diff --git a/renderer/components/Charts/DataRelated.tsx b/renderer/components/Charts/DataRelated.tsx new file mode 100644 index 0000000..4abec6e --- /dev/null +++ b/renderer/components/Charts/DataRelated.tsx @@ -0,0 +1,73 @@ +import { BottomArrow, DataRelatedChart, TopArrow } from "../../types/Charts"; + +export default function DataRelated({ + data_package, + storage_available, + total_size, +}: DataRelatedChart) { + return ( +
+
+ +
+ +
+ +
+ +
+ +
+
+ ); +} + +function TopArrow({ value, unit, color }: TopArrow) { + return ( +
+
+ +
+ +
+ +
+ {value} {unit} +
+
+ ); +} + +function BottomArrow({ value, unit, color }: BottomArrow) { + return ( +
+
+ +
+ +
+ +
+ {value} {unit} +
+
+ ); +} diff --git a/renderer/pages/dashboard.tsx b/renderer/pages/dashboard.tsx index 3eff4e7..1c1fedd 100644 --- a/renderer/pages/dashboard.tsx +++ b/renderer/pages/dashboard.tsx @@ -3,6 +3,10 @@ import { MainLayout } from "../layouts"; import { setMinorState, selectMinorState } from "../store/minorSlice"; import { useDispatch, useSelector } from "react-redux"; import ScrollSpy from "react-ui-scrollspy"; +import DataRelated from "../components/Charts/DataRelated"; +import { Metrics } from "../types/Minor"; +import { DataRelatedChart } from "../types/Charts"; +import { convertToGbFromPetabytes } from "../util/minor"; interface MenuItems { label: string; @@ -17,6 +21,20 @@ interface SubMenuItems { export default function DashboardPage() { const minorState = useSelector(selectMinorState); const dispatch = useDispatch(); + const [dataRelated, setDataRelated] = React.useState({ + data_package: { + size: 0, + unit: "GB", + }, + storage_available: { + size: 0, + unit: "GB", + }, + total_size: { + size: 0, + unit: "TB", + }, + }); const [activeMenu, setActiveMenu] = React.useState(); @@ -43,9 +61,29 @@ export default function DashboardPage() { React.useEffect(() => { (async () => { - const data = await window.ipc.requestMetrics(); + const data: Metrics = await window.ipc.requestMetrics(); + console.log("requestMetrics", data); + if (data) { + dispatch(setMinorState(data)); - dispatch(setMinorState(data)); + setDataRelated((prev) => { + return { + ...prev, + data_package: { + size: convertToGbFromPetabytes(data.data_packaged) || 0, + unit: "GB", + }, + storage_available: { + size: convertToGbFromPetabytes(data.data_unpackaged) || 0, + unit: "GB", + }, + total_size: { + size: data.data_packaged + data.data_unpackaged, + unit: "TB", + }, + }; + }); + } })(); }, []); @@ -120,10 +158,11 @@ export default function DashboardPage() {

Data Related

-

Data packaged: {minorState.data_packaged}

- {minorState.data_unpackaged ? ( -

Data unpackaged: {minorState.data_unpackaged}

- ) : null} +

Hash Rate

diff --git a/renderer/types/Charts.ts b/renderer/types/Charts.ts new file mode 100644 index 0000000..081a853 --- /dev/null +++ b/renderer/types/Charts.ts @@ -0,0 +1,26 @@ +export type DataRelatedChart = { + data_package: { + size: number; + unit: string; + }; + storage_available: { + size: number; + unit: string; + }; + total_size: { + size: number; + unit: string; + }; +}; + +export type TopArrow = { + value: number; + unit: string; + color: string; +}; + +export type BottomArrow = { + value: number; + unit: string; + color: string; +}; diff --git a/renderer/types/Minor.ts b/renderer/types/Minor.ts index d1c0fcc..4c1af70 100644 --- a/renderer/types/Minor.ts +++ b/renderer/types/Minor.ts @@ -9,3 +9,11 @@ export type MinorParser = { }; }[]; }; + +export type Metrics = { + data_packaged: number; + data_unpackaged: number; + earnings: number; + hash_rate: number; + vdf_time_lower_bound: number; +}; diff --git a/renderer/util/minor.ts b/renderer/util/minor.ts new file mode 100644 index 0000000..57cdff2 --- /dev/null +++ b/renderer/util/minor.ts @@ -0,0 +1,4 @@ +export function convertToGbFromPetabytes(value: number): number { + const gigabytes = value * 1e9; // 1 petabyte = 1e9 gigabytes + return parseFloat(gigabytes.toFixed(2)); +}