Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace secondsToDuration with utils move to ic-js #3773

Merged
merged 3 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -69,14 +69,16 @@
<!-- Sale is adopted -->
{#if lifecycle === SnsSwapLifecycle.Adopted && durationTillStart !== undefined}
<dt class="label">{$i18n.sns_project_detail.starts}</dt>
<dd class="value">{secondsToDuration(durationTillStart)}</dd>
<dd class="value">
{secondsToDuration({ seconds: durationTillStart, i18n: $i18n.time })}
</dd>
{/if}

<!-- Sale is open -->
{#if lifecycle === SnsSwapLifecycle.Open && durationTillDeadline !== undefined}
<dt class="label">{$i18n.sns_project_detail.deadline}</dt>
<dd class="value" data-tid="project-deadline">
{secondsToDuration(durationTillDeadline)}
{secondsToDuration({ seconds: durationTillDeadline, i18n: $i18n.time })}
</dd>
{/if}
</TestIdWrapper>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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"
}`}</span
>
<svelte:fragment slot="subtitle">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -44,7 +44,7 @@

<div class="wrapper" data-tid="confirm-dissolve-delay-container">
<div class="main-info">
<h3>{secondsToDuration(delayInSeconds)}</h3>
<h3>{secondsToDuration({ seconds: delayInSeconds, i18n: $i18n.time })}</h3>
</div>
<div>
<p class="label">{$i18n.neurons.neuron_id}</p>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { NeuronState } from "@dfinity/nns";
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 { Html, KeyValuePair } from "@dfinity/gix-components";

Expand All @@ -17,31 +17,40 @@
<p class="duration label" class:default-gaps={defaultGaps}>
<Html
text={replacePlaceholders($i18n.neurons.inline_remaining, {
$duration: secondsToDuration(timeInSeconds),
$duration: secondsToDuration({
seconds: timeInSeconds,
i18n: $i18n.time,
}),
})}
/>
</p>
{:else}
<KeyValuePair>
<span slot="key" class="label">{$i18n.neurons.remaining}</span>
<span slot="value" class="value"
>{secondsToDuration(timeInSeconds)}</span
>{secondsToDuration({
seconds: timeInSeconds,
i18n: $i18n.time,
})}</span
>
</KeyValuePair>
{/if}
{:else if state === NeuronState.Locked}
{#if inline}
<p class="duration label" class:default-gaps={defaultGaps}>
{secondsToDuration(timeInSeconds)} – {$i18n.neurons
.dissolve_delay_title}
{secondsToDuration({ seconds: timeInSeconds, i18n: $i18n.time })} – {$i18n
.neurons.dissolve_delay_title}
</p>
{:else}
<KeyValuePair>
<span slot="key" class="label"
>{$i18n.neurons.dissolve_delay_title}</span
>
<span slot="value" class="value"
>{secondsToDuration(timeInSeconds)}</span
>{secondsToDuration({
seconds: timeInSeconds,
i18n: $i18n.time,
})}</span
>
</KeyValuePair>
{/if}
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lib/components/neurons/NnsNeuronAge.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import type { NeuronInfo } from "@dfinity/nns";
import { i18n } from "$lib/stores/i18n";
import { KeyValuePair } from "@dfinity/gix-components";
import { secondsToDuration } from "$lib/utils/date.utils";
import { secondsToDuration } from "@dfinity/utils";
import { neuronAge } from "$lib/utils/neuron.utils";
import TestIdWrapper from "../common/TestIdWrapper.svelte";

Expand All @@ -14,7 +14,7 @@
<KeyValuePair>
<span class="label" slot="key">{$i18n.neurons.age}</span>
<span class="value" slot="value" data-tid="nns-neuron-age">
{secondsToDuration(neuronAge(neuron))}
{secondsToDuration({ seconds: neuronAge(neuron), i18n: $i18n.time })}
</span>
</KeyValuePair>
{/if}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import AmountDisplay from "$lib/components/ic/AmountDisplay.svelte";
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 {
formatVotingPower,
Expand Down Expand Up @@ -42,13 +42,16 @@
<KeyValuePair testId="dissolve-delay">
<span slot="key" class="label">{$i18n.neurons.dissolve_delay_title}</span>
<span slot="value" class="value"
>{secondsToDuration(neuron.dissolveDelaySeconds)}</span
>{secondsToDuration({
seconds: neuron.dissolveDelaySeconds,
i18n: $i18n.time,
})}</span
>
</KeyValuePair>
<KeyValuePair testId="age">
<span class="label" slot="key">{$i18n.neurons.age}</span>
<span class="value" slot="value" data-tid="nns-neuron-age">
{secondsToDuration(neuronAge(neuron))}
{secondsToDuration({ seconds: neuronAge(neuron), i18n: $i18n.time })}
</span>
</KeyValuePair>
<KeyValuePair testId="voting-power">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
durationTillSwapDeadline,
durationTillSwapStart,
} from "$lib/utils/projects.utils";
import { secondsToDuration } from "$lib/utils/date.utils";
import { secondsToDuration } from "@dfinity/utils";
import { Value, KeyValuePair } from "@dfinity/gix-components";
import { SnsSwapLifecycle } from "@dfinity/sns";
import { TokenAmount, nonNullish } from "@dfinity/utils";
Expand Down Expand Up @@ -55,7 +55,7 @@
{$i18n.sns_project_detail.deadline}
</span>
<Value slot="value">
{secondsToDuration(durationTillDeadline)}
{secondsToDuration({ seconds: durationTillDeadline, i18n: $i18n.time })}
</Value>
</KeyValuePair>
{/if}
Expand All @@ -65,7 +65,7 @@
{$i18n.sns_project_detail.starts}
</span>
<Value slot="value">
{secondsToDuration(durationTillStart)}
{secondsToDuration({ seconds: durationTillStart, i18n: $i18n.time })}
</Value>
</KeyValuePair>
{/if}
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/lib/components/proposals/Countdown.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import { onDestroy, onMount } from "svelte";
import { nowInSeconds, secondsToDuration } from "$lib/utils/date.utils";
import { nowInSeconds } from "$lib/utils/date.utils";
import { secondsToDuration } from "@dfinity/utils";
import { i18n } from "$lib/stores/i18n";
import { AUTH_SESSION_DURATION } from "$lib/constants/identity.constants";

Expand Down Expand Up @@ -70,7 +71,7 @@

{#if countdown !== undefined && countdown > ZERO}
<p data-tid="countdown">
{secondsToDuration(countdown)}
{secondsToDuration({ seconds: countdown, i18n: $i18n.time })}
{$i18n.proposal_detail.remaining}
</p>
{/if}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { NeuronState } from "@dfinity/nns";
import CommonItemAction from "../ui/CommonItemAction.svelte";
import { keyOf } from "$lib/utils/utils";
import { secondsToDuration } from "$lib/utils/date.utils";
import { secondsToDuration } from "@dfinity/utils";
import type { SnsNervousSystemParameters, SnsNeuron } from "@dfinity/sns";
import {
dissolveDelayMultiplier,
Expand Down Expand Up @@ -58,7 +58,11 @@
>{`${keyOf({
obj: $i18n.neuron_detail,
key: stateTextMapper[state],
})} ${dissolvingTime > 0n ? secondsToDuration(dissolvingTime) : "0"}`}</span
})} ${
dissolvingTime > 0n
? secondsToDuration({ seconds: dissolvingTime, i18n: $i18n.time })
: "0"
}`}</span
>
<svelte:fragment slot="subtitle">
{#if dissolvingTime >= minimumDelayToVoteInSeconds}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import TestIdWrapper from "../common/TestIdWrapper.svelte";
import { KeyValuePair } from "@dfinity/gix-components";
import { i18n } from "$lib/stores/i18n";
import { secondsToDuration } from "$lib/utils/date.utils";
import { secondsToDuration } from "@dfinity/utils";
import { isVesting, vestingInSeconds } from "$lib/utils/sns-neuron.utils";

export let neuron: SnsNeuron;
Expand All @@ -14,7 +14,10 @@
<KeyValuePair testId="sns-neuron-vesting-period">
<span class="label" slot="key">{$i18n.neurons.vestion_period}</span>
<span class="value" slot="value">
{secondsToDuration(vestingInSeconds(neuron))}
{secondsToDuration({
seconds: vestingInSeconds(neuron),
i18n: $i18n.time,
})}
</span>
</KeyValuePair>
{/if}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import SnsNeuronStateItemAction from "./SnsNeuronStateItemAction.svelte";
import SnsNeuronDissolveDelayItemAction from "./SnsNeuronDissolveDelayItemAction.svelte";
import { formatToken } from "$lib/utils/token.utils";
import { secondsToDuration } from "$lib/utils/date.utils";
import { secondsToDuration } from "@dfinity/utils";
import { Html, Section } from "@dfinity/gix-components";
import { Principal } from "@dfinity/principal";

Expand Down Expand Up @@ -70,11 +70,12 @@
text={replacePlaceholders(
$i18n.neuron_detail.voting_power_section_description_expanded_zero,
{
$minDuration: secondsToDuration(
fromDefinedNullable(
$minDuration: secondsToDuration({
seconds: fromDefinedNullable(
parameters.neuron_minimum_dissolve_delay_to_vote_seconds
)
),
),
i18n: $i18n.time,
}),
$dashboardLink: neuronDashboardUrl({
neuron,
rootCanisterId: Principal.fromText(universe.canisterId),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import Tooltip from "$lib/components/ui/Tooltip.svelte";
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 { isVesting, vestingInSeconds } from "$lib/utils/sns-neuron.utils";
import type { SnsNeuron } from "@dfinity/sns";
Expand All @@ -17,7 +17,10 @@
text={replacePlaceholders(
$i18n.sns_neuron_detail.vesting_period_tooltip,
{
$remainingVesting: secondsToDuration(vestingInSeconds(neuron)),
$remainingVesting: secondsToDuration({
seconds: vestingInSeconds(neuron),
i18n: $i18n.time,
}),
}
)}
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script lang="ts">
import { createEventDispatcher } from "svelte";
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 { formatVotingPower } from "$lib/utils/neuron.utils";
Expand Down Expand Up @@ -47,7 +47,9 @@

<div class="wrapper" data-tid="confirm-dissolve-delay-container">
<div class="main-info">
<h3>{secondsToDuration(BigInt(delayInSeconds))}</h3>
<h3>
{secondsToDuration({ seconds: BigInt(delayInSeconds), i18n: $i18n.time })}
</h3>
</div>
<div>
<p class="label">{$i18n.neurons.neuron_id}</p>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lib/components/sns-neurons/SnsNeuronAge.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { i18n } from "$lib/stores/i18n";
import { secondsToDuration } from "$lib/utils/date.utils";
import { secondsToDuration } from "@dfinity/utils";
import { neuronAge } from "$lib/utils/sns-neuron.utils";
import { KeyValuePair } from "@dfinity/gix-components";
import type { SnsNeuron } from "@dfinity/sns";
Expand All @@ -17,7 +17,7 @@
<KeyValuePair testId="sns-neuron-age">
<span class="label" slot="key">{$i18n.neurons.age}</span>
<span class="value" slot="value">
{secondsToDuration(age)}
{secondsToDuration({ seconds: age, i18n: $i18n.time })}
</span>
</KeyValuePair>
{/if}
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/lib/routes/Settings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
SkeletonText,
} from "@dfinity/gix-components";
import Hash from "$lib/components/ui/Hash.svelte";
import { secondsToDuration } from "$lib/utils/date.utils";
import { secondsToDuration } from "@dfinity/utils";
import { authRemainingTimeStore, authStore } from "$lib/stores/auth.store";
import { i18n } from "$lib/stores/i18n";
import { debounce, nonNullish } from "@dfinity/utils";
Expand Down Expand Up @@ -57,7 +57,10 @@
{#if nonNullish(remainingTimeMilliseconds)}
{remainingTimeMilliseconds <= 0
? "0"
: secondsToDuration(BigInt(remainingTimeMilliseconds) / 1000n)}
: secondsToDuration({
seconds: BigInt(remainingTimeMilliseconds) / 1000n,
i18n: $i18n.time,
})}
{:else}
<div class="skeleton"><SkeletonText /></div>
{/if}
Expand Down
Loading
Loading