diff --git a/src/tribler/core/libtorrent/download_manager/download_state.py b/src/tribler/core/libtorrent/download_manager/download_state.py index 655a1d977e..e618521a43 100644 --- a/src/tribler/core/libtorrent/download_manager/download_state.py +++ b/src/tribler/core/libtorrent/download_manager/download_state.py @@ -6,7 +6,6 @@ from __future__ import annotations import logging -import math from enum import Enum from typing import TYPE_CHECKING @@ -214,7 +213,8 @@ def get_all_time_ratio(self) -> float: return 0 if not self.all_time_download: - return 0 if not self.all_time_upload else math.inf + # We're returning -1 instead of infinity, as it avoids issues when JSON encoding. + return 0 if not self.all_time_upload else -1 return self.all_time_upload / self.all_time_download diff --git a/src/tribler/test_unit/core/libtorrent/download_manager/test_download_state.py b/src/tribler/test_unit/core/libtorrent/download_manager/test_download_state.py index 9096a177c2..bcf6e49ec2 100644 --- a/src/tribler/test_unit/core/libtorrent/download_manager/test_download_state.py +++ b/src/tribler/test_unit/core/libtorrent/download_manager/test_download_state.py @@ -116,7 +116,7 @@ def test_all_time_ratio_no_all_time_download_inf(self) -> None: """ state = DownloadState(Mock(), Mock(all_time_upload=200, all_time_download=0), None) - self.assertEqual(math.inf, state.get_all_time_ratio()) + self.assertEqual(-1, state.get_all_time_ratio()) def test_get_files_completion(self) -> None: """ diff --git a/src/tribler/ui/src/pages/Downloads/Details.tsx b/src/tribler/ui/src/pages/Downloads/Details.tsx index ca5b6649ab..7f4c156262 100644 --- a/src/tribler/ui/src/pages/Downloads/Details.tsx +++ b/src/tribler/ui/src/pages/Downloads/Details.tsx @@ -68,7 +68,12 @@ export default function DownloadDetails({ selectedDownloads }: { selectedDownloa
{t('Ratio')}
-
{download?.all_time_ratio.toFixed(2)} ({formatBytes(download?.all_time_upload)} upload; {formatBytes(download?.all_time_download)} dowload)
+
{ + download.all_time_ratio < 0 ? + String(`∞`) : + download?.all_time_ratio.toFixed(2)} +  ({formatBytes(download?.all_time_upload)} upload; {formatBytes(download?.all_time_download)} dowload) +
{t('Availability')}