Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into NNS1-3485/range-filte…
Browse files Browse the repository at this point in the history
…r-for-fetching-transactions
  • Loading branch information
yhabib committed Dec 13, 2024
2 parents a13bad2 + 483c392 commit bb892e2
Show file tree
Hide file tree
Showing 53 changed files with 1,114 additions and 274 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-Nns-Dapp-unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ proposal is successful, the changes it released will be moved from this file to
#### Added

- Show USD values of tokens.
- Reporting page for NNS Neurons and ICP transactions.

#### Changed

Expand Down
2 changes: 1 addition & 1 deletion dfx.json
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@
"ENABLE_CKTESTBTC": false,
"DISABLE_IMPORT_TOKEN_VALIDATION_FOR_TESTING": false,
"ENABLE_PERIODIC_FOLLOWING_CONFIRMATION": false,
"ENABLE_EXPORT_NEURONS_REPORT": false,
"ENABLE_EXPORT_NEURONS_REPORT": true,
"ENABLE_USD_VALUES": true,
"ENABLE_USD_VALUES_FOR_NEURONS": false
}
Expand Down
12 changes: 6 additions & 6 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions frontend/src/lib/components/ic/AmountWithUsd.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<script lang="ts">
import AmountDisplay from "$lib/components/ic/AmountDisplay.svelte";
import { formatNumber } from "$lib/utils/format.utils";
import { UnavailableTokenAmount } from "$lib/utils/token.utils";
import { TokenAmountV2 } from "@dfinity/utils";
import { nonNullish } from "@dfinity/utils";
export let amount: TokenAmountV2 | UnavailableTokenAmount;
export let amountInUsd: number | undefined;
</script>

