diff --git a/src/components/traffic.tsx b/src/components/traffic.tsx index 51c1b83f2d4d3c2b7082f8cfe21bf037d7561e0e..27863064e9b4862e3f3dc504c610d67b33b54c04 100644 --- a/src/components/traffic.tsx +++ b/src/components/traffic.tsx @@ -54,7 +54,7 @@ const Traffic = () => { color={+up > 0 ? "primary" : "disabled"} /> <Typography {...valStyle}>{up}</Typography> - <Typography {...unitStyle}>{upUnit}</Typography> + <Typography {...unitStyle}>{upUnit}/s</Typography> </Box> <Box display="flex" alignItems="center" whiteSpace="nowrap"> @@ -63,7 +63,7 @@ const Traffic = () => { color={+down > 0 ? "primary" : "disabled"} /> <Typography {...valStyle}>{down}</Typography> - <Typography {...unitStyle}>{downUnit}</Typography> + <Typography {...unitStyle}>{downUnit}/s</Typography> </Box> </Box> ); diff --git a/src/utils/parse-traffic.ts b/src/utils/parse-traffic.ts index 529cc3d09bd09c86486d9279763fb7ef5cac0613..b19e31fd3dab7dd8f010cd43105e1f8b6accf8fc 100644 --- a/src/utils/parse-traffic.ts +++ b/src/utils/parse-traffic.ts @@ -1,3 +1,10 @@ +/** + * parse the traffic to + * xxx B + * xxx KB + * xxx MB + * xxx GB + */ const parseTraffic = (num: number) => { const gb = 1024 ** 3; const mb = 1024 ** 2; @@ -5,7 +12,7 @@ const parseTraffic = (num: number) => { let t = num; let u = "B"; - if (num < 1000) return [`${Math.round(t)}`, "B/s"]; + if (num < 1000) return [`${Math.round(t)}`, "B"]; if (num <= mb) { t = num / kb; u = "KB"; @@ -16,8 +23,8 @@ const parseTraffic = (num: number) => { t = num / gb; u = "GB"; } - if (t >= 100) return [`${Math.round(t)}`, `${u}/s`]; - return [`${Math.round(t * 10) / 10}`, `${u}/s`]; + if (t >= 100) return [`${Math.round(t)}`, u]; + return [`${Math.round(t * 10) / 10}`, u]; }; export default parseTraffic;