-
Notifications
You must be signed in to change notification settings - Fork 43
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
Draft: vp from network economics #6165
Closed
Closed
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
88407bf
Add getNetworkEconomicsParameters api
mstrasinskis e93002e
New networkEconomicsParametersStore
mstrasinskis b89fc21
Add networkEconomicsStore to debug store
mstrasinskis 118f24d
Load network economics on app load
mstrasinskis ffc2829
Add voting power economics derived stores
mstrasinskis 41ea854
Switch to economics in ConfirmFollowingBanner
mstrasinskis c7e984d
Switch to economics in ConfirmFollowingBanner
mstrasinskis 3c21b86
reset network economics store
mstrasinskis dea54fb
Switch to economics in NnsNeuronRewardStatusAction
mstrasinskis 240508e
Switch to economics in LosingRewardsBanner
mstrasinskis 3e31a89
Switch to economics in LosingRewardNeuronsModal
mstrasinskis c9b6a78
Merge branch 'main' into get-network-economics-parameters
mstrasinskis e6affe1
Update utils to use derived stores
mstrasinskis 8d238cb
Update tests
mstrasinskis b1d4eba
Merge branch 'main' into get-network-economics-parameters
mstrasinskis cd61a3b
Merge branch 'get-network-economics-parameters' of github.com:dfinity…
mstrasinskis 16bbe25
Extend utility tests
mstrasinskis 770bb73
Merge branch 'main' into get-network-economics-parameters
mstrasinskis 78c83c2
Typo
mstrasinskis 4688ccf
Merge branch 'get-network-economics-parameters' of github.com:dfinity…
mstrasinskis ae5f1b2
Merge branch 'main' into get-network-economics-parameters
mstrasinskis 6bc3127
Merge branch 'main' into get-network-economics-parameters
mstrasinskis 1a6cdf8
Merge branch 'main' into get-network-economics-parameters
mstrasinskis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,6 @@ | |
import ConfirmFollowingActionButton from "$lib/components/neuron-detail/actions/ConfirmFollowingActionButton.svelte"; | ||
import FollowNeuronsButton from "$lib/components/neuron-detail/actions/FollowNeuronsButton.svelte"; | ||
import CommonItemAction from "$lib/components/ui/CommonItemAction.svelte"; | ||
import { START_REDUCING_VOTING_POWER_AFTER_SECONDS } from "$lib/constants/neurons.constants"; | ||
import { i18n } from "$lib/stores/i18n"; | ||
import { secondsToDissolveDelayDuration } from "$lib/utils/date.utils"; | ||
import { replacePlaceholders } from "$lib/utils/i18n.utils"; | ||
|
@@ -18,19 +17,37 @@ | |
IconWarning, | ||
} from "@dfinity/gix-components"; | ||
import { type NeuronInfo } from "@dfinity/nns"; | ||
import { secondsToDuration } from "@dfinity/utils"; | ||
import { nonNullish, secondsToDuration } from "@dfinity/utils"; | ||
import { | ||
clearFollowingAfterSecondsStore, | ||
startReducingVotingPowerAfterSecondsStore, | ||
} from "$lib/derived/network-economics.derived"; | ||
|
||
export let neuron: NeuronInfo; | ||
|
||
let isFollowingReset = false; | ||
$: isFollowingReset = isNeuronFollowingReset(neuron); | ||
$: isFollowingReset = isNeuronFollowingReset({ | ||
neuron, | ||
startReducingVotingPowerAfterSeconds: | ||
$startReducingVotingPowerAfterSecondsStore, | ||
clearFollowingAfterSeconds: $clearFollowingAfterSecondsStore, | ||
}); | ||
|
||
let isLosingRewards = false; | ||
$: isLosingRewards = isNeuronLosingRewards(neuron); | ||
$: isLosingRewards = isNeuronLosingRewards({ | ||
neuron, | ||
startReducingVotingPowerAfterSeconds: | ||
$startReducingVotingPowerAfterSecondsStore, | ||
}); | ||
|
||
let isLosingRewardsSoon = false; | ||
$: isLosingRewardsSoon = | ||
!isLosingRewards && shouldDisplayRewardLossNotification(neuron); | ||
!isLosingRewards && | ||
shouldDisplayRewardLossNotification({ | ||
neuron, | ||
startReducingVotingPowerAfterSeconds: | ||
$startReducingVotingPowerAfterSecondsStore, | ||
}); | ||
|
||
let icon: typeof IconError | typeof IconWarning | typeof IconCheckCircleFill; | ||
$: icon = | ||
|
@@ -48,15 +65,26 @@ | |
? $i18n.neuron_detail.reward_status_losing_soon | ||
: $i18n.neuron_detail.reward_status_active; | ||
|
||
const getDescription = (neuron: NeuronInfo): string => { | ||
const getDescription = ({ | ||
neuron, | ||
startReducingVotingPowerAfterSeconds, | ||
}: { | ||
neuron: NeuronInfo; | ||
startReducingVotingPowerAfterSeconds: bigint; | ||
}): 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)), | ||
seconds: BigInt( | ||
secondsUntilLosingRewards({ | ||
neuron, | ||
startReducingVotingPowerAfterSeconds, | ||
}) | ||
), | ||
i18n: $i18n.time, | ||
}); | ||
return replacePlaceholders( | ||
|
@@ -66,46 +94,50 @@ | |
} | ||
); | ||
}; | ||
|
||
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" | ||
{tooltipText} | ||
tooltipId="neuron-reward-status-icon" | ||
> | ||
<span | ||
slot="icon" | ||
class="icon" | ||
class:isLosingRewards | ||
class:isLosingRewardsSoon | ||
> | ||
<svelte:component this={icon} /> | ||
</span> | ||
<span slot="title" data-tid="state-title"> | ||
{title} | ||
</span> | ||
|
||
<span | ||
slot="subtitle" | ||
class="description" | ||
class:negative={isLosingRewards || isLosingRewardsSoon} | ||
data-tid="state-description" | ||
{#if nonNullish($startReducingVotingPowerAfterSecondsStore) && nonNullish($clearFollowingAfterSecondsStore)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
<CommonItemAction | ||
testId="nns-neuron-reward-status-action-component" | ||
tooltipText={replacePlaceholders($i18n.losing_rewards.description, { | ||
$period: secondsToDissolveDelayDuration( | ||
$startReducingVotingPowerAfterSecondsStore | ||
), | ||
})} | ||
tooltipId="neuron-reward-status-icon" | ||
> | ||
{getDescription(neuron)} | ||
</span> | ||
|
||
{#if isFollowingReset} | ||
<FollowNeuronsButton variant="secondary" /> | ||
{:else} | ||
<ConfirmFollowingActionButton {neuron} /> | ||
{/if} | ||
</CommonItemAction> | ||
<span | ||
slot="icon" | ||
class="icon" | ||
class:isLosingRewards | ||
class:isLosingRewardsSoon | ||
> | ||
<svelte:component this={icon} /> | ||
</span> | ||
<span slot="title" data-tid="state-title"> | ||
{title} | ||
</span> | ||
|
||
<span | ||
slot="subtitle" | ||
class="description" | ||
class:negative={isLosingRewards || isLosingRewardsSoon} | ||
data-tid="state-description" | ||
> | ||
{getDescription({ | ||
neuron, | ||
startReducingVotingPowerAfterSeconds: | ||
$startReducingVotingPowerAfterSecondsStore, | ||
})} | ||
</span> | ||
|
||
{#if isFollowingReset} | ||
<FollowNeuronsButton variant="secondary" /> | ||
{:else} | ||
<ConfirmFollowingActionButton {neuron} /> | ||
{/if} | ||
</CommonItemAction> | ||
{/if} | ||
|
||
<style lang="scss"> | ||
.icon { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,37 +11,53 @@ | |
import { replacePlaceholders } from "$lib/utils/i18n.utils"; | ||
import { nonNullish, secondsToDuration } from "@dfinity/utils"; | ||
import type { NeuronInfo } from "@dfinity/nns"; | ||
import { START_REDUCING_VOTING_POWER_AFTER_SECONDS } from "$lib/constants/neurons.constants"; | ||
import { secondsToDissolveDelayDuration } from "$lib/utils/date.utils"; | ||
import TestIdWrapper from "$lib/components/common/TestIdWrapper.svelte"; | ||
import LosingRewardNeuronsModal from "$lib/modals/neurons/LosingRewardNeuronsModal.svelte"; | ||
import { startReducingVotingPowerAfterSecondsStore } from "$lib/derived/network-economics.derived"; | ||
|
||
// The neurons in the store are sorted by the time they will lose rewards. | ||
let mostInactiveNeuron: NeuronInfo | undefined; | ||
$: mostInactiveNeuron = $soonLosingRewardNeuronsStore[0]; | ||
|
||
const getTitle = (neuron: NeuronInfo) => | ||
isNeuronLosingRewards(neuron) | ||
const getTitle = ({ | ||
neuron, | ||
startReducingVotingPowerAfterSeconds, | ||
}: { | ||
neuron: NeuronInfo; | ||
startReducingVotingPowerAfterSeconds: bigint; | ||
}) => | ||
isNeuronLosingRewards({ neuron, startReducingVotingPowerAfterSeconds }) | ||
? $i18n.losing_rewards_banner.rewards_missing_title | ||
: replacePlaceholders($i18n.losing_rewards_banner.days_left_title, { | ||
$timeLeft: secondsToDuration({ | ||
seconds: BigInt(secondsUntilLosingRewards(neuron)), | ||
seconds: BigInt( | ||
secondsUntilLosingRewards({ | ||
neuron, | ||
startReducingVotingPowerAfterSeconds, | ||
}) | ||
), | ||
i18n: $i18n.time, | ||
}), | ||
}); | ||
const text = replacePlaceholders($i18n.losing_rewards.description, { | ||
// TODO(mstr): Rename to secondsToRoundedDuration | ||
$period: secondsToDissolveDelayDuration( | ||
BigInt(START_REDUCING_VOTING_POWER_AFTER_SECONDS) | ||
), | ||
}); | ||
|
||
let isModalVisible = false; | ||
</script> | ||
|
||
<TestIdWrapper testId="losing-rewards-banner-component"> | ||
{#if nonNullish(mostInactiveNeuron)} | ||
<Banner title={getTitle(mostInactiveNeuron)} {text}> | ||
{#if nonNullish(mostInactiveNeuron) && nonNullish($startReducingVotingPowerAfterSecondsStore)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
<Banner | ||
title={getTitle({ | ||
neuron: mostInactiveNeuron, | ||
startReducingVotingPowerAfterSeconds: | ||
$startReducingVotingPowerAfterSecondsStore, | ||
})} | ||
text={replacePlaceholders($i18n.losing_rewards.description, { | ||
$period: secondsToDissolveDelayDuration( | ||
$startReducingVotingPowerAfterSecondsStore | ||
), | ||
})} | ||
> | ||
<BannerIcon slot="icon" status="error"> | ||
<IconInfo /> | ||
</BannerIcon> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test update https://github.com/dfinity/nns-dapp/pull/6165/files#diff-07e2a4105956046f4e177fd738f11f1e0d8e0530c38d0696805dc9860888a37eR15