From 277d7ab8bdba15b0fe784df4f175609f32ccd4e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lloren=C3=A7=20Muntaner?= Date: Tue, 19 Sep 2023 12:38:48 +0200 Subject: [PATCH] GIX-1890: Check transaction fee disburse maturity (#3331) # Motivation Users can't disburse maturity if less than transaction fee. It's just used as a minimum, it's not that a fee is applied to the amount. # Changes * A new prop `disabledText` in NeuronSelectPercentage. * New prop in DisburseMaturityModal. Check to enable or disable first screen. * New neuron util `minimumAmountToDisburseMaturity`. * Rename `SPAWN_VARIANCE_PERCENTAGE` to `MATURITY_MODULATION_VARIANCE_PERCENTAGE`. # Tests * Add test case in SnsDisburseMaturityModal.spec. * Add test for new neuron util. # Todos - [ ] Add entry to changelog (if necessary). Already covered by disburse maturity entry. --- .../NeuronSelectPercentage.svelte | 32 ++++++++++++++----- .../actions/SpawnNeuronButton.svelte | 17 ++++++---- .../actions/SnsDisburseMaturityButton.svelte | 11 +++++-- .../src/lib/constants/neurons.constants.ts | 2 +- frontend/src/lib/i18n/en.json | 4 +-- .../neurons/DisburseMaturityModal.svelte | 21 +++++++++++- .../neurons/SnsDisburseMaturityModal.svelte | 15 +++++++-- frontend/src/lib/utils/neuron.utils.ts | 7 ++-- frontend/src/lib/utils/sns-neuron.utils.ts | 14 ++++++-- .../actions/SnsDisburseMaturityButton.spec.ts | 4 +-- .../sns/SnsDisburseMaturityModal.spec.ts | 20 ++++++++++++ .../tests/lib/utils/sns-neuron.utils.spec.ts | 19 ++++++++--- 12 files changed, 133 insertions(+), 33 deletions(-) diff --git a/frontend/src/lib/components/neuron-detail/NeuronSelectPercentage.svelte b/frontend/src/lib/components/neuron-detail/NeuronSelectPercentage.svelte index 8aad36b5299..6ebaebf3427 100644 --- a/frontend/src/lib/components/neuron-detail/NeuronSelectPercentage.svelte +++ b/frontend/src/lib/components/neuron-detail/NeuronSelectPercentage.svelte @@ -6,11 +6,14 @@ import TestIdWrapper from "$lib/components/common/TestIdWrapper.svelte"; import { formatMaturity } from "$lib/utils/neuron.utils"; import { replacePlaceholders } from "$lib/utils/i18n.utils"; + import { nonNullish } from "@dfinity/utils"; + import Tooltip from "../ui/Tooltip.svelte"; export let availableMaturityE8s: bigint; export let percentage: number; export let buttonText: string; export let disabled = false; + export let disabledText: string | undefined = undefined; let selectedMaturityE8s: bigint; $: selectedMaturityE8s = (availableMaturityE8s * BigInt(percentage)) / 100n; @@ -59,14 +62,27 @@ - + {#if nonNullish(disabledText)} + + + + {:else} + + {/if} diff --git a/frontend/src/lib/components/neuron-detail/actions/SpawnNeuronButton.svelte b/frontend/src/lib/components/neuron-detail/actions/SpawnNeuronButton.svelte index 12181e1a53b..6cc21bbcfe4 100644 --- a/frontend/src/lib/components/neuron-detail/actions/SpawnNeuronButton.svelte +++ b/frontend/src/lib/components/neuron-detail/actions/SpawnNeuronButton.svelte @@ -3,7 +3,7 @@ import { E8S_PER_ICP } from "$lib/constants/icp.constants"; import { MIN_NEURON_STAKE, - SPAWN_VARIANCE_PERCENTAGE, + MATURITY_MODULATION_VARIANCE_PERCENTAGE, } from "$lib/constants/neurons.constants"; import { i18n } from "$lib/stores/i18n"; import { formatNumber, formatPercentage } from "$lib/utils/format.utils"; @@ -49,17 +49,22 @@ $i18n.neuron_detail.spawn_neuron_disabled_tooltip, { $amount: formatNumber( - MIN_NEURON_STAKE / E8S_PER_ICP / SPAWN_VARIANCE_PERCENTAGE, + MIN_NEURON_STAKE / + E8S_PER_ICP / + MATURITY_MODULATION_VARIANCE_PERCENTAGE, { minFraction: 4, maxFraction: 4 } ), $min: formatNumber(MIN_NEURON_STAKE / E8S_PER_ICP, { minFraction: 0, maxFraction: 0, }), - $varibility: formatPercentage(SPAWN_VARIANCE_PERCENTAGE, { - minFraction: 0, - maxFraction: 0, - }), + $variability: formatPercentage( + MATURITY_MODULATION_VARIANCE_PERCENTAGE, + { + minFraction: 0, + maxFraction: 0, + } + ), } )} > diff --git a/frontend/src/lib/components/sns-neuron-detail/actions/SnsDisburseMaturityButton.svelte b/frontend/src/lib/components/sns-neuron-detail/actions/SnsDisburseMaturityButton.svelte index f7714fb75f1..95186711dd0 100644 --- a/frontend/src/lib/components/sns-neuron-detail/actions/SnsDisburseMaturityButton.svelte +++ b/frontend/src/lib/components/sns-neuron-detail/actions/SnsDisburseMaturityButton.svelte @@ -1,5 +1,8 @@