From 0855f73a5595c84c0bbda95a989dfd83a66a2605 Mon Sep 17 00:00:00 2001 From: Jaco Date: Mon, 12 Dec 2022 13:29:11 +0200 Subject: [PATCH] VoteValue noDefault set 0 default (#8520) --- packages/react-components/src/VoteValue.tsx | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/packages/react-components/src/VoteValue.tsx b/packages/react-components/src/VoteValue.tsx index 52b5ff8b07..dfc77b7454 100644 --- a/packages/react-components/src/VoteValue.tsx +++ b/packages/react-components/src/VoteValue.tsx @@ -29,14 +29,16 @@ interface ValueState { value: BN; } -function getValues (selectedId: string | null | undefined, isCouncil: boolean | undefined, allBalances: DeriveBalancesAll, existential: BN): ValueState { +function getValues (selectedId: string | null | undefined, isCouncil: boolean | undefined, noDefault: boolean | undefined, allBalances: DeriveBalancesAll, existential: BN): ValueState { const value = allBalances.lockedBalance; const maxValue = allBalances.votingBalance.add(isCouncil ? allBalances.reservedBalance : BN_ZERO); - const defaultValue = value.isZero() - ? maxValue.gt(existential) - ? maxValue.sub(existential) - : BN_ZERO - : value; + const defaultValue = noDefault + ? BN_ZERO + : value.isZero() + ? maxValue.gt(existential) + ? maxValue.sub(existential) + : BN_ZERO + : value; return { defaultValue, @@ -56,10 +58,10 @@ function VoteValue ({ accountId, autoFocus, isCouncil, label, noDefault, onChang // if the set accountId changes and the new balances is for that id, set it allBalances && allBalances.accountId.eq(accountId) && setValue((state) => state.selectedId !== accountId - ? getValues(accountId, isCouncil, allBalances, api.consts.balances.existentialDeposit) + ? getValues(accountId, isCouncil, noDefault, allBalances, api.consts.balances.existentialDeposit) : state ); - }, [allBalances, accountId, api, isCouncil]); + }, [allBalances, accountId, api, isCouncil, noDefault]); // only do onChange to parent when the BN value comes in, not our formatted version useEffect((): void => { @@ -81,7 +83,7 @@ function VoteValue ({ accountId, autoFocus, isCouncil, label, noDefault, onChang