summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTobias Järvelöv <tobias.jarvelov@mullvad.net>2025-04-09 13:45:09 +0200
committerSebastian Holmin <sebastian.holmin@mullvad.net>2025-05-28 13:25:30 +0200
commit8ab9f8c7dfbda57801d7a2381bbd2003ba735956 (patch)
tree6da239a4d914d04879669903cdda082d1be0e31b
parent736054bd9e33bb63c7deabc7352a2180ff8c49c8 (diff)
downloadmullvadvpn-8ab9f8c7dfbda57801d7a2381bbd2003ba735956.tar.xz
mullvadvpn-8ab9f8c7dfbda57801d7a2381bbd2003ba735956.zip
Handle time left potentially being undefined
-rw-r--r--desktop/packages/mullvad-vpn/src/renderer/components/views/app-upgrade/components/download-progress/hooks/useMessage/hooks/useGetMessageTimeLeft.ts34
1 files changed, 19 insertions, 15 deletions
diff --git a/desktop/packages/mullvad-vpn/src/renderer/components/views/app-upgrade/components/download-progress/hooks/useMessage/hooks/useGetMessageTimeLeft.ts b/desktop/packages/mullvad-vpn/src/renderer/components/views/app-upgrade/components/download-progress/hooks/useMessage/hooks/useGetMessageTimeLeft.ts
index ee2bd530d5..0052b9a80c 100644
--- a/desktop/packages/mullvad-vpn/src/renderer/components/views/app-upgrade/components/download-progress/hooks/useMessage/hooks/useGetMessageTimeLeft.ts
+++ b/desktop/packages/mullvad-vpn/src/renderer/components/views/app-upgrade/components/download-progress/hooks/useMessage/hooks/useGetMessageTimeLeft.ts
@@ -1,6 +1,7 @@
import { sprintf } from 'sprintf-js';
import { messages } from '../../../../../../../../../shared/gettext';
+import { isNumber } from '../../../../../../../../../shared/utils';
import { useAppUpgradeEvent } from '../../../../../../../../redux/hooks';
export const useGetMessageTimeLeft = () => {
@@ -9,30 +10,33 @@ export const useGetMessageTimeLeft = () => {
const getMessageTimeLeft = () => {
if (appUpgradeEvent?.type === 'APP_UPGRADE_STATUS_DOWNLOAD_PROGRESS') {
const { timeLeft } = appUpgradeEvent;
+ const isTimeLeftNumeric = isNumber(timeLeft);
- if (timeLeft > 90) {
- const minutes = Math.round(timeLeft / 60);
+ if (isTimeLeftNumeric) {
+ if (timeLeft > 90) {
+ const minutes = Math.round(timeLeft / 60);
+
+ return sprintf(
+ // TRANSLATORS: Status text displayed below a progress bar when the update is being downloaded
+ // TRANSLATORS: Available placeholders:
+ // TRANSLATORS: %(minutes)s - Will be replaced with remaining minutes until download is complete
+ messages.pgettext('app-upgrade-view', 'About %(minutes)s minutes remaining...'),
+ {
+ minutes,
+ },
+ );
+ }
return sprintf(
// TRANSLATORS: Status text displayed below a progress bar when the update is being downloaded
// TRANSLATORS: Available placeholders:
- // TRANSLATORS: %(minutes)s - Will be replaced with remaining minutes until download is complete
- messages.pgettext('app-upgrade-view', 'About %(minutes)s minutes remaining...'),
+ // TRANSLATORS: %(second)s - Will be replaced with remaining seconds until download is complete
+ messages.pgettext('app-upgrade-view', 'About %(seconds)s seconds remaining...'),
{
- minutes,
+ seconds: timeLeft,
},
);
}
-
- return sprintf(
- // TRANSLATORS: Status text displayed below a progress bar when the update is being downloaded
- // TRANSLATORS: Available placeholders:
- // TRANSLATORS: %(second)s - Will be replaced with remaining seconds until download is complete
- messages.pgettext('app-upgrade-view', 'About %(seconds)s seconds remaining...'),
- {
- seconds: timeLeft,
- },
- );
}
return null;