From 11f213c6b529dc513f646c323fc4bd81295b18dd Mon Sep 17 00:00:00 2001 From: Jaco Date: Sun, 16 May 2021 18:02:16 +0300 Subject: [PATCH] Cater for prev-gen council votes (#5301) --- packages/page-council/src/Overview/Vote.tsx | 34 ++++++++++++--------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/packages/page-council/src/Overview/Vote.tsx b/packages/page-council/src/Overview/Vote.tsx index 54e809e1e6..01c20946b7 100644 --- a/packages/page-council/src/Overview/Vote.tsx +++ b/packages/page-council/src/Overview/Vote.tsx @@ -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 { 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 { 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 { valueLabel={t('my ordered votes')} /> - - ('The amount that is reserved')} - isDisabled - label={t('voting bond')} - /> - + {bondValue && ( + + ('The amount that is reserved')} + isDisabled + label={t('voting bond')} + /> + + )}