fix vote input bug (#6113)
* update bifrost types * update bifrost types * update bifrost types * update bifrost types * fix vote input bug * update code structure
This commit is contained in:
parent
4b01961033
commit
056a0c2fe7
@ -21,6 +21,7 @@ interface Props {
|
||||
}
|
||||
|
||||
interface ValueState {
|
||||
defaultValue: BN;
|
||||
maxValue: BN;
|
||||
selectedId?: string | null;
|
||||
value: BN;
|
||||
@ -29,15 +30,17 @@ interface ValueState {
|
||||
function getValues (selectedId: string | null | undefined, isCouncil: 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;
|
||||
|
||||
return {
|
||||
defaultValue,
|
||||
maxValue,
|
||||
selectedId,
|
||||
value: value.isZero()
|
||||
? maxValue.gt(existential)
|
||||
? maxValue.sub(existential)
|
||||
: BN_ZERO
|
||||
: value
|
||||
value: defaultValue
|
||||
};
|
||||
}
|
||||
|
||||
@ -45,7 +48,7 @@ function VoteValue ({ accountId, autoFocus, isCouncil, onChange }: Props): React
|
||||
const { t } = useTranslation();
|
||||
const { api } = useApi();
|
||||
const allBalances = useCall<DeriveBalancesAll>(api.derive.balances?.all, [accountId]);
|
||||
const [{ maxValue, selectedId, value }, setValue] = useState<ValueState>({ maxValue: BN_ZERO, value: BN_ZERO });
|
||||
const [{ defaultValue, maxValue, selectedId, value }, setValue] = useState<ValueState>({ defaultValue: BN_ZERO, maxValue: BN_ZERO, value: BN_ZERO });
|
||||
|
||||
useEffect((): void => {
|
||||
// if the set accountId changes and the new balances is for that id, set it
|
||||
@ -78,7 +81,7 @@ function VoteValue ({ accountId, autoFocus, isCouncil, onChange }: Props): React
|
||||
defaultValue={
|
||||
isDisabled
|
||||
? undefined
|
||||
: value
|
||||
: defaultValue
|
||||
}
|
||||
help={t<string>('The amount that is associated with this vote. This value is locked for the duration of the vote.')}
|
||||
isDisabled={isDisabled}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user