Skip to content

Commit

Permalink
GIX-1890: Apply new minimum
Browse files Browse the repository at this point in the history
  • Loading branch information
lmuntaner committed Sep 19, 2023
1 parent 27e9fd0 commit 2b74a21
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<script lang="ts">
import { hasEnoughMaturityToDisburse } from "$lib/utils/sns-neuron.utils";
import {
hasEnoughMaturityToDisburse,
minimumAmountToDisburseMaturity,
} from "$lib/utils/sns-neuron.utils";
import { openSnsNeuronModal } from "$lib/utils/modals.utils";
import type { SnsNeuron } from "@dfinity/sns";
import DisburseMaturityButton from "$lib/components/neuron-detail/actions/DisburseMaturityButton.svelte";
Expand All @@ -17,7 +20,9 @@
$: disabledText = !enoughMaturity
? replacePlaceholders(
$i18n.neuron_detail.disburse_maturity_disabled_tooltip,
{ $fee: formatToken({ value: feeE8s }) }
{
$fee: formatToken({ value: minimumAmountToDisburseMaturity(feeE8s) }),
}
)
: undefined;
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/lib/modals/neurons/DisburseMaturityModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
$: disabledText =
disableDisburse && percentageToDisburse > 0
? replacePlaceholders(
$i18n.neuron_detail.disburse_maturity_modal_disabled_tooltip,
{ $amount: formatToken({ value: minimumAmountE8s }) }
$i18n.neuron_detail.disburse_maturity_disabled_tooltip,
{ $fee: formatToken({ value: minimumAmountE8s }) }
)
: undefined;
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/lib/utils/sns-neuron.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ export const hasEnoughMaturityToStake = (
): boolean => (neuron?.maturity_e8s_equivalent ?? BigInt(0)) > BigInt(0);

/**
* Is the maturity of the neuron bigger than the transaction fee?
* Is the maturity of the neuron bigger than the minimum amount to disburse?
* @param {SnsNeuron} neuron
* @param {bigint} feeE8s
*/
Expand All @@ -516,7 +516,8 @@ export const hasEnoughMaturityToDisburse = ({
}: {
feeE8s: bigint;
neuron: SnsNeuron;
}): boolean => maturity_e8s_equivalent >= feeE8s;
}): boolean =>
maturity_e8s_equivalent >= minimumAmountToDisburseMaturity(feeE8s);

/**
* Does the neuron has staked maturity?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("SnsDisburseMaturityButton", () => {
const po = renderComponent(
{
...mockSnsNeuron,
maturity_e8s_equivalent: fee + 10n,
maturity_e8s_equivalent: fee * 2n,
staked_maturity_e8s_equivalent: [],
},
fee
Expand All @@ -50,7 +50,7 @@ describe("SnsDisburseMaturityButton", () => {

expect(await po.isDisabled()).toBe(true);
expect(await po.getTooltipText()).toBe(
"You do not have enough maturity to disburse. The minimum is: 0.0001."
"You do not have enough maturity to disburse. The minimum is: 0.00010526."
);
});

Expand Down
8 changes: 4 additions & 4 deletions frontend/src/tests/lib/utils/sns-neuron.utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1392,10 +1392,10 @@ describe("sns-neuron utils", () => {

describe("hasEnoughMaturityToDisburse", () => {
const feeE8s = 10_000n;
it("should return true if maturity is more than fee", () => {
it("should return true if maturity is more than fee in worst modulation scenario", () => {
const neuron = {
...mockSnsNeuron,
maturity_e8s_equivalent: feeE8s + 1n,
maturity_e8s_equivalent: 10526n + 1n,
};
expect(hasEnoughMaturityToDisburse({ neuron, feeE8s })).toBe(true);
});
Expand All @@ -1408,12 +1408,12 @@ describe("sns-neuron utils", () => {
expect(hasEnoughMaturityToDisburse({ neuron, feeE8s })).toBe(false);
});

it("should return true if maturity is same as fee", () => {
it("should return false if maturity is same as fee", () => {
const neuron = {
...mockSnsNeuron,
maturity_e8s_equivalent: feeE8s,
};
expect(hasEnoughMaturityToDisburse({ neuron, feeE8s })).toBe(true);
expect(hasEnoughMaturityToDisburse({ neuron, feeE8s })).toBe(false);
});
});

Expand Down

0 comments on commit 2b74a21

Please sign in to comment.