Default to no-lockup conviction (#3443)

This commit is contained in:
Jaco Greeff 2020-08-19 12:38:24 +02:00 committed by GitHub
parent 7405360b0a
commit 7f7414749f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 8 deletions

View File

@ -30,7 +30,7 @@ function Delegate ({ onClose, previousAmount, previousConviction, previousDelega
const [delegatingAccount, setDelegatingAccount] = useState<string | null>(previousDelegatingAccount || null);
const [delegatedAccount, setDelegatedAccount] = useState<string | null>(previousDelegatedAccount || null);
const defaultConviction = previousConviction === undefined
? 1
? 0
: previousConviction.toNumber();
const [conviction, setConviction] = useState(defaultConviction);

View File

@ -23,7 +23,7 @@ function Voting ({ proposal, referendumId }: Props): React.ReactElement<Props> |
const { hasAccounts } = useAccounts();
const [accountId, setAccountId] = useState<string | null>(null);
const [balance, setBalance] = useState<BN | undefined>();
const [conviction, setConviction] = useState(1);
const [conviction, setConviction] = useState(0);
const [isVotingOpen, toggleVoting] = useToggle();
const [aye, setVoteValue] = useState(true);

View File

@ -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<Props> | null {
const { api } = useApi();
const { t } = useTranslation();
const optionsRef = useRef([
function createOptions (api: ApiPromise, 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 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<Props> | null {
const { api } = useApi();
const { t } = useTranslation();
const optionsRef = useRef(createOptions(api, t));
return (
<Dropdown