diff --git a/packages/react-components/src/VoteValue.tsx b/packages/react-components/src/VoteValue.tsx index 0dd9eb5171..4820de29da 100644 --- a/packages/react-components/src/VoteValue.tsx +++ b/packages/react-components/src/VoteValue.tsx @@ -5,7 +5,7 @@ import { DeriveBalancesAll } from '@polkadot/api-derive/types'; import BN from 'bn.js'; -import React, { useCallback, useEffect, useState } from 'react'; +import React, { useCallback, useEffect, useState, useMemo } from 'react'; import { useApi, useCall } from '@polkadot/react-hooks'; import { BalanceVoting } from '@polkadot/react-query'; import { isBn } from '@polkadot/util'; @@ -30,6 +30,11 @@ function VoteValue ({ accountId, autoFocus, isCouncil, onChange }: Props): React const { api } = useApi(); const allBalances = useCall(api.derive.balances.all, [accountId]); const [{ selectedId, value }, setValue] = useState({}); + const maxVotingBalance = useMemo(() => + isCouncil + ? allBalances?.votingBalance.add(allBalances?.reservedBalance) + : allBalances?.votingBalance + , [allBalances?.reservedBalance, allBalances?.votingBalance, isCouncil]); useEffect((): void => { // if the set accountId changes and the new balances is for that id, set it @@ -37,7 +42,7 @@ function VoteValue ({ accountId, autoFocus, isCouncil, onChange }: Props): React selectedId: accountId, value: allBalances.lockedBalance }); - }, [accountId, selectedId, allBalances]); + }, [allBalances, accountId, maxVotingBalance, selectedId]); // only do onChange to parent when the BN value comes in, not our formatted version useEffect((): void => { @@ -54,7 +59,10 @@ function VoteValue ({ accountId, autoFocus, isCouncil, onChange }: Props): React return ( ('The amount that is associated with this vote. This value is is locked for the duration of the vote.')} isDisabled={isDisabled} isZeroable @@ -66,7 +74,7 @@ function VoteValue ({ accountId, autoFocus, isCouncil, onChange }: Props): React params={accountId} /> } - maxValue={allBalances?.votingBalance} + maxValue={maxVotingBalance} onChange={_setValue} /> ); diff --git a/packages/react-query/src/BalanceVoting.tsx b/packages/react-query/src/BalanceVoting.tsx index 061c925ce5..226f65a868 100644 --- a/packages/react-query/src/BalanceVoting.tsx +++ b/packages/react-query/src/BalanceVoting.tsx @@ -18,7 +18,7 @@ interface Props { params?: AccountId | AccountIndex | Address | string | Uint8Array | null; } -function BalanceVoting ({ children, className = '', label, params }: Props): React.ReactElement { +function BalanceVoting ({ children, className = '', isCouncil, label, params }: Props): React.ReactElement { const { api } = useApi(); const allBalances = useCall(api.derive.balances.all, [params]); @@ -26,7 +26,10 @@ function BalanceVoting ({ children, className = '', label, params }: Props): Rea {children}