<div class="values" data-tid="amount-with-usd-component">
<AmountDisplay singleLine {amount} />
<span data-tid="usd-value" class="usd-value">
{#if nonNullish(amountInUsd)}
${formatNumber(amountInUsd)}
{:else}
$-/-
{/if}
</span>
</div>

<style lang="scss">
.values {
display: flex;
flex-direction: column;
gap: var(--padding-0_5x);
align-items: flex-end;
.usd-value {
color: var(--text-description);
font-size: var(--font-size-small);
}
}
</style>
Original file line number Diff line number Diff line change
@@ -1,59 +1,83 @@
<script lang="ts">
import { i18n } from "$lib/stores/i18n";
import {
isNeuronFollowingReset,
isNeuronLosingRewards,
secondsUntilLosingRewards,
shouldDisplayRewardLossNotification,
} from "$lib/utils/neuron.utils";
import {
IconCheckCircle,
IconCheckCircleFill,
IconError,
IconWarning,
} from "@dfinity/gix-components";
import CommonItemAction from "$lib/components/ui/CommonItemAction.svelte";
import { type NeuronInfo } from "@dfinity/nns";
import { secondsToDuration } from "@dfinity/utils";
import { replacePlaceholders } from "$lib/utils/i18n.utils";
import FollowNeuronsButton from "./actions/FollowNeuronsButton.svelte";
import { secondsToDissolveDelayDuration } from "$lib/utils/date.utils";
import { START_REDUCING_VOTING_POWER_AFTER_SECONDS } from "$lib/constants/neurons.constants";
export let neuron: NeuronInfo;
let isFollowingReset = false;
$: isFollowingReset = isNeuronFollowingReset(neuron);
let isLosingRewards = false;
$: isLosingRewards = isNeuronLosingRewards(neuron);
let isLosingRewardsSoon = false;
$: isLosingRewardsSoon =
!isLosingRewards && shouldDisplayRewardLossNotification(neuron);
let icon: typeof IconError | typeof IconWarning | typeof IconCheckCircle;
$: icon = isLosingRewards
? IconError
: isLosingRewardsSoon
? IconWarning
: // TODO(mstr): Replace with the filled version.
IconCheckCircle;
let icon: typeof IconError | typeof IconWarning | typeof IconCheckCircleFill;
$: icon =
isFollowingReset || isLosingRewards
? IconError
: isLosingRewardsSoon
? IconWarning
: IconCheckCircleFill;
let title: string;
$: title = isLosingRewards
? $i18n.neuron_detail.reward_status_inactive
: isLosingRewardsSoon
? $i18n.neuron_detail.reward_status_losing_soon
: $i18n.neuron_detail.reward_status_active;
const getDescription = (neuron: NeuronInfo): string =>
isLosingRewards
? $i18n.neuron_detail.reward_status_inactive_description
: replacePlaceholders(
$i18n.neuron_detail.reward_status_losing_soon_description,
{
$time: secondsToDuration({
seconds: BigInt(secondsUntilLosingRewards(neuron)),
i18n: $i18n.time,
}),
}
);
$: title =
isFollowingReset || isLosingRewards
? $i18n.neuron_detail.reward_status_inactive
: isLosingRewardsSoon
? $i18n.neuron_detail.reward_status_losing_soon
: $i18n.neuron_detail.reward_status_active;
const getDescription = (neuron: NeuronInfo): string => {
if (isFollowingReset)
return $i18n.neuron_detail.reward_status_inactive_reset_description;
if (isLosingRewards)
return $i18n.neuron_detail.reward_status_inactive_description;
const timeUntilLoss = secondsToDuration({
seconds: BigInt(secondsUntilLosingRewards(neuron)),
i18n: $i18n.time,
});
return replacePlaceholders(
$i18n.neuron_detail.reward_status_losing_soon_description,
{
$time: timeUntilLoss,
}
);
};
const tooltipText = replacePlaceholders($i18n.losing_rewards.description, {
$period: secondsToDissolveDelayDuration(
BigInt(START_REDUCING_VOTING_POWER_AFTER_SECONDS)
),
});
</script>

<CommonItemAction testId="nns-neuron-reward-status-action-component">
<CommonItemAction
testId="nns-neuron-reward-status-action-component"
{tooltipText}
tooltipId="neuron-reward-status-icon"
>
<span
slot="icon"
class="icon"
Expand All @@ -75,6 +99,9 @@
{getDescription(neuron)}
</span>

{#if isFollowingReset}
<FollowNeuronsButton />
{/if}
<!-- TODO(mstr): Add a button to confirm a single following. -->
</CommonItemAction>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<script lang="ts">
import { i18n } from "$lib/stores/i18n";
import { startBusy, stopBusy } from "$lib/stores/busy.store";
import { refreshVotingPowerForNeurons } from "$lib/services/neurons.services";
import { createEventDispatcher } from "svelte";
export let neuronIds: bigint[];
const dispatcher = createEventDispatcher<{
nnsComplete: { successCount: number; totalCount: number };
}>();
const onClick = async () => {
startBusy({
initiator: "refresh-voting-power",
labelKey: "losing_rewards.confirming",
});
const totalCount = neuronIds.length;
const { successCount } = await refreshVotingPowerForNeurons({ neuronIds });
stopBusy("refresh-voting-power");
dispatcher("nnsComplete", { successCount, totalCount });
};
</script>

<button
on:click={onClick}
class="secondary"
data-tid="confirm-following-button-component"
>{$i18n.losing_rewards.confirm}</button
>
37 changes: 20 additions & 17 deletions frontend/src/lib/components/reporting/ReportingNeuronsButton.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
CsvGenerationError,
FileSystemAccessError,
generateCsvFileToSave,
} from "$lib/utils/export-to-csv.utils";
} from "$lib/utils/reporting.utils";
import { toastsError } from "$lib/stores/toasts.store";
import { formatDateCompact } from "$lib/utils/date.utils";
import type { NeuronInfo } from "@dfinity/nns";
Expand All @@ -33,7 +33,10 @@
const exportNeurons = async () => {
try {
loading = true;
startBusy({ initiator: "reporting-neurons" });
startBusy({
initiator: "reporting-neurons",
labelKey: "reporting.busy_screen",
});
// we are logged in to be able to interact with the button
const signIdentity = await getAuthenticatedIdentity();
Expand All @@ -50,51 +53,51 @@
headers: [
{
id: "neuronId",
label: $i18n.export_csv_neurons.neuron_id,
label: $i18n.reporting.neuron_id,
},
{
id: "project",
label: $i18n.export_csv_neurons.project,
label: $i18n.reporting.project,
},
{
id: "symbol",
label: $i18n.export_csv_neurons.symbol,
label: $i18n.reporting.symbol,
},
{
id: "neuronAccountId",
label: $i18n.export_csv_neurons.neuron_account_id,
label: $i18n.reporting.neuron_account_id,
},
{
id: "controllerId",
label: $i18n.export_csv_neurons.controller_id,
label: $i18n.reporting.controller_id,
},
{
id: "stake",
label: $i18n.export_csv_neurons.stake,
label: $i18n.reporting.stake,
},
{
id: "availableMaturity",
label: $i18n.export_csv_neurons.available_maturity,
label: $i18n.reporting.available_maturity,
},
{
id: "stakedMaturity",
label: $i18n.export_csv_neurons.staked_maturity,
label: $i18n.reporting.staked_maturity,
},
{
id: "dissolveDelaySeconds",
label: $i18n.export_csv_neurons.dissolve_delay,
label: $i18n.reporting.dissolve_delay,
},
{
id: "dissolveDate",
label: $i18n.export_csv_neurons.dissolve_date,
label: $i18n.reporting.dissolve_date,
},
{
id: "creationDate",
label: $i18n.export_csv_neurons.creation_date,
label: $i18n.reporting.creation_date,
},
{
id: "state",
label: $i18n.export_csv_neurons.state,
label: $i18n.reporting.state,
},
],
fileName,
Expand All @@ -104,15 +107,15 @@
if (error instanceof FileSystemAccessError) {
toastsError({
labelKey: "export_error.file_system_access",
labelKey: "reporting.error_file_system_access",
});
} else if (error instanceof CsvGenerationError) {
toastsError({
labelKey: "export_error.csv_generation",
labelKey: "reporting.error_csv_generation",
});
} else {
toastsError({
labelKey: "export_error.neurons",
labelKey: "reporting.error_neurons",
});
}
} finally {
Expand Down
Loading

0 comments on commit bb892e2

Please sign in to comment.