diff --git a/packages/react-components/src/ConvictionDropdown.tsx b/packages/react-components/src/ConvictionDropdown.tsx index 9565279fa0..fcf10e7825 100644 --- a/packages/react-components/src/ConvictionDropdown.tsx +++ b/packages/react-components/src/ConvictionDropdown.tsx @@ -6,7 +6,7 @@ import BN from 'bn.js'; import { TFunction } from 'i18next'; import React, { useRef } from 'react'; import { ApiPromise } from '@polkadot/api'; -import { useApi } from '@polkadot/react-hooks'; +import { useApi, useBlockTime } from '@polkadot/react-hooks'; import Dropdown from './Dropdown'; import { useTranslation } from './translate'; @@ -22,14 +22,14 @@ export interface Props { const CONVICTIONS: [number, number, BN][] = [1, 2, 4, 8, 16, 32].map((lock, index) => [index + 1, lock, new BN(lock)]); const SEC_DAY = 60 * 60 * 24; -function createOptions (api: ApiPromise, t: TFunction): { text: string; value: number }[] { +function createOptions (api: ApiPromise, t: TFunction, blockTime: number): { text: string; value: number }[] { return [ { text: t('0.1x voting balance, no lockup period'), value: 0 }, ...CONVICTIONS.map(([value, lock, bnLock]): { text: string; value: number } => ({ text: t('{{value}}x voting balance, locked for {{lock}}x enactment ({{period}} days)', { replace: { lock, - period: (bnLock.mul(api.consts.democracy.enactmentPeriod.mul(api.consts.timestamp.minimumPeriod.muln(2)).divn(1000)).toNumber() / SEC_DAY).toFixed(2), + period: (bnLock.mul(api.consts.democracy.enactmentPeriod.muln(blockTime).divn(1000)).toNumber() / SEC_DAY).toFixed(2), value } }), @@ -41,8 +41,9 @@ function createOptions (api: ApiPromise, t: TFunction): { text: string; value: n function Convictions ({ className = '', help, label, onChange, value }: Props): React.ReactElement | null { const { api } = useApi(); const { t } = useTranslation(); + const [blockTime] = useBlockTime(); - const optionsRef = useRef(createOptions(api, t)); + const optionsRef = useRef(createOptions(api, t, blockTime)); return (