@polkadot/types#GenericVote TypeScript Examples
The following examples show how to use
@polkadot/types#GenericVote.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Vote.tsx From crust-apps with Apache License 2.0 | 5 votes |
function Vote ({ className = '', defaultValue: { value }, isDisabled, isError, onChange, withLabel }: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const optAyeRef = useRef([
{ text: t<string>('Nay'), value: 0 },
{ text: t<string>('Aye'), value: -1 }
]);
const optConvRef = useRef([
{ text: t<string>('None'), value: 0 },
{ text: t<string>('Locked1x'), value: 1 },
{ text: t<string>('Locked2x'), value: 2 },
{ text: t<string>('Locked3x'), value: 3 },
{ text: t<string>('Locked4x'), value: 4 },
{ text: t<string>('Locked5x'), value: 5 },
{ text: t<string>('Locked6x'), value: 6 }
]);
const defaultValue = value instanceof BN
? value.toNumber()
: value instanceof GenericVote
? (value.isAye ? -1 : 0)
: value as number;
const defaultConv = value instanceof GenericVote
? value.conviction.index
: 0;
return (
<Bare className={className}>
<Dropdown
className='full'
defaultValue={defaultValue}
isDisabled={isDisabled}
isError={isError}
label={t<string>('aye: bool')}
onChange={doChange(onChange)}
options={optAyeRef.current}
withLabel={withLabel}
/>
{isDisabled && (
<Dropdown
className='full'
defaultValue={defaultConv}
isDisabled={isDisabled}
isError={isError}
label={t<string>('conviction: Conviction')}
options={optConvRef.current}
withLabel={withLabel}
/>
)}
</Bare>
);
}
Example #2
Source File: Vote.tsx From subscan-multisig-react with Apache License 2.0 | 5 votes |
// eslint-disable-next-line complexity
function Vote({
className = '',
defaultValue: { value },
isDisabled,
isError,
onChange,
withLabel,
}: Props): React.ReactElement<Props> {
const { t } = useTranslation();
const optAyeRef = useRef([
{ text: t<string>('Nay'), value: 0 },
{ text: t<string>('Aye'), value: -1 },
]);
const optConvRef = useRef([
{ text: t<string>('None'), value: 0 },
{ text: t<string>('Locked1x'), value: 1 },
{ text: t<string>('Locked2x'), value: 2 },
{ text: t<string>('Locked3x'), value: 3 },
{ text: t<string>('Locked4x'), value: 4 },
{ text: t<string>('Locked5x'), value: 5 },
{ text: t<string>('Locked6x'), value: 6 },
]);
const defaultValue = isBn(value)
? value.toNumber()
: value instanceof GenericVote
? value.isAye
? -1
: 0
: (value as number);
const defaultConv = value instanceof GenericVote ? value.conviction.index : 0;
return (
<Bare className={className}>
<Dropdown
className="full"
defaultValue={defaultValue}
isDisabled={isDisabled}
isError={isError}
label={t<string>('aye: bool')}
onChange={doChange(onChange)}
options={optAyeRef.current}
withLabel={withLabel}
/>
{isDisabled && (
<Dropdown
className="full"
defaultValue={defaultConv}
isDisabled={isDisabled}
isError={isError}
label={t<string>('conviction: Conviction')}
options={optConvRef.current}
withLabel={withLabel}
/>
)}
</Bare>
);
}