Cater for prev-gen council votes (#5301)

This commit is contained in:
Jaco 2021-05-16 18:02:16 +03:00 committed by GitHub
parent 40fd615249
commit 11f213c6b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,8 +1,8 @@
// Copyright 2017-2021 @polkadot/app-council authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type BN from 'bn.js';
import type { DeriveElectionsInfo } from '@polkadot/api-derive/types';
import type { BalanceOf } from '@polkadot/types/interfaces';
import React, { useEffect, useMemo, useState } from 'react';
@ -35,7 +35,7 @@ function Vote ({ electionsInfo }: Props): React.ReactElement<Props> {
setAvailable(
members
.map(([accountId]): string => accountId.toString())
.map(([accountId]) => accountId.toString())
.concat(runnersUp.map(([accountId]) => accountId.toString()))
.concat(candidates.map((accountId) => accountId.toString()))
);
@ -46,16 +46,18 @@ function Vote ({ electionsInfo }: Props): React.ReactElement<Props> {
accountId && api.derive.council.votesOf(accountId).then(({ votes }): void => {
setDefaultVotes(
votes
.map((accountId): string => accountId.toString())
.filter((accountId): boolean => available.includes(accountId))
.map((accountId) => accountId.toString())
.filter((accountId) => available.includes(accountId))
);
});
}, [api, accountId, available]);
const bondValue = useMemo(
() => ((api.consts.phragmenElection || api.consts.electionsPhragmen || api.consts.elections).votingBondBase as BalanceOf).add(
((api.consts.phragmenElection || api.consts.electionsPhragmen || api.consts.elections).votingBondFactor as BalanceOf).muln(votes.length)
),
(): BN | undefined => {
const location = api.consts.elections || api.consts.phragmenElection || api.consts.electionsPhragmen;
return location?.votingBondBase && location.votingBondBase.add(location.votingBondFactor.muln(votes.length));
},
[api, votes]
);
@ -104,14 +106,16 @@ function Vote ({ electionsInfo }: Props): React.ReactElement<Props> {
valueLabel={t<string>('my ordered votes')}
/>
</Modal.Columns>
<Modal.Columns hint={t('The amount will be reserved for the duration of your vote')}>
<InputBalance
defaultValue={bondValue}
help={t<string>('The amount that is reserved')}
isDisabled
label={t<string>('voting bond')}
/>
</Modal.Columns>
{bondValue && (
<Modal.Columns hint={t('The amount will be reserved for the duration of your vote')}>
<InputBalance
defaultValue={bondValue}
help={t<string>('The amount that is reserved')}
isDisabled
label={t<string>('voting bond')}
/>
</Modal.Columns>
)}
</Modal.Content>
<Modal.Actions onCancel={toggleVisible}>
<TxButton