-
Notifications
You must be signed in to change notification settings - Fork 620
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(providers): add proxy provider traffic display support
- Loading branch information
Showing
3 changed files
with
59 additions
and
2 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
45 changes: 45 additions & 0 deletions
45
frontend/nyanpasu/src/components/providers/proxies-provider-traffic.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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import parseTraffic from "@/utils/parse-traffic"; | ||
import { LinearProgress, Tooltip } from "@mui/material"; | ||
import { ProxiesProviderProps } from "./proxies-provider"; | ||
|
||
export const ProxiesProviderTraffic = ({ provider }: ProxiesProviderProps) => { | ||
const calc = () => { | ||
let progress = 0; | ||
let total = 0; | ||
let used = 0; | ||
|
||
if (provider.subscriptionInfo) { | ||
const { | ||
Download: download, | ||
Upload: upload, | ||
Total: t, | ||
} = provider.subscriptionInfo; | ||
|
||
total = t ?? 0; | ||
|
||
used = (download ?? 0) + (upload ?? 0); | ||
|
||
progress = (used / (total ?? 0)) * 100; | ||
} | ||
|
||
return { progress, total, used }; | ||
}; | ||
|
||
const { progress, total, used } = calc(); | ||
|
||
return ( | ||
<div className="flex items-center justify-between gap-4"> | ||
<div className="w-full"> | ||
<LinearProgress variant="determinate" value={progress} /> | ||
</div> | ||
|
||
<Tooltip title={`${parseTraffic(used)} / ${parseTraffic(total)}`}> | ||
<div className="text-sm font-bold"> | ||
{((used / total) * 100).toFixed(2)}% | ||
</div> | ||
</Tooltip> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ProxiesProviderTraffic; |
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