From b0642f2de89746c0635dd4e00fab304aa1885677 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Thu, 16 Nov 2023 08:32:57 +0100 Subject: [PATCH] Replace secondsToDuration with utils move to ic-js (#3773) # Motivation `secondsToDuration` has been moved to `@dfinity/utils` therefore this PR replaces the usage of the function by the one in the library. It also remove the duplicate implementation within NNS dapp which becomes unused. # PRs - [x] Function moved in https://github.com/dfinity/ic-js/pull/467 --- .../launchpad/ProjectCardSwapInfo.svelte | 8 +- .../NnsNeuronDissolveDelayItemAction.svelte | 6 +- .../neurons/ConfirmDissolveDelay.svelte | 4 +- .../neurons/NeuronStateRemainingTime.svelte | 21 ++- .../components/neurons/NnsNeuronAge.svelte | 4 +- .../neurons/NnsNeuronDetailCard.svelte | 9 +- .../ProjectTimelineUserCommitment.svelte | 6 +- .../lib/components/proposals/Countdown.svelte | 5 +- .../SnsNeuronDissolveDelayItemAction.svelte | 8 +- .../SnsNeuronVestingPeriodRemaining.svelte | 7 +- .../SnsNeuronVotingPowerSection.svelte | 11 +- .../VestingTooltipWrapper.svelte | 7 +- .../ConfirmSnsDissolveDelay.svelte | 6 +- .../sns-neurons/SnsNeuronAge.svelte | 4 +- frontend/src/lib/routes/Settings.svelte | 7 +- frontend/src/lib/utils/date.utils.ts | 71 ++-------- .../ProjectTimelineUserCommitment.spec.ts | 15 +- .../components/proposals/Countdown.spec.ts | 5 +- .../proposals/NnsProposalCard.spec.ts | 4 +- .../ConfirmSnsDissolveDelay.spec.ts | 5 +- .../sns-neurons/SetSnsDissolveDelay.spec.ts | 5 +- .../src/tests/lib/utils/date.utils.spec.ts | 131 +----------------- 22 files changed, 99 insertions(+), 250 deletions(-) diff --git a/frontend/src/lib/components/launchpad/ProjectCardSwapInfo.svelte b/frontend/src/lib/components/launchpad/ProjectCardSwapInfo.svelte index f751797fbee..ffefc782219 100644 --- a/frontend/src/lib/components/launchpad/ProjectCardSwapInfo.svelte +++ b/frontend/src/lib/components/launchpad/ProjectCardSwapInfo.svelte @@ -11,7 +11,7 @@ } from "$lib/utils/projects.utils"; import { TokenAmount, ICPToken } from "@dfinity/utils"; import { i18n } from "$lib/stores/i18n"; - import { secondsToDuration } from "$lib/utils/date.utils"; + import { secondsToDuration } from "@dfinity/utils"; import AmountDisplay from "$lib/components/ic/AmountDisplay.svelte"; import { SnsSwapLifecycle } from "@dfinity/sns"; import ProjectUserCommitmentLabel from "$lib/components/project-detail/ProjectUserCommitmentLabel.svelte"; @@ -69,14 +69,16 @@ {#if lifecycle === SnsSwapLifecycle.Adopted && durationTillStart !== undefined}
{$i18n.sns_project_detail.starts}
-
{secondsToDuration(durationTillStart)}
+
+ {secondsToDuration({ seconds: durationTillStart, i18n: $i18n.time })} +
{/if} {#if lifecycle === SnsSwapLifecycle.Open && durationTillDeadline !== undefined}
{$i18n.sns_project_detail.deadline}
- {secondsToDuration(durationTillDeadline)} + {secondsToDuration({ seconds: durationTillDeadline, i18n: $i18n.time })}
{/if} diff --git a/frontend/src/lib/components/neuron-detail/NnsNeuronDissolveDelayItemAction.svelte b/frontend/src/lib/components/neuron-detail/NnsNeuronDissolveDelayItemAction.svelte index 0f222f8c704..441a0b3fcdd 100644 --- a/frontend/src/lib/components/neuron-detail/NnsNeuronDissolveDelayItemAction.svelte +++ b/frontend/src/lib/components/neuron-detail/NnsNeuronDissolveDelayItemAction.svelte @@ -11,7 +11,7 @@ import CommonItemAction from "../ui/CommonItemAction.svelte"; import IncreaseDissolveDelayButton from "./actions/IncreaseDissolveDelayButton.svelte"; import { keyOf } from "$lib/utils/utils"; - import { secondsToDuration } from "$lib/utils/date.utils"; + import { secondsToDuration } from "@dfinity/utils"; import { NNS_MINIMUM_DISSOLVE_DELAY_TO_VOTE } from "$lib/constants/neurons.constants"; import { authStore } from "$lib/stores/auth.store"; import { icpAccountsStore } from "$lib/stores/icp-accounts.store"; @@ -55,7 +55,9 @@ obj: $i18n.neuron_detail, key: stateTextMapper[neuron.state], })} ${ - remainingTimeSeconds > 0n ? secondsToDuration(remainingTimeSeconds) : "0" + remainingTimeSeconds > 0n + ? secondsToDuration({ seconds: remainingTimeSeconds, i18n: $i18n.time }) + : "0" }`} diff --git a/frontend/src/lib/components/neurons/ConfirmDissolveDelay.svelte b/frontend/src/lib/components/neurons/ConfirmDissolveDelay.svelte index 2045a5d4763..af9c03863ce 100644 --- a/frontend/src/lib/components/neurons/ConfirmDissolveDelay.svelte +++ b/frontend/src/lib/components/neurons/ConfirmDissolveDelay.svelte @@ -3,7 +3,7 @@ import { createEventDispatcher } from "svelte"; import { updateDelay } from "$lib/services/neurons.services"; import { i18n } from "$lib/stores/i18n"; - import { secondsToDuration } from "$lib/utils/date.utils"; + import { secondsToDuration } from "@dfinity/utils"; import { replacePlaceholders } from "$lib/utils/i18n.utils"; import { formatToken } from "$lib/utils/token.utils"; import { @@ -44,7 +44,7 @@
-

{secondsToDuration(delayInSeconds)}

+

{secondsToDuration({ seconds: delayInSeconds, i18n: $i18n.time })}

{$i18n.neurons.neuron_id}

diff --git a/frontend/src/lib/components/neurons/NeuronStateRemainingTime.svelte b/frontend/src/lib/components/neurons/NeuronStateRemainingTime.svelte index 5bedbfa8224..4a49599c2bb 100644 --- a/frontend/src/lib/components/neurons/NeuronStateRemainingTime.svelte +++ b/frontend/src/lib/components/neurons/NeuronStateRemainingTime.svelte @@ -1,7 +1,7 @@