diff options
| author | Tobias Järvelöv <tobias.jarvelov@mullvad.net> | 2025-04-09 13:45:09 +0200 |
|---|---|---|
| committer | Sebastian Holmin <sebastian.holmin@mullvad.net> | 2025-05-28 13:25:30 +0200 |
| commit | 8ab9f8c7dfbda57801d7a2381bbd2003ba735956 (patch) | |
| tree | 6da239a4d914d04879669903cdda082d1be0e31b | |
| parent | 736054bd9e33bb63c7deabc7352a2180ff8c49c8 (diff) | |
| download | mullvadvpn-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.ts | 34 |
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; |
