Always pass through voting lock period (#8601)
* Always pass through voting lock period * const from voting pallet * Only allow non-empty
This commit is contained in:
parent
9e1b8bd45b
commit
685b6aa732
@ -100,6 +100,10 @@ function Delegate ({ onClose, previousAmount, previousConviction, previousDelega
|
||||
label={t<string>('conviction')}
|
||||
onChange={setConviction}
|
||||
value={conviction}
|
||||
voteLockingPeriod={
|
||||
api.consts.democracy.voteLockingPeriod ||
|
||||
api.consts.democracy.enactmentPeriod
|
||||
}
|
||||
/>
|
||||
</Modal.Columns>
|
||||
</Modal.Content>
|
||||
|
||||
@ -74,6 +74,10 @@ function Voting ({ proposal, referendumId }: Props): React.ReactElement<Props> |
|
||||
label={t<string>('conviction')}
|
||||
onChange={setConviction}
|
||||
value={conviction}
|
||||
voteLockingPeriod={
|
||||
api.consts.democracy.voteLockingPeriod ||
|
||||
api.consts.democracy.enactmentPeriod
|
||||
}
|
||||
/>
|
||||
</Modal.Columns>
|
||||
</Modal.Content>
|
||||
|
||||
@ -146,7 +146,7 @@ function Voting ({ className, id, isConvictionVote, isMember, members, palletVot
|
||||
id={id}
|
||||
isAye
|
||||
onChange={setParams}
|
||||
voteLockingPeriod={api.consts.convictionVoting.voteLockingPeriod}
|
||||
voteLockingPeriod={api.consts[palletVote as 'convictionVoting'].voteLockingPeriod}
|
||||
/>
|
||||
)
|
||||
: voteTypeIndex === 1
|
||||
@ -155,7 +155,7 @@ function Voting ({ className, id, isConvictionVote, isMember, members, palletVot
|
||||
accountId={accountId}
|
||||
id={id}
|
||||
onChange={setParams}
|
||||
voteLockingPeriod={api.consts.convictionVoting.voteLockingPeriod}
|
||||
voteLockingPeriod={api.consts[palletVote as 'convictionVoting'].voteLockingPeriod}
|
||||
/>
|
||||
)
|
||||
: voteTypeIndex === 2
|
||||
|
||||
@ -11,7 +11,7 @@ import { ConvictionDropdown, Modal, VoteValue } from '@polkadot/react-components
|
||||
import { useTranslation } from '../translate';
|
||||
|
||||
interface Props extends VoteTypeProps {
|
||||
voteLockingPeriod?: BN;
|
||||
voteLockingPeriod: BN;
|
||||
}
|
||||
|
||||
function VoteStandard ({ accountId, id, isAye, onChange, voteLockingPeriod }: Props): React.ReactElement<Props> {
|
||||
|
||||
@ -5,10 +5,9 @@ import type { TFunction } from 'i18next';
|
||||
|
||||
import React, { useRef } from 'react';
|
||||
|
||||
import { ApiPromise } from '@polkadot/api';
|
||||
import { useApi, useBlockInterval } from '@polkadot/react-hooks';
|
||||
import { useBlockInterval } from '@polkadot/react-hooks';
|
||||
import { calcBlockTime } from '@polkadot/react-hooks/useBlockTime';
|
||||
import { BN } from '@polkadot/util';
|
||||
import { BN, BN_ZERO } from '@polkadot/util';
|
||||
|
||||
import Dropdown from './Dropdown';
|
||||
import { useTranslation } from './translate';
|
||||
@ -19,23 +18,21 @@ export interface Props {
|
||||
label?: React.ReactNode;
|
||||
onChange?: (value: number) => void;
|
||||
value?: number;
|
||||
voteLockingPeriod?: BN;
|
||||
voteLockingPeriod: BN;
|
||||
}
|
||||
|
||||
const CONVICTIONS: [number, number, BN][] = [1, 2, 4, 8, 16, 32].map((lock, index) => [index + 1, lock, new BN(lock)]);
|
||||
const CONVICTIONS = [1, 2, 4, 8, 16, 32].map((lock, index): [value: number, duration: number, durationBn: BN] => [index + 1, lock, new BN(lock)]);
|
||||
|
||||
function createOptions (api: ApiPromise, t: TFunction, blockTime: BN, voteLockingPeriod?: BN): { text: string; value: number }[] {
|
||||
function createOptions (blockTime: BN, voteLockingPeriod: BN, t: TFunction): { 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 duration ({{period}})', {
|
||||
...CONVICTIONS.map(([value, duration, durationBn]): { text: string; value: number } => ({
|
||||
text: t<string>('{{value}}x voting balance, locked for {{duration}}x duration{{period}}', {
|
||||
replace: {
|
||||
lock,
|
||||
period: calcBlockTime(blockTime, bnLock.mul(
|
||||
voteLockingPeriod ||
|
||||
api.consts.democracy.voteLockingPeriod ||
|
||||
api.consts.democracy.enactmentPeriod
|
||||
), t)[1],
|
||||
duration,
|
||||
period: voteLockingPeriod && voteLockingPeriod.gt(BN_ZERO)
|
||||
? ` (${calcBlockTime(blockTime, durationBn.mul(voteLockingPeriod), t)[1]})`
|
||||
: '',
|
||||
value
|
||||
}
|
||||
}),
|
||||
@ -45,11 +42,9 @@ function createOptions (api: ApiPromise, t: TFunction, blockTime: BN, voteLockin
|
||||
}
|
||||
|
||||
function Convictions ({ className = '', help, label, onChange, value, voteLockingPeriod }: Props): React.ReactElement<Props> | null {
|
||||
const { api } = useApi();
|
||||
const { t } = useTranslation();
|
||||
const blockTime = useBlockInterval();
|
||||
|
||||
const optionsRef = useRef(createOptions(api, t, blockTime, voteLockingPeriod));
|
||||
const optionsRef = useRef(createOptions(blockTime, voteLockingPeriod, t));
|
||||
|
||||
return (
|
||||
<Dropdown
|
||||
|
||||
Loading…
Reference in New Issue
Block a user