Fix conviction dropdown block time display (#3479)
* Fix conviction dropdown block time display * Use divn instead of / * Move useBlockTime out of createOptions * Fix space
This commit is contained in:
parent
8dc1f593e0
commit
b1e967833d
@ -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<string>('0.1x voting balance, no lockup period'), value: 0 },
|
||||
...CONVICTIONS.map(([value, lock, bnLock]): { text: string; value: number } => ({
|
||||
text: t<string>('{{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<Props> | null {
|
||||
const { api } = useApi();
|
||||
const { t } = useTranslation();
|
||||
const [blockTime] = useBlockTime();
|
||||
|
||||
const optionsRef = useRef(createOptions(api, t));
|
||||
const optionsRef = useRef(createOptions(api, t, blockTime));
|
||||
|
||||
return (
|
||||
<Dropdown
|
||||
|
||||
Loading…
Reference in New Issue
Block a user