diff --git a/packages/page-accounts/src/Accounts/modals/Delegate.tsx b/packages/page-accounts/src/Accounts/modals/Delegate.tsx index 6456e6b73a..1ff1f3716d 100644 --- a/packages/page-accounts/src/Accounts/modals/Delegate.tsx +++ b/packages/page-accounts/src/Accounts/modals/Delegate.tsx @@ -30,7 +30,7 @@ function Delegate ({ onClose, previousAmount, previousConviction, previousDelega const [delegatingAccount, setDelegatingAccount] = useState(previousDelegatingAccount || null); const [delegatedAccount, setDelegatedAccount] = useState(previousDelegatedAccount || null); const defaultConviction = previousConviction === undefined - ? 1 + ? 0 : previousConviction.toNumber(); const [conviction, setConviction] = useState(defaultConviction); diff --git a/packages/page-democracy/src/Overview/Voting.tsx b/packages/page-democracy/src/Overview/Voting.tsx index a60cd71174..ca568034ff 100644 --- a/packages/page-democracy/src/Overview/Voting.tsx +++ b/packages/page-democracy/src/Overview/Voting.tsx @@ -23,7 +23,7 @@ function Voting ({ proposal, referendumId }: Props): React.ReactElement | const { hasAccounts } = useAccounts(); const [accountId, setAccountId] = useState(null); const [balance, setBalance] = useState(); - const [conviction, setConviction] = useState(1); + const [conviction, setConviction] = useState(0); const [isVotingOpen, toggleVoting] = useToggle(); const [aye, setVoteValue] = useState(true); diff --git a/packages/react-components/src/ConvictionDropdown.tsx b/packages/react-components/src/ConvictionDropdown.tsx index b6a5e56c09..9565279fa0 100644 --- a/packages/react-components/src/ConvictionDropdown.tsx +++ b/packages/react-components/src/ConvictionDropdown.tsx @@ -3,7 +3,9 @@ // of the Apache-2.0 license. See the LICENSE file for details. 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 Dropdown from './Dropdown'; @@ -20,11 +22,8 @@ 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 Convictions ({ className = '', help, label, onChange, value }: Props): React.ReactElement | null { - const { api } = useApi(); - const { t } = useTranslation(); - - const optionsRef = useRef([ +function createOptions (api: ApiPromise, t: TFunction): { 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)', { @@ -36,7 +35,14 @@ function Convictions ({ className = '', help, label, onChange, value }: Props): }), value })) - ]); + ]; +} + +function Convictions ({ className = '', help, label, onChange, value }: Props): React.ReactElement | null { + const { api } = useApi(); + const { t } = useTranslation(); + + const optionsRef = useRef(createOptions(api, t)); return (