From 4486f734bb8a388deca4e6391ca7c695895f2dac Mon Sep 17 00:00:00 2001 From: Tunglies <77394545+Tunglies@users.noreply.github.com> Date: Sat, 28 Jun 2025 20:00:49 +0800 Subject: [PATCH] fix: correct traffic percentage calculation to handle zero total gracefully #3920 --- src/components/home/home-profile-card.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/components/home/home-profile-card.tsx b/src/components/home/home-profile-card.tsx index 8a02d1c8..183c4388 100644 --- a/src/components/home/home-profile-card.tsx +++ b/src/components/home/home-profile-card.tsx @@ -100,11 +100,9 @@ const ProfileDetails = ({ }, [current.extra]); const trafficPercentage = useMemo(() => { - if (!current.extra || !current.extra.total) return 1; - return Math.min( - Math.round((usedTraffic * 100) / (current.extra.total + 0.01)) + 1, - 100, - ); + if (!current.extra || !current.extra.total || current.extra.total <= 0) + return 0; + return Math.min(Math.round((usedTraffic / current.extra.total) * 100), 100); }, [current.extra, usedTraffic]); return